@univerjs/sheets-hyper-link-ui 0.2.14 → 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,284 +2,465 @@ 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 { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, UniverInstanceType, BuildTextUtils, DataStreamTreeTokenType, CustomRangeType, TextX, CellValueType, sequenceExecuteAsync, generateRandomId, Tools, sequenceExecute, getBodySlice, isValidRange, Inject, LocaleService, RANGE_TYPE, Rectangle, IConfigService, useDependency, DOCS_ZEN_EDITOR_UNIT_ID_KEY, DEFAULT_EMPTY_DOCUMENT_VALUE, Disposable, IContextService, createInternalEditorID, FOCUSING_SHEET, Injector, Range, ObjectMatrix, OnLifecycle, LifecycleStages, DataValidationType, ThemeService, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, IPermissionService, DisposableCollection, Plugin, DependentOn } from "@univerjs/core";
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, getPlainTextFormBody, getPlainText, getPlainTextFormDocument, DocCanvasPopManagerService, DocEventManagerService, UniverDocsUIPlugin } from "@univerjs/docs-ui";
8
- import { IRenderManagerService } from "@univerjs/engine-render";
9
- import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SetSelectionsOperation, SetWorksheetActiveOperation, getSheetCommandTarget, SheetsSelectionsService, 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
13
  import { Subject, BehaviorSubject, map, mergeMap, Observable, debounceTime } from "rxjs";
13
- import { IMessageService, useObservable, IZenZoneService, useEvent, KeyCode, RangeSelector, IEditorService, IRangeSelectorService, MenuItemType, MenuPosition, MenuGroup, MetaKeys, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IShortcutService, IMenuManagerService } from "@univerjs/ui";
14
- import require$$0, { forwardRef, useRef, createElement, useState, useEffect, useMemo } from "react";
14
+ import { addCustomRangeBySelectionFactory, replaceSelectionFactory, DocSelectionRenderService, RangeSelector, deleteCustomRangeFactory, DocCanvasPopManagerService, IEditorService, IRangeSelectorService, DocEventManagerService, UniverDocsUIPlugin } from "@univerjs/docs-ui";
15
+ import require$$0, { useState, useMemo, useRef, useEffect, forwardRef, createElement } from "react";
16
+ import { IRenderManagerService } from "@univerjs/engine-render";
15
17
  import cs from "clsx";
16
- import { MessageType, Tooltip, FormLayout, Input, Select, Button } from "@univerjs/design";
17
- import { deserializeRangeWithSheet, serializeRangeWithSheet, serializeRange, IDefinedNamesService, serializeRangeToRefString } from "@univerjs/engine-formula";
18
- const AddHyperLinkCommand = {
19
- type: CommandType.COMMAND,
20
- id: "sheets.command.add-hyper-link",
21
- // eslint-disable-next-line max-lines-per-function
22
- async handler(accessor, params) {
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) {
23
67
  var _a15;
24
- if (!params)
25
- return !1;
26
- const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), renderManagerService = accessor.get(IRenderManagerService), univerInstanceService = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), { unitId, subUnitId, link } = params, workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), currentRender = renderManagerService.getRenderById(unitId);
27
- if (!currentRender || !workbook)
28
- return !1;
29
- const worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId), skeleton = (_a15 = currentRender.with(SheetSkeletonManagerService).getCurrent()) == null ? void 0 : _a15.skeleton;
30
- if (!worksheet || !skeleton)
31
- return !1;
32
- const { payload, display, row, column, id } = link, cellData = worksheet.getCell(row, column), doc = skeleton.getBlankCellDocumentModel(cellData), snapshot = doc.documentModel.getSnapshot(), body = snapshot.body;
33
- if (!body)
34
- return !1;
35
- let textX;
36
- if (display ? textX = BuildTextUtils.selection.replace({
37
- selection: {
38
- startOffset: 0,
39
- endOffset: body.dataStream.length - 2,
40
- collapsed: !0
41
- },
42
- body: {
43
- dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
44
- customRanges: [{
45
- startIndex: 0,
46
- endIndex: display.length + 1,
47
- rangeType: CustomRangeType.HYPERLINK,
48
- rangeId: id,
49
- properties: {
50
- url: payload
51
- // refId: id,
52
- }
53
- }]
54
- },
55
- doc: doc.documentModel
56
- }) : textX = BuildTextUtils.customRange.add({
57
- body,
58
- range: { startOffset: 0, endOffset: body.dataStream.length - 2, collapsed: !1 },
59
- rangeId: id,
60
- rangeType: CustomRangeType.HYPERLINK,
61
- properties: {
62
- url: payload,
63
- refId: id
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;
64
109
  }
65
- }), !textX)
66
- return !1;
67
- const newBody = TextX.apply(body, textX.serialize()), rangeValue = {
68
- ...snapshot,
69
- body: newBody
70
- }, redoParams = {
71
- unitId,
72
- subUnitId,
73
- cellValue: {
74
- [link.row]: {
75
- [link.column]: {
76
- p: rangeValue,
77
- t: CellValueType.STRING
78
- }
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
+ }]
79
157
  }
80
- }
81
- }, redo = {
82
- id: SetRangeValuesMutation.id,
83
- params: redoParams
84
- }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redoParams), undo = {
85
- id: SetRangeValuesMutation.id,
86
- params: undoParams
87
- }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
88
- return modelLink && (redos.push({
89
- id: RemoveHyperLinkMutation.id,
90
- params: {
91
- unitId,
92
- subUnitId,
93
- id: modelLink.id
94
- }
95
- }), undos.push({
96
- id: AddHyperLinkMutation.id,
97
- params: {
98
- unitId,
99
- subUnitId,
100
- link: modelLink
101
- }
102
- })), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
103
- redoMutations: redos,
104
- undoMutations: undos,
105
- unitID: unitId
106
- }), !0) : !1;
158
+ ), await this._commandService.executeCommand(ScrollToRangeOperation.id, {
159
+ range: realRange
160
+ });
161
+ }
107
162
  }
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())
163
+ async navigateToSheet(unitId, sheetName) {
164
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
165
+ if (!workbook)
116
166
  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)))
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)
150
187
  return !1;
151
- const textX = BuildTextUtils.customRange.delete(accessor, { documentDataModel: doc.documentModel, rangeId: id });
152
- if (!textX)
188
+ const worksheet = workbook.getActiveSheet();
189
+ if (!worksheet)
153
190
  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
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();
177
233
  });
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({
196
- redoMutations: redos,
197
- undoMutations: undos,
198
- unitID: unitId
199
- }), !0) : !1;
200
234
  }
201
- }, CancelRichHyperLinkCommand = {
202
- type: CommandType.COMMAND,
203
- id: "sheets.command.cancel-rich-hyper-link",
204
- handler(accessor, params) {
205
- var _a15, _b;
206
- if (!params)
207
- return !1;
208
- 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);
209
- let insert = null;
210
- link && link.endIndex === doc.getBody().dataStream.length - 3 && (insert = {
211
- dataStream: " "
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
212
279
  });
213
- const doMutation = deleteCustomRangeFactory(accessor, { unitId: documentId, rangeId: linkId, insert });
214
- return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
215
280
  }
216
- }, UpdateHyperLinkCommand = {
217
- type: CommandType.COMMAND,
218
- id: "sheets.command.update-hyper-link",
219
- // eslint-disable-next-line max-lines-per-function, complexity
220
- async handler(accessor, params) {
221
- var _a15, _b, _c, _d;
222
- if (!params)
223
- return !1;
224
- const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), renderManagerService = accessor.get(IRenderManagerService), univerInstanceService = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), { unitId, subUnitId, payload: link, row, column, id } = params, workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), currentRender = renderManagerService.getRenderById(unitId);
225
- if (!currentRender || !workbook)
226
- return !1;
227
- const worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId), skeleton = (_a15 = currentRender.with(SheetSkeletonManagerService).getCurrent()) == null ? void 0 : _a15.skeleton;
228
- if (!worksheet || !skeleton)
229
- return !1;
230
- const { payload, display = "" } = link, cellData = worksheet.getCell(row, column);
231
- if (!cellData)
232
- return !1;
233
- const doc = skeleton.getCellDocumentModelWithFormula(cellData);
234
- if (!(doc != null && doc.documentModel))
235
- return !1;
236
- const snapshot = doc.documentModel.getSnapshot(), range = (_c = (_b = snapshot.body) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((range2) => range2.rangeId === id);
237
- if (!range)
238
- return !1;
239
- const newId = generateRandomId(), textRun = (_d = getBodySlice(doc.documentModel.getBody(), range.startIndex, range.endIndex + 1).textRuns) == null ? void 0 : _d[0];
240
- textRun && (textRun.ed = display.length + 1);
241
- const replaceSelection = replaceSelectionFactory(accessor, {
281
+ _collect(unitId, subUnitId, range) {
282
+ const matrix = new ObjectMatrix();
283
+ this._copyInfo = {
242
284
  unitId,
243
- body: {
244
- dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
245
- customRanges: [{
246
- rangeId: newId,
247
- rangeType: CustomRangeType.HYPERLINK,
248
- startIndex: 0,
249
- endIndex: display.length + 1,
250
- properties: {
251
- url: payload
252
- }
253
- }],
254
- textRuns: textRun ? [textRun] : void 0
255
- },
256
- selection: {
257
- startOffset: range.startIndex,
258
- endOffset: range.endIndex + 1,
259
- collapsed: !1
260
- },
261
- doc: doc.documentModel
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
+ });
262
298
  });
263
- if (!replaceSelection)
264
- return !1;
265
- const newBody = TextX.apply(snapshot.body, replaceSelection.textX.serialize()), redo = {
266
- id: SetRangeValuesMutation.id,
267
- params: {
268
- unitId,
269
- subUnitId,
270
- cellValue: {
271
- [row]: {
272
- [column]: {
273
- p: {
274
- ...snapshot,
275
- body: newBody
276
- },
277
- t: CellValueType.STRING
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
278
345
  }
279
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;
397
+ const AddHyperLinkCommand = {
398
+ type: CommandType.COMMAND,
399
+ id: "sheets.command.add-hyper-link",
400
+ // eslint-disable-next-line max-lines-per-function
401
+ async handler(accessor, params) {
402
+ var _a15;
403
+ if (!params)
404
+ return !1;
405
+ const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), renderManagerService = accessor.get(IRenderManagerService), univerInstanceService = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), { unitId, subUnitId, link } = params, workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), currentRender = renderManagerService.getRenderById(unitId);
406
+ if (!currentRender || !workbook)
407
+ return !1;
408
+ const worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId), skeleton = (_a15 = currentRender.with(SheetSkeletonManagerService).getCurrent()) == null ? void 0 : _a15.skeleton;
409
+ if (!worksheet || !skeleton)
410
+ return !1;
411
+ const { payload, display, row, column, id } = link, cellData = worksheet.getCell(row, column), doc = skeleton.getBlankCellDocumentModel(cellData), snapshot = doc.documentModel.getSnapshot(), body = Tools.deepClone(snapshot.body);
412
+ if (!body)
413
+ return !1;
414
+ let textX;
415
+ if (display ? textX = BuildTextUtils.selection.replace({
416
+ selection: {
417
+ startOffset: 0,
418
+ endOffset: body.dataStream.length - 2,
419
+ collapsed: !0
420
+ },
421
+ body: {
422
+ dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
423
+ customRanges: [{
424
+ startIndex: 0,
425
+ endIndex: display.length + 1,
426
+ rangeType: CustomRangeType.HYPERLINK,
427
+ rangeId: id,
428
+ properties: {
429
+ url: payload
430
+ // refId: id,
431
+ }
432
+ }]
433
+ },
434
+ doc: doc.documentModel
435
+ }) : textX = BuildTextUtils.customRange.add({
436
+ body,
437
+ range: { startOffset: 0, endOffset: body.dataStream.length - 2, collapsed: !1 },
438
+ rangeId: id,
439
+ rangeType: CustomRangeType.HYPERLINK,
440
+ properties: {
441
+ url: payload,
442
+ refId: id
443
+ }
444
+ }), !textX)
445
+ return !1;
446
+ const newBody = TextX.apply(body, textX.serialize()), rangeValue = {
447
+ ...snapshot,
448
+ body: newBody
449
+ }, redoParams = {
450
+ unitId,
451
+ subUnitId,
452
+ cellValue: {
453
+ [link.row]: {
454
+ [link.column]: {
455
+ p: rangeValue,
456
+ t: CellValueType.STRING
457
+ }
280
458
  }
281
459
  }
282
- }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redo.params), undo = {
460
+ }, redo = {
461
+ id: SetRangeValuesMutation.id,
462
+ params: redoParams
463
+ }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redoParams), undo = {
283
464
  id: SetRangeValuesMutation.id,
284
465
  params: undoParams
285
466
  }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
@@ -303,480 +484,156 @@ const AddHyperLinkCommand = {
303
484
  unitID: unitId
304
485
  }), !0) : !1;
305
486
  }
306
- }, UpdateRichHyperLinkCommand = {
487
+ }, AddRichHyperLinkCommand = {
488
+ id: "sheets.command.add-rich-hyper-link",
307
489
  type: CommandType.COMMAND,
308
- id: "sheets.command.update-rich-hyper-link",
309
- handler: /* @__PURE__ */ __name((accessor, params) => {
310
- var _a15, _b, _c, _d;
490
+ handler: /* @__PURE__ */ __name(async (accessor, params) => {
311
491
  if (!params)
312
492
  return !1;
313
- const { documentId: unitId, payload, id: rangeId } = params, univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
314
- if (!doc)
315
- return !1;
316
- const range = (_b = (_a15 = doc.getBody()) == null ? void 0 : _a15.customRanges) == null ? void 0 : _b.find((range2) => range2.rangeId === rangeId);
317
- if (!range)
493
+ const { documentId, link } = params, commandService = accessor.get(ICommandService), textSelectionService = accessor.get(DocSelectionManagerService), newId = generateRandomId(), { payload } = link;
494
+ if (!textSelectionService.getActiveTextRange())
318
495
  return !1;
319
- 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];
320
- textRun && (textRun.ed = display.length + 1);
321
- const replaceSelection = replaceSelectionFactory(accessor, {
322
- unitId,
323
- body: {
324
- dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
325
- customRanges: [{
326
- rangeId: newId,
327
- rangeType: CustomRangeType.HYPERLINK,
328
- startIndex: 0,
329
- endIndex: display.length + 1,
330
- properties: {
331
- url: payload.payload
332
- }
333
- }],
334
- textRuns: textRun ? [textRun] : void 0
335
- },
336
- selection: {
337
- startOffset: range.startIndex,
338
- endOffset: range.endIndex + 1,
339
- collapsed: !1
340
- },
341
- doc
496
+ const replaceSelection = addCustomRangeBySelectionFactory(accessor, {
497
+ unitId: documentId,
498
+ rangeId: newId,
499
+ rangeType: CustomRangeType.HYPERLINK,
500
+ properties: {
501
+ url: payload,
502
+ refId: newId
503
+ }
342
504
  });
343
505
  return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
344
506
  }, "handler")
345
- };
346
- var 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, __assign = function() {
370
- return __assign = Object.assign || function(t) {
371
- for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
372
- s = arguments[i];
373
- for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && (t[p2] = s[p2]);
374
- }
375
- return t;
376
- }, __assign.apply(this, arguments);
377
- }, __rest = function(s, e) {
378
- var t = {};
379
- for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0 && (t[p2] = s[p2]);
380
- if (s != null && typeof Object.getOwnPropertySymbols == "function")
381
- for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++)
382
- e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]) && (t[p2[i]] = s[p2[i]]);
383
- return t;
384
- }, IconBase = forwardRef(function(props, ref) {
385
- var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
386
- return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
387
- });
388
- function render(node, id, runtimeProps, rootProps, extend) {
389
- return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
390
- return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
391
- }));
392
- }
393
- __name(render, "render");
394
- function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
395
- var attrs = __assign({}, node.attrs);
396
- extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
397
- var defIds = runtimeProps.defIds;
398
- return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a15) {
399
- var key = _a15[0], value = _a15[1];
400
- typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
401
- })), attrs;
402
- }
403
- __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
404
- function replaceRuntimeIdsInDefs(node, runtimeProps) {
405
- var _a15, defIds = runtimeProps.defIds;
406
- return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a15 = node.children) === null || _a15 === void 0) && _a15.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
407
- return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
408
- }) }) : node;
409
- }
410
- __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
411
- function generateShortUuid() {
412
- return Math.random().toString(36).substring(2, 8);
413
- }
414
- __name(generateShortUuid, "generateShortUuid");
415
- IconBase.displayName = "UniverIcon";
416
- var element$5 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M7.9999 1.12915C8.03875 1.12915 8.07673 1.13284 8.11352 1.13989H12.2599C13.6958 1.13989 14.8599 2.30395 14.8599 3.73989V7.88619C14.867 7.92301 14.8707 7.96102 14.8707 7.9999C14.8707 8.03878 14.867 8.0768 14.8599 8.11362V12.2599C14.8599 13.6958 13.6958 14.8599 12.2599 14.8599H8.11362C8.0768 14.867 8.03878 14.8707 7.9999 14.8707C7.96102 14.8707 7.92301 14.867 7.88619 14.8599H3.73989C2.30396 14.8599 1.13989 13.6958 1.13989 12.2599V8.11352C1.13284 8.07673 1.12915 8.03875 1.12915 7.9999C1.12915 7.96106 1.13284 7.92308 1.13989 7.88629V3.73989C1.13989 2.30396 2.30395 1.13989 3.73989 1.13989H7.88629C7.92308 1.13284 7.96106 1.12915 7.9999 1.12915ZM2.33989 8.5999V12.2599C2.33989 13.0331 2.9667 13.6599 3.73989 13.6599H7.3999V8.5999H2.33989ZM7.3999 7.3999H2.33989V3.73989C2.33989 2.9667 2.96669 2.33989 3.73989 2.33989H7.3999V7.3999ZM8.5999 8.5999V13.6599H12.2599C13.0331 13.6599 13.6599 13.0331 13.6599 12.2599V8.5999H8.5999ZM13.6599 7.3999H8.5999V2.33989H12.2599C13.0331 2.33989 13.6599 2.96669 13.6599 3.73989V7.3999Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, AllBorderSingle = forwardRef(function(props, ref) {
417
- return createElement(IconBase, Object.assign({}, props, {
418
- id: "all-border-single",
419
- ref,
420
- icon: element$5
421
- }));
422
- });
423
- AllBorderSingle.displayName = "AllBorderSingle";
424
- var element$4 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, CopySingle = forwardRef(function(props, ref) {
425
- return createElement(IconBase, Object.assign({}, props, {
426
- id: "copy-single",
427
- ref,
428
- icon: element$4
429
- }));
430
- });
431
- CopySingle.displayName = "CopySingle";
432
- var element$3 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.9564 2.91332C4.91407 1.87102 3.22413 1.87101 2.18182 2.91333L2.18182 2.91333C1.13953 3.95567 1.13952 5.6456 2.18182 6.68791L8.27777 12.7838C9.72408 14.2302 12.069 14.2302 13.5154 12.7839L13.0911 12.3596L13.5154 12.7839C14.9617 11.3375 14.9617 8.99257 13.5154 7.54626L8.39476 2.42566C8.16044 2.19134 7.78054 2.19134 7.54623 2.42566C7.31191 2.65997 7.31191 3.03987 7.54623 3.27419L12.6668 8.39479L13.0911 7.97052L12.6668 8.39479C13.6445 9.37247 13.6445 10.9576 12.6668 11.9353L13.0399 12.3084L12.6668 11.9353C11.6891 12.913 10.104 12.913 9.1263 11.9353L3.03035 5.83938C2.45668 5.26571 2.45667 4.33556 3.03036 3.76184C3.60403 3.18818 4.53416 3.18817 5.10788 3.76185C5.10788 3.76186 5.10788 3.76186 5.10789 3.76186L11.2038 9.8578L11.601 9.46061L11.2038 9.8578C11.3735 10.0275 11.3735 10.3026 11.2038 10.4723L11.2038 10.4723C11.0341 10.642 10.759 10.642 10.5893 10.4723L5.46874 5.35171C5.23442 5.1174 4.85452 5.1174 4.62021 5.35171C4.38589 5.58602 4.38589 5.96592 4.62021 6.20024L9.74078 11.3208C10.3791 11.9591 11.414 11.9591 12.0523 11.3208C12.0523 11.3208 12.0523 11.3208 12.0523 11.3208M12.0523 11.3208C12.6907 10.6825 12.6906 9.64757 12.0523 9.00927L5.95641 2.91333L5.9564 2.91332", fillRule: "evenodd", clipRule: "evenodd" } }] }, LinkSingle = forwardRef(function(props, ref) {
433
- return createElement(IconBase, Object.assign({}, props, {
434
- id: "link-single",
435
- ref,
436
- icon: element$3
437
- }));
438
- });
439
- LinkSingle.displayName = "LinkSingle";
440
- var element$2 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 17", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157 6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449 14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797 11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302zM3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395 4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092 3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721 8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606zM3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332 2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302 13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332z" } }] }, UnlinkSingle = forwardRef(function(props, ref) {
441
- return createElement(IconBase, Object.assign({}, props, {
442
- id: "unlink-single",
443
- ref,
444
- icon: element$2
445
- }));
446
- });
447
- UnlinkSingle.displayName = "UnlinkSingle";
448
- var element$1 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z" } }] }, WriteSingle = forwardRef(function(props, ref) {
449
- return createElement(IconBase, Object.assign({}, props, {
450
- id: "write-single",
451
- ref,
452
- icon: element$1
453
- }));
454
- });
455
- WriteSingle.displayName = "WriteSingle";
456
- var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "#35BD4B", d: "M3.4535 1.12549C2.7002 1.12549 2.08954 1.73615 2.08954 2.48945V13.5104C2.08954 14.2637 2.7002 14.8744 3.4535 14.8744H12.5465C13.2998 14.8744 13.9105 14.2637 13.9105 13.5104V5.0992L10.0091 1.12549H3.4535Z" } }, { tag: "path", attrs: { fill: "#32A846", d: "M10.0075 1.12549L13.9104 5.09842H10.6742C10.306 5.09842 10.0075 4.79994 10.0075 4.43175V1.12549Z" } }, { tag: "path", attrs: { fill: "#fff", d: "M7.8088 10.2949L6.3764 12.403C6.26259 12.5705 6.03455 12.614 5.86705 12.5002C5.69955 12.3864 5.65603 12.1584 5.76984 11.9909L7.3655 9.64252L5.94042 7.54519C5.82661 7.37769 5.87013 7.14964 6.03763 7.03583C6.20512 6.92202 6.43317 6.96555 6.54698 7.13304L7.8088 8.9901L9.07062 7.13304C9.18443 6.96555 9.41248 6.92202 9.57997 7.03583C9.74747 7.14964 9.79099 7.37769 9.67718 7.54519L8.2521 9.64252L9.84776 11.9909C9.96157 12.1584 9.91805 12.3864 9.75055 12.5002C9.58305 12.614 9.35501 12.5705 9.2412 12.403L7.8088 10.2949Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Xlsx = forwardRef(function(props, ref) {
457
- return createElement(IconBase, Object.assign({}, props, {
458
- id: "xlsx",
459
- ref,
460
- icon: element
461
- }));
462
- });
463
- Xlsx.displayName = "Xlsx";
464
- const PLUGIN_CONFIG_KEY = "sheets-hyper-link-ui.config", defaultPluginConfig = {};
465
- var __defProp$c = Object.defineProperty, __getOwnPropDesc$c = Object.getOwnPropertyDescriptor, __decorateClass$c = /* @__PURE__ */ __name((decorators, target, key, kind) => {
466
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$c(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
467
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
468
- return kind && result && __defProp$c(target, key, result), result;
469
- }, "__decorateClass$c"), __decorateParam$c = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$c");
470
- function getContainRange(range, worksheet) {
471
- const mergedCells = worksheet.getMergeData(), maxCol = worksheet.getMaxColumns() - 1, maxRow = worksheet.getMaxRows() - 1;
472
- if (maxCol < range.endColumn && (range.endColumn = maxCol), maxRow < range.endRow && (range.endRow = maxRow), range.rangeType === RANGE_TYPE.COLUMN || RANGE_TYPE.ROW)
473
- return range;
474
- const relativeCells = [];
475
- return mergedCells.forEach((cell) => {
476
- Rectangle.intersects(range, cell) && relativeCells.push(cell);
477
- }), Rectangle.realUnion(range, ...relativeCells);
478
- }
479
- __name(getContainRange, "getContainRange");
480
- var _a;
481
- let SheetsHyperLinkResolverService = (_a = class {
482
- constructor(_univerInstanceService, _commandService, _definedNamesService, _messageService, _localeService, _configService) {
483
- this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._definedNamesService = _definedNamesService, this._messageService = _messageService, this._localeService = _localeService, this._configService = _configService;
484
- }
485
- _getURLName(params) {
486
- var _a15;
487
- const { gid, range, rangeid, unitid } = params, workbook = unitid ? this._univerInstanceService.getUnit(unitid, UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), invalidLink = {
488
- type: SheetHyperLinkType.INVALID,
489
- name: this._localeService.t("hyperLink.message.refError")
490
- };
491
- if (!workbook)
492
- return invalidLink;
493
- const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet(), sheetName = (_a15 = sheet == null ? void 0 : sheet.getName()) != null ? _a15 : "";
494
- if (range) {
495
- if (!sheet) return invalidLink;
496
- const rangeObj = deserializeRangeWithSheet(range).range;
497
- return isValidRange(rangeObj, sheet) && range !== ERROR_RANGE ? {
498
- type: SheetHyperLinkType.RANGE,
499
- name: serializeRangeWithSheet(sheetName, rangeObj)
500
- } : invalidLink;
501
- }
502
- if (rangeid) {
503
- const range2 = this._definedNamesService.getValueById(workbook.getUnitId(), rangeid);
504
- return range2 ? {
505
- type: SheetHyperLinkType.DEFINE_NAME,
506
- name: range2.formulaOrRefString
507
- } : invalidLink;
508
- }
509
- if (gid) {
510
- const worksheet = workbook.getSheetBySheetId(gid);
511
- return worksheet ? {
512
- type: SheetHyperLinkType.SHEET,
513
- name: worksheet.getName()
514
- } : invalidLink;
515
- }
516
- return invalidLink;
517
- }
518
- navigateTo(params) {
519
- const { gid, range, rangeid } = params, workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
520
- if (!workbook)
521
- return;
522
- const unitId = workbook.getUnitId();
523
- if (rangeid && this.navigateToDefineName(unitId, rangeid), !!gid) {
524
- if (range) {
525
- const rangeInfo = deserializeRangeWithSheet(range);
526
- isValidRange(rangeInfo.range) && range !== ERROR_RANGE && this.navigateToRange(unitId, gid, rangeInfo.range);
527
- return;
528
- }
529
- this.navigateToSheetById(unitId, gid);
530
- }
531
- }
532
- buildHyperLink(unitId, sheetId, range) {
533
- return `#${SheetHyperLinkType.SHEET}=${sheetId}}${range ? `${typeof range == "string" ? SheetHyperLinkType.DEFINE_NAME : SheetHyperLinkType.RANGE}=${typeof range == "string" ? range : serializeRange(range)}` : ""}`;
534
- }
535
- parseHyperLink(urlStr) {
507
+ }, UpdateHyperLinkCommand = {
508
+ type: CommandType.COMMAND,
509
+ id: "sheets.command.update-hyper-link",
510
+ // eslint-disable-next-line max-lines-per-function, complexity
511
+ async handler(accessor, params) {
536
512
  var _a15, _b, _c, _d;
537
- if (urlStr.startsWith("#")) {
538
- const search = new URLSearchParams(urlStr.slice(1)), searchObj = {
539
- gid: (_a15 = search.get("gid")) != null ? _a15 : "",
540
- range: (_b = search.get("range")) != null ? _b : "",
541
- rangeid: (_c = search.get("rangeid")) != null ? _c : "",
542
- unitid: (_d = search.get("unitid")) != null ? _d : ""
543
- }, urlInfo = this._getURLName(searchObj);
544
- return {
545
- type: urlInfo.type,
546
- name: urlInfo.name,
547
- url: urlStr,
548
- searchObj,
549
- handler: /* @__PURE__ */ __name(() => {
550
- this.navigateTo(searchObj);
551
- }, "handler")
552
- };
553
- } else
554
- return {
555
- type: SheetHyperLinkType.URL,
556
- name: urlStr,
557
- url: urlStr,
558
- handler: /* @__PURE__ */ __name(() => {
559
- this.navigateToOtherWebsite(urlStr);
560
- }, "handler"),
561
- searchObj: null
562
- };
563
- }
564
- async navigateToRange(unitId, subUnitId, range) {
565
- const worksheet = await this.navigateToSheetById(unitId, subUnitId);
566
- if (worksheet) {
567
- const realRange = getContainRange(range, worksheet);
568
- await this._commandService.executeCommand(
569
- SetSelectionsOperation.id,
570
- {
571
- unitId,
572
- subUnitId,
573
- selections: [{
574
- range: realRange
575
- }]
576
- }
577
- ), await this._commandService.executeCommand(ScrollToRangeOperation.id, {
578
- range: realRange
579
- });
580
- }
581
- }
582
- async navigateToSheet(unitId, sheetName) {
583
- const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
584
- if (!workbook)
513
+ if (!params)
585
514
  return !1;
586
- const worksheet = workbook.getActiveSheet();
587
- if ((worksheet == null ? void 0 : worksheet.getName()) === sheetName)
588
- return !0;
589
- const targetSheet = workbook.getSheetBySheetName(sheetName);
590
- if (!targetSheet) {
591
- this._messageService.show({
592
- content: this._localeService.t("hyperLink.message.noSheet"),
593
- type: MessageType.Error
594
- });
595
- return;
596
- }
597
- const sheetId = targetSheet.getSheetId();
598
- return workbook.getHiddenWorksheets().indexOf(sheetId) > -1 && this._messageService.show({
599
- content: this._localeService.t("hyperLink.message.hiddenSheet"),
600
- type: MessageType.Error
601
- }), await this._commandService.executeCommand(SetWorksheetActiveOperation.id, { unitId, subUnitId: sheetId });
602
- }
603
- async navigateToSheetById(unitId, subUnitId) {
604
- const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
605
- if (!workbook)
515
+ const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), renderManagerService = accessor.get(IRenderManagerService), univerInstanceService = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), { unitId, subUnitId, payload: link, row, column, id } = params, workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), currentRender = renderManagerService.getRenderById(unitId);
516
+ if (!currentRender || !workbook)
517
+ return !1;
518
+ const worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId), skeleton = (_a15 = currentRender.with(SheetSkeletonManagerService).getCurrent()) == null ? void 0 : _a15.skeleton;
519
+ if (!worksheet || !skeleton)
520
+ return !1;
521
+ const { payload, display = "" } = link, cellData = worksheet.getCell(row, column);
522
+ if (!cellData)
606
523
  return !1;
607
- const worksheet = workbook.getActiveSheet();
608
- if (!worksheet)
524
+ const doc = skeleton.getCellDocumentModelWithFormula(cellData);
525
+ if (!(doc != null && doc.documentModel))
609
526
  return !1;
610
- if (worksheet.getSheetId() === subUnitId)
611
- return worksheet;
612
- const targetSheet = workbook.getSheetBySheetId(subUnitId);
613
- return targetSheet ? workbook.getHiddenWorksheets().indexOf(subUnitId) > -1 ? (this._messageService.show({
614
- content: this._localeService.t("hyperLink.message.hiddenSheet"),
615
- type: MessageType.Error
616
- }), !1) : await this._commandService.executeCommand(SetWorksheetActiveOperation.id, { unitId, subUnitId }) ? targetSheet : !1 : (this._messageService.show({
617
- content: this._localeService.t("hyperLink.message.noSheet"),
618
- type: MessageType.Error
619
- }), !1);
620
- }
621
- async navigateToDefineName(unitId, rangeid) {
622
- return this._definedNamesService.focusRange(unitId, rangeid), !0;
623
- }
624
- async navigateToOtherWebsite(url) {
625
- var _a15;
626
- const config = this._configService.getConfig(PLUGIN_CONFIG_KEY);
627
- if ((_a15 = config == null ? void 0 : config.urlHandler) != null && _a15.navigateToOtherWebsite)
628
- return config.urlHandler.navigateToOtherWebsite(url);
629
- window.open(url, "_blank", "noopener noreferrer");
630
- }
631
- }, __name(_a, "SheetsHyperLinkResolverService"), _a);
632
- SheetsHyperLinkResolverService = __decorateClass$c([
633
- __decorateParam$c(0, IUniverInstanceService),
634
- __decorateParam$c(1, ICommandService),
635
- __decorateParam$c(2, IDefinedNamesService),
636
- __decorateParam$c(3, IMessageService),
637
- __decorateParam$c(4, Inject(LocaleService)),
638
- __decorateParam$c(5, IConfigService)
639
- ], SheetsHyperLinkResolverService);
640
- var HyperLinkEditSourceType = /* @__PURE__ */ ((HyperLinkEditSourceType2) => (HyperLinkEditSourceType2.EDITING = "editing", HyperLinkEditSourceType2.VIEWING = "viewing", HyperLinkEditSourceType2.ZEN_EDITOR = "zen_mode", HyperLinkEditSourceType2))(HyperLinkEditSourceType || {});
641
- const 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$1 = {
642
- cellLink,
643
- cellLinkType,
644
- cellLinkContent,
645
- cellLinkContentError,
646
- cellLinkUrl,
647
- cellLinkOperations,
648
- cellLinkOperation,
649
- cellLinkOperationError
650
- }, iconsMap = {
651
- [SheetHyperLinkType.URL]: /* @__PURE__ */ jsxRuntimeExports.jsx(LinkSingle, {}),
652
- [SheetHyperLinkType.SHEET]: /* @__PURE__ */ jsxRuntimeExports.jsx(Xlsx, {}),
653
- [SheetHyperLinkType.RANGE]: /* @__PURE__ */ jsxRuntimeExports.jsx(AllBorderSingle, {}),
654
- [SheetHyperLinkType.DEFINE_NAME]: /* @__PURE__ */ jsxRuntimeExports.jsx(AllBorderSingle, {}),
655
- [SheetHyperLinkType.INVALID]: /* @__PURE__ */ jsxRuntimeExports.jsx(AllBorderSingle, {})
656
- }, CellLinkPopup = /* @__PURE__ */ __name(() => {
657
- var _a15, _b;
658
- const popupService = useDependency(SheetsHyperLinkPopupService), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService), [currentPopup, setCurrentPopup] = useState(null), resolverService = useDependency(SheetsHyperLinkResolverService), editorBridgeService = useDependency(IEditorBridgeService);
659
- if (useEffect(() => {
660
- setCurrentPopup(popupService.currentPopup);
661
- const ob = popupService.currentPopup$.subscribe((popup) => {
662
- setCurrentPopup(popup);
527
+ const snapshot = doc.documentModel.getSnapshot(), range = (_c = (_b = snapshot.body) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((range2) => range2.rangeId === id);
528
+ if (!range)
529
+ return !1;
530
+ const newId = generateRandomId(), textRun = (_d = getBodySlice(doc.documentModel.getBody(), range.startIndex, range.endIndex + 1).textRuns) == null ? void 0 : _d[0];
531
+ textRun && (textRun.ed = display.length + 1);
532
+ const replaceSelection = replaceSelectionFactory(accessor, {
533
+ unitId,
534
+ body: {
535
+ dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
536
+ customRanges: [{
537
+ rangeId: newId,
538
+ rangeType: CustomRangeType.HYPERLINK,
539
+ startIndex: 0,
540
+ endIndex: display.length + 1,
541
+ properties: {
542
+ url: payload
543
+ }
544
+ }],
545
+ textRuns: textRun ? [textRun] : void 0
546
+ },
547
+ selection: {
548
+ startOffset: range.startIndex,
549
+ endOffset: range.endIndex + 1,
550
+ collapsed: !1
551
+ },
552
+ doc: doc.documentModel
663
553
  });
664
- return () => {
665
- ob.unsubscribe();
666
- };
667
- }, [popupService.currentPopup, popupService.currentPopup$]), !currentPopup)
668
- return null;
669
- const { unitId, subUnitId, customRange, row, col } = currentPopup;
670
- if (!((_a15 = customRange == null ? void 0 : customRange.properties) != null && _a15.url))
671
- return null;
672
- const linkObj = resolverService.parseHyperLink((_b = customRange.properties.url) != null ? _b : ""), isError = linkObj.type === SheetHyperLinkType.INVALID;
673
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.cellLink, onClick: /* @__PURE__ */ __name(() => popupService.hideCurrentPopup(), "onClick"), children: [
674
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cs(styles$1.cellLinkContent, { [styles$1.cellLinkContentError]: isError }), onClick: linkObj.handler, children: [
675
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles$1.cellLinkType, children: iconsMap[linkObj.type] }),
676
- /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { showIfEllipsis: !0, title: linkObj.name, children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: styles$1.cellLinkUrl, children: linkObj.name }) })
677
- ] }),
678
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.cellLinkOperations, children: [
679
- currentPopup.copyPermission && /* @__PURE__ */ jsxRuntimeExports.jsx(
680
- "div",
681
- {
682
- className: cs(styles$1.cellLinkOperation, { [styles$1.cellLinkOperationError]: isError }),
683
- onClick: /* @__PURE__ */ __name(() => {
684
- if (!isError) {
685
- if (linkObj.type !== SheetHyperLinkType.URL) {
686
- const url = new URL(window.location.href);
687
- url.hash = linkObj.url.slice(1), navigator.clipboard.writeText(url.href);
688
- } else
689
- navigator.clipboard.writeText(linkObj.url);
690
- messageService.show({
691
- content: localeService.t("hyperLink.message.coped"),
692
- type: MessageType.Info
693
- });
554
+ if (!replaceSelection)
555
+ return !1;
556
+ const newBody = TextX.apply(Tools.deepClone(snapshot.body), replaceSelection.textX.serialize()), redo = {
557
+ id: SetRangeValuesMutation.id,
558
+ params: {
559
+ unitId,
560
+ subUnitId,
561
+ cellValue: {
562
+ [row]: {
563
+ [column]: {
564
+ p: {
565
+ ...snapshot,
566
+ body: newBody
567
+ },
568
+ t: CellValueType.STRING
694
569
  }
695
- }, "onClick"),
696
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { placement: "bottom", title: localeService.t("hyperLink.popup.copy"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(CopySingle, {}) })
697
- }
698
- ),
699
- currentPopup.editPermission && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
700
- /* @__PURE__ */ jsxRuntimeExports.jsx(
701
- "div",
702
- {
703
- className: styles$1.cellLinkOperation,
704
- onClick: /* @__PURE__ */ __name(() => {
705
- commandService.executeCommand(OpenHyperLinkEditPanelOperation.id, {
706
- unitId,
707
- subUnitId,
708
- row,
709
- col,
710
- customRangeId: customRange.rangeId,
711
- type: currentPopup.type
712
- });
713
- }, "onClick"),
714
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { placement: "bottom", title: localeService.t("hyperLink.popup.edit"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(WriteSingle, {}) })
715
- }
716
- ),
717
- /* @__PURE__ */ jsxRuntimeExports.jsx(
718
- "div",
719
- {
720
- className: styles$1.cellLinkOperation,
721
- onClick: /* @__PURE__ */ __name(() => {
722
- const commandId = currentPopup.type === HyperLinkEditSourceType.EDITING || currentPopup.type === HyperLinkEditSourceType.ZEN_EDITOR ? CancelRichHyperLinkCommand.id : CancelHyperLinkCommand.id;
723
- commandService.syncExecuteCommand(commandId, {
724
- unitId,
725
- subUnitId,
726
- id: customRange.rangeId,
727
- row,
728
- column: col,
729
- documentId: currentPopup.type === HyperLinkEditSourceType.ZEN_EDITOR ? DOCS_ZEN_EDITOR_UNIT_ID_KEY : editorBridgeService.getCurrentEditorId()
730
- }) && popupService.hideCurrentPopup(void 0, !0);
731
- }, "onClick"),
732
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { placement: "bottom", title: localeService.t("hyperLink.popup.cancel"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(UnlinkSingle, {}) })
733
570
  }
734
- )
735
- ] })
736
- ] })
737
- ] });
738
- }, "CellLinkPopup");
739
- CellLinkPopup.componentKey = "univer.sheet.cell-link-popup";
740
- function isLegalLink(link) {
741
- return Tools.isLegalUrl(link);
742
- }
743
- __name(isLegalLink, "isLegalLink");
744
- function hasProtocol(urlString) {
745
- return /^[a-zA-Z]+:\/\//.test(urlString);
746
- }
747
- __name(hasProtocol, "hasProtocol");
748
- function isEmail(url) {
749
- return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
750
- }
751
- __name(isEmail, "isEmail");
752
- function serializeUrl(urlStr) {
753
- if (isLegalLink(urlStr)) {
754
- const transformedUrl = hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `http://${urlStr}`;
755
- let url;
756
- try {
757
- url = new URL(transformedUrl);
758
- } catch {
759
- return urlStr;
760
- }
761
- return url.hostname === location.hostname && url.port === location.port && url.protocol === location.protocol && url.pathname === location.pathname && url.hash && !url.search ? url.hash : transformedUrl;
571
+ }
572
+ }
573
+ }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redo.params), undo = {
574
+ id: SetRangeValuesMutation.id,
575
+ params: undoParams
576
+ }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
577
+ return modelLink && (redos.push({
578
+ id: RemoveHyperLinkMutation.id,
579
+ params: {
580
+ unitId,
581
+ subUnitId,
582
+ id: modelLink.id
583
+ }
584
+ }), undos.push({
585
+ id: AddHyperLinkMutation.id,
586
+ params: {
587
+ unitId,
588
+ subUnitId,
589
+ link: modelLink
590
+ }
591
+ })), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
592
+ redoMutations: redos,
593
+ undoMutations: undos,
594
+ unitID: unitId
595
+ }), !0) : !1;
762
596
  }
763
- return urlStr;
764
- }
765
- __name(serializeUrl, "serializeUrl");
766
- function getCellValueOrigin(cell) {
767
- if (cell === null)
768
- return "";
769
- if (cell != null && cell.p) {
770
- const body = cell == null ? void 0 : cell.p.body;
771
- if (body == null)
772
- return "";
773
- const data = body.dataStream;
774
- return data.substring(data.length - 2, data.length) === DEFAULT_EMPTY_DOCUMENT_VALUE ? data.substring(0, data.length - 2) : data;
775
- }
776
- return cell == null ? void 0 : cell.v;
777
- }
778
- __name(getCellValueOrigin, "getCellValueOrigin");
779
- const _SheetsHyperLinkSidePanelService = class _SheetsHyperLinkSidePanelService extends Disposable {
597
+ }, UpdateRichHyperLinkCommand = {
598
+ type: CommandType.COMMAND,
599
+ id: "sheets.command.update-rich-hyper-link",
600
+ handler: /* @__PURE__ */ __name((accessor, params) => {
601
+ var _a15, _b, _c, _d;
602
+ if (!params)
603
+ return !1;
604
+ const { documentId: unitId, payload, id: rangeId } = params, univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
605
+ if (!doc)
606
+ return !1;
607
+ const range = (_b = (_a15 = doc.getBody()) == null ? void 0 : _a15.customRanges) == null ? void 0 : _b.find((range2) => range2.rangeId === rangeId);
608
+ if (!range)
609
+ return !1;
610
+ 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];
611
+ textRun && (textRun.ed = display.length + 1);
612
+ const replaceSelection = replaceSelectionFactory(accessor, {
613
+ unitId,
614
+ body: {
615
+ dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
616
+ customRanges: [{
617
+ rangeId: newId,
618
+ rangeType: CustomRangeType.HYPERLINK,
619
+ startIndex: 0,
620
+ endIndex: display.length + 1,
621
+ properties: {
622
+ url: payload.payload
623
+ }
624
+ }],
625
+ textRuns: textRun ? [textRun] : void 0
626
+ },
627
+ selection: {
628
+ startOffset: range.startIndex,
629
+ endOffset: range.endIndex + 1,
630
+ collapsed: !1
631
+ },
632
+ doc
633
+ });
634
+ return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
635
+ }, "handler")
636
+ }, _SheetsHyperLinkSidePanelService = class _SheetsHyperLinkSidePanelService extends Disposable {
780
637
  constructor() {
781
638
  super(...arguments);
782
639
  __publicField(this, "_customHyperLinks", /* @__PURE__ */ new Map());
@@ -806,12 +663,12 @@ const _SheetsHyperLinkSidePanelService = class _SheetsHyperLinkSidePanelService
806
663
  };
807
664
  __name(_SheetsHyperLinkSidePanelService, "SheetsHyperLinkSidePanelService");
808
665
  let SheetsHyperLinkSidePanelService = _SheetsHyperLinkSidePanelService;
809
- const cellLinkEdit = "univer-cell-link-edit", cellLinkEditButtons = "univer-cell-link-edit-buttons", styles = {
666
+ const cellLinkEdit = "univer-cell-link-edit", cellLinkEditButtons = "univer-cell-link-edit-buttons", styles$1 = {
810
667
  cellLinkEdit,
811
668
  cellLinkEditButtons
812
669
  }, CellLinkEdit = /* @__PURE__ */ __name(() => {
813
670
  var _a15;
814
- 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(() => {
815
672
  if (!sidePanelService.isBuiltInLinkType(type))
816
673
  return sidePanelService.getCustomHyperLink(type);
817
674
  }, [sidePanelService, type]), [showError, setShowError] = useState(!1), setByPayload = useRef(!1);
@@ -832,7 +689,7 @@ const cellLinkEdit = "univer-cell-link-edit", cellLinkEditButtons = "univer-cell
832
689
  const workbook2 = univerInstanceService.getUnit(editing.unitId), worksheet = workbook2 == null ? void 0 : workbook2.getSheetBySheetId(editing.subUnitId), cell = worksheet == null ? void 0 : worksheet.getCellRaw(editing.row, editing.col), range = (_f = (_e = (_d = cell == null ? void 0 : cell.p) == null ? void 0 : _d.body) == null ? void 0 : _e.customRanges) == null ? void 0 : _f.find((range2) => {
833
690
  var _a17;
834
691
  return range2.rangeType === CustomRangeType.HYPERLINK && ((_a17 = range2.properties) == null ? void 0 : _a17.url);
835
- }), cellValue = `${(_g = getCellValueOrigin(cell)) != null ? _g : ""}`;
692
+ }), cellValue = `${(_g = getOriginCellValue(cell)) != null ? _g : ""}`;
836
693
  cell && (cell.p || cellValue) && setShowLabel(!1), link = {
837
694
  id: "",
838
695
  display: "",
@@ -885,34 +742,48 @@ const cellLinkEdit = "univer-cell-link-edit", cellLinkEditButtons = "univer-cell
885
742
  }
886
743
  }
887
744
  }, [editing, resolverService, sidePanelService, textSelectionService, univerInstanceService]), useEffect(() => {
888
- let id2 = null;
889
- return editing && editing.type === HyperLinkEditSourceType.VIEWING && Tools.isDefine(editing.row) && Tools.isDefine(editing.col) && (id2 = markSelectionService.addShape(
890
- {
891
- range: {
892
- startColumn: editing.col,
893
- endColumn: editing.col,
894
- startRow: editing.row,
895
- endRow: editing.row
896
- },
897
- style: {
898
- hasAutoFill: !1,
899
- fill: "rgb(255, 189, 55, 0.35)",
900
- strokeWidth: 1,
901
- stroke: "#FFBD37",
902
- widgets: {}
745
+ var _a16;
746
+ let id2 = null;
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
903
765
  },
904
- primary: null
905
- },
906
- [],
907
- -1
908
- )), () => {
766
+ [],
767
+ -1
768
+ );
769
+ }
770
+ return () => {
909
771
  id2 && markSelectionService.removeShape(id2);
910
772
  };
911
773
  }, [editing, markSelectionService]);
912
774
  const payloadInitial = useMemo(() => payload, [type]);
913
- useEffect(() => () => {
914
- editorBridgeService.disableForceKeepVisible();
915
- }, [editorBridgeService]);
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]);
916
787
  const linkTypeOptions = [
917
788
  {
918
789
  label: localeService.t("hyperLink.form.link"),
@@ -1006,7 +877,7 @@ const cellLinkEdit = "univer-cell-link-edit", cellLinkEditButtons = "univer-cell
1006
877
  }
1007
878
  commandService.executeCommand(CloseHyperLinkPopupOperation.id);
1008
879
  }, "handleSubmit");
1009
- return editing ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLinkEdit, style: { display: hide ? "none" : "block" }, children: [
880
+ return editing ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.cellLinkEdit, style: { display: hide ? "none" : "block" }, children: [
1010
881
  showLabel ? /* @__PURE__ */ jsxRuntimeExports.jsx(
1011
882
  FormLayout,
1012
883
  {
@@ -1116,42 +987,324 @@ const cellLinkEdit = "univer-cell-link-edit", cellLinkEditButtons = "univer-cell
1116
987
  setPayload
1117
988
  }
1118
989
  ),
1119
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLinkEditButtons, children: [
990
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.cellLinkEditButtons, children: [
1120
991
  /* @__PURE__ */ jsxRuntimeExports.jsx(
1121
992
  Button,
1122
993
  {
1123
994
  onClick: /* @__PURE__ */ __name(() => {
1124
995
  editing && resolverService.navigateToRange(editing.unitId, editing.subUnitId, { startRow: editing.row, endRow: editing.row, startColumn: editing.col, endColumn: editing.col }), commandService.executeCommand(CloseHyperLinkPopupOperation.id);
1125
996
  }, "onClick"),
1126
- children: localeService.t("hyperLink.form.cancel")
997
+ children: localeService.t("hyperLink.form.cancel")
998
+ }
999
+ ),
1000
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1001
+ Button,
1002
+ {
1003
+ type: "primary",
1004
+ style: { marginLeft: 8 },
1005
+ onClick: /* @__PURE__ */ __name(async () => {
1006
+ handleSubmit();
1007
+ }, "onClick"),
1008
+ children: localeService.t("hyperLink.form.ok")
1009
+ }
1010
+ )
1011
+ ] })
1012
+ ] }) : null;
1013
+ }, "CellLinkEdit");
1014
+ CellLinkEdit.componentKey = "univer.sheet.cell-link-edit";
1015
+ var __assign = function() {
1016
+ return __assign = Object.assign || function(t) {
1017
+ for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
1018
+ s = arguments[i];
1019
+ for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && (t[p2] = s[p2]);
1020
+ }
1021
+ return t;
1022
+ }, __assign.apply(this, arguments);
1023
+ }, __rest = function(s, e) {
1024
+ var t = {};
1025
+ for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0 && (t[p2] = s[p2]);
1026
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
1027
+ for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++)
1028
+ e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]) && (t[p2[i]] = s[p2[i]]);
1029
+ return t;
1030
+ }, IconBase = forwardRef(function(props, ref) {
1031
+ var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
1032
+ return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
1033
+ });
1034
+ function render(node, id, runtimeProps, rootProps, extend) {
1035
+ return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
1036
+ return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
1037
+ }));
1038
+ }
1039
+ __name(render, "render");
1040
+ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
1041
+ var attrs = __assign({}, node.attrs);
1042
+ extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
1043
+ var defIds = runtimeProps.defIds;
1044
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a15) {
1045
+ var key = _a15[0], value = _a15[1];
1046
+ typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
1047
+ })), attrs;
1048
+ }
1049
+ __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
1050
+ function replaceRuntimeIdsInDefs(node, runtimeProps) {
1051
+ var _a15, defIds = runtimeProps.defIds;
1052
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a15 = node.children) === null || _a15 === void 0) && _a15.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
1053
+ return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
1054
+ }) }) : node;
1055
+ }
1056
+ __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
1057
+ function generateShortUuid() {
1058
+ return Math.random().toString(36).substring(2, 8);
1059
+ }
1060
+ __name(generateShortUuid, "generateShortUuid");
1061
+ IconBase.displayName = "UniverIcon";
1062
+ var element$5 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M7.9999 1.12915C8.03875 1.12915 8.07673 1.13284 8.11352 1.13989H12.2599C13.6958 1.13989 14.8599 2.30395 14.8599 3.73989V7.88619C14.867 7.92301 14.8707 7.96102 14.8707 7.9999C14.8707 8.03878 14.867 8.0768 14.8599 8.11362V12.2599C14.8599 13.6958 13.6958 14.8599 12.2599 14.8599H8.11362C8.0768 14.867 8.03878 14.8707 7.9999 14.8707C7.96102 14.8707 7.92301 14.867 7.88619 14.8599H3.73989C2.30396 14.8599 1.13989 13.6958 1.13989 12.2599V8.11352C1.13284 8.07673 1.12915 8.03875 1.12915 7.9999C1.12915 7.96106 1.13284 7.92308 1.13989 7.88629V3.73989C1.13989 2.30396 2.30395 1.13989 3.73989 1.13989H7.88629C7.92308 1.13284 7.96106 1.12915 7.9999 1.12915ZM2.33989 8.5999V12.2599C2.33989 13.0331 2.9667 13.6599 3.73989 13.6599H7.3999V8.5999H2.33989ZM7.3999 7.3999H2.33989V3.73989C2.33989 2.9667 2.96669 2.33989 3.73989 2.33989H7.3999V7.3999ZM8.5999 8.5999V13.6599H12.2599C13.0331 13.6599 13.6599 13.0331 13.6599 12.2599V8.5999H8.5999ZM13.6599 7.3999H8.5999V2.33989H12.2599C13.0331 2.33989 13.6599 2.96669 13.6599 3.73989V7.3999Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, AllBorderSingle = forwardRef(function(props, ref) {
1063
+ return createElement(IconBase, Object.assign({}, props, {
1064
+ id: "all-border-single",
1065
+ ref,
1066
+ icon: element$5
1067
+ }));
1068
+ });
1069
+ AllBorderSingle.displayName = "AllBorderSingle";
1070
+ var element$4 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, CopySingle = forwardRef(function(props, ref) {
1071
+ return createElement(IconBase, Object.assign({}, props, {
1072
+ id: "copy-single",
1073
+ ref,
1074
+ icon: element$4
1075
+ }));
1076
+ });
1077
+ CopySingle.displayName = "CopySingle";
1078
+ var element$3 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.9564 2.91332C4.91407 1.87102 3.22413 1.87101 2.18182 2.91333L2.18182 2.91333C1.13953 3.95567 1.13952 5.6456 2.18182 6.68791L8.27777 12.7838C9.72408 14.2302 12.069 14.2302 13.5154 12.7839L13.0911 12.3596L13.5154 12.7839C14.9617 11.3375 14.9617 8.99257 13.5154 7.54626L8.39476 2.42566C8.16044 2.19134 7.78054 2.19134 7.54623 2.42566C7.31191 2.65997 7.31191 3.03987 7.54623 3.27419L12.6668 8.39479L13.0911 7.97052L12.6668 8.39479C13.6445 9.37247 13.6445 10.9576 12.6668 11.9353L13.0399 12.3084L12.6668 11.9353C11.6891 12.913 10.104 12.913 9.1263 11.9353L3.03035 5.83938C2.45668 5.26571 2.45667 4.33556 3.03036 3.76184C3.60403 3.18818 4.53416 3.18817 5.10788 3.76185C5.10788 3.76186 5.10788 3.76186 5.10789 3.76186L11.2038 9.8578L11.601 9.46061L11.2038 9.8578C11.3735 10.0275 11.3735 10.3026 11.2038 10.4723L11.2038 10.4723C11.0341 10.642 10.759 10.642 10.5893 10.4723L5.46874 5.35171C5.23442 5.1174 4.85452 5.1174 4.62021 5.35171C4.38589 5.58602 4.38589 5.96592 4.62021 6.20024L9.74078 11.3208C10.3791 11.9591 11.414 11.9591 12.0523 11.3208C12.0523 11.3208 12.0523 11.3208 12.0523 11.3208M12.0523 11.3208C12.6907 10.6825 12.6906 9.64757 12.0523 9.00927L5.95641 2.91333L5.9564 2.91332", fillRule: "evenodd", clipRule: "evenodd" } }] }, LinkSingle = forwardRef(function(props, ref) {
1079
+ return createElement(IconBase, Object.assign({}, props, {
1080
+ id: "link-single",
1081
+ ref,
1082
+ icon: element$3
1083
+ }));
1084
+ });
1085
+ LinkSingle.displayName = "LinkSingle";
1086
+ var element$2 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 17", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157 6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449 14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797 11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302zM3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395 4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092 3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721 8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606zM3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332 2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302 13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332z" } }] }, UnlinkSingle = forwardRef(function(props, ref) {
1087
+ return createElement(IconBase, Object.assign({}, props, {
1088
+ id: "unlink-single",
1089
+ ref,
1090
+ icon: element$2
1091
+ }));
1092
+ });
1093
+ UnlinkSingle.displayName = "UnlinkSingle";
1094
+ var element$1 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z" } }] }, WriteSingle = forwardRef(function(props, ref) {
1095
+ return createElement(IconBase, Object.assign({}, props, {
1096
+ id: "write-single",
1097
+ ref,
1098
+ icon: element$1
1099
+ }));
1100
+ });
1101
+ WriteSingle.displayName = "WriteSingle";
1102
+ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "#35BD4B", d: "M3.4535 1.12549C2.7002 1.12549 2.08954 1.73615 2.08954 2.48945V13.5104C2.08954 14.2637 2.7002 14.8744 3.4535 14.8744H12.5465C13.2998 14.8744 13.9105 14.2637 13.9105 13.5104V5.0992L10.0091 1.12549H3.4535Z" } }, { tag: "path", attrs: { fill: "#32A846", d: "M10.0075 1.12549L13.9104 5.09842H10.6742C10.306 5.09842 10.0075 4.79994 10.0075 4.43175V1.12549Z" } }, { tag: "path", attrs: { fill: "#fff", d: "M7.8088 10.2949L6.3764 12.403C6.26259 12.5705 6.03455 12.614 5.86705 12.5002C5.69955 12.3864 5.65603 12.1584 5.76984 11.9909L7.3655 9.64252L5.94042 7.54519C5.82661 7.37769 5.87013 7.14964 6.03763 7.03583C6.20512 6.92202 6.43317 6.96555 6.54698 7.13304L7.8088 8.9901L9.07062 7.13304C9.18443 6.96555 9.41248 6.92202 9.57997 7.03583C9.74747 7.14964 9.79099 7.37769 9.67718 7.54519L8.2521 9.64252L9.84776 11.9909C9.96157 12.1584 9.91805 12.3864 9.75055 12.5002C9.58305 12.614 9.35501 12.5705 9.2412 12.403L7.8088 10.2949Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Xlsx = forwardRef(function(props, ref) {
1103
+ return createElement(IconBase, Object.assign({}, props, {
1104
+ id: "xlsx",
1105
+ ref,
1106
+ icon: element
1107
+ }));
1108
+ });
1109
+ Xlsx.displayName = "Xlsx";
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 = {
1199
+ cellLink,
1200
+ cellLinkType,
1201
+ cellLinkContent,
1202
+ cellLinkContentError,
1203
+ cellLinkUrl,
1204
+ cellLinkOperations,
1205
+ cellLinkOperation,
1206
+ cellLinkOperationError
1207
+ }, iconsMap = {
1208
+ [SheetHyperLinkType.URL]: /* @__PURE__ */ jsxRuntimeExports.jsx(LinkSingle, {}),
1209
+ [SheetHyperLinkType.SHEET]: /* @__PURE__ */ jsxRuntimeExports.jsx(Xlsx, {}),
1210
+ [SheetHyperLinkType.RANGE]: /* @__PURE__ */ jsxRuntimeExports.jsx(AllBorderSingle, {}),
1211
+ [SheetHyperLinkType.DEFINE_NAME]: /* @__PURE__ */ jsxRuntimeExports.jsx(AllBorderSingle, {}),
1212
+ [SheetHyperLinkType.INVALID]: /* @__PURE__ */ jsxRuntimeExports.jsx(AllBorderSingle, {})
1213
+ }, CellLinkPopup = /* @__PURE__ */ __name(() => {
1214
+ var _a15, _b;
1215
+ const popupService = useDependency(SheetsHyperLinkPopupService), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService), [currentPopup, setCurrentPopup] = useState(null), resolverService = useDependency(SheetsHyperLinkResolverService), editorBridgeService = useDependency(IEditorBridgeService);
1216
+ if (useEffect(() => {
1217
+ setCurrentPopup(popupService.currentPopup);
1218
+ const ob = popupService.currentPopup$.subscribe((popup) => {
1219
+ setCurrentPopup(popup);
1220
+ });
1221
+ return () => {
1222
+ ob.unsubscribe();
1223
+ };
1224
+ }, [popupService.currentPopup, popupService.currentPopup$]), !currentPopup)
1225
+ return null;
1226
+ const { unitId, subUnitId, customRange, row, col } = currentPopup;
1227
+ if (!((_a15 = customRange == null ? void 0 : customRange.properties) != null && _a15.url))
1228
+ return null;
1229
+ const linkObj = resolverService.parseHyperLink((_b = customRange.properties.url) != null ? _b : ""), isError = linkObj.type === SheetHyperLinkType.INVALID;
1230
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLink, onClick: /* @__PURE__ */ __name(() => popupService.hideCurrentPopup(), "onClick"), children: [
1231
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cs(styles.cellLinkContent, { [styles.cellLinkContentError]: isError }), onClick: linkObj.handler, children: [
1232
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.cellLinkType, children: iconsMap[linkObj.type] }),
1233
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { showIfEllipsis: !0, title: linkObj.name, children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: styles.cellLinkUrl, children: linkObj.name }) })
1234
+ ] }),
1235
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLinkOperations, children: [
1236
+ currentPopup.copyPermission && /* @__PURE__ */ jsxRuntimeExports.jsx(
1237
+ "div",
1238
+ {
1239
+ className: cs(styles.cellLinkOperation, { [styles.cellLinkOperationError]: isError }),
1240
+ onClick: /* @__PURE__ */ __name(() => {
1241
+ if (!isError) {
1242
+ if (linkObj.type !== SheetHyperLinkType.URL) {
1243
+ const url = new URL(window.location.href);
1244
+ url.hash = linkObj.url.slice(1), navigator.clipboard.writeText(url.href);
1245
+ } else
1246
+ navigator.clipboard.writeText(linkObj.url);
1247
+ messageService.show({
1248
+ content: localeService.t("hyperLink.message.coped"),
1249
+ type: MessageType.Info
1250
+ });
1251
+ }
1252
+ }, "onClick"),
1253
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { placement: "bottom", title: localeService.t("hyperLink.popup.copy"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(CopySingle, {}) })
1127
1254
  }
1128
1255
  ),
1129
- /* @__PURE__ */ jsxRuntimeExports.jsx(
1130
- Button,
1131
- {
1132
- type: "primary",
1133
- style: { marginLeft: 8 },
1134
- onClick: /* @__PURE__ */ __name(async () => {
1135
- handleSubmit();
1136
- }, "onClick"),
1137
- children: localeService.t("hyperLink.form.ok")
1138
- }
1139
- )
1256
+ currentPopup.editPermission && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1257
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1258
+ "div",
1259
+ {
1260
+ className: styles.cellLinkOperation,
1261
+ onClick: /* @__PURE__ */ __name(() => {
1262
+ commandService.executeCommand(OpenHyperLinkEditPanelOperation.id, {
1263
+ unitId,
1264
+ subUnitId,
1265
+ row,
1266
+ col,
1267
+ customRangeId: customRange.rangeId,
1268
+ type: currentPopup.type
1269
+ });
1270
+ }, "onClick"),
1271
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { placement: "bottom", title: localeService.t("hyperLink.popup.edit"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(WriteSingle, {}) })
1272
+ }
1273
+ ),
1274
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
1275
+ "div",
1276
+ {
1277
+ className: styles.cellLinkOperation,
1278
+ onClick: /* @__PURE__ */ __name(() => {
1279
+ const commandId = currentPopup.type === HyperLinkEditSourceType.EDITING || currentPopup.type === HyperLinkEditSourceType.ZEN_EDITOR ? CancelRichHyperLinkCommand.id : CancelHyperLinkCommand.id;
1280
+ commandService.syncExecuteCommand(commandId, {
1281
+ unitId,
1282
+ subUnitId,
1283
+ id: customRange.rangeId,
1284
+ row,
1285
+ column: col,
1286
+ documentId: currentPopup.type === HyperLinkEditSourceType.ZEN_EDITOR ? DOCS_ZEN_EDITOR_UNIT_ID_KEY : editorBridgeService.getCurrentEditorId()
1287
+ }) && popupService.hideCurrentPopup(void 0, !0);
1288
+ }, "onClick"),
1289
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { placement: "bottom", title: localeService.t("hyperLink.popup.cancel"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(UnlinkSingle, {}) })
1290
+ }
1291
+ )
1292
+ ] })
1140
1293
  ] })
1141
- ] }) : null;
1142
- }, "CellLinkEdit");
1143
- CellLinkEdit.componentKey = "univer.sheet.cell-link-edit";
1144
- var __defProp$b = Object.defineProperty, __getOwnPropDesc$b = Object.getOwnPropertyDescriptor, __decorateClass$b = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1145
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1294
+ ] });
1295
+ }, "CellLinkPopup");
1296
+ CellLinkPopup.componentKey = "univer.sheet.cell-link-popup";
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--)
1146
1299
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1147
- return kind && result && __defProp$b(target, key, result), result;
1148
- }, "__decorateClass$b"), __decorateParam$b = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$b");
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");
1149
1302
  const isEqualLink = /* @__PURE__ */ __name((a, b) => {
1150
1303
  var _a15, _b;
1151
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;
1152
1305
  }, "isEqualLink");
1153
- var _a2;
1154
- let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
1306
+ var _a3;
1307
+ let SheetsHyperLinkPopupService = (_a3 = class extends Disposable {
1155
1308
  constructor(_sheetCanvasPopManagerService, _injector, _univerInstanceService, _editorBridgeService, _textSelectionManagerService, _docCanvasPopManagerService, _editorService, _rangeSelectorService, _zenZoneService) {
1156
1309
  super();
1157
1310
  __publicField(this, "_currentPopup", null);
@@ -1232,7 +1385,7 @@ let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
1232
1385
  startOffset: 0,
1233
1386
  endOffset: body.dataStream.length - 2,
1234
1387
  collapsed: body.dataStream.length - 2 === 0,
1235
- label: getPlainTextFormBody(body)
1388
+ label: BuildTextUtils.transform.getPlainText(body.dataStream)
1236
1389
  };
1237
1390
  const links = BuildTextUtils.customRange.getCustomRangesInterestsWithRange(textRange, (_c = (_b = body.customRanges) == null ? void 0 : _b.filter((i) => i.rangeType === CustomRangeType.HYPERLINK)) != null ? _c : []);
1238
1391
  let start = textRange.startOffset, end = textRange.endOffset;
@@ -1242,7 +1395,7 @@ let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
1242
1395
  startOffset: start,
1243
1396
  endOffset: end,
1244
1397
  collapsed: start === end,
1245
- label: getPlainText(body.dataStream.slice(start, end))
1398
+ label: BuildTextUtils.transform.getPlainText(body.dataStream.slice(start, end))
1246
1399
  };
1247
1400
  }
1248
1401
  return null;
@@ -1259,7 +1412,7 @@ let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
1259
1412
  };
1260
1413
  }
1261
1414
  startAddEditing(link) {
1262
- var _a15, _b, _c;
1415
+ var _a15, _b, _c, _d, _e;
1263
1416
  const { unitId, subUnitId, type } = link;
1264
1417
  if (type === HyperLinkEditSourceType.ZEN_EDITOR) {
1265
1418
  const document = this._univerInstanceService.getUnit(DOCS_ZEN_EDITOR_UNIT_ID_KEY, UniverInstanceType.UNIVER_DOC);
@@ -1301,7 +1454,7 @@ let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
1301
1454
  const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId), cell = worksheet == null ? void 0 : worksheet.getCellRaw(link.row, link.col);
1302
1455
  this._currentEditing$.next({
1303
1456
  ...link,
1304
- label: cell != null && cell.p ? getPlainTextFormDocument(cell.p) : ((_c = cell == null ? void 0 : cell.v) != null ? _c : "").toString()
1457
+ label: cell != null && cell.p ? BuildTextUtils.transform.getPlainText((_d = (_c = cell.p.body) == null ? void 0 : _c.dataStream) != null ? _d : "") : ((_e = cell == null ? void 0 : cell.v) != null ? _e : "").toString()
1305
1458
  });
1306
1459
  }
1307
1460
  }
@@ -1365,19 +1518,57 @@ let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
1365
1518
  const current = this._currentEditing$.getValue();
1366
1519
  current && (!type || type === current.type) && ((_a15 = this._currentEditingPopup) == null || _a15.dispose(), this._currentEditing$.next(null));
1367
1520
  }
1368
- }, __name(_a2, "SheetsHyperLinkPopupService"), _a2);
1369
- SheetsHyperLinkPopupService = __decorateClass$b([
1370
- __decorateParam$b(0, Inject(SheetCanvasPopManagerService)),
1371
- __decorateParam$b(1, Inject(Injector)),
1372
- __decorateParam$b(2, IUniverInstanceService),
1373
- __decorateParam$b(3, IEditorBridgeService),
1374
- __decorateParam$b(4, Inject(DocSelectionManagerService)),
1375
- __decorateParam$b(5, Inject(DocCanvasPopManagerService)),
1376
- __decorateParam$b(6, IEditorService),
1377
- __decorateParam$b(7, IRangeSelectorService),
1378
- __decorateParam$b(8, IZenZoneService)
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)
1379
1532
  ], SheetsHyperLinkPopupService);
1380
- const OpenHyperLinkEditPanelOperation = {
1533
+ const getShouldDisableCellLink = /* @__PURE__ */ __name((worksheet, row, col) => {
1534
+ const cell = worksheet.getCell(row, col);
1535
+ if (cell != null && cell.f || cell != null && cell.si)
1536
+ return !0;
1537
+ const disables = [
1538
+ DataValidationType.CHECKBOX,
1539
+ DataValidationType.LIST,
1540
+ DataValidationType.LIST_MULTIPLE
1541
+ ];
1542
+ return !!(cell != null && cell.dataValidation && disables.includes(cell.dataValidation.rule.type));
1543
+ }, "getShouldDisableCellLink"), getShouldDisableCurrentCellLink = /* @__PURE__ */ __name((accessor) => {
1544
+ const unit = accessor.get(IUniverInstanceService).getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
1545
+ if (!unit)
1546
+ return !0;
1547
+ const worksheet = unit.getActiveSheet(), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
1548
+ if (!selections.length)
1549
+ return !0;
1550
+ const row = selections[0].range.startRow, col = selections[0].range.startColumn;
1551
+ return getShouldDisableCellLink(worksheet, row, col);
1552
+ }, "getShouldDisableCurrentCellLink"), shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
1553
+ var _a15;
1554
+ const textSelectionService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges = textSelectionService.getDocRanges();
1555
+ if (!textRanges.length || textRanges.length > 1)
1556
+ return !0;
1557
+ const activeRange = textRanges[0], doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
1558
+ if (!doc || !activeRange || activeRange.collapsed)
1559
+ return !0;
1560
+ const body = doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody(), paragraphs = body == null ? void 0 : body.paragraphs;
1561
+ if (!paragraphs)
1562
+ return !0;
1563
+ for (let i = 0, len = paragraphs.length; i < len; i++) {
1564
+ const p2 = paragraphs[i];
1565
+ if (activeRange.startOffset <= p2.startIndex && activeRange.endOffset > p2.startIndex)
1566
+ return !0;
1567
+ if (p2.startIndex > activeRange.endOffset)
1568
+ break;
1569
+ }
1570
+ return !BuildTextUtils.customRange.getCustomRangesInterestsWithRange(activeRange, (_a15 = body.customRanges) != null ? _a15 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
1571
+ }, "shouldDisableAddLink"), OpenHyperLinkEditPanelOperation = {
1381
1572
  type: CommandType.OPERATION,
1382
1573
  id: "sheet.operation.open-hyper-link-edit-panel",
1383
1574
  handler(accessor, params) {
@@ -1416,163 +1607,12 @@ const OpenHyperLinkEditPanelOperation = {
1416
1607
  type: CommandType.OPERATION,
1417
1608
  id: "sheet.operation.insert-hyper-link-toolbar",
1418
1609
  handler(accessor) {
1610
+ if (getShouldDisableCurrentCellLink(accessor))
1611
+ return !1;
1419
1612
  const commandService = accessor.get(ICommandService);
1420
1613
  return accessor.get(SheetsHyperLinkPopupService).currentEditing ? commandService.executeCommand(CloseHyperLinkPopupOperation.id) : commandService.executeCommand(InsertHyperLinkOperation.id);
1421
1614
  }
1422
- }, SHEET_HYPER_LINK_UI_PLUGIN = "SHEET_HYPER_LINK_UI_PLUGIN";
1423
- var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1424
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1425
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1426
- return kind && result && __defProp$a(target, key, result), result;
1427
- }, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a"), _a3;
1428
- let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
1429
- constructor(_sheetClipboardService, _hyperLinkModel, _injector, _resolverService) {
1430
- super();
1431
- __publicField(this, "_plainTextFilter", /* @__PURE__ */ new Set());
1432
- __publicField(this, "_copyInfo");
1433
- this._sheetClipboardService = _sheetClipboardService, this._hyperLinkModel = _hyperLinkModel, this._injector = _injector, this._resolverService = _resolverService, this._initCopyPaste(), this.disposeWithMe(() => {
1434
- this._plainTextFilter.clear();
1435
- });
1436
- }
1437
- registerPlainTextFilter(filter) {
1438
- this._plainTextFilter.add(filter);
1439
- }
1440
- removePlainTextFilter(filter) {
1441
- this._plainTextFilter.delete(filter);
1442
- }
1443
- /* If return false the process of paste text will be stop */
1444
- _filterPlainText(text) {
1445
- return Array.from(this._plainTextFilter).every((filter) => filter(text));
1446
- }
1447
- _initCopyPaste() {
1448
- this._sheetClipboardService.addClipboardHook({
1449
- id: SHEET_HYPER_LINK_UI_PLUGIN,
1450
- onBeforeCopy: /* @__PURE__ */ __name((unitId, subUnitId, range) => this._collect(unitId, subUnitId, range), "onBeforeCopy"),
1451
- onPasteCells: /* @__PURE__ */ __name((pasteFrom, pasteTo, data, payload) => {
1452
- const { copyType = COPY_TYPE.COPY, pasteType } = payload, { range: copyRange } = pasteFrom || {}, { range: pastedRange, unitId, subUnitId } = pasteTo;
1453
- return this._generateMutations(pastedRange, { copyType, pasteType, copyRange, unitId, subUnitId });
1454
- }, "onPasteCells"),
1455
- onPastePlainText: /* @__PURE__ */ __name((pasteTo, clipText) => {
1456
- const filterResult = this._filterPlainText(clipText);
1457
- if (isLegalLink(clipText) && filterResult) {
1458
- const { range, unitId, subUnitId } = pasteTo, { ranges: [pasteToRange], mapFunc } = virtualizeDiscreteRanges([range]), redos = [], undos = [];
1459
- return Range.foreach(pasteToRange, (originRow, originCol) => {
1460
- const { row, col: column } = mapFunc(originRow, originCol), link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
1461
- link && redos.push({
1462
- id: RemoveHyperLinkMutation.id,
1463
- params: {
1464
- unitId,
1465
- subUnitId,
1466
- id: link.id
1467
- }
1468
- }), link && undos.push({
1469
- id: AddHyperLinkMutation.id,
1470
- params: {
1471
- unitId,
1472
- subUnitId,
1473
- link
1474
- }
1475
- });
1476
- }), { redos, undos };
1477
- }
1478
- return { undos: [], redos: [] };
1479
- }, "onPastePlainText"),
1480
- priority: 99
1481
- });
1482
- }
1483
- _collect(unitId, subUnitId, range) {
1484
- const matrix = new ObjectMatrix();
1485
- this._copyInfo = {
1486
- unitId,
1487
- subUnitId,
1488
- matrix
1489
- };
1490
- const discreteRange = this._injector.invoke((accessor) => rangeToDiscreteRange(range, accessor, unitId, subUnitId));
1491
- if (!discreteRange)
1492
- return;
1493
- const { rows, cols } = discreteRange;
1494
- rows.forEach((row, rowIndex) => {
1495
- cols.forEach((col, colIndex) => {
1496
- var _a15;
1497
- const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1498
- matrix.setValue(rowIndex, colIndex, (_a15 = link == null ? void 0 : link.id) != null ? _a15 : "");
1499
- });
1500
- });
1501
- }
1502
- // eslint-disable-next-line max-lines-per-function
1503
- _generateMutations(pastedRange, copyInfo) {
1504
- if (!this._copyInfo)
1505
- return { redos: [], undos: [] };
1506
- if (!this._copyInfo || !this._copyInfo.matrix.getSizeOf() || !copyInfo.copyRange)
1507
- return { redos: [], undos: [] };
1508
- if ([
1509
- PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,
1510
- PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,
1511
- PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,
1512
- PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA
1513
- ].includes(
1514
- copyInfo.pasteType
1515
- ))
1516
- return { redos: [], undos: [] };
1517
- const { unitId, subUnitId } = this._copyInfo, redos = [], undos = [], { ranges: [vCopyRange, vPastedRange], mapFunc } = virtualizeDiscreteRanges([copyInfo.copyRange, pastedRange]);
1518
- return getRepeatRange(vCopyRange, vPastedRange, !0).forEach(({ startRange }) => {
1519
- var _a15;
1520
- (_a15 = this._copyInfo) == null || _a15.matrix.forValue((row, col, ruleId) => {
1521
- const range = Rectangle.getPositionRange(
1522
- {
1523
- startRow: row,
1524
- endRow: row,
1525
- startColumn: col,
1526
- endColumn: col
1527
- },
1528
- startRange
1529
- ), 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();
1530
- currentLink && redos.push({
1531
- id: RemoveHyperLinkMutation.id,
1532
- params: {
1533
- unitId: copyInfo.unitId,
1534
- subUnitId: copyInfo.subUnitId,
1535
- id: currentLink.id
1536
- }
1537
- }), oldLink && (redos.push({
1538
- id: AddHyperLinkMutation.id,
1539
- params: {
1540
- unitId: copyInfo.unitId,
1541
- subUnitId: copyInfo.subUnitId,
1542
- link: {
1543
- ...oldLink,
1544
- id,
1545
- row: startRow,
1546
- column: startColumn
1547
- }
1548
- }
1549
- }), undos.push({
1550
- id: RemoveHyperLinkMutation.id,
1551
- params: {
1552
- unitId: copyInfo.unitId,
1553
- subUnitId: copyInfo.subUnitId,
1554
- id
1555
- }
1556
- })), currentLink && undos.push({
1557
- id: AddHyperLinkMutation.id,
1558
- params: {
1559
- unitId: copyInfo.unitId,
1560
- subUnitId: copyInfo.subUnitId,
1561
- link: currentLink
1562
- }
1563
- });
1564
- });
1565
- }), { redos, undos };
1566
- }
1567
- }, __name(_a3, "SheetsHyperLinkCopyPasteController"), _a3);
1568
- SheetsHyperLinkCopyPasteController = __decorateClass$a([
1569
- OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkCopyPasteController),
1570
- __decorateParam$a(0, ISheetClipboardService),
1571
- __decorateParam$a(1, Inject(HyperLinkModel)),
1572
- __decorateParam$a(2, Inject(Injector)),
1573
- __decorateParam$a(3, Inject(SheetsHyperLinkResolverService))
1574
- ], SheetsHyperLinkCopyPasteController);
1575
- const getLinkDisable$ = /* @__PURE__ */ __name((accessor) => {
1615
+ }, getLinkDisable$ = /* @__PURE__ */ __name((accessor) => {
1576
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(
1577
1617
  map((focused) => focused ? univerInstanceService.getUnit(focused, UniverInstanceType.UNIVER_SHEET) : null),
1578
1618
  mergeMap((unit) => unit ? unit.activeSheet$ : new Observable((sub) => {
@@ -1585,41 +1625,26 @@ const getLinkDisable$ = /* @__PURE__ */ __name((accessor) => {
1585
1625
  const { selections, sheet } = sheetWithSelection;
1586
1626
  if (!selections.length)
1587
1627
  return !0;
1588
- const row = selections[0].range.startRow, col = selections[0].range.startColumn, cell = sheet.getCell(row, col);
1589
- if (cell != null && cell.f || cell != null && cell.si)
1590
- return !0;
1591
- const disables = [
1592
- DataValidationType.CHECKBOX,
1593
- DataValidationType.LIST,
1594
- DataValidationType.LIST_MULTIPLE
1595
- ];
1596
- return !!(cell != null && cell.dataValidation && disables.includes(cell.dataValidation.rule.type));
1628
+ const row = selections[0].range.startRow, col = selections[0].range.startColumn;
1629
+ return getShouldDisableCellLink(sheet, row, col);
1597
1630
  })
1598
1631
  );
1599
1632
  return disableRange$.pipe(mergeMap((disableRange) => disableCell$.pipe(map((disableCell) => disableRange || disableCell))));
1600
- }, "getLinkDisable$"), shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
1601
- var _a15;
1602
- const textSelectionService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges = textSelectionService.getDocRanges();
1603
- if (!textRanges.length || textRanges.length > 1)
1604
- return !0;
1605
- const activeRange = textRanges[0], doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
1606
- if (!doc || !activeRange || activeRange.collapsed)
1607
- return !0;
1608
- const body = doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody(), paragraphs = body == null ? void 0 : body.paragraphs;
1609
- if (!paragraphs)
1610
- return !0;
1611
- for (let i = 0, len = paragraphs.length; i < len; i++) {
1612
- const p2 = paragraphs[i];
1613
- if (activeRange.startOffset <= p2.startIndex && activeRange.endOffset > p2.startIndex)
1614
- return !0;
1615
- if (p2.startIndex > activeRange.endOffset)
1616
- break;
1617
- }
1618
- return !BuildTextUtils.customRange.getCustomRangesInterestsWithRange(activeRange, (_a15 = body.customRanges) != null ? _a15 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
1619
- }, "shouldDisableAddLink"), getZenLinkDisable$ = /* @__PURE__ */ __name((accessor) => accessor.get(IUniverInstanceService).focused$.pipe(
1620
- mergeMap((focused) => !focused || focused !== DOCS_ZEN_EDITOR_UNIT_ID_KEY ? new Observable((sub) => sub.next(null)) : accessor.get(DocSelectionManagerService).textSelection$),
1621
- map((selection) => !selection || selection.unitId !== DOCS_ZEN_EDITOR_UNIT_ID_KEY ? !0 : shouldDisableAddLink(accessor))
1622
- ), "getZenLinkDisable$"), linkMenu = {
1633
+ }, "getLinkDisable$"), getZenLinkDisable$ = /* @__PURE__ */ __name((accessor) => {
1634
+ const univerInstanceService = accessor.get(IUniverInstanceService);
1635
+ return univerInstanceService.focused$.pipe(
1636
+ mergeMap((focused) => !focused || focused !== DOCS_ZEN_EDITOR_UNIT_ID_KEY ? new Observable((sub) => sub.next(null)) : accessor.get(DocSelectionManagerService).textSelection$),
1637
+ map((selection) => {
1638
+ if (!selection || selection.unitId !== DOCS_ZEN_EDITOR_UNIT_ID_KEY)
1639
+ return !0;
1640
+ const state = accessor.get(IEditorBridgeService).getEditCellState();
1641
+ if (!state)
1642
+ return !0;
1643
+ const target = getSheetCommandTarget(univerInstanceService, { unitId: state.unitId, subUnitId: state.sheetId });
1644
+ return !(target != null && target.worksheet) || getShouldDisableCellLink(target.worksheet, state.row, state.column) ? !0 : shouldDisableAddLink(accessor);
1645
+ })
1646
+ );
1647
+ }, "getZenLinkDisable$"), linkMenu = {
1623
1648
  commandId: InsertHyperLinkOperation.id,
1624
1649
  type: MenuItemType.BUTTON,
1625
1650
  positions: [MenuPosition.CONTEXT_MENU],
@@ -1748,6 +1773,8 @@ let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
1748
1773
  this._sheetInterceptorService.intercept(
1749
1774
  INTERCEPTOR_POINT.CELL_CONTENT,
1750
1775
  {
1776
+ effect: InterceptorEffectEnum.Value,
1777
+ priority: 100,
1751
1778
  handler: /* @__PURE__ */ __name((cell, pos, next) => {
1752
1779
  const { row, col, unitId, subUnitId } = pos, link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1753
1780
  return next(link ? {
@@ -1755,8 +1782,7 @@ let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
1755
1782
  linkUrl: link.payload,
1756
1783
  linkId: link.id
1757
1784
  } : cell);
1758
- }, "handler"),
1759
- priority: 100
1785
+ }, "handler")
1760
1786
  }
1761
1787
  )
1762
1788
  );
@@ -1874,7 +1900,7 @@ let SheetHyperLinkSetRangeController = (_a7 = class extends Disposable {
1874
1900
  dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${cell.v}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
1875
1901
  customRanges: [{
1876
1902
  startIndex: 0,
1877
- endIndex: cell.v.length,
1903
+ endIndex: cell.v.length + 1,
1878
1904
  rangeId: generateRandomId(),
1879
1905
  rangeType: CustomRangeType.HYPERLINK,
1880
1906
  properties: {
@@ -1925,7 +1951,14 @@ let SheetsHyperLinkPopupController = (_a8 = class extends Disposable {
1925
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();
1926
1952
  }
1927
1953
  _getLinkPermission(location2) {
1928
- const { unitId, subUnitId, row: currentRow, col: currentCol } = location2, viewPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
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({
1929
1962
  workbookTypes: [WorkbookViewPermission],
1930
1963
  worksheetTypes: [WorksheetViewPermission],
1931
1964
  rangeTypes: [RangeProtectionPermissionViewPoint]