@univerjs/sheets-hyper-link-ui 0.2.15 → 0.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js
CHANGED
|
@@ -2,19 +2,398 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
-
import {
|
|
5
|
+
import { Tools, Inject, LocaleService, UniverInstanceType, isValidRange, IUniverInstanceService, ICommandService, IConfigService, RANGE_TYPE, Rectangle, OnLifecycle, LifecycleStages, Injector, Disposable, Range, ObjectMatrix, CommandType, IUndoRedoService, BuildTextUtils, DataStreamTreeTokenType, CustomRangeType, TextX, CellValueType, sequenceExecuteAsync, generateRandomId, getBodySlice, useDependency, IContextService, getOriginCellValue, DisposableCollection, createInternalEditorID, FOCUSING_SHEET, DOCS_ZEN_EDITOR_UNIT_ID_KEY, sequenceExecute, DataValidationType, ThemeService, InterceptorEffectEnum, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, IPermissionService, DependentOn, Plugin } from "@univerjs/core";
|
|
6
|
+
import { SheetHyperLinkType, ERROR_RANGE, HyperLinkModel, RemoveHyperLinkMutation, AddHyperLinkMutation, UniverSheetsHyperLinkPlugin } from "@univerjs/sheets-hyper-link";
|
|
7
|
+
import { ScrollToRangeOperation, COPY_TYPE, virtualizeDiscreteRanges, rangeToDiscreteRange, PREDEFINED_HOOK_NAME, getRepeatRange, ISheetClipboardService, SheetSkeletonManagerService, IEditorBridgeService, IMarkSelectionService, SheetCanvasPopManagerService, getEditingCustomRangePosition, getCustomRangePosition, whenSheetEditorFocused, getCurrentRangeDisable$, HoverManagerService, SheetPermissionInterceptorBaseController, HoverRenderController, IAutoFillService, APPLY_TYPE, getAutoFillRepeatRange } from "@univerjs/sheets-ui";
|
|
8
|
+
import { MessageType, FormLayout, Input, Select, Button, Tooltip } from "@univerjs/design";
|
|
9
|
+
import { deserializeRangeWithSheet, serializeRangeWithSheet, serializeRange, IDefinedNamesService, serializeRangeToRefString } from "@univerjs/engine-formula";
|
|
10
|
+
import { SetSelectionsOperation, SetWorksheetActiveOperation, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetsSelectionsService, getSheetCommandTarget, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission, RangeProtectionPermissionEditPoint, SheetInterceptorService, RemoveSheetCommand, INTERCEPTOR_POINT, SetRangeValuesCommand, ClearSelectionContentCommand, ClearSelectionAllCommand, ClearSelectionFormatCommand, WorkbookViewPermission, WorksheetViewPermission, RangeProtectionPermissionViewPoint, WorkbookCopyPermission, WorksheetCopyPermission, RefRangeService, handleDefaultRangeChangeWithEffectRefCommands } from "@univerjs/sheets";
|
|
11
|
+
import { IMessageService, useObservable, IZenZoneService, useEvent, KeyCode, MenuItemType, MenuPosition, MenuGroup, MetaKeys, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IShortcutService, IMenuManagerService } from "@univerjs/ui";
|
|
6
12
|
import { DocSelectionManagerService } from "@univerjs/docs";
|
|
7
|
-
import { addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory, DocCanvasPopManagerService, DocEventManagerService, UniverDocsUIPlugin } from "@univerjs/docs-ui";
|
|
8
|
-
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
9
|
-
import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SetSelectionsOperation, SetWorksheetActiveOperation, SheetsSelectionsService, getSheetCommandTarget, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission, RangeProtectionPermissionEditPoint, RemoveSheetCommand, SheetInterceptorService, INTERCEPTOR_POINT, SetRangeValuesCommand, ClearSelectionContentCommand, ClearSelectionAllCommand, ClearSelectionFormatCommand, WorkbookViewPermission, WorksheetViewPermission, RangeProtectionPermissionViewPoint, WorkbookCopyPermission, WorksheetCopyPermission, RefRangeService, handleDefaultRangeChangeWithEffectRefCommands } from "@univerjs/sheets";
|
|
10
|
-
import { HyperLinkModel, RemoveHyperLinkMutation, AddHyperLinkMutation, SheetHyperLinkType, ERROR_RANGE, UniverSheetsHyperLinkPlugin } from "@univerjs/sheets-hyper-link";
|
|
11
|
-
import { SheetSkeletonManagerService, ScrollToRangeOperation, IEditorBridgeService, IMarkSelectionService, getEditingCustomRangePosition, getCustomRangePosition, SheetCanvasPopManagerService, COPY_TYPE, virtualizeDiscreteRanges, rangeToDiscreteRange, PREDEFINED_HOOK_NAME, getRepeatRange, ISheetClipboardService, whenSheetEditorFocused, getCurrentRangeDisable$, HoverRenderController, HoverManagerService, SheetPermissionInterceptorBaseController, APPLY_TYPE, IAutoFillService, getAutoFillRepeatRange } from "@univerjs/sheets-ui";
|
|
12
|
-
import { IMessageService, useObservable, IZenZoneService, useEvent, KeyCode, RangeSelector, IEditorService, IRangeSelectorService, MenuItemType, MenuPosition, MenuGroup, MetaKeys, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IShortcutService, IMenuManagerService } from "@univerjs/ui";
|
|
13
13
|
import { Subject, BehaviorSubject, map, mergeMap, Observable, debounceTime } from "rxjs";
|
|
14
|
+
import { addCustomRangeBySelectionFactory, replaceSelectionFactory, DocSelectionRenderService, RangeSelector, deleteCustomRangeFactory, DocCanvasPopManagerService, IEditorService, IRangeSelectorService, DocEventManagerService, UniverDocsUIPlugin } from "@univerjs/docs-ui";
|
|
14
15
|
import require$$0, { useState, useMemo, useRef, useEffect, forwardRef, createElement } from "react";
|
|
15
|
-
import {
|
|
16
|
-
import { deserializeRangeWithSheet, serializeRangeWithSheet, serializeRange, IDefinedNamesService, serializeRangeToRefString } from "@univerjs/engine-formula";
|
|
16
|
+
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
17
17
|
import cs from "clsx";
|
|
18
|
+
const SHEET_HYPER_LINK_UI_PLUGIN = "SHEET_HYPER_LINK_UI_PLUGIN";
|
|
19
|
+
function isLegalLink(link) {
|
|
20
|
+
return Tools.isLegalUrl(link);
|
|
21
|
+
}
|
|
22
|
+
__name(isLegalLink, "isLegalLink");
|
|
23
|
+
function hasProtocol(urlString) {
|
|
24
|
+
return /^[a-zA-Z]+:\/\//.test(urlString);
|
|
25
|
+
}
|
|
26
|
+
__name(hasProtocol, "hasProtocol");
|
|
27
|
+
function isEmail(url) {
|
|
28
|
+
return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
|
|
29
|
+
}
|
|
30
|
+
__name(isEmail, "isEmail");
|
|
31
|
+
function serializeUrl(urlStr) {
|
|
32
|
+
if (isLegalLink(urlStr)) {
|
|
33
|
+
const transformedUrl = hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `http://${urlStr}`;
|
|
34
|
+
let url;
|
|
35
|
+
try {
|
|
36
|
+
url = new URL(transformedUrl);
|
|
37
|
+
} catch {
|
|
38
|
+
return urlStr;
|
|
39
|
+
}
|
|
40
|
+
return url.hostname === location.hostname && url.port === location.port && url.protocol === location.protocol && url.pathname === location.pathname && url.hash && !url.search ? url.hash : transformedUrl;
|
|
41
|
+
}
|
|
42
|
+
return urlStr;
|
|
43
|
+
}
|
|
44
|
+
__name(serializeUrl, "serializeUrl");
|
|
45
|
+
const PLUGIN_CONFIG_KEY = "sheets-hyper-link-ui.config", defaultPluginConfig = {};
|
|
46
|
+
var __defProp$c = Object.defineProperty, __getOwnPropDesc$c = Object.getOwnPropertyDescriptor, __decorateClass$c = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
47
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$c(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
48
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
49
|
+
return kind && result && __defProp$c(target, key, result), result;
|
|
50
|
+
}, "__decorateClass$c"), __decorateParam$c = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$c");
|
|
51
|
+
function getContainRange(range, worksheet) {
|
|
52
|
+
const mergedCells = worksheet.getMergeData(), maxCol = worksheet.getMaxColumns() - 1, maxRow = worksheet.getMaxRows() - 1;
|
|
53
|
+
if (maxCol < range.endColumn && (range.endColumn = maxCol), maxRow < range.endRow && (range.endRow = maxRow), range.rangeType === RANGE_TYPE.COLUMN || RANGE_TYPE.ROW)
|
|
54
|
+
return range;
|
|
55
|
+
const relativeCells = [];
|
|
56
|
+
return mergedCells.forEach((cell) => {
|
|
57
|
+
Rectangle.intersects(range, cell) && relativeCells.push(cell);
|
|
58
|
+
}), Rectangle.realUnion(range, ...relativeCells);
|
|
59
|
+
}
|
|
60
|
+
__name(getContainRange, "getContainRange");
|
|
61
|
+
var _a;
|
|
62
|
+
let SheetsHyperLinkResolverService = (_a = class {
|
|
63
|
+
constructor(_univerInstanceService, _commandService, _definedNamesService, _messageService, _localeService, _configService) {
|
|
64
|
+
this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._definedNamesService = _definedNamesService, this._messageService = _messageService, this._localeService = _localeService, this._configService = _configService;
|
|
65
|
+
}
|
|
66
|
+
_getURLName(params) {
|
|
67
|
+
var _a15;
|
|
68
|
+
const { gid, range, rangeid, unitid } = params, workbook = unitid ? this._univerInstanceService.getUnit(unitid, UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), invalidLink = {
|
|
69
|
+
type: SheetHyperLinkType.INVALID,
|
|
70
|
+
name: this._localeService.t("hyperLink.message.refError")
|
|
71
|
+
};
|
|
72
|
+
if (!workbook)
|
|
73
|
+
return invalidLink;
|
|
74
|
+
const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet(), sheetName = (_a15 = sheet == null ? void 0 : sheet.getName()) != null ? _a15 : "";
|
|
75
|
+
if (range) {
|
|
76
|
+
if (!sheet) return invalidLink;
|
|
77
|
+
const rangeObj = deserializeRangeWithSheet(range).range;
|
|
78
|
+
return isValidRange(rangeObj, sheet) && range !== ERROR_RANGE ? {
|
|
79
|
+
type: SheetHyperLinkType.RANGE,
|
|
80
|
+
name: serializeRangeWithSheet(sheetName, rangeObj)
|
|
81
|
+
} : invalidLink;
|
|
82
|
+
}
|
|
83
|
+
if (rangeid) {
|
|
84
|
+
const range2 = this._definedNamesService.getValueById(workbook.getUnitId(), rangeid);
|
|
85
|
+
return range2 ? {
|
|
86
|
+
type: SheetHyperLinkType.DEFINE_NAME,
|
|
87
|
+
name: range2.formulaOrRefString
|
|
88
|
+
} : invalidLink;
|
|
89
|
+
}
|
|
90
|
+
if (gid) {
|
|
91
|
+
const worksheet = workbook.getSheetBySheetId(gid);
|
|
92
|
+
return worksheet ? {
|
|
93
|
+
type: SheetHyperLinkType.SHEET,
|
|
94
|
+
name: worksheet.getName()
|
|
95
|
+
} : invalidLink;
|
|
96
|
+
}
|
|
97
|
+
return invalidLink;
|
|
98
|
+
}
|
|
99
|
+
navigateTo(params) {
|
|
100
|
+
const { gid, range, rangeid } = params, workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
101
|
+
if (!workbook)
|
|
102
|
+
return;
|
|
103
|
+
const unitId = workbook.getUnitId();
|
|
104
|
+
if (rangeid && this.navigateToDefineName(unitId, rangeid), !!gid) {
|
|
105
|
+
if (range) {
|
|
106
|
+
const rangeInfo = deserializeRangeWithSheet(range);
|
|
107
|
+
isValidRange(rangeInfo.range) && range !== ERROR_RANGE && this.navigateToRange(unitId, gid, rangeInfo.range);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.navigateToSheetById(unitId, gid);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
buildHyperLink(unitId, sheetId, range) {
|
|
114
|
+
return `#${SheetHyperLinkType.SHEET}=${sheetId}${range ? `&${typeof range == "string" ? SheetHyperLinkType.DEFINE_NAME : SheetHyperLinkType.RANGE}=${typeof range == "string" ? range : serializeRange(range)}` : ""}`;
|
|
115
|
+
}
|
|
116
|
+
parseHyperLink(urlStr) {
|
|
117
|
+
var _a15, _b, _c, _d;
|
|
118
|
+
if (urlStr.startsWith("#")) {
|
|
119
|
+
const search = new URLSearchParams(urlStr.slice(1)), searchObj = {
|
|
120
|
+
gid: (_a15 = search.get("gid")) != null ? _a15 : "",
|
|
121
|
+
range: (_b = search.get("range")) != null ? _b : "",
|
|
122
|
+
rangeid: (_c = search.get("rangeid")) != null ? _c : "",
|
|
123
|
+
unitid: (_d = search.get("unitid")) != null ? _d : ""
|
|
124
|
+
}, urlInfo = this._getURLName(searchObj);
|
|
125
|
+
return {
|
|
126
|
+
type: urlInfo.type,
|
|
127
|
+
name: urlInfo.name,
|
|
128
|
+
url: urlStr,
|
|
129
|
+
searchObj,
|
|
130
|
+
handler: /* @__PURE__ */ __name(() => {
|
|
131
|
+
this.navigateTo(searchObj);
|
|
132
|
+
}, "handler")
|
|
133
|
+
};
|
|
134
|
+
} else
|
|
135
|
+
return {
|
|
136
|
+
type: SheetHyperLinkType.URL,
|
|
137
|
+
name: urlStr,
|
|
138
|
+
url: urlStr,
|
|
139
|
+
handler: /* @__PURE__ */ __name(() => {
|
|
140
|
+
this.navigateToOtherWebsite(urlStr);
|
|
141
|
+
}, "handler"),
|
|
142
|
+
searchObj: null
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async navigateToRange(unitId, subUnitId, range) {
|
|
146
|
+
const worksheet = await this.navigateToSheetById(unitId, subUnitId);
|
|
147
|
+
if (worksheet) {
|
|
148
|
+
const realRange = getContainRange(range, worksheet);
|
|
149
|
+
await this._commandService.executeCommand(
|
|
150
|
+
SetSelectionsOperation.id,
|
|
151
|
+
{
|
|
152
|
+
unitId,
|
|
153
|
+
subUnitId,
|
|
154
|
+
selections: [{
|
|
155
|
+
range: realRange
|
|
156
|
+
}]
|
|
157
|
+
}
|
|
158
|
+
), await this._commandService.executeCommand(ScrollToRangeOperation.id, {
|
|
159
|
+
range: realRange
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async navigateToSheet(unitId, sheetName) {
|
|
164
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
165
|
+
if (!workbook)
|
|
166
|
+
return !1;
|
|
167
|
+
const worksheet = workbook.getActiveSheet();
|
|
168
|
+
if ((worksheet == null ? void 0 : worksheet.getName()) === sheetName)
|
|
169
|
+
return !0;
|
|
170
|
+
const targetSheet = workbook.getSheetBySheetName(sheetName);
|
|
171
|
+
if (!targetSheet) {
|
|
172
|
+
this._messageService.show({
|
|
173
|
+
content: this._localeService.t("hyperLink.message.noSheet"),
|
|
174
|
+
type: MessageType.Error
|
|
175
|
+
});
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const sheetId = targetSheet.getSheetId();
|
|
179
|
+
return workbook.getHiddenWorksheets().indexOf(sheetId) > -1 && this._messageService.show({
|
|
180
|
+
content: this._localeService.t("hyperLink.message.hiddenSheet"),
|
|
181
|
+
type: MessageType.Error
|
|
182
|
+
}), await this._commandService.executeCommand(SetWorksheetActiveOperation.id, { unitId, subUnitId: sheetId });
|
|
183
|
+
}
|
|
184
|
+
async navigateToSheetById(unitId, subUnitId) {
|
|
185
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
186
|
+
if (!workbook)
|
|
187
|
+
return !1;
|
|
188
|
+
const worksheet = workbook.getActiveSheet();
|
|
189
|
+
if (!worksheet)
|
|
190
|
+
return !1;
|
|
191
|
+
if (worksheet.getSheetId() === subUnitId)
|
|
192
|
+
return worksheet;
|
|
193
|
+
const targetSheet = workbook.getSheetBySheetId(subUnitId);
|
|
194
|
+
return targetSheet ? workbook.getHiddenWorksheets().indexOf(subUnitId) > -1 ? (this._messageService.show({
|
|
195
|
+
content: this._localeService.t("hyperLink.message.hiddenSheet"),
|
|
196
|
+
type: MessageType.Error
|
|
197
|
+
}), !1) : await this._commandService.executeCommand(SetWorksheetActiveOperation.id, { unitId, subUnitId }) ? targetSheet : !1 : (this._messageService.show({
|
|
198
|
+
content: this._localeService.t("hyperLink.message.noSheet"),
|
|
199
|
+
type: MessageType.Error
|
|
200
|
+
}), !1);
|
|
201
|
+
}
|
|
202
|
+
async navigateToDefineName(unitId, rangeid) {
|
|
203
|
+
return this._definedNamesService.focusRange(unitId, rangeid), !0;
|
|
204
|
+
}
|
|
205
|
+
async navigateToOtherWebsite(url) {
|
|
206
|
+
var _a15;
|
|
207
|
+
const config = this._configService.getConfig(PLUGIN_CONFIG_KEY);
|
|
208
|
+
if ((_a15 = config == null ? void 0 : config.urlHandler) != null && _a15.navigateToOtherWebsite)
|
|
209
|
+
return config.urlHandler.navigateToOtherWebsite(url);
|
|
210
|
+
window.open(url, "_blank", "noopener noreferrer");
|
|
211
|
+
}
|
|
212
|
+
}, __name(_a, "SheetsHyperLinkResolverService"), _a);
|
|
213
|
+
SheetsHyperLinkResolverService = __decorateClass$c([
|
|
214
|
+
__decorateParam$c(0, IUniverInstanceService),
|
|
215
|
+
__decorateParam$c(1, ICommandService),
|
|
216
|
+
__decorateParam$c(2, IDefinedNamesService),
|
|
217
|
+
__decorateParam$c(3, IMessageService),
|
|
218
|
+
__decorateParam$c(4, Inject(LocaleService)),
|
|
219
|
+
__decorateParam$c(5, IConfigService)
|
|
220
|
+
], SheetsHyperLinkResolverService);
|
|
221
|
+
var __defProp$b = Object.defineProperty, __getOwnPropDesc$b = Object.getOwnPropertyDescriptor, __decorateClass$b = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
222
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
223
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
224
|
+
return kind && result && __defProp$b(target, key, result), result;
|
|
225
|
+
}, "__decorateClass$b"), __decorateParam$b = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$b"), _a2;
|
|
226
|
+
let SheetsHyperLinkCopyPasteController = (_a2 = class extends Disposable {
|
|
227
|
+
constructor(_sheetClipboardService, _hyperLinkModel, _injector, _resolverService) {
|
|
228
|
+
super();
|
|
229
|
+
__publicField(this, "_plainTextFilter", /* @__PURE__ */ new Set());
|
|
230
|
+
__publicField(this, "_copyInfo");
|
|
231
|
+
this._sheetClipboardService = _sheetClipboardService, this._hyperLinkModel = _hyperLinkModel, this._injector = _injector, this._resolverService = _resolverService, this._initCopyPaste(), this.disposeWithMe(() => {
|
|
232
|
+
this._plainTextFilter.clear();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
registerPlainTextFilter(filter) {
|
|
236
|
+
this._plainTextFilter.add(filter);
|
|
237
|
+
}
|
|
238
|
+
removePlainTextFilter(filter) {
|
|
239
|
+
this._plainTextFilter.delete(filter);
|
|
240
|
+
}
|
|
241
|
+
/* If return false the process of paste text will be stop */
|
|
242
|
+
_filterPlainText(text) {
|
|
243
|
+
return Array.from(this._plainTextFilter).every((filter) => filter(text));
|
|
244
|
+
}
|
|
245
|
+
_initCopyPaste() {
|
|
246
|
+
this._sheetClipboardService.addClipboardHook({
|
|
247
|
+
id: SHEET_HYPER_LINK_UI_PLUGIN,
|
|
248
|
+
onBeforeCopy: /* @__PURE__ */ __name((unitId, subUnitId, range) => this._collect(unitId, subUnitId, range), "onBeforeCopy"),
|
|
249
|
+
onPasteCells: /* @__PURE__ */ __name((pasteFrom, pasteTo, data, payload) => {
|
|
250
|
+
const { copyType = COPY_TYPE.COPY, pasteType } = payload, { range: copyRange } = pasteFrom || {}, { range: pastedRange, unitId, subUnitId } = pasteTo;
|
|
251
|
+
return this._generateMutations(pastedRange, { copyType, pasteType, copyRange, unitId, subUnitId });
|
|
252
|
+
}, "onPasteCells"),
|
|
253
|
+
onPastePlainText: /* @__PURE__ */ __name((pasteTo, clipText) => {
|
|
254
|
+
const filterResult = this._filterPlainText(clipText);
|
|
255
|
+
if (isLegalLink(clipText) && filterResult) {
|
|
256
|
+
const { range, unitId, subUnitId } = pasteTo, { ranges: [pasteToRange], mapFunc } = virtualizeDiscreteRanges([range]), redos = [], undos = [];
|
|
257
|
+
return Range.foreach(pasteToRange, (originRow, originCol) => {
|
|
258
|
+
const { row, col: column } = mapFunc(originRow, originCol), link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
|
|
259
|
+
link && redos.push({
|
|
260
|
+
id: RemoveHyperLinkMutation.id,
|
|
261
|
+
params: {
|
|
262
|
+
unitId,
|
|
263
|
+
subUnitId,
|
|
264
|
+
id: link.id
|
|
265
|
+
}
|
|
266
|
+
}), link && undos.push({
|
|
267
|
+
id: AddHyperLinkMutation.id,
|
|
268
|
+
params: {
|
|
269
|
+
unitId,
|
|
270
|
+
subUnitId,
|
|
271
|
+
link
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}), { redos, undos };
|
|
275
|
+
}
|
|
276
|
+
return { undos: [], redos: [] };
|
|
277
|
+
}, "onPastePlainText"),
|
|
278
|
+
priority: 99
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
_collect(unitId, subUnitId, range) {
|
|
282
|
+
const matrix = new ObjectMatrix();
|
|
283
|
+
this._copyInfo = {
|
|
284
|
+
unitId,
|
|
285
|
+
subUnitId,
|
|
286
|
+
matrix
|
|
287
|
+
};
|
|
288
|
+
const discreteRange = this._injector.invoke((accessor) => rangeToDiscreteRange(range, accessor, unitId, subUnitId));
|
|
289
|
+
if (!discreteRange)
|
|
290
|
+
return;
|
|
291
|
+
const { rows, cols } = discreteRange;
|
|
292
|
+
rows.forEach((row, rowIndex) => {
|
|
293
|
+
cols.forEach((col, colIndex) => {
|
|
294
|
+
var _a15;
|
|
295
|
+
const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
|
|
296
|
+
matrix.setValue(rowIndex, colIndex, (_a15 = link == null ? void 0 : link.id) != null ? _a15 : "");
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
// eslint-disable-next-line max-lines-per-function
|
|
301
|
+
_generateMutations(pastedRange, copyInfo) {
|
|
302
|
+
if (!this._copyInfo)
|
|
303
|
+
return { redos: [], undos: [] };
|
|
304
|
+
if (!this._copyInfo || !this._copyInfo.matrix.getSizeOf() || !copyInfo.copyRange)
|
|
305
|
+
return { redos: [], undos: [] };
|
|
306
|
+
if ([
|
|
307
|
+
PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,
|
|
308
|
+
PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,
|
|
309
|
+
PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,
|
|
310
|
+
PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA
|
|
311
|
+
].includes(
|
|
312
|
+
copyInfo.pasteType
|
|
313
|
+
))
|
|
314
|
+
return { redos: [], undos: [] };
|
|
315
|
+
const { unitId, subUnitId } = this._copyInfo, redos = [], undos = [], { ranges: [vCopyRange, vPastedRange], mapFunc } = virtualizeDiscreteRanges([copyInfo.copyRange, pastedRange]);
|
|
316
|
+
return getRepeatRange(vCopyRange, vPastedRange, !0).forEach(({ startRange }) => {
|
|
317
|
+
var _a15;
|
|
318
|
+
(_a15 = this._copyInfo) == null || _a15.matrix.forValue((row, col, ruleId) => {
|
|
319
|
+
const range = Rectangle.getPositionRange(
|
|
320
|
+
{
|
|
321
|
+
startRow: row,
|
|
322
|
+
endRow: row,
|
|
323
|
+
startColumn: col,
|
|
324
|
+
endColumn: col
|
|
325
|
+
},
|
|
326
|
+
startRange
|
|
327
|
+
), oldLink = this._hyperLinkModel.getHyperLink(unitId, subUnitId, ruleId), { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn), currentLink = this._hyperLinkModel.getHyperLinkByLocation(copyInfo.unitId, copyInfo.subUnitId, startRow, startColumn), id = Tools.generateRandomId();
|
|
328
|
+
currentLink && redos.push({
|
|
329
|
+
id: RemoveHyperLinkMutation.id,
|
|
330
|
+
params: {
|
|
331
|
+
unitId: copyInfo.unitId,
|
|
332
|
+
subUnitId: copyInfo.subUnitId,
|
|
333
|
+
id: currentLink.id
|
|
334
|
+
}
|
|
335
|
+
}), oldLink && (redos.push({
|
|
336
|
+
id: AddHyperLinkMutation.id,
|
|
337
|
+
params: {
|
|
338
|
+
unitId: copyInfo.unitId,
|
|
339
|
+
subUnitId: copyInfo.subUnitId,
|
|
340
|
+
link: {
|
|
341
|
+
...oldLink,
|
|
342
|
+
id,
|
|
343
|
+
row: startRow,
|
|
344
|
+
column: startColumn
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}), undos.push({
|
|
348
|
+
id: RemoveHyperLinkMutation.id,
|
|
349
|
+
params: {
|
|
350
|
+
unitId: copyInfo.unitId,
|
|
351
|
+
subUnitId: copyInfo.subUnitId,
|
|
352
|
+
id
|
|
353
|
+
}
|
|
354
|
+
})), currentLink && undos.push({
|
|
355
|
+
id: AddHyperLinkMutation.id,
|
|
356
|
+
params: {
|
|
357
|
+
unitId: copyInfo.unitId,
|
|
358
|
+
subUnitId: copyInfo.subUnitId,
|
|
359
|
+
link: currentLink
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
}), { redos, undos };
|
|
364
|
+
}
|
|
365
|
+
}, __name(_a2, "SheetsHyperLinkCopyPasteController"), _a2);
|
|
366
|
+
SheetsHyperLinkCopyPasteController = __decorateClass$b([
|
|
367
|
+
OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkCopyPasteController),
|
|
368
|
+
__decorateParam$b(0, ISheetClipboardService),
|
|
369
|
+
__decorateParam$b(1, Inject(HyperLinkModel)),
|
|
370
|
+
__decorateParam$b(2, Inject(Injector)),
|
|
371
|
+
__decorateParam$b(3, Inject(SheetsHyperLinkResolverService))
|
|
372
|
+
], SheetsHyperLinkCopyPasteController);
|
|
373
|
+
var HyperLinkEditSourceType = /* @__PURE__ */ ((HyperLinkEditSourceType2) => (HyperLinkEditSourceType2.EDITING = "editing", HyperLinkEditSourceType2.VIEWING = "viewing", HyperLinkEditSourceType2.ZEN_EDITOR = "zen_mode", HyperLinkEditSourceType2))(HyperLinkEditSourceType || {}), jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
|
|
374
|
+
/**
|
|
375
|
+
* @license React
|
|
376
|
+
* react-jsx-runtime.production.min.js
|
|
377
|
+
*
|
|
378
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
379
|
+
*
|
|
380
|
+
* This source code is licensed under the MIT license found in the
|
|
381
|
+
* LICENSE file in the root directory of this source tree.
|
|
382
|
+
*/
|
|
383
|
+
var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
384
|
+
function q(c, a, g) {
|
|
385
|
+
var b, d = {}, e = null, h = null;
|
|
386
|
+
g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
|
|
387
|
+
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
388
|
+
if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
|
|
389
|
+
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
390
|
+
}
|
|
391
|
+
__name(q, "q");
|
|
392
|
+
reactJsxRuntime_production_min.Fragment = l;
|
|
393
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
394
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
395
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
396
|
+
var jsxRuntimeExports = jsxRuntime.exports;
|
|
18
397
|
const AddHyperLinkCommand = {
|
|
19
398
|
type: CommandType.COMMAND,
|
|
20
399
|
id: "sheets.command.add-hyper-link",
|
|
@@ -99,120 +478,32 @@ const AddHyperLinkCommand = {
|
|
|
99
478
|
subUnitId,
|
|
100
479
|
link: modelLink
|
|
101
480
|
}
|
|
102
|
-
})), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
|
|
103
|
-
redoMutations: redos,
|
|
104
|
-
undoMutations: undos,
|
|
105
|
-
unitID: unitId
|
|
106
|
-
}), !0) : !1;
|
|
107
|
-
}
|
|
108
|
-
}, AddRichHyperLinkCommand = {
|
|
109
|
-
id: "sheets.command.add-rich-hyper-link",
|
|
110
|
-
type: CommandType.COMMAND,
|
|
111
|
-
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
112
|
-
if (!params)
|
|
113
|
-
return !1;
|
|
114
|
-
const { documentId, link } = params, commandService = accessor.get(ICommandService), textSelectionService = accessor.get(DocSelectionManagerService), newId = generateRandomId(), { payload } = link;
|
|
115
|
-
if (!textSelectionService.getActiveTextRange())
|
|
116
|
-
return !1;
|
|
117
|
-
const replaceSelection = addCustomRangeBySelectionFactory(accessor, {
|
|
118
|
-
unitId: documentId,
|
|
119
|
-
rangeId: newId,
|
|
120
|
-
rangeType: CustomRangeType.HYPERLINK,
|
|
121
|
-
properties: {
|
|
122
|
-
url: payload,
|
|
123
|
-
refId: newId
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
|
|
127
|
-
}, "handler")
|
|
128
|
-
}, CancelHyperLinkCommand = {
|
|
129
|
-
type: CommandType.COMMAND,
|
|
130
|
-
id: "sheets.command.cancel-hyper-link",
|
|
131
|
-
// eslint-disable-next-line max-lines-per-function
|
|
132
|
-
handler(accessor, params) {
|
|
133
|
-
var _a15, _b, _c;
|
|
134
|
-
if (!params)
|
|
135
|
-
return !1;
|
|
136
|
-
const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), renderManagerService = accessor.get(IRenderManagerService), univerInstanceService = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), { unitId, subUnitId, row, column, id } = params, workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), currentRender = renderManagerService.getRenderById(unitId);
|
|
137
|
-
if (!currentRender || !workbook)
|
|
138
|
-
return !1;
|
|
139
|
-
const worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId), skeleton = (_a15 = currentRender.with(SheetSkeletonManagerService).getCurrent()) == null ? void 0 : _a15.skeleton;
|
|
140
|
-
if (!worksheet || !skeleton)
|
|
141
|
-
return !1;
|
|
142
|
-
const cellData = worksheet.getCell(row, column);
|
|
143
|
-
if (!cellData)
|
|
144
|
-
return !1;
|
|
145
|
-
const doc = skeleton.getCellDocumentModelWithFormula(cellData);
|
|
146
|
-
if (!(doc != null && doc.documentModel))
|
|
147
|
-
return !1;
|
|
148
|
-
const snapshot = Tools.deepClone(doc.documentModel.getSnapshot());
|
|
149
|
-
if (!((_c = (_b = snapshot.body) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((range2) => range2.rangeId === id)))
|
|
150
|
-
return !1;
|
|
151
|
-
const textX = BuildTextUtils.customRange.delete(accessor, { documentDataModel: doc.documentModel, rangeId: id });
|
|
152
|
-
if (!textX)
|
|
153
|
-
return !1;
|
|
154
|
-
const newBody = TextX.apply(snapshot.body, textX.serialize()), redos = [], undos = [], setRangeParams = {
|
|
155
|
-
unitId,
|
|
156
|
-
subUnitId,
|
|
157
|
-
cellValue: {
|
|
158
|
-
[row]: {
|
|
159
|
-
[column]: {
|
|
160
|
-
p: {
|
|
161
|
-
...snapshot,
|
|
162
|
-
body: newBody
|
|
163
|
-
},
|
|
164
|
-
t: CellValueType.STRING
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
redos.push({
|
|
170
|
-
id: SetRangeValuesMutation.id,
|
|
171
|
-
params: setRangeParams
|
|
172
|
-
});
|
|
173
|
-
const undoParams = SetRangeValuesUndoMutationFactory(accessor, setRangeParams);
|
|
174
|
-
undos.push({
|
|
175
|
-
id: SetRangeValuesMutation.id,
|
|
176
|
-
params: undoParams
|
|
177
|
-
});
|
|
178
|
-
const link = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
|
|
179
|
-
return link && (redos.push({
|
|
180
|
-
id: RemoveHyperLinkMutation.id,
|
|
181
|
-
params: {
|
|
182
|
-
unitId,
|
|
183
|
-
subUnitId,
|
|
184
|
-
id
|
|
185
|
-
}
|
|
186
|
-
}), undos.push({
|
|
187
|
-
id: AddHyperLinkMutation.id,
|
|
188
|
-
params: {
|
|
189
|
-
unitId,
|
|
190
|
-
subUnitId,
|
|
191
|
-
link: {
|
|
192
|
-
...link
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
})), sequenceExecute(redos, commandService).result ? (undoRedoService.pushUndoRedo({
|
|
481
|
+
})), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
|
|
196
482
|
redoMutations: redos,
|
|
197
483
|
undoMutations: undos,
|
|
198
484
|
unitID: unitId
|
|
199
485
|
}), !0) : !1;
|
|
200
486
|
}
|
|
201
|
-
},
|
|
487
|
+
}, AddRichHyperLinkCommand = {
|
|
488
|
+
id: "sheets.command.add-rich-hyper-link",
|
|
202
489
|
type: CommandType.COMMAND,
|
|
203
|
-
|
|
204
|
-
handler(accessor, params) {
|
|
205
|
-
var _a15, _b;
|
|
490
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
206
491
|
if (!params)
|
|
207
492
|
return !1;
|
|
208
|
-
const {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
493
|
+
const { documentId, link } = params, commandService = accessor.get(ICommandService), textSelectionService = accessor.get(DocSelectionManagerService), newId = generateRandomId(), { payload } = link;
|
|
494
|
+
if (!textSelectionService.getActiveTextRange())
|
|
495
|
+
return !1;
|
|
496
|
+
const replaceSelection = addCustomRangeBySelectionFactory(accessor, {
|
|
497
|
+
unitId: documentId,
|
|
498
|
+
rangeId: newId,
|
|
499
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
500
|
+
properties: {
|
|
501
|
+
url: payload,
|
|
502
|
+
refId: newId
|
|
503
|
+
}
|
|
212
504
|
});
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
505
|
+
return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
|
|
506
|
+
}, "handler")
|
|
216
507
|
}, UpdateHyperLinkCommand = {
|
|
217
508
|
type: CommandType.COMMAND,
|
|
218
509
|
id: "sheets.command.update-hyper-link",
|
|
@@ -341,235 +632,8 @@ const AddHyperLinkCommand = {
|
|
|
341
632
|
doc
|
|
342
633
|
});
|
|
343
634
|
return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
|
|
344
|
-
}, "handler")
|
|
345
|
-
}
|
|
346
|
-
var HyperLinkEditSourceType = /* @__PURE__ */ ((HyperLinkEditSourceType2) => (HyperLinkEditSourceType2.EDITING = "editing", HyperLinkEditSourceType2.VIEWING = "viewing", HyperLinkEditSourceType2.ZEN_EDITOR = "zen_mode", HyperLinkEditSourceType2))(HyperLinkEditSourceType || {}), jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
|
|
347
|
-
/**
|
|
348
|
-
* @license React
|
|
349
|
-
* react-jsx-runtime.production.min.js
|
|
350
|
-
*
|
|
351
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
352
|
-
*
|
|
353
|
-
* This source code is licensed under the MIT license found in the
|
|
354
|
-
* LICENSE file in the root directory of this source tree.
|
|
355
|
-
*/
|
|
356
|
-
var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
357
|
-
function q(c, a, g) {
|
|
358
|
-
var b, d = {}, e = null, h = null;
|
|
359
|
-
g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
|
|
360
|
-
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
361
|
-
if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
|
|
362
|
-
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
363
|
-
}
|
|
364
|
-
__name(q, "q");
|
|
365
|
-
reactJsxRuntime_production_min.Fragment = l;
|
|
366
|
-
reactJsxRuntime_production_min.jsx = q;
|
|
367
|
-
reactJsxRuntime_production_min.jsxs = q;
|
|
368
|
-
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
369
|
-
var jsxRuntimeExports = jsxRuntime.exports;
|
|
370
|
-
function isLegalLink(link) {
|
|
371
|
-
return Tools.isLegalUrl(link);
|
|
372
|
-
}
|
|
373
|
-
__name(isLegalLink, "isLegalLink");
|
|
374
|
-
function hasProtocol(urlString) {
|
|
375
|
-
return /^[a-zA-Z]+:\/\//.test(urlString);
|
|
376
|
-
}
|
|
377
|
-
__name(hasProtocol, "hasProtocol");
|
|
378
|
-
function isEmail(url) {
|
|
379
|
-
return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
|
|
380
|
-
}
|
|
381
|
-
__name(isEmail, "isEmail");
|
|
382
|
-
function serializeUrl(urlStr) {
|
|
383
|
-
if (isLegalLink(urlStr)) {
|
|
384
|
-
const transformedUrl = hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `http://${urlStr}`;
|
|
385
|
-
let url;
|
|
386
|
-
try {
|
|
387
|
-
url = new URL(transformedUrl);
|
|
388
|
-
} catch {
|
|
389
|
-
return urlStr;
|
|
390
|
-
}
|
|
391
|
-
return url.hostname === location.hostname && url.port === location.port && url.protocol === location.protocol && url.pathname === location.pathname && url.hash && !url.search ? url.hash : transformedUrl;
|
|
392
|
-
}
|
|
393
|
-
return urlStr;
|
|
394
|
-
}
|
|
395
|
-
__name(serializeUrl, "serializeUrl");
|
|
396
|
-
const PLUGIN_CONFIG_KEY = "sheets-hyper-link-ui.config", defaultPluginConfig = {};
|
|
397
|
-
var __defProp$c = Object.defineProperty, __getOwnPropDesc$c = Object.getOwnPropertyDescriptor, __decorateClass$c = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
398
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$c(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
399
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
400
|
-
return kind && result && __defProp$c(target, key, result), result;
|
|
401
|
-
}, "__decorateClass$c"), __decorateParam$c = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$c");
|
|
402
|
-
function getContainRange(range, worksheet) {
|
|
403
|
-
const mergedCells = worksheet.getMergeData(), maxCol = worksheet.getMaxColumns() - 1, maxRow = worksheet.getMaxRows() - 1;
|
|
404
|
-
if (maxCol < range.endColumn && (range.endColumn = maxCol), maxRow < range.endRow && (range.endRow = maxRow), range.rangeType === RANGE_TYPE.COLUMN || RANGE_TYPE.ROW)
|
|
405
|
-
return range;
|
|
406
|
-
const relativeCells = [];
|
|
407
|
-
return mergedCells.forEach((cell) => {
|
|
408
|
-
Rectangle.intersects(range, cell) && relativeCells.push(cell);
|
|
409
|
-
}), Rectangle.realUnion(range, ...relativeCells);
|
|
410
|
-
}
|
|
411
|
-
__name(getContainRange, "getContainRange");
|
|
412
|
-
var _a;
|
|
413
|
-
let SheetsHyperLinkResolverService = (_a = class {
|
|
414
|
-
constructor(_univerInstanceService, _commandService, _definedNamesService, _messageService, _localeService, _configService) {
|
|
415
|
-
this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._definedNamesService = _definedNamesService, this._messageService = _messageService, this._localeService = _localeService, this._configService = _configService;
|
|
416
|
-
}
|
|
417
|
-
_getURLName(params) {
|
|
418
|
-
var _a15;
|
|
419
|
-
const { gid, range, rangeid, unitid } = params, workbook = unitid ? this._univerInstanceService.getUnit(unitid, UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), invalidLink = {
|
|
420
|
-
type: SheetHyperLinkType.INVALID,
|
|
421
|
-
name: this._localeService.t("hyperLink.message.refError")
|
|
422
|
-
};
|
|
423
|
-
if (!workbook)
|
|
424
|
-
return invalidLink;
|
|
425
|
-
const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet(), sheetName = (_a15 = sheet == null ? void 0 : sheet.getName()) != null ? _a15 : "";
|
|
426
|
-
if (range) {
|
|
427
|
-
if (!sheet) return invalidLink;
|
|
428
|
-
const rangeObj = deserializeRangeWithSheet(range).range;
|
|
429
|
-
return isValidRange(rangeObj, sheet) && range !== ERROR_RANGE ? {
|
|
430
|
-
type: SheetHyperLinkType.RANGE,
|
|
431
|
-
name: serializeRangeWithSheet(sheetName, rangeObj)
|
|
432
|
-
} : invalidLink;
|
|
433
|
-
}
|
|
434
|
-
if (rangeid) {
|
|
435
|
-
const range2 = this._definedNamesService.getValueById(workbook.getUnitId(), rangeid);
|
|
436
|
-
return range2 ? {
|
|
437
|
-
type: SheetHyperLinkType.DEFINE_NAME,
|
|
438
|
-
name: range2.formulaOrRefString
|
|
439
|
-
} : invalidLink;
|
|
440
|
-
}
|
|
441
|
-
if (gid) {
|
|
442
|
-
const worksheet = workbook.getSheetBySheetId(gid);
|
|
443
|
-
return worksheet ? {
|
|
444
|
-
type: SheetHyperLinkType.SHEET,
|
|
445
|
-
name: worksheet.getName()
|
|
446
|
-
} : invalidLink;
|
|
447
|
-
}
|
|
448
|
-
return invalidLink;
|
|
449
|
-
}
|
|
450
|
-
navigateTo(params) {
|
|
451
|
-
const { gid, range, rangeid } = params, workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
452
|
-
if (!workbook)
|
|
453
|
-
return;
|
|
454
|
-
const unitId = workbook.getUnitId();
|
|
455
|
-
if (rangeid && this.navigateToDefineName(unitId, rangeid), !!gid) {
|
|
456
|
-
if (range) {
|
|
457
|
-
const rangeInfo = deserializeRangeWithSheet(range);
|
|
458
|
-
isValidRange(rangeInfo.range) && range !== ERROR_RANGE && this.navigateToRange(unitId, gid, rangeInfo.range);
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
this.navigateToSheetById(unitId, gid);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
buildHyperLink(unitId, sheetId, range) {
|
|
465
|
-
return `#${SheetHyperLinkType.SHEET}=${sheetId}${range ? `&${typeof range == "string" ? SheetHyperLinkType.DEFINE_NAME : SheetHyperLinkType.RANGE}=${typeof range == "string" ? range : serializeRange(range)}` : ""}`;
|
|
466
|
-
}
|
|
467
|
-
parseHyperLink(urlStr) {
|
|
468
|
-
var _a15, _b, _c, _d;
|
|
469
|
-
if (urlStr.startsWith("#")) {
|
|
470
|
-
const search = new URLSearchParams(urlStr.slice(1)), searchObj = {
|
|
471
|
-
gid: (_a15 = search.get("gid")) != null ? _a15 : "",
|
|
472
|
-
range: (_b = search.get("range")) != null ? _b : "",
|
|
473
|
-
rangeid: (_c = search.get("rangeid")) != null ? _c : "",
|
|
474
|
-
unitid: (_d = search.get("unitid")) != null ? _d : ""
|
|
475
|
-
}, urlInfo = this._getURLName(searchObj);
|
|
476
|
-
return {
|
|
477
|
-
type: urlInfo.type,
|
|
478
|
-
name: urlInfo.name,
|
|
479
|
-
url: urlStr,
|
|
480
|
-
searchObj,
|
|
481
|
-
handler: /* @__PURE__ */ __name(() => {
|
|
482
|
-
this.navigateTo(searchObj);
|
|
483
|
-
}, "handler")
|
|
484
|
-
};
|
|
485
|
-
} else
|
|
486
|
-
return {
|
|
487
|
-
type: SheetHyperLinkType.URL,
|
|
488
|
-
name: urlStr,
|
|
489
|
-
url: urlStr,
|
|
490
|
-
handler: /* @__PURE__ */ __name(() => {
|
|
491
|
-
this.navigateToOtherWebsite(urlStr);
|
|
492
|
-
}, "handler"),
|
|
493
|
-
searchObj: null
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
async navigateToRange(unitId, subUnitId, range) {
|
|
497
|
-
const worksheet = await this.navigateToSheetById(unitId, subUnitId);
|
|
498
|
-
if (worksheet) {
|
|
499
|
-
const realRange = getContainRange(range, worksheet);
|
|
500
|
-
await this._commandService.executeCommand(
|
|
501
|
-
SetSelectionsOperation.id,
|
|
502
|
-
{
|
|
503
|
-
unitId,
|
|
504
|
-
subUnitId,
|
|
505
|
-
selections: [{
|
|
506
|
-
range: realRange
|
|
507
|
-
}]
|
|
508
|
-
}
|
|
509
|
-
), await this._commandService.executeCommand(ScrollToRangeOperation.id, {
|
|
510
|
-
range: realRange
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
async navigateToSheet(unitId, sheetName) {
|
|
515
|
-
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
516
|
-
if (!workbook)
|
|
517
|
-
return !1;
|
|
518
|
-
const worksheet = workbook.getActiveSheet();
|
|
519
|
-
if ((worksheet == null ? void 0 : worksheet.getName()) === sheetName)
|
|
520
|
-
return !0;
|
|
521
|
-
const targetSheet = workbook.getSheetBySheetName(sheetName);
|
|
522
|
-
if (!targetSheet) {
|
|
523
|
-
this._messageService.show({
|
|
524
|
-
content: this._localeService.t("hyperLink.message.noSheet"),
|
|
525
|
-
type: MessageType.Error
|
|
526
|
-
});
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
const sheetId = targetSheet.getSheetId();
|
|
530
|
-
return workbook.getHiddenWorksheets().indexOf(sheetId) > -1 && this._messageService.show({
|
|
531
|
-
content: this._localeService.t("hyperLink.message.hiddenSheet"),
|
|
532
|
-
type: MessageType.Error
|
|
533
|
-
}), await this._commandService.executeCommand(SetWorksheetActiveOperation.id, { unitId, subUnitId: sheetId });
|
|
534
|
-
}
|
|
535
|
-
async navigateToSheetById(unitId, subUnitId) {
|
|
536
|
-
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
537
|
-
if (!workbook)
|
|
538
|
-
return !1;
|
|
539
|
-
const worksheet = workbook.getActiveSheet();
|
|
540
|
-
if (!worksheet)
|
|
541
|
-
return !1;
|
|
542
|
-
if (worksheet.getSheetId() === subUnitId)
|
|
543
|
-
return worksheet;
|
|
544
|
-
const targetSheet = workbook.getSheetBySheetId(subUnitId);
|
|
545
|
-
return targetSheet ? workbook.getHiddenWorksheets().indexOf(subUnitId) > -1 ? (this._messageService.show({
|
|
546
|
-
content: this._localeService.t("hyperLink.message.hiddenSheet"),
|
|
547
|
-
type: MessageType.Error
|
|
548
|
-
}), !1) : await this._commandService.executeCommand(SetWorksheetActiveOperation.id, { unitId, subUnitId }) ? targetSheet : !1 : (this._messageService.show({
|
|
549
|
-
content: this._localeService.t("hyperLink.message.noSheet"),
|
|
550
|
-
type: MessageType.Error
|
|
551
|
-
}), !1);
|
|
552
|
-
}
|
|
553
|
-
async navigateToDefineName(unitId, rangeid) {
|
|
554
|
-
return this._definedNamesService.focusRange(unitId, rangeid), !0;
|
|
555
|
-
}
|
|
556
|
-
async navigateToOtherWebsite(url) {
|
|
557
|
-
var _a15;
|
|
558
|
-
const config = this._configService.getConfig(PLUGIN_CONFIG_KEY);
|
|
559
|
-
if ((_a15 = config == null ? void 0 : config.urlHandler) != null && _a15.navigateToOtherWebsite)
|
|
560
|
-
return config.urlHandler.navigateToOtherWebsite(url);
|
|
561
|
-
window.open(url, "_blank", "noopener noreferrer");
|
|
562
|
-
}
|
|
563
|
-
}, __name(_a, "SheetsHyperLinkResolverService"), _a);
|
|
564
|
-
SheetsHyperLinkResolverService = __decorateClass$c([
|
|
565
|
-
__decorateParam$c(0, IUniverInstanceService),
|
|
566
|
-
__decorateParam$c(1, ICommandService),
|
|
567
|
-
__decorateParam$c(2, IDefinedNamesService),
|
|
568
|
-
__decorateParam$c(3, IMessageService),
|
|
569
|
-
__decorateParam$c(4, Inject(LocaleService)),
|
|
570
|
-
__decorateParam$c(5, IConfigService)
|
|
571
|
-
], SheetsHyperLinkResolverService);
|
|
572
|
-
const _SheetsHyperLinkSidePanelService = class _SheetsHyperLinkSidePanelService extends Disposable {
|
|
635
|
+
}, "handler")
|
|
636
|
+
}, _SheetsHyperLinkSidePanelService = class _SheetsHyperLinkSidePanelService extends Disposable {
|
|
573
637
|
constructor() {
|
|
574
638
|
super(...arguments);
|
|
575
639
|
__publicField(this, "_customHyperLinks", /* @__PURE__ */ new Map());
|
|
@@ -604,7 +668,7 @@ const cellLinkEdit = "univer-cell-link-edit", cellLinkEditButtons = "univer-cell
|
|
|
604
668
|
cellLinkEditButtons
|
|
605
669
|
}, CellLinkEdit = /* @__PURE__ */ __name(() => {
|
|
606
670
|
var _a15;
|
|
607
|
-
const [id, setId] = useState(""), [hide, setHide] = useState(!1), [display, setDisplay] = useState(""), [showLabel, setShowLabel] = useState(!0), [type, setType] = useState(SheetHyperLinkType.URL), [payload, setPayload] = useState(""), localeService = useDependency(LocaleService), definedNameService = useDependency(IDefinedNamesService), editorBridgeService = useDependency(IEditorBridgeService), univerInstanceService = useDependency(IUniverInstanceService), popupService = useDependency(SheetsHyperLinkPopupService), editing = useObservable(popupService.currentEditing$), resolverService = useDependency(SheetsHyperLinkResolverService), commandService = useDependency(ICommandService), sidePanelService = useDependency(SheetsHyperLinkSidePanelService), sidePanelOptions = useMemo(() => sidePanelService.getOptions(), [sidePanelService]), zenZoneService = useDependency(IZenZoneService), markSelectionService = useDependency(IMarkSelectionService), textSelectionService = useDependency(DocSelectionManagerService), contextService = useDependency(IContextService), customHyperLinkSidePanel = useMemo(() => {
|
|
671
|
+
const [id, setId] = useState(""), [hide, setHide] = useState(!1), [display, setDisplay] = useState(""), [showLabel, setShowLabel] = useState(!0), [type, setType] = useState(SheetHyperLinkType.URL), [payload, setPayload] = useState(""), localeService = useDependency(LocaleService), definedNameService = useDependency(IDefinedNamesService), editorBridgeService = useDependency(IEditorBridgeService), univerInstanceService = useDependency(IUniverInstanceService), popupService = useDependency(SheetsHyperLinkPopupService), editing = useObservable(popupService.currentEditing$), resolverService = useDependency(SheetsHyperLinkResolverService), commandService = useDependency(ICommandService), sidePanelService = useDependency(SheetsHyperLinkSidePanelService), sidePanelOptions = useMemo(() => sidePanelService.getOptions(), [sidePanelService]), zenZoneService = useDependency(IZenZoneService), renderManagerService = useDependency(IRenderManagerService), markSelectionService = useDependency(IMarkSelectionService), textSelectionService = useDependency(DocSelectionManagerService), contextService = useDependency(IContextService), customHyperLinkSidePanel = useMemo(() => {
|
|
608
672
|
if (!sidePanelService.isBuiltInLinkType(type))
|
|
609
673
|
return sidePanelService.getCustomHyperLink(type);
|
|
610
674
|
}, [sidePanelService, type]), [showError, setShowError] = useState(!1), setByPayload = useRef(!1);
|
|
@@ -678,34 +742,48 @@ const cellLinkEdit = "univer-cell-link-edit", cellLinkEditButtons = "univer-cell
|
|
|
678
742
|
}
|
|
679
743
|
}
|
|
680
744
|
}, [editing, resolverService, sidePanelService, textSelectionService, univerInstanceService]), useEffect(() => {
|
|
745
|
+
var _a16;
|
|
681
746
|
let id2 = null;
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
747
|
+
if (editing && editing.type === HyperLinkEditSourceType.VIEWING && Tools.isDefine(editing.row) && Tools.isDefine(editing.col)) {
|
|
748
|
+
const worksheet = (_a16 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a16.getSheetBySheetId(editing.subUnitId), mergeInfo = worksheet == null ? void 0 : worksheet.getMergedCell(editing.row, editing.col);
|
|
749
|
+
id2 = markSelectionService.addShape(
|
|
750
|
+
{
|
|
751
|
+
range: mergeInfo != null ? mergeInfo : {
|
|
752
|
+
startColumn: editing.col,
|
|
753
|
+
endColumn: editing.col,
|
|
754
|
+
startRow: editing.row,
|
|
755
|
+
endRow: editing.row
|
|
756
|
+
},
|
|
757
|
+
style: {
|
|
758
|
+
hasAutoFill: !1,
|
|
759
|
+
fill: "rgb(255, 189, 55, 0.35)",
|
|
760
|
+
strokeWidth: 1,
|
|
761
|
+
stroke: "#FFBD37",
|
|
762
|
+
widgets: {}
|
|
763
|
+
},
|
|
764
|
+
primary: null
|
|
696
765
|
},
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
766
|
+
[],
|
|
767
|
+
-1
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
return () => {
|
|
702
771
|
id2 && markSelectionService.removeShape(id2);
|
|
703
772
|
};
|
|
704
773
|
}, [editing, markSelectionService]);
|
|
705
774
|
const payloadInitial = useMemo(() => payload, [type]);
|
|
706
|
-
useEffect(() =>
|
|
707
|
-
editorBridgeService.
|
|
708
|
-
|
|
775
|
+
useEffect(() => {
|
|
776
|
+
const render2 = renderManagerService.getRenderById(editorBridgeService.getCurrentEditorId()), disposeCollection = new DisposableCollection();
|
|
777
|
+
if (render2) {
|
|
778
|
+
const selectionRenderService = render2.with(DocSelectionRenderService);
|
|
779
|
+
selectionRenderService.setReserveRangesStatus(!0), disposeCollection.add(() => {
|
|
780
|
+
selectionRenderService.setReserveRangesStatus(!1);
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
return () => {
|
|
784
|
+
editorBridgeService.disableForceKeepVisible(), disposeCollection.dispose();
|
|
785
|
+
};
|
|
786
|
+
}, [editorBridgeService, renderManagerService]);
|
|
709
787
|
const linkTypeOptions = [
|
|
710
788
|
{
|
|
711
789
|
label: localeService.t("hyperLink.form.link"),
|
|
@@ -1029,7 +1107,95 @@ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width:
|
|
|
1029
1107
|
}));
|
|
1030
1108
|
});
|
|
1031
1109
|
Xlsx.displayName = "Xlsx";
|
|
1032
|
-
const
|
|
1110
|
+
const CancelHyperLinkCommand = {
|
|
1111
|
+
type: CommandType.COMMAND,
|
|
1112
|
+
id: "sheets.command.cancel-hyper-link",
|
|
1113
|
+
// eslint-disable-next-line max-lines-per-function
|
|
1114
|
+
handler(accessor, params) {
|
|
1115
|
+
var _a15, _b, _c;
|
|
1116
|
+
if (!params)
|
|
1117
|
+
return !1;
|
|
1118
|
+
const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), renderManagerService = accessor.get(IRenderManagerService), univerInstanceService = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), { unitId, subUnitId, row, column, id } = params, workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), currentRender = renderManagerService.getRenderById(unitId);
|
|
1119
|
+
if (!currentRender || !workbook)
|
|
1120
|
+
return !1;
|
|
1121
|
+
const worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId), skeleton = (_a15 = currentRender.with(SheetSkeletonManagerService).getCurrent()) == null ? void 0 : _a15.skeleton;
|
|
1122
|
+
if (!worksheet || !skeleton)
|
|
1123
|
+
return !1;
|
|
1124
|
+
const cellData = worksheet.getCell(row, column);
|
|
1125
|
+
if (!cellData)
|
|
1126
|
+
return !1;
|
|
1127
|
+
const doc = skeleton.getCellDocumentModelWithFormula(cellData);
|
|
1128
|
+
if (!(doc != null && doc.documentModel))
|
|
1129
|
+
return !1;
|
|
1130
|
+
const snapshot = Tools.deepClone(doc.documentModel.getSnapshot());
|
|
1131
|
+
if (!((_c = (_b = snapshot.body) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((range2) => range2.rangeId === id)))
|
|
1132
|
+
return !1;
|
|
1133
|
+
const textX = BuildTextUtils.customRange.delete(accessor, { documentDataModel: doc.documentModel, rangeId: id });
|
|
1134
|
+
if (!textX)
|
|
1135
|
+
return !1;
|
|
1136
|
+
const newBody = TextX.apply(snapshot.body, textX.serialize()), redos = [], undos = [], setRangeParams = {
|
|
1137
|
+
unitId,
|
|
1138
|
+
subUnitId,
|
|
1139
|
+
cellValue: {
|
|
1140
|
+
[row]: {
|
|
1141
|
+
[column]: {
|
|
1142
|
+
p: {
|
|
1143
|
+
...snapshot,
|
|
1144
|
+
body: newBody
|
|
1145
|
+
},
|
|
1146
|
+
t: CellValueType.STRING
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
redos.push({
|
|
1152
|
+
id: SetRangeValuesMutation.id,
|
|
1153
|
+
params: setRangeParams
|
|
1154
|
+
});
|
|
1155
|
+
const undoParams = SetRangeValuesUndoMutationFactory(accessor, setRangeParams);
|
|
1156
|
+
undos.push({
|
|
1157
|
+
id: SetRangeValuesMutation.id,
|
|
1158
|
+
params: undoParams
|
|
1159
|
+
});
|
|
1160
|
+
const link = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
|
|
1161
|
+
return link && (redos.push({
|
|
1162
|
+
id: RemoveHyperLinkMutation.id,
|
|
1163
|
+
params: {
|
|
1164
|
+
unitId,
|
|
1165
|
+
subUnitId,
|
|
1166
|
+
id
|
|
1167
|
+
}
|
|
1168
|
+
}), undos.push({
|
|
1169
|
+
id: AddHyperLinkMutation.id,
|
|
1170
|
+
params: {
|
|
1171
|
+
unitId,
|
|
1172
|
+
subUnitId,
|
|
1173
|
+
link: {
|
|
1174
|
+
...link
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
})), sequenceExecute(redos, commandService).result ? (undoRedoService.pushUndoRedo({
|
|
1178
|
+
redoMutations: redos,
|
|
1179
|
+
undoMutations: undos,
|
|
1180
|
+
unitID: unitId
|
|
1181
|
+
}), !0) : !1;
|
|
1182
|
+
}
|
|
1183
|
+
}, CancelRichHyperLinkCommand = {
|
|
1184
|
+
type: CommandType.COMMAND,
|
|
1185
|
+
id: "sheets.command.cancel-rich-hyper-link",
|
|
1186
|
+
handler(accessor, params) {
|
|
1187
|
+
var _a15, _b;
|
|
1188
|
+
if (!params)
|
|
1189
|
+
return !1;
|
|
1190
|
+
const { id: linkId, documentId } = params, commandService = accessor.get(ICommandService), doc = accessor.get(IUniverInstanceService).getUnit(documentId, UniverInstanceType.UNIVER_DOC), link = (_b = (_a15 = doc == null ? void 0 : doc.getBody()) == null ? void 0 : _a15.customRanges) == null ? void 0 : _b.find((i) => i.rangeId === linkId);
|
|
1191
|
+
let insert = null;
|
|
1192
|
+
link && link.endIndex === doc.getBody().dataStream.length - 3 && (insert = {
|
|
1193
|
+
dataStream: " "
|
|
1194
|
+
});
|
|
1195
|
+
const doMutation = deleteCustomRangeFactory(accessor, { unitId: documentId, rangeId: linkId, insert });
|
|
1196
|
+
return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
|
|
1197
|
+
}
|
|
1198
|
+
}, cellLink = "univer-cell-link", cellLinkType = "univer-cell-link-type", cellLinkContent = "univer-cell-link-content", cellLinkContentError = "univer-cell-link-content-error", cellLinkUrl = "univer-cell-link-url", cellLinkOperations = "univer-cell-link-operations", cellLinkOperation = "univer-cell-link-operation", cellLinkOperationError = "univer-cell-link-operation-error", styles = {
|
|
1033
1199
|
cellLink,
|
|
1034
1200
|
cellLinkType,
|
|
1035
1201
|
cellLinkContent,
|
|
@@ -1128,17 +1294,17 @@ const cellLink = "univer-cell-link", cellLinkType = "univer-cell-link-type", cel
|
|
|
1128
1294
|
] });
|
|
1129
1295
|
}, "CellLinkPopup");
|
|
1130
1296
|
CellLinkPopup.componentKey = "univer.sheet.cell-link-popup";
|
|
1131
|
-
var __defProp$
|
|
1132
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
1297
|
+
var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1298
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1133
1299
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1134
|
-
return kind && result && __defProp$
|
|
1135
|
-
}, "__decorateClass$
|
|
1300
|
+
return kind && result && __defProp$a(target, key, result), result;
|
|
1301
|
+
}, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a");
|
|
1136
1302
|
const isEqualLink = /* @__PURE__ */ __name((a, b) => {
|
|
1137
1303
|
var _a15, _b;
|
|
1138
1304
|
return a.unitId === b.unitId && a.subUnitId === b.subUnitId && a.row === b.row && a.col === b.col && ((_a15 = a.customRange) == null ? void 0 : _a15.rangeId) === ((_b = b.customRange) == null ? void 0 : _b.rangeId) && a.type === b.type;
|
|
1139
1305
|
}, "isEqualLink");
|
|
1140
|
-
var
|
|
1141
|
-
let SheetsHyperLinkPopupService = (
|
|
1306
|
+
var _a3;
|
|
1307
|
+
let SheetsHyperLinkPopupService = (_a3 = class extends Disposable {
|
|
1142
1308
|
constructor(_sheetCanvasPopManagerService, _injector, _univerInstanceService, _editorBridgeService, _textSelectionManagerService, _docCanvasPopManagerService, _editorService, _rangeSelectorService, _zenZoneService) {
|
|
1143
1309
|
super();
|
|
1144
1310
|
__publicField(this, "_currentPopup", null);
|
|
@@ -1352,17 +1518,17 @@ let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
|
|
|
1352
1518
|
const current = this._currentEditing$.getValue();
|
|
1353
1519
|
current && (!type || type === current.type) && ((_a15 = this._currentEditingPopup) == null || _a15.dispose(), this._currentEditing$.next(null));
|
|
1354
1520
|
}
|
|
1355
|
-
}, __name(
|
|
1356
|
-
SheetsHyperLinkPopupService = __decorateClass$
|
|
1357
|
-
__decorateParam$
|
|
1358
|
-
__decorateParam$
|
|
1359
|
-
__decorateParam$
|
|
1360
|
-
__decorateParam$
|
|
1361
|
-
__decorateParam$
|
|
1362
|
-
__decorateParam$
|
|
1363
|
-
__decorateParam$
|
|
1364
|
-
__decorateParam$
|
|
1365
|
-
__decorateParam$
|
|
1521
|
+
}, __name(_a3, "SheetsHyperLinkPopupService"), _a3);
|
|
1522
|
+
SheetsHyperLinkPopupService = __decorateClass$a([
|
|
1523
|
+
__decorateParam$a(0, Inject(SheetCanvasPopManagerService)),
|
|
1524
|
+
__decorateParam$a(1, Inject(Injector)),
|
|
1525
|
+
__decorateParam$a(2, IUniverInstanceService),
|
|
1526
|
+
__decorateParam$a(3, IEditorBridgeService),
|
|
1527
|
+
__decorateParam$a(4, Inject(DocSelectionManagerService)),
|
|
1528
|
+
__decorateParam$a(5, Inject(DocCanvasPopManagerService)),
|
|
1529
|
+
__decorateParam$a(6, IEditorService),
|
|
1530
|
+
__decorateParam$a(7, IRangeSelectorService),
|
|
1531
|
+
__decorateParam$a(8, IZenZoneService)
|
|
1366
1532
|
], SheetsHyperLinkPopupService);
|
|
1367
1533
|
const getShouldDisableCellLink = /* @__PURE__ */ __name((worksheet, row, col) => {
|
|
1368
1534
|
const cell = worksheet.getCell(row, col);
|
|
@@ -1446,160 +1612,7 @@ const getShouldDisableCellLink = /* @__PURE__ */ __name((worksheet, row, col) =>
|
|
|
1446
1612
|
const commandService = accessor.get(ICommandService);
|
|
1447
1613
|
return accessor.get(SheetsHyperLinkPopupService).currentEditing ? commandService.executeCommand(CloseHyperLinkPopupOperation.id) : commandService.executeCommand(InsertHyperLinkOperation.id);
|
|
1448
1614
|
}
|
|
1449
|
-
},
|
|
1450
|
-
var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
1451
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1452
|
-
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1453
|
-
return kind && result && __defProp$a(target, key, result), result;
|
|
1454
|
-
}, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a"), _a3;
|
|
1455
|
-
let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
|
|
1456
|
-
constructor(_sheetClipboardService, _hyperLinkModel, _injector, _resolverService) {
|
|
1457
|
-
super();
|
|
1458
|
-
__publicField(this, "_plainTextFilter", /* @__PURE__ */ new Set());
|
|
1459
|
-
__publicField(this, "_copyInfo");
|
|
1460
|
-
this._sheetClipboardService = _sheetClipboardService, this._hyperLinkModel = _hyperLinkModel, this._injector = _injector, this._resolverService = _resolverService, this._initCopyPaste(), this.disposeWithMe(() => {
|
|
1461
|
-
this._plainTextFilter.clear();
|
|
1462
|
-
});
|
|
1463
|
-
}
|
|
1464
|
-
registerPlainTextFilter(filter) {
|
|
1465
|
-
this._plainTextFilter.add(filter);
|
|
1466
|
-
}
|
|
1467
|
-
removePlainTextFilter(filter) {
|
|
1468
|
-
this._plainTextFilter.delete(filter);
|
|
1469
|
-
}
|
|
1470
|
-
/* If return false the process of paste text will be stop */
|
|
1471
|
-
_filterPlainText(text) {
|
|
1472
|
-
return Array.from(this._plainTextFilter).every((filter) => filter(text));
|
|
1473
|
-
}
|
|
1474
|
-
_initCopyPaste() {
|
|
1475
|
-
this._sheetClipboardService.addClipboardHook({
|
|
1476
|
-
id: SHEET_HYPER_LINK_UI_PLUGIN,
|
|
1477
|
-
onBeforeCopy: /* @__PURE__ */ __name((unitId, subUnitId, range) => this._collect(unitId, subUnitId, range), "onBeforeCopy"),
|
|
1478
|
-
onPasteCells: /* @__PURE__ */ __name((pasteFrom, pasteTo, data, payload) => {
|
|
1479
|
-
const { copyType = COPY_TYPE.COPY, pasteType } = payload, { range: copyRange } = pasteFrom || {}, { range: pastedRange, unitId, subUnitId } = pasteTo;
|
|
1480
|
-
return this._generateMutations(pastedRange, { copyType, pasteType, copyRange, unitId, subUnitId });
|
|
1481
|
-
}, "onPasteCells"),
|
|
1482
|
-
onPastePlainText: /* @__PURE__ */ __name((pasteTo, clipText) => {
|
|
1483
|
-
const filterResult = this._filterPlainText(clipText);
|
|
1484
|
-
if (isLegalLink(clipText) && filterResult) {
|
|
1485
|
-
const { range, unitId, subUnitId } = pasteTo, { ranges: [pasteToRange], mapFunc } = virtualizeDiscreteRanges([range]), redos = [], undos = [];
|
|
1486
|
-
return Range.foreach(pasteToRange, (originRow, originCol) => {
|
|
1487
|
-
const { row, col: column } = mapFunc(originRow, originCol), link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
|
|
1488
|
-
link && redos.push({
|
|
1489
|
-
id: RemoveHyperLinkMutation.id,
|
|
1490
|
-
params: {
|
|
1491
|
-
unitId,
|
|
1492
|
-
subUnitId,
|
|
1493
|
-
id: link.id
|
|
1494
|
-
}
|
|
1495
|
-
}), link && undos.push({
|
|
1496
|
-
id: AddHyperLinkMutation.id,
|
|
1497
|
-
params: {
|
|
1498
|
-
unitId,
|
|
1499
|
-
subUnitId,
|
|
1500
|
-
link
|
|
1501
|
-
}
|
|
1502
|
-
});
|
|
1503
|
-
}), { redos, undos };
|
|
1504
|
-
}
|
|
1505
|
-
return { undos: [], redos: [] };
|
|
1506
|
-
}, "onPastePlainText"),
|
|
1507
|
-
priority: 99
|
|
1508
|
-
});
|
|
1509
|
-
}
|
|
1510
|
-
_collect(unitId, subUnitId, range) {
|
|
1511
|
-
const matrix = new ObjectMatrix();
|
|
1512
|
-
this._copyInfo = {
|
|
1513
|
-
unitId,
|
|
1514
|
-
subUnitId,
|
|
1515
|
-
matrix
|
|
1516
|
-
};
|
|
1517
|
-
const discreteRange = this._injector.invoke((accessor) => rangeToDiscreteRange(range, accessor, unitId, subUnitId));
|
|
1518
|
-
if (!discreteRange)
|
|
1519
|
-
return;
|
|
1520
|
-
const { rows, cols } = discreteRange;
|
|
1521
|
-
rows.forEach((row, rowIndex) => {
|
|
1522
|
-
cols.forEach((col, colIndex) => {
|
|
1523
|
-
var _a15;
|
|
1524
|
-
const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
|
|
1525
|
-
matrix.setValue(rowIndex, colIndex, (_a15 = link == null ? void 0 : link.id) != null ? _a15 : "");
|
|
1526
|
-
});
|
|
1527
|
-
});
|
|
1528
|
-
}
|
|
1529
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1530
|
-
_generateMutations(pastedRange, copyInfo) {
|
|
1531
|
-
if (!this._copyInfo)
|
|
1532
|
-
return { redos: [], undos: [] };
|
|
1533
|
-
if (!this._copyInfo || !this._copyInfo.matrix.getSizeOf() || !copyInfo.copyRange)
|
|
1534
|
-
return { redos: [], undos: [] };
|
|
1535
|
-
if ([
|
|
1536
|
-
PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,
|
|
1537
|
-
PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,
|
|
1538
|
-
PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,
|
|
1539
|
-
PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA
|
|
1540
|
-
].includes(
|
|
1541
|
-
copyInfo.pasteType
|
|
1542
|
-
))
|
|
1543
|
-
return { redos: [], undos: [] };
|
|
1544
|
-
const { unitId, subUnitId } = this._copyInfo, redos = [], undos = [], { ranges: [vCopyRange, vPastedRange], mapFunc } = virtualizeDiscreteRanges([copyInfo.copyRange, pastedRange]);
|
|
1545
|
-
return getRepeatRange(vCopyRange, vPastedRange, !0).forEach(({ startRange }) => {
|
|
1546
|
-
var _a15;
|
|
1547
|
-
(_a15 = this._copyInfo) == null || _a15.matrix.forValue((row, col, ruleId) => {
|
|
1548
|
-
const range = Rectangle.getPositionRange(
|
|
1549
|
-
{
|
|
1550
|
-
startRow: row,
|
|
1551
|
-
endRow: row,
|
|
1552
|
-
startColumn: col,
|
|
1553
|
-
endColumn: col
|
|
1554
|
-
},
|
|
1555
|
-
startRange
|
|
1556
|
-
), oldLink = this._hyperLinkModel.getHyperLink(unitId, subUnitId, ruleId), { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn), currentLink = this._hyperLinkModel.getHyperLinkByLocation(copyInfo.unitId, copyInfo.subUnitId, startRow, startColumn), id = Tools.generateRandomId();
|
|
1557
|
-
currentLink && redos.push({
|
|
1558
|
-
id: RemoveHyperLinkMutation.id,
|
|
1559
|
-
params: {
|
|
1560
|
-
unitId: copyInfo.unitId,
|
|
1561
|
-
subUnitId: copyInfo.subUnitId,
|
|
1562
|
-
id: currentLink.id
|
|
1563
|
-
}
|
|
1564
|
-
}), oldLink && (redos.push({
|
|
1565
|
-
id: AddHyperLinkMutation.id,
|
|
1566
|
-
params: {
|
|
1567
|
-
unitId: copyInfo.unitId,
|
|
1568
|
-
subUnitId: copyInfo.subUnitId,
|
|
1569
|
-
link: {
|
|
1570
|
-
...oldLink,
|
|
1571
|
-
id,
|
|
1572
|
-
row: startRow,
|
|
1573
|
-
column: startColumn
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
}), undos.push({
|
|
1577
|
-
id: RemoveHyperLinkMutation.id,
|
|
1578
|
-
params: {
|
|
1579
|
-
unitId: copyInfo.unitId,
|
|
1580
|
-
subUnitId: copyInfo.subUnitId,
|
|
1581
|
-
id
|
|
1582
|
-
}
|
|
1583
|
-
})), currentLink && undos.push({
|
|
1584
|
-
id: AddHyperLinkMutation.id,
|
|
1585
|
-
params: {
|
|
1586
|
-
unitId: copyInfo.unitId,
|
|
1587
|
-
subUnitId: copyInfo.subUnitId,
|
|
1588
|
-
link: currentLink
|
|
1589
|
-
}
|
|
1590
|
-
});
|
|
1591
|
-
});
|
|
1592
|
-
}), { redos, undos };
|
|
1593
|
-
}
|
|
1594
|
-
}, __name(_a3, "SheetsHyperLinkCopyPasteController"), _a3);
|
|
1595
|
-
SheetsHyperLinkCopyPasteController = __decorateClass$a([
|
|
1596
|
-
OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkCopyPasteController),
|
|
1597
|
-
__decorateParam$a(0, ISheetClipboardService),
|
|
1598
|
-
__decorateParam$a(1, Inject(HyperLinkModel)),
|
|
1599
|
-
__decorateParam$a(2, Inject(Injector)),
|
|
1600
|
-
__decorateParam$a(3, Inject(SheetsHyperLinkResolverService))
|
|
1601
|
-
], SheetsHyperLinkCopyPasteController);
|
|
1602
|
-
const getLinkDisable$ = /* @__PURE__ */ __name((accessor) => {
|
|
1615
|
+
}, getLinkDisable$ = /* @__PURE__ */ __name((accessor) => {
|
|
1603
1616
|
const disableRange$ = getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }), univerInstanceService = accessor.get(IUniverInstanceService), sheetSelectionService = accessor.get(SheetsSelectionsService), disableCell$ = univerInstanceService.focused$.pipe(
|
|
1604
1617
|
map((focused) => focused ? univerInstanceService.getUnit(focused, UniverInstanceType.UNIVER_SHEET) : null),
|
|
1605
1618
|
mergeMap((unit) => unit ? unit.activeSheet$ : new Observable((sub) => {
|
|
@@ -1760,6 +1773,8 @@ let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
|
|
|
1760
1773
|
this._sheetInterceptorService.intercept(
|
|
1761
1774
|
INTERCEPTOR_POINT.CELL_CONTENT,
|
|
1762
1775
|
{
|
|
1776
|
+
effect: InterceptorEffectEnum.Value,
|
|
1777
|
+
priority: 100,
|
|
1763
1778
|
handler: /* @__PURE__ */ __name((cell, pos, next) => {
|
|
1764
1779
|
const { row, col, unitId, subUnitId } = pos, link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
|
|
1765
1780
|
return next(link ? {
|
|
@@ -1767,8 +1782,7 @@ let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
|
|
|
1767
1782
|
linkUrl: link.payload,
|
|
1768
1783
|
linkId: link.id
|
|
1769
1784
|
} : cell);
|
|
1770
|
-
}, "handler")
|
|
1771
|
-
priority: 100
|
|
1785
|
+
}, "handler")
|
|
1772
1786
|
}
|
|
1773
1787
|
)
|
|
1774
1788
|
);
|
|
@@ -1937,7 +1951,14 @@ let SheetsHyperLinkPopupController = (_a8 = class extends Disposable {
|
|
|
1937
1951
|
super(), this._hoverManagerService = _hoverManagerService, this._sheetsHyperLinkPopupService = _sheetsHyperLinkPopupService, this._renderManagerService = _renderManagerService, this._permissionService = _permissionService, this._sheetPermissionInterceptorBaseController = _sheetPermissionInterceptorBaseController, this._commandService = _commandService, this._editorBridgeService = _editorBridgeService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this._zenZoneService = _zenZoneService, this._initHoverListener(), this._initCommandListener(), this._initHoverEditingListener(), this._initTextSelectionListener(), this._initZenEditor();
|
|
1938
1952
|
}
|
|
1939
1953
|
_getLinkPermission(location2) {
|
|
1940
|
-
const { unitId, subUnitId, row: currentRow, col: currentCol } = location2,
|
|
1954
|
+
const { unitId, subUnitId, row: currentRow, col: currentCol } = location2, workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
1955
|
+
if (!(workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId)))
|
|
1956
|
+
return {
|
|
1957
|
+
viewPermission: !1,
|
|
1958
|
+
editPermission: !1,
|
|
1959
|
+
copyPermission: !1
|
|
1960
|
+
};
|
|
1961
|
+
const viewPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
|
|
1941
1962
|
workbookTypes: [WorkbookViewPermission],
|
|
1942
1963
|
worksheetTypes: [WorksheetViewPermission],
|
|
1943
1964
|
rangeTypes: [RangeProtectionPermissionViewPoint]
|