@univerjs/sheets-hyper-link-ui 0.2.12 → 0.2.13

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,49 +2,347 @@ 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 { Disposable, UniverInstanceType, isValidRange, Inject, LocaleService, RANGE_TYPE, Rectangle, IUniverInstanceService, ICommandService, IConfigService, Tools, DEFAULT_EMPTY_DOCUMENT_VALUE, CommandType, IUndoRedoService, sequenceExecuteAsync, useDependency, createInternalEditorID, Range, ObjectMatrix, OnLifecycle, LifecycleStages, Injector, BooleanNumber, ThemeService, CellValueType, CustomRangeType, IPermissionService, Plugin, DependentOn } from "@univerjs/core";
6
- import { ERROR_RANGE, AddHyperLinkMutation, RemoveHyperLinkMutation, HyperLinkModel, UpdateHyperLinkMutation, UniverSheetsHyperLinkPlugin } from "@univerjs/sheets-hyper-link";
7
- import { ScrollToRangeOperation, SheetCanvasPopManagerService, COPY_TYPE, virtualizeDiscreteRanges, rangeToDiscreteRange, PREDEFINED_HOOK_NAME, getRepeatRange, ISheetClipboardService, SheetSkeletonManagerService, IEditorBridgeService, HoverManagerService, SheetPermissionInterceptorBaseController, whenSheetEditorFocused, getObservableWithExclusiveRange$, getCurrentRangeDisable$, APPLY_TYPE, IAutoFillService, getAutoFillRepeatRange } from "@univerjs/sheets-ui";
8
- import { Subject, BehaviorSubject, debounceTime } from "rxjs";
9
- import require$$0, { forwardRef, useRef, createElement, useState, useMemo, useEffect } from "react";
10
- import cs from "clsx";
11
- import { MessageType, FormLayout, Input, Select, Button, Tooltip } from "@univerjs/design";
12
- import { IMessageService, useObservable, useEvent, RangeSelector, ISidebarService, KeyCode, MetaKeys, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IShortcutService, IMenuManagerService } from "@univerjs/ui";
13
- import { deserializeRangeWithSheet, serializeRangeWithSheet, IDefinedNamesService, serializeRangeToRefString, serializeRange } from "@univerjs/engine-formula";
14
- import { SetSelectionsOperation, SetWorksheetActiveOperation, SheetInterceptorService, getSheetCommandTarget, SheetsSelectionsService, RemoveSheetCommand, INTERCEPTOR_POINT, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SetRangeValuesCommand, ClearSelectionContentCommand, ClearSelectionAllCommand, ClearSelectionFormatCommand, WorkbookViewPermission, WorksheetViewPermission, RangeProtectionPermissionViewPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, RangeProtectionPermissionEditPoint, WorkbookCopyPermission, WorksheetCopyPermission, WorksheetSetCellValuePermission } from "@univerjs/sheets";
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";
6
+ import { DocSelectionManagerService } from "@univerjs/docs";
7
+ import { addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory, getPlainTextFormBody, getPlainText, getPlainTextFormDocument, DocCanvasPopManagerService, DocEventManagerService, UniverDocsUIPlugin } from "@univerjs/docs-ui";
15
8
  import { IRenderManagerService } from "@univerjs/engine-render";
16
- import { getPlainTextFormDocument } from "@univerjs/docs";
17
- var LinkType = /* @__PURE__ */ ((LinkType2) => (LinkType2.link = "link", LinkType2.range = "range", LinkType2.sheet = "gid", LinkType2.definedName = "rangeid", LinkType2))(LinkType || {});
18
- const _SheetsHyperLinkSidePanelService = class _SheetsHyperLinkSidePanelService extends Disposable {
19
- constructor() {
20
- super(...arguments);
21
- __publicField(this, "_customHyperLinks", /* @__PURE__ */ new Map());
22
- }
23
- isBuiltInLinkType(type) {
24
- return !!LinkType[type];
25
- }
26
- getOptions() {
27
- return Array.from(this._customHyperLinks.values()).map(({ option }) => option);
28
- }
29
- findCustomHyperLink(link) {
30
- return Array.from(this._customHyperLinks.values()).find((item) => item.match(link));
31
- }
32
- registerCustomHyperLink(customHyperLink) {
33
- this._customHyperLinks.set(customHyperLink.type, customHyperLink);
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
+ import { Subject, BehaviorSubject, map, mergeMap, Observable, debounceTime } from "rxjs";
13
+ import { IMessageService, useObservable, IZenZoneService, useEvent, RangeSelector, IEditorService, IRangeSelectorService, MenuItemType, MenuPosition, MenuGroup, KeyCode, MetaKeys, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IShortcutService, IMenuManagerService } from "@univerjs/ui";
14
+ import require$$0, { forwardRef, useRef, createElement, useState, useEffect, useMemo } from "react";
15
+ 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) {
23
+ 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
64
+ }
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
+ }
79
+ }
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;
34
107
  }
35
- getCustomHyperLink(type) {
36
- return this._customHyperLinks.get(type);
108
+ }, AddRichHyperLinkCommand = {
109
+ id: "sheets.command.add-rich-hyper-link",
110
+ type: CommandType.COMMAND,
111
+ handler: /* @__PURE__ */ __name(async (accessor, params) => {
112
+ if (!params)
113
+ return !1;
114
+ const { documentId, link } = params, commandService = accessor.get(ICommandService), textSelectionService = accessor.get(DocSelectionManagerService), newId = generateRandomId(), { payload } = link;
115
+ if (!textSelectionService.getActiveTextRange())
116
+ return !1;
117
+ const replaceSelection = addCustomRangeBySelectionFactory(accessor, {
118
+ unitId: documentId,
119
+ rangeId: newId,
120
+ rangeType: CustomRangeType.HYPERLINK,
121
+ properties: {
122
+ url: payload,
123
+ refId: newId
124
+ }
125
+ });
126
+ return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
127
+ }, "handler")
128
+ }, CancelHyperLinkCommand = {
129
+ type: CommandType.COMMAND,
130
+ id: "sheets.command.cancel-hyper-link",
131
+ // eslint-disable-next-line max-lines-per-function
132
+ handler(accessor, params) {
133
+ var _a15, _b, _c;
134
+ if (!params)
135
+ return !1;
136
+ const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), renderManagerService = accessor.get(IRenderManagerService), univerInstanceService = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), { unitId, subUnitId, row, column, id } = params, workbook = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), currentRender = renderManagerService.getRenderById(unitId);
137
+ if (!currentRender || !workbook)
138
+ return !1;
139
+ const worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId), skeleton = (_a15 = currentRender.with(SheetSkeletonManagerService).getCurrent()) == null ? void 0 : _a15.skeleton;
140
+ if (!worksheet || !skeleton)
141
+ return !1;
142
+ const cellData = worksheet.getCell(row, column);
143
+ if (!cellData)
144
+ return !1;
145
+ const doc = skeleton.getCellDocumentModelWithFormula(cellData);
146
+ if (!(doc != null && doc.documentModel))
147
+ return !1;
148
+ const snapshot = Tools.deepClone(doc.documentModel.getSnapshot());
149
+ if (!((_c = (_b = snapshot.body) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((range2) => range2.rangeId === id)))
150
+ return !1;
151
+ const textX = BuildTextUtils.customRange.delete(accessor, { documentDataModel: doc.documentModel, rangeId: id });
152
+ if (!textX)
153
+ return !1;
154
+ const newBody = TextX.apply(snapshot.body, textX.serialize()), redos = [], undos = [], setRangeParams = {
155
+ unitId,
156
+ subUnitId,
157
+ cellValue: {
158
+ [row]: {
159
+ [column]: {
160
+ p: {
161
+ ...snapshot,
162
+ body: newBody
163
+ },
164
+ t: CellValueType.STRING
165
+ }
166
+ }
167
+ }
168
+ };
169
+ redos.push({
170
+ id: SetRangeValuesMutation.id,
171
+ params: setRangeParams
172
+ });
173
+ const undoParams = SetRangeValuesUndoMutationFactory(accessor, setRangeParams);
174
+ undos.push({
175
+ id: SetRangeValuesMutation.id,
176
+ params: undoParams
177
+ });
178
+ const link = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
179
+ return link && (redos.push({
180
+ id: RemoveHyperLinkMutation.id,
181
+ params: {
182
+ unitId,
183
+ subUnitId,
184
+ id
185
+ }
186
+ }), undos.push({
187
+ id: AddHyperLinkMutation.id,
188
+ params: {
189
+ unitId,
190
+ subUnitId,
191
+ link: {
192
+ ...link
193
+ }
194
+ }
195
+ })), sequenceExecute(redos, commandService).result ? (undoRedoService.pushUndoRedo({
196
+ redoMutations: redos,
197
+ undoMutations: undos,
198
+ unitID: unitId
199
+ }), !0) : !1;
37
200
  }
38
- removeCustomHyperLink(type) {
39
- const { _customHyperLinks } = this;
40
- _customHyperLinks.delete(type);
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: " "
212
+ });
213
+ const doMutation = deleteCustomRangeFactory(accessor, { unitId: documentId, rangeId: linkId, insert });
214
+ return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
41
215
  }
42
- dispose() {
43
- super.dispose(), this._customHyperLinks.clear();
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, {
242
+ 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
262
+ });
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
278
+ }
279
+ }
280
+ }
281
+ }
282
+ }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redo.params), undo = {
283
+ id: SetRangeValuesMutation.id,
284
+ params: undoParams
285
+ }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
286
+ return modelLink && (redos.push({
287
+ id: RemoveHyperLinkMutation.id,
288
+ params: {
289
+ unitId,
290
+ subUnitId,
291
+ id: modelLink.id
292
+ }
293
+ }), undos.push({
294
+ id: AddHyperLinkMutation.id,
295
+ params: {
296
+ unitId,
297
+ subUnitId,
298
+ link: modelLink
299
+ }
300
+ })), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
301
+ redoMutations: redos,
302
+ undoMutations: undos,
303
+ unitID: unitId
304
+ }), !0) : !1;
44
305
  }
306
+ }, UpdateRichHyperLinkCommand = {
307
+ type: CommandType.COMMAND,
308
+ id: "sheets.command.update-rich-hyper-link",
309
+ handler: /* @__PURE__ */ __name((accessor, params) => {
310
+ var _a15, _b, _c, _d;
311
+ if (!params)
312
+ 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)
318
+ 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
342
+ });
343
+ return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
344
+ }, "handler")
45
345
  };
46
- __name(_SheetsHyperLinkSidePanelService, "SheetsHyperLinkSidePanelService");
47
- let SheetsHyperLinkSidePanelService = _SheetsHyperLinkSidePanelService;
48
346
  var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
49
347
  /**
50
348
  * @license React
@@ -97,15 +395,15 @@ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
97
395
  var attrs = __assign({}, node.attrs);
98
396
  extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
99
397
  var defIds = runtimeProps.defIds;
100
- return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a14) {
101
- var key = _a14[0], value = _a14[1];
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];
102
400
  typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
103
401
  })), attrs;
104
402
  }
105
403
  __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
106
404
  function replaceRuntimeIdsInDefs(node, runtimeProps) {
107
- var _a14, defIds = runtimeProps.defIds;
108
- return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a14 = node.children) === null || _a14 === void 0) && _a14.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
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) {
109
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;
110
408
  }) }) : node;
111
409
  }
@@ -164,11 +462,11 @@ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width:
164
462
  });
165
463
  Xlsx.displayName = "Xlsx";
166
464
  const PLUGIN_CONFIG_KEY = "sheets-hyper-link-ui.config", defaultPluginConfig = {};
167
- var __defProp$b = Object.defineProperty, __getOwnPropDesc$b = Object.getOwnPropertyDescriptor, __decorateClass$b = /* @__PURE__ */ __name((decorators, target, key, kind) => {
168
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
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--)
169
467
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
170
- return kind && result && __defProp$b(target, key, result), result;
171
- }, "__decorateClass$b"), __decorateParam$b = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$b");
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");
172
470
  function getContainRange(range, worksheet) {
173
471
  const mergedCells = worksheet.getMergeData(), maxCol = worksheet.getMaxColumns() - 1, maxRow = worksheet.getMaxRows() - 1;
174
472
  if (maxCol < range.endColumn && (range.endColumn = maxCol), maxRow < range.endRow && (range.endRow = maxRow), range.rangeType === RANGE_TYPE.COLUMN || RANGE_TYPE.ROW)
@@ -185,42 +483,37 @@ let SheetsHyperLinkResolverService = (_a = class {
185
483
  this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._definedNamesService = _definedNamesService, this._messageService = _messageService, this._localeService = _localeService, this._configService = _configService;
186
484
  }
187
485
  _getURLName(params) {
188
- var _a14;
189
- const { gid, range, rangeid } = params, workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
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
+ };
190
491
  if (!workbook)
191
- return null;
192
- const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet(), sheetName = (_a14 = sheet == null ? void 0 : sheet.getName()) != null ? _a14 : "";
492
+ return invalidLink;
493
+ const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet(), sheetName = (_a15 = sheet == null ? void 0 : sheet.getName()) != null ? _a15 : "";
193
494
  if (range) {
495
+ if (!sheet) return invalidLink;
194
496
  const rangeObj = deserializeRangeWithSheet(range).range;
195
- return isValidRange(rangeObj) && range !== ERROR_RANGE ? {
196
- type: "range",
497
+ return isValidRange(rangeObj, sheet) && range !== ERROR_RANGE ? {
498
+ type: SheetHyperLinkType.RANGE,
197
499
  name: serializeRangeWithSheet(sheetName, rangeObj)
198
- } : {
199
- type: "range-error",
200
- name: this._localeService.t("hyperLink.message.refError")
201
- };
500
+ } : invalidLink;
202
501
  }
203
502
  if (rangeid) {
204
503
  const range2 = this._definedNamesService.getValueById(workbook.getUnitId(), rangeid);
205
504
  return range2 ? {
206
- type: "defineName",
505
+ type: SheetHyperLinkType.DEFINE_NAME,
207
506
  name: range2.formulaOrRefString
208
- } : {
209
- type: "range-error",
210
- name: this._localeService.t("hyperLink.message.refError")
211
- };
507
+ } : invalidLink;
212
508
  }
213
509
  if (gid) {
214
510
  const worksheet = workbook.getSheetBySheetId(gid);
215
511
  return worksheet ? {
216
- type: "sheet",
512
+ type: SheetHyperLinkType.SHEET,
217
513
  name: worksheet.getName()
218
- } : {
219
- type: "sheet-error",
220
- name: this._localeService.t("hyperLink.message.refError")
221
- };
514
+ } : invalidLink;
222
515
  }
223
- return null;
516
+ return invalidLink;
224
517
  }
225
518
  navigateTo(params) {
226
519
  const { gid, range, rangeid } = params, workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
@@ -236,17 +529,21 @@ let SheetsHyperLinkResolverService = (_a = class {
236
529
  this.navigateToSheetById(unitId, gid);
237
530
  }
238
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
+ }
239
535
  parseHyperLink(urlStr) {
240
- var _a14, _b, _c;
241
- if (urlStr != null && urlStr.startsWith("#")) {
536
+ var _a15, _b, _c, _d;
537
+ if (urlStr.startsWith("#")) {
242
538
  const search = new URLSearchParams(urlStr.slice(1)), searchObj = {
243
- gid: (_a14 = search.get("gid")) != null ? _a14 : "",
539
+ gid: (_a15 = search.get("gid")) != null ? _a15 : "",
244
540
  range: (_b = search.get("range")) != null ? _b : "",
245
- rangeid: (_c = search.get("rangeid")) != null ? _c : ""
541
+ rangeid: (_c = search.get("rangeid")) != null ? _c : "",
542
+ unitid: (_d = search.get("unitid")) != null ? _d : ""
246
543
  }, urlInfo = this._getURLName(searchObj);
247
544
  return {
248
- type: (urlInfo == null ? void 0 : urlInfo.type) || "link",
249
- name: (urlInfo == null ? void 0 : urlInfo.name) || urlStr,
545
+ type: urlInfo.type,
546
+ name: urlInfo.name,
250
547
  url: urlStr,
251
548
  searchObj,
252
549
  handler: /* @__PURE__ */ __name(() => {
@@ -255,12 +552,13 @@ let SheetsHyperLinkResolverService = (_a = class {
255
552
  };
256
553
  } else
257
554
  return {
258
- type: "outer",
555
+ type: SheetHyperLinkType.URL,
259
556
  name: urlStr,
260
557
  url: urlStr,
261
558
  handler: /* @__PURE__ */ __name(() => {
262
559
  this.navigateToOtherWebsite(urlStr);
263
- }, "handler")
560
+ }, "handler"),
561
+ searchObj: null
264
562
  };
265
563
  }
266
564
  async navigateToRange(unitId, subUnitId, range) {
@@ -324,21 +622,121 @@ let SheetsHyperLinkResolverService = (_a = class {
324
622
  return this._definedNamesService.focusRange(unitId, rangeid), !0;
325
623
  }
326
624
  async navigateToOtherWebsite(url) {
327
- var _a14;
625
+ var _a15;
328
626
  const config = this._configService.getConfig(PLUGIN_CONFIG_KEY);
329
- if ((_a14 = config == null ? void 0 : config.urlHandler) != null && _a14.navigateToOtherWebsite)
627
+ if ((_a15 = config == null ? void 0 : config.urlHandler) != null && _a15.navigateToOtherWebsite)
330
628
  return config.urlHandler.navigateToOtherWebsite(url);
331
629
  window.open(url, "_blank", "noopener noreferrer");
332
630
  }
333
631
  }, __name(_a, "SheetsHyperLinkResolverService"), _a);
334
- SheetsHyperLinkResolverService = __decorateClass$b([
335
- __decorateParam$b(0, IUniverInstanceService),
336
- __decorateParam$b(1, ICommandService),
337
- __decorateParam$b(2, IDefinedNamesService),
338
- __decorateParam$b(3, IMessageService),
339
- __decorateParam$b(4, Inject(LocaleService)),
340
- __decorateParam$b(5, IConfigService)
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)
341
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);
663
+ });
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
+ });
694
+ }
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
+ }
734
+ )
735
+ ] })
736
+ ] })
737
+ ] });
738
+ }, "CellLinkPopup");
739
+ CellLinkPopup.componentKey = "univer.sheet.cell-link-popup";
342
740
  function isLegalLink(link) {
343
741
  return Tools.isLegalUrl(link);
344
742
  }
@@ -378,182 +776,216 @@ function getCellValueOrigin(cell) {
378
776
  return cell == null ? void 0 : cell.v;
379
777
  }
380
778
  __name(getCellValueOrigin, "getCellValueOrigin");
381
- const AddHyperLinkCommand = {
382
- type: CommandType.COMMAND,
383
- id: "sheets.command.add-hyper-link",
384
- async handler(accessor, params) {
385
- if (!params)
386
- return !1;
387
- const sheetInterceptorService = accessor.get(SheetInterceptorService), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), { unitId, subUnitId, link } = params, { redos, undos } = sheetInterceptorService.onCommandExecute({
388
- id: AddHyperLinkCommand.id,
389
- params
390
- }), redo = {
391
- id: AddHyperLinkMutation.id,
392
- params
393
- }, undo = {
394
- id: RemoveHyperLinkMutation.id,
395
- params: {
396
- unitId,
397
- subUnitId,
398
- id: link.id
399
- }
400
- };
401
- return (await sequenceExecuteAsync([redo, ...redos], commandService)).result ? (undoRedoService.pushUndoRedo({
402
- redoMutations: [redo, ...redos],
403
- undoMutations: [undo, ...undos],
404
- unitID: unitId
405
- }), !0) : !1;
779
+ const _SheetsHyperLinkSidePanelService = class _SheetsHyperLinkSidePanelService extends Disposable {
780
+ constructor() {
781
+ super(...arguments);
782
+ __publicField(this, "_customHyperLinks", /* @__PURE__ */ new Map());
406
783
  }
407
- };
408
- function getHyperLinkContent(link) {
409
- const { row, column, id, ...content } = link;
410
- return content;
411
- }
412
- __name(getHyperLinkContent, "getHyperLinkContent");
413
- const UpdateHyperLinkCommand = {
414
- type: CommandType.COMMAND,
415
- id: "sheets.command.update-hyper-link",
416
- async handler(accessor, params) {
417
- if (!params)
418
- return !1;
419
- const sheetInterceptorService = accessor.get(SheetInterceptorService), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), model = accessor.get(HyperLinkModel), { unitId, subUnitId, id } = params, link = model.getHyperLink(unitId, subUnitId, id);
420
- if (!link)
421
- return !1;
422
- const { redos, undos } = sheetInterceptorService.onCommandExecute({
423
- id: UpdateHyperLinkCommand.id,
424
- params
425
- }), redo = {
426
- id: UpdateHyperLinkMutation.id,
427
- params
428
- }, undo = {
429
- id: UpdateHyperLinkMutation.id,
430
- params: {
431
- unitId,
432
- subUnitId,
433
- id,
434
- payload: getHyperLinkContent(link)
435
- }
436
- };
437
- return (await sequenceExecuteAsync([redo, ...redos], commandService)).result ? (undoRedoService.pushUndoRedo({
438
- redoMutations: [redo, ...redos],
439
- undoMutations: [undo, ...undos],
440
- unitID: unitId
441
- }), !0) : !1;
784
+ isBuiltInLinkType(type) {
785
+ return type !== SheetHyperLinkType.URL;
786
+ }
787
+ getOptions() {
788
+ return Array.from(this._customHyperLinks.values()).map(({ option }) => option);
789
+ }
790
+ findCustomHyperLink(link) {
791
+ return Array.from(this._customHyperLinks.values()).find((item) => item.match(link));
792
+ }
793
+ registerCustomHyperLink(customHyperLink) {
794
+ this._customHyperLinks.set(customHyperLink.type, customHyperLink);
795
+ }
796
+ getCustomHyperLink(type) {
797
+ return this._customHyperLinks.get(type);
798
+ }
799
+ removeCustomHyperLink(type) {
800
+ const { _customHyperLinks } = this;
801
+ _customHyperLinks.delete(type);
802
+ }
803
+ dispose() {
804
+ super.dispose(), this._customHyperLinks.clear();
442
805
  }
443
- }, cellLinkEditButtons = "univer-cell-link-edit-buttons", styles$1 = {
806
+ };
807
+ __name(_SheetsHyperLinkSidePanelService, "SheetsHyperLinkSidePanelService");
808
+ let SheetsHyperLinkSidePanelService = _SheetsHyperLinkSidePanelService;
809
+ const cellLinkEdit = "univer-cell-link-edit", cellLinkEditButtons = "univer-cell-link-edit-buttons", styles = {
810
+ cellLinkEdit,
444
811
  cellLinkEditButtons
445
812
  }, CellLinkEdit = /* @__PURE__ */ __name(() => {
446
- var _a14;
447
- const [id, setId] = useState(""), [display, setDisplay] = useState(""), [type, setType] = useState(LinkType.link), [payload, setPayload] = useState(""), localeService = useDependency(LocaleService), definedNameService = useDependency(IDefinedNamesService), univerInstanceService = useDependency(IUniverInstanceService), popupService = useDependency(SheetsHyperLinkPopupService), editing = useObservable(popupService.currentEditing$), hyperLinkModel = useDependency(HyperLinkModel), resolverService = useDependency(SheetsHyperLinkResolverService), commandService = useDependency(ICommandService), sidePanelService = useDependency(SheetsHyperLinkSidePanelService), sidePanelOptions = useMemo(() => sidePanelService.getOptions(), [sidePanelService]), customHyperLinkSidePanel = useMemo(() => {
813
+ 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(() => {
448
815
  if (!sidePanelService.isBuiltInLinkType(type))
449
816
  return sidePanelService.getCustomHyperLink(type);
450
817
  }, [sidePanelService, type]), [showError, setShowError] = useState(!1), setByPayload = useRef(!1);
451
818
  useEffect(() => {
452
- var _a15, _b, _c;
453
- if ((editing == null ? void 0 : editing.row) !== void 0 && editing.column !== void 0) {
454
- const link = hyperLinkModel.getHyperLinkByLocationSync(editing.unitId, editing.subUnitId, editing.row, editing.column);
455
- if (link) {
456
- setId(link.id);
457
- const customLink = sidePanelService.findCustomHyperLink(link);
458
- if (customLink) {
459
- const customLinkInfo = customLink.convert(link);
460
- setType(customLinkInfo.type), setPayload(customLinkInfo.payload), setDisplay(customLinkInfo.display);
461
- return;
819
+ var _a16, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
820
+ if ((editing == null ? void 0 : editing.row) !== void 0 && editing.col !== void 0) {
821
+ const { label, customRange, row, col } = editing;
822
+ let link;
823
+ if (customRange)
824
+ link = {
825
+ id: (_a16 = customRange == null ? void 0 : customRange.rangeId) != null ? _a16 : "",
826
+ display: label != null ? label : "",
827
+ payload: (_c = (_b = customRange == null ? void 0 : customRange.properties) == null ? void 0 : _b.url) != null ? _c : "",
828
+ row,
829
+ column: col
830
+ };
831
+ else if (editing.type === HyperLinkEditSourceType.VIEWING) {
832
+ 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
+ var _a17;
834
+ return range2.rangeType === CustomRangeType.HYPERLINK && ((_a17 = range2.properties) == null ? void 0 : _a17.url);
835
+ }), cellValue = `${(_g = getCellValueOrigin(cell)) != null ? _g : ""}`;
836
+ cell && (cell.p || cellValue) && setShowLabel(!1), link = {
837
+ id: "",
838
+ display: "",
839
+ payload: (_i = (_h = range == null ? void 0 : range.properties) == null ? void 0 : _h.url) != null ? _i : "",
840
+ row,
841
+ column: col
842
+ };
843
+ } else {
844
+ const doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), selection = textSelectionService.getActiveTextRange(), customRange2 = selection && ((_l = BuildTextUtils.customRange.getCustomRangesInterestsWithRange(selection, (_k = (_j = doc == null ? void 0 : doc.getBody()) == null ? void 0 : _j.customRanges) != null ? _k : [])) == null ? void 0 : _l[0]);
845
+ setShowLabel(!1), link = {
846
+ id: "",
847
+ display: label != null ? label : "",
848
+ payload: (_n = (_m = customRange2 == null ? void 0 : customRange2.properties) == null ? void 0 : _m.url) != null ? _n : "",
849
+ row,
850
+ column: col
851
+ };
852
+ }
853
+ setId(link.id);
854
+ const customLink = sidePanelService.findCustomHyperLink(link);
855
+ if (customLink) {
856
+ const customLinkInfo = customLink.convert(link);
857
+ setType(customLinkInfo.type), setPayload(customLinkInfo.payload), setDisplay(customLinkInfo.display);
858
+ return;
859
+ }
860
+ setDisplay(link.display);
861
+ const linkInfo = resolverService.parseHyperLink(link.payload);
862
+ switch (setType(linkInfo.type === SheetHyperLinkType.INVALID ? SheetHyperLinkType.RANGE : linkInfo.type), linkInfo.type) {
863
+ case SheetHyperLinkType.URL: {
864
+ setPayload(linkInfo.url), linkInfo.url === link.display && (setByPayload.current = !0);
865
+ break;
462
866
  }
463
- setDisplay(link.display);
464
- const linkInfo = resolverService.parseHyperLink(link.payload);
465
- if (linkInfo.type === "outer") {
466
- setType(LinkType.link), setPayload(linkInfo.url), linkInfo.url === link.display && (setByPayload.current = !0);
467
- return;
468
- } else {
867
+ case SheetHyperLinkType.RANGE: {
868
+ const params = linkInfo.searchObj, sheetName = params.gid && (_q = (_p = (_o = univerInstanceService.getUnit(editing.unitId)) == null ? void 0 : _o.getSheetBySheetId(params.gid)) == null ? void 0 : _p.getName()) != null ? _q : "", payload2 = serializeRangeWithSheet(sheetName, deserializeRangeWithSheet(params.range).range);
869
+ setPayload(payload2), payload2 === link.display && (setByPayload.current = !0);
870
+ break;
871
+ }
872
+ case SheetHyperLinkType.SHEET: {
469
873
  const params = linkInfo.searchObj;
470
- if (params.rangeid) {
471
- setType(LinkType.definedName), setPayload(params.rangeid);
472
- return;
473
- }
474
- if (params.range) {
475
- const sheetName = params.gid && (_c = (_b = (_a15 = univerInstanceService.getUnit(editing.unitId)) == null ? void 0 : _a15.getSheetBySheetId(params.gid)) == null ? void 0 : _b.getName()) != null ? _c : "";
476
- if (setType(LinkType.range), params.range === ERROR_RANGE)
477
- setPayload("");
478
- else {
479
- const payload2 = serializeRangeWithSheet(sheetName, deserializeRangeWithSheet(params.range).range);
480
- setPayload(payload2), payload2 === link.display && (setByPayload.current = !0);
481
- }
482
- return;
483
- }
484
- if (params.gid) {
485
- setType(LinkType.sheet), setPayload(params.gid);
486
- return;
487
- }
874
+ setPayload(params.gid);
875
+ break;
488
876
  }
877
+ case SheetHyperLinkType.DEFINE_NAME: {
878
+ const params = linkInfo.searchObj;
879
+ setPayload(params.rangeid);
880
+ break;
881
+ }
882
+ default:
883
+ setPayload("");
884
+ break;
489
885
  }
490
- 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.column), cellValue = getCellValueOrigin(cell);
491
- setType(LinkType.link), setPayload(""), setDisplay((cellValue != null ? cellValue : "").toString()), setId("");
492
- return;
493
886
  }
494
- setType(LinkType.link), setPayload(""), setDisplay(""), setId("");
495
- }, [editing, hyperLinkModel, resolverService, univerInstanceService]);
496
- const payloadInitial = useMemo(() => payload, [type]), linkTypeOptions = [
887
+ }, [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: {}
903
+ },
904
+ primary: null
905
+ },
906
+ [],
907
+ -1
908
+ )), () => {
909
+ id2 && markSelectionService.removeShape(id2);
910
+ };
911
+ }, [editing, markSelectionService]);
912
+ const payloadInitial = useMemo(() => payload, [type]);
913
+ useEffect(() => () => {
914
+ editorBridgeService.disableForceKeepVisible();
915
+ }, [editorBridgeService]);
916
+ const linkTypeOptions = [
497
917
  {
498
918
  label: localeService.t("hyperLink.form.link"),
499
- value: LinkType.link
919
+ value: SheetHyperLinkType.URL
500
920
  },
501
921
  {
502
922
  label: localeService.t("hyperLink.form.range"),
503
- value: LinkType.range
923
+ value: SheetHyperLinkType.RANGE
504
924
  },
505
925
  {
506
926
  label: localeService.t("hyperLink.form.worksheet"),
507
- value: LinkType.sheet
927
+ value: SheetHyperLinkType.SHEET
508
928
  },
509
929
  {
510
930
  label: localeService.t("hyperLink.form.definedName"),
511
- value: LinkType.definedName
931
+ value: SheetHyperLinkType.DEFINE_NAME
512
932
  },
513
933
  ...sidePanelOptions
514
934
  ], workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
515
935
  if (!workbook)
516
936
  return;
517
- const hiddens = workbook.getHiddenWorksheets(), sheetsOption = workbook.getSheets().map((sheet) => ({ label: sheet.getName(), value: sheet.getSheetId() })).filter((opt) => hiddens.indexOf(opt.value) === -1), definedNames = Object.values((_a14 = definedNameService.getDefinedNameMap(workbook.getUnitId())) != null ? _a14 : {}).map((value) => ({
937
+ const hiddens = workbook.getHiddenWorksheets(), sheetsOption = workbook.getSheets().map((sheet) => ({ label: sheet.getName(), value: sheet.getSheetId() })).filter((opt) => hiddens.indexOf(opt.value) === -1), definedNames = Object.values((_a15 = definedNameService.getDefinedNameMap(workbook.getUnitId())) != null ? _a15 : {}).map((value) => ({
518
938
  label: value.name,
519
939
  value: value.id
520
940
  })), formatUrl = /* @__PURE__ */ __name((type2, payload2) => {
521
- if (type2 === LinkType.link)
941
+ if (type2 === SheetHyperLinkType.URL)
522
942
  return serializeUrl(payload2);
523
- if (type2 === LinkType.range) {
943
+ if (type2 === SheetHyperLinkType.RANGE) {
524
944
  const info = deserializeRangeWithSheet(payload2), worksheet = workbook.getSheetBySheetName(info.sheetName);
525
945
  if (worksheet)
526
946
  return `#gid=${worksheet.getSheetId()}&range=${serializeRange(info.range)}`;
527
947
  }
528
948
  return `#${type2}=${payload2}`;
529
949
  }, "formatUrl"), handleRangeChange = useEvent((newValue) => {
530
- var _a15;
950
+ var _a16;
531
951
  const range = newValue[0];
532
952
  if (!range || !isValidRange(range.range))
533
953
  return;
534
- range.sheetName || (range.sheetName = ((_a15 = workbook.getActiveSheet()) == null ? void 0 : _a15.getName()) || "");
954
+ range.sheetName || (range.sheetName = ((_a16 = workbook.getActiveSheet()) == null ? void 0 : _a16.getName()) || "");
535
955
  const newPayload = serializeRangeToRefString(range);
536
956
  setPayload(newPayload), newPayload && (setByPayload.current || !display) && (setDisplay(newPayload), setByPayload.current = !0);
537
957
  }), handleSubmit = /* @__PURE__ */ __name(async () => {
538
- if (editing && (id ? await commandService.executeCommand(UpdateHyperLinkCommand.id, {
539
- unitId: editing.unitId,
540
- subUnitId: editing.subUnitId,
541
- id,
542
- payload: {
543
- display,
544
- payload: formatUrl(type, payload)
545
- }
546
- }) : await commandService.executeCommand(AddHyperLinkCommand.id, {
547
- unitId: editing.unitId,
548
- subUnitId: editing.subUnitId,
549
- link: {
550
- id: Tools.generateRandomId(),
551
- row: editing.row,
552
- column: editing.column,
553
- payload: formatUrl(type, payload),
554
- display
958
+ if (editing)
959
+ if (id) {
960
+ const commandId = editing.type === HyperLinkEditSourceType.ZEN_EDITOR || editing.type === HyperLinkEditSourceType.EDITING ? UpdateRichHyperLinkCommand.id : UpdateHyperLinkCommand.id;
961
+ await commandService.executeCommand(commandId, {
962
+ id,
963
+ unitId: editing.unitId,
964
+ subUnitId: editing.subUnitId,
965
+ payload: {
966
+ display: showLabel ? display : "",
967
+ payload: formatUrl(type, payload)
968
+ },
969
+ row: editing.row,
970
+ column: editing.col,
971
+ documentId: editing.type === HyperLinkEditSourceType.ZEN_EDITOR ? DOCS_ZEN_EDITOR_UNIT_ID_KEY : editorBridgeService.getCurrentEditorId()
972
+ });
973
+ } else {
974
+ const commandId = editing.type === HyperLinkEditSourceType.ZEN_EDITOR || editing.type === HyperLinkEditSourceType.EDITING ? AddRichHyperLinkCommand.id : AddHyperLinkCommand.id;
975
+ await commandService.executeCommand(commandId, {
976
+ unitId: editing.unitId,
977
+ subUnitId: editing.subUnitId,
978
+ link: {
979
+ id: generateRandomId(),
980
+ row: editing.row,
981
+ column: editing.col,
982
+ payload: formatUrl(type, payload),
983
+ display: showLabel ? display : ""
984
+ },
985
+ documentId: editing.type === HyperLinkEditSourceType.ZEN_EDITOR ? DOCS_ZEN_EDITOR_UNIT_ID_KEY : editorBridgeService.getCurrentEditorId()
986
+ });
555
987
  }
556
- })), editing) {
988
+ if ((editing == null ? void 0 : editing.type) === HyperLinkEditSourceType.VIEWING) {
557
989
  await commandService.executeCommand(SetWorksheetActiveOperation.id, {
558
990
  unitId: editing.unitId,
559
991
  subUnitId: editing.subUnitId
@@ -563,15 +995,15 @@ const UpdateHyperLinkCommand = {
563
995
  range: {
564
996
  startRow: Math.max(editing.row - GAP, 0),
565
997
  endRow: editing.row + GAP,
566
- startColumn: Math.max(editing.column - GAP, 0),
567
- endColumn: editing.column + GAP
998
+ startColumn: Math.max(editing.col - GAP, 0),
999
+ endColumn: editing.col + GAP
568
1000
  }
569
1001
  });
570
1002
  }
571
- commandService.executeCommand(CloseHyperLinkSidebarOperation.id);
1003
+ commandService.executeCommand(CloseHyperLinkPopupOperation.id);
572
1004
  }, "handleSubmit");
573
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
574
- /* @__PURE__ */ jsxRuntimeExports.jsx(
1005
+ return editing ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLinkEdit, style: { display: hide ? "none" : "block" }, children: [
1006
+ showLabel ? /* @__PURE__ */ jsxRuntimeExports.jsx(
575
1007
  FormLayout,
576
1008
  {
577
1009
  label: localeService.t("hyperLink.form.label"),
@@ -587,8 +1019,8 @@ const UpdateHyperLinkCommand = {
587
1019
  }
588
1020
  )
589
1021
  }
590
- ),
591
- /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("hyperLink.form.type"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1022
+ ) : null,
1023
+ /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("hyperLink.form.type"), contentStyle: { marginBottom: 0 }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
592
1024
  Select,
593
1025
  {
594
1026
  options: linkTypeOptions,
@@ -598,7 +1030,7 @@ const UpdateHyperLinkCommand = {
598
1030
  }, "onChange")
599
1031
  }
600
1032
  ) }),
601
- type === LinkType.link && /* @__PURE__ */ jsxRuntimeExports.jsx(
1033
+ type === SheetHyperLinkType.URL && /* @__PURE__ */ jsxRuntimeExports.jsx(
602
1034
  FormLayout,
603
1035
  {
604
1036
  error: showError ? payload ? isLegalLink(payload) ? "" : localeService.t("hyperLink.form.linkError") : localeService.t("hyperLink.form.inputError") : "",
@@ -614,38 +1046,46 @@ const UpdateHyperLinkCommand = {
614
1046
  )
615
1047
  }
616
1048
  ),
617
- type === LinkType.range && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.inputError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1049
+ type === SheetHyperLinkType.RANGE && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.inputError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
618
1050
  RangeSelector,
619
1051
  {
620
1052
  openForSheetUnitId: workbook.getUnitId(),
621
1053
  id: createInternalEditorID("hyper-link-edit"),
622
1054
  isSingleChoice: !0,
623
1055
  value: payloadInitial,
624
- onChange: handleRangeChange
1056
+ onChange: handleRangeChange,
1057
+ disableInput: editing.type === HyperLinkEditSourceType.ZEN_EDITOR,
1058
+ onSelectorVisibleChange: /* @__PURE__ */ __name(async (visible) => {
1059
+ visible ? (editing.type === HyperLinkEditSourceType.ZEN_EDITOR && (zenZoneService.hide(), contextService.setContextValue(FOCUSING_SHEET, !0)), editing.type !== HyperLinkEditSourceType.VIEWING && editorBridgeService.enableForceKeepVisible(), setHide(!0)) : (await resolverService.navigateToRange(editing.unitId, editing.subUnitId, { startRow: editing.row, endRow: editing.row, startColumn: editing.col, endColumn: editing.col }), editing.type === HyperLinkEditSourceType.ZEN_EDITOR && (await commandService.executeCommand(SetSelectionsOperation.id, {
1060
+ unitId: editing.unitId,
1061
+ subUnitId: editing.subUnitId,
1062
+ selections: [{ range: { startRow: editing.row, endRow: editing.row, startColumn: editing.col, endColumn: editing.col } }]
1063
+ }), zenZoneService.show(), contextService.setContextValue(FOCUSING_SHEET, !1)), editorBridgeService.disableForceKeepVisible(), setHide(!1));
1064
+ }, "onSelectorVisibleChange")
625
1065
  }
626
1066
  ) }),
627
- type === LinkType.sheet && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1067
+ type === SheetHyperLinkType.SHEET && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
628
1068
  Select,
629
1069
  {
630
1070
  options: sheetsOption,
631
1071
  value: payload,
632
1072
  onChange: /* @__PURE__ */ __name((newPayload) => {
633
- var _a15, _b;
1073
+ var _a16, _b;
634
1074
  setPayload(newPayload);
635
- const label = (_a15 = sheetsOption.find((i) => i.value === newPayload)) == null ? void 0 : _a15.label, oldLabel = (_b = sheetsOption.find((i) => i.value === payload)) == null ? void 0 : _b.label;
1075
+ const label = (_a16 = sheetsOption.find((i) => i.value === newPayload)) == null ? void 0 : _a16.label, oldLabel = (_b = sheetsOption.find((i) => i.value === payload)) == null ? void 0 : _b.label;
636
1076
  label && (setByPayload.current || !display || display === oldLabel) && (setDisplay(label), setByPayload.current = !0);
637
1077
  }, "onChange")
638
1078
  }
639
1079
  ) }),
640
- type === LinkType.definedName && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1080
+ type === SheetHyperLinkType.DEFINE_NAME && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
641
1081
  Select,
642
1082
  {
643
1083
  options: definedNames,
644
1084
  value: payload,
645
1085
  onChange: /* @__PURE__ */ __name((newValue) => {
646
- var _a15, _b;
1086
+ var _a16, _b;
647
1087
  setPayload(newValue);
648
- const label = (_a15 = definedNames.find((i) => i.value === newValue)) == null ? void 0 : _a15.label, oldLabel = (_b = definedNames.find((i) => i.value === payload)) == null ? void 0 : _b.label;
1088
+ const label = (_a16 = definedNames.find((i) => i.value === newValue)) == null ? void 0 : _a16.label, oldLabel = (_b = definedNames.find((i) => i.value === payload)) == null ? void 0 : _b.label;
649
1089
  label && (setByPayload.current || !display || display === oldLabel) && (setDisplay(label), setByPayload.current = !0);
650
1090
  }, "onChange")
651
1091
  }
@@ -664,15 +1104,12 @@ const UpdateHyperLinkCommand = {
664
1104
  setPayload
665
1105
  }
666
1106
  ),
667
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.cellLinkEditButtons, children: [
1107
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLinkEditButtons, children: [
668
1108
  /* @__PURE__ */ jsxRuntimeExports.jsx(
669
1109
  Button,
670
1110
  {
671
1111
  onClick: /* @__PURE__ */ __name(() => {
672
- editing && commandService.executeCommand(SetWorksheetActiveOperation.id, {
673
- unitId: editing.unitId,
674
- subUnitId: editing.subUnitId
675
- }), commandService.executeCommand(CloseHyperLinkSidebarOperation.id);
1112
+ editing && resolverService.navigateToRange(editing.unitId, editing.subUnitId, { startRow: editing.row, endRow: editing.row, startColumn: editing.col, endColumn: editing.col }), commandService.executeCommand(CloseHyperLinkPopupOperation.id);
676
1113
  }, "onClick"),
677
1114
  children: localeService.t("hyperLink.form.cancel")
678
1115
  }
@@ -683,7 +1120,7 @@ const UpdateHyperLinkCommand = {
683
1120
  type: "primary",
684
1121
  style: { marginLeft: 8 },
685
1122
  onClick: /* @__PURE__ */ __name(async () => {
686
- if (!display || !payload || type === LinkType.link && !isLegalLink(payload)) {
1123
+ if (showLabel && !display || !payload || type === SheetHyperLinkType.URL && !isLegalLink(payload)) {
687
1124
  setShowError(!0);
688
1125
  return;
689
1126
  }
@@ -693,216 +1130,29 @@ const UpdateHyperLinkCommand = {
693
1130
  }
694
1131
  )
695
1132
  ] })
696
- ] });
1133
+ ] }) : null;
697
1134
  }, "CellLinkEdit");
698
1135
  CellLinkEdit.componentKey = "univer.sheet.cell-link-edit";
699
- const OpenHyperLinkSidebarOperation = {
700
- type: CommandType.OPERATION,
701
- id: "sheet.operation.open-hyper-link-sidebar",
702
- handler(accessor, params) {
703
- if (!params)
704
- return !1;
705
- const { unitId, subUnitId, row, column } = params, hyperLinkModel = accessor.get(HyperLinkModel), sidebarService = accessor.get(ISidebarService), popupService = accessor.get(SheetsHyperLinkPopupService), currentLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
706
- return popupService.startEditing(params), sidebarService.open({
707
- header: {
708
- title: currentLink ? "hyperLink.form.editTitle" : "hyperLink.form.addTitle"
709
- },
710
- children: {
711
- label: CellLinkEdit.componentKey
712
- }
713
- }), !0;
714
- }
715
- }, CloseHyperLinkSidebarOperation = {
716
- type: CommandType.OPERATION,
717
- id: "sheet.operation.close-hyper-link-sidebar",
718
- handler(accessor) {
719
- const sidebarService = accessor.get(ISidebarService), popupService = accessor.get(SheetsHyperLinkPopupService);
720
- return sidebarService.close(), popupService.endEditing(), !0;
721
- }
722
- }, InsertHyperLinkOperation = {
723
- type: CommandType.OPERATION,
724
- id: "sheet.operation.insert-hyper-link",
725
- handler(accessor) {
726
- const univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService);
727
- if (!target)
728
- return !1;
729
- const commandService = accessor.get(ICommandService), selection = accessor.get(SheetsSelectionsService).getCurrentLastSelection();
730
- if (!selection)
731
- return !1;
732
- const row = selection.primary.startRow, column = selection.primary.startColumn;
733
- return commandService.executeCommand(OpenHyperLinkSidebarOperation.id, {
734
- unitId: target.unitId,
735
- subUnitId: target.subUnitId,
736
- row,
737
- column
738
- });
739
- }
740
- }, InsertHyperLinkToolbarOperation = {
741
- type: CommandType.OPERATION,
742
- id: "sheet.operation.insert-hyper-link-toolbar",
743
- handler(accessor) {
744
- const commandService = accessor.get(ICommandService);
745
- return accessor.get(SheetsHyperLinkPopupService).currentEditing ? commandService.executeCommand(CloseHyperLinkSidebarOperation.id) : commandService.executeCommand(InsertHyperLinkOperation.id);
746
- }
747
- }, RemoveHyperLinkCommand = {
748
- type: CommandType.COMMAND,
749
- id: "sheets.command.remove-hyper-link",
750
- async handler(accessor, params) {
751
- if (!params)
752
- return !1;
753
- const sheetInterceptorService = accessor.get(SheetInterceptorService), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), model = accessor.get(HyperLinkModel), { unitId, subUnitId, id } = params, link = model.getHyperLink(unitId, subUnitId, id), { redos, undos } = sheetInterceptorService.onCommandExecute({
754
- id: RemoveHyperLinkCommand.id,
755
- params
756
- }), redo = {
757
- id: RemoveHyperLinkMutation.id,
758
- params
759
- }, undo = {
760
- id: AddHyperLinkMutation.id,
761
- params: {
762
- unitId,
763
- subUnitId,
764
- link
765
- }
766
- };
767
- return (await sequenceExecuteAsync([redo, ...redos], commandService)).result ? (undoRedoService.pushUndoRedo({
768
- redoMutations: [redo, ...redos],
769
- undoMutations: [undo, ...undos],
770
- unitID: unitId
771
- }), !0) : !1;
772
- }
773
- }, CancelHyperLinkCommand = {
774
- type: CommandType.COMMAND,
775
- id: "sheets.command.cancel-hyper-link",
776
- async handler(accessor, params) {
777
- if (!params)
778
- return !1;
779
- const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), model = accessor.get(HyperLinkModel), { unitId, subUnitId, id } = params, link = model.getHyperLink(unitId, subUnitId, id), redo = {
780
- id: RemoveHyperLinkMutation.id,
781
- params
782
- }, undo = {
783
- id: AddHyperLinkMutation.id,
784
- params: {
785
- unitId,
786
- subUnitId,
787
- link
788
- }
789
- };
790
- return (await sequenceExecuteAsync([redo], commandService)).result ? (undoRedoService.pushUndoRedo({
791
- redoMutations: [redo],
792
- undoMutations: [undo],
793
- unitID: unitId
794
- }), !0) : !1;
795
- }
796
- }, 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 = {
797
- cellLink,
798
- cellLinkType,
799
- cellLinkContent,
800
- cellLinkContentError,
801
- cellLinkUrl,
802
- cellLinkOperations,
803
- cellLinkOperation,
804
- cellLinkOperationError
805
- }, iconsMap = {
806
- outer: /* @__PURE__ */ jsxRuntimeExports.jsx(LinkSingle, {}),
807
- link: /* @__PURE__ */ jsxRuntimeExports.jsx(LinkSingle, {}),
808
- sheet: /* @__PURE__ */ jsxRuntimeExports.jsx(Xlsx, {}),
809
- range: /* @__PURE__ */ jsxRuntimeExports.jsx(AllBorderSingle, {}),
810
- defineName: /* @__PURE__ */ jsxRuntimeExports.jsx(AllBorderSingle, {}),
811
- "range-error": /* @__PURE__ */ jsxRuntimeExports.jsx(AllBorderSingle, {}),
812
- "sheet-error": /* @__PURE__ */ jsxRuntimeExports.jsx(Xlsx, {})
813
- }, CellLinkPopup = /* @__PURE__ */ __name(() => {
814
- const popupService = useDependency(SheetsHyperLinkPopupService), hyperLinkModel = useDependency(HyperLinkModel), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService), [currentPopup, setCurrentPopup] = useState(null), resolverService = useDependency(SheetsHyperLinkResolverService);
815
- if (useEffect(() => {
816
- setCurrentPopup(popupService.currentPopup);
817
- const ob = popupService.currentPopup$.subscribe((popup) => {
818
- setCurrentPopup(popup);
819
- });
820
- return () => {
821
- ob.unsubscribe();
822
- };
823
- }, [popupService.currentPopup, popupService.currentPopup$]), !currentPopup)
824
- return null;
825
- const { unitId, subUnitId, id } = currentPopup, link = hyperLinkModel.getHyperLink(unitId, subUnitId, id);
826
- if (!link)
827
- return null;
828
- const linkObj = resolverService.parseHyperLink(link.payload), isError = linkObj.type.indexOf("error") > -1;
829
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLink, onClick: /* @__PURE__ */ __name(() => popupService.hideCurrentPopup(), "onClick"), children: [
830
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cs(styles.cellLinkContent, { [styles.cellLinkContentError]: isError }), onClick: linkObj.handler, children: [
831
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.cellLinkType, children: iconsMap[linkObj.type] }),
832
- /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { showIfEllipsis: !0, title: linkObj.name, children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: styles.cellLinkUrl, children: linkObj.name }) })
833
- ] }),
834
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLinkOperations, children: [
835
- currentPopup.copyPermission && /* @__PURE__ */ jsxRuntimeExports.jsx(
836
- "div",
837
- {
838
- className: cs(styles.cellLinkOperation, { [styles.cellLinkOperationError]: isError }),
839
- onClick: /* @__PURE__ */ __name(() => {
840
- if (!isError) {
841
- if (linkObj.type !== "outer") {
842
- const url = new URL(window.location.href);
843
- url.hash = linkObj.url.slice(1), navigator.clipboard.writeText(url.href);
844
- } else
845
- navigator.clipboard.writeText(linkObj.url);
846
- messageService.show({
847
- content: localeService.t("hyperLink.message.coped"),
848
- type: MessageType.Info
849
- });
850
- }
851
- }, "onClick"),
852
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { placement: "bottom", title: localeService.t("hyperLink.popup.copy"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(CopySingle, {}) })
853
- }
854
- ),
855
- currentPopup.editPermission && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
856
- /* @__PURE__ */ jsxRuntimeExports.jsx(
857
- "div",
858
- {
859
- className: styles.cellLinkOperation,
860
- onClick: /* @__PURE__ */ __name(() => {
861
- commandService.executeCommand(OpenHyperLinkSidebarOperation.id, {
862
- unitId,
863
- subUnitId,
864
- row: link.row,
865
- column: link.column
866
- });
867
- }, "onClick"),
868
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { placement: "bottom", title: localeService.t("hyperLink.popup.edit"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(WriteSingle, {}) })
869
- }
870
- ),
871
- /* @__PURE__ */ jsxRuntimeExports.jsx(
872
- "div",
873
- {
874
- className: styles.cellLinkOperation,
875
- onClick: /* @__PURE__ */ __name(() => {
876
- commandService.executeCommand(CancelHyperLinkCommand.id, {
877
- unitId,
878
- subUnitId,
879
- id: link.id
880
- });
881
- }, "onClick"),
882
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { placement: "bottom", title: localeService.t("hyperLink.popup.cancel"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(UnlinkSingle, {}) })
883
- }
884
- )
885
- ] })
886
- ] })
887
- ] });
888
- }, "CellLinkPopup");
889
- CellLinkPopup.componentKey = "univer.sheet.cell-link-popup";
890
- var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
891
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1136
+ var __defProp$b = Object.defineProperty, __getOwnPropDesc$b = Object.getOwnPropertyDescriptor, __decorateClass$b = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1137
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
892
1138
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
893
- return kind && result && __defProp$a(target, key, result), result;
894
- }, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a");
895
- const isEqualLink = /* @__PURE__ */ __name((a, b) => a.unitId === b.unitId && a.subUnitId === b.subUnitId && a.row === b.row && a.col === b.col, "isEqualLink");
1139
+ return kind && result && __defProp$b(target, key, result), result;
1140
+ }, "__decorateClass$b"), __decorateParam$b = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$b");
1141
+ const isEqualLink = /* @__PURE__ */ __name((a, b) => {
1142
+ var _a15, _b;
1143
+ 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;
1144
+ }, "isEqualLink");
896
1145
  var _a2;
897
1146
  let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
898
- constructor(_hyperLinkModel, _sheetCanvasPopManagerService) {
1147
+ constructor(_sheetCanvasPopManagerService, _injector, _univerInstanceService, _editorBridgeService, _textSelectionManagerService, _docCanvasPopManagerService, _editorService, _rangeSelectorService, _zenZoneService) {
899
1148
  super();
900
1149
  __publicField(this, "_currentPopup", null);
901
1150
  __publicField(this, "_currentPopup$", new Subject());
902
1151
  __publicField(this, "currentPopup$", this._currentPopup$.asObservable());
1152
+ __publicField(this, "_currentEditingPopup", null);
903
1153
  __publicField(this, "_currentEditing$", new BehaviorSubject(null));
904
1154
  __publicField(this, "currentEditing$", this._currentEditing$.asObservable());
905
- this._hyperLinkModel = _hyperLinkModel, this._sheetCanvasPopManagerService = _sheetCanvasPopManagerService, this.disposeWithMe(() => {
1155
+ this._sheetCanvasPopManagerService = _sheetCanvasPopManagerService, this._injector = _injector, this._univerInstanceService = _univerInstanceService, this._editorBridgeService = _editorBridgeService, this._textSelectionManagerService = _textSelectionManagerService, this._docCanvasPopManagerService = _docCanvasPopManagerService, this._editorService = _editorService, this._rangeSelectorService = _rangeSelectorService, this._zenZoneService = _zenZoneService, this.disposeWithMe(() => {
906
1156
  this.hideCurrentPopup(), this.endEditing(), this._currentEditing$.complete(), this._currentPopup$.complete();
907
1157
  });
908
1158
  }
@@ -913,52 +1163,260 @@ let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
913
1163
  return this._currentEditing$.getValue();
914
1164
  }
915
1165
  showPopup(location2) {
916
- if (this._currentPopup && isEqualLink(location2, this._currentPopup))
1166
+ if (this._currentPopup && isEqualLink(location2, this._currentPopup) || (this.hideCurrentPopup(void 0, !0), location2.type !== HyperLinkEditSourceType.ZEN_EDITOR && this._zenZoneService.visible))
1167
+ return;
1168
+ const currentEditing = this._currentEditing$.getValue();
1169
+ if (currentEditing && isEqualLink(location2, currentEditing))
917
1170
  return;
918
- this.hideCurrentPopup();
919
- const { unitId, subUnitId, row, col } = location2, link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
920
- if (!link)
1171
+ const { unitId, subUnitId, row, col, customRangeRect, customRange } = location2;
1172
+ if (!customRange)
921
1173
  return;
922
- const disposable = this._sheetCanvasPopManagerService.attachPopupToCell(row, col, {
1174
+ let disposable;
1175
+ const popup = {
923
1176
  componentKey: CellLinkPopup.componentKey,
924
1177
  direction: "bottom",
925
- closeOnSelfTarget: !0,
926
1178
  onClickOutside: /* @__PURE__ */ __name(() => {
927
1179
  this.hideCurrentPopup();
928
- }, "onClickOutside")
929
- });
930
- disposable && (this._currentPopup = {
1180
+ }, "onClickOutside"),
1181
+ onClick: /* @__PURE__ */ __name(() => {
1182
+ this.hideCurrentPopup(location2.type, !0);
1183
+ }, "onClick")
1184
+ };
1185
+ location2.type === HyperLinkEditSourceType.EDITING ? disposable = customRangeRect && this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(
1186
+ customRangeRect,
1187
+ popup
1188
+ ) : location2.type === HyperLinkEditSourceType.ZEN_EDITOR ? disposable = this._docCanvasPopManagerService.attachPopupToRange(
1189
+ {
1190
+ startOffset: customRange.startIndex,
1191
+ endOffset: customRange.endIndex + 1,
1192
+ collapsed: !1
1193
+ },
1194
+ popup,
1195
+ DOCS_ZEN_EDITOR_UNIT_ID_KEY
1196
+ ) : disposable = customRangeRect && this._sheetCanvasPopManagerService.attachPopupByPosition(
1197
+ customRangeRect,
1198
+ popup
1199
+ ), disposable && (this._currentPopup = {
931
1200
  unitId,
932
1201
  subUnitId,
933
- id: link.id,
934
1202
  disposable,
935
1203
  row,
936
1204
  col,
937
1205
  editPermission: !!location2.editPermission,
938
- copyPermission: !!location2.copyPermission
1206
+ copyPermission: !!location2.copyPermission,
1207
+ customRange,
1208
+ type: location2.type
939
1209
  }, this._currentPopup$.next(this._currentPopup));
940
1210
  }
941
- hideCurrentPopup() {
942
- var _a14;
943
- this._currentPopup && ((_a14 = this._currentPopup.disposable) == null || _a14.dispose(), this._currentPopup = null, this._currentPopup$.next(null));
1211
+ hideCurrentPopup(type, force) {
1212
+ var _a15, _b;
1213
+ this._currentPopup && ((!type || type === this._currentPopup.type) && this._currentPopup.disposable.canDispose() || force) && ((_b = (_a15 = this._currentPopup) == null ? void 0 : _a15.disposable) == null || _b.dispose(), this._currentPopup = null, this._currentPopup$.next(null));
1214
+ }
1215
+ _getEditingRange() {
1216
+ var _a15, _b, _c;
1217
+ const visible = this._editorBridgeService.isVisible().visible, state = this._editorBridgeService.getEditCellState();
1218
+ if (visible && state) {
1219
+ const textRange = this._textSelectionManagerService.getActiveTextRange(), body = (_a15 = state.documentLayoutObject.documentModel) == null ? void 0 : _a15.getBody();
1220
+ if (!body)
1221
+ return null;
1222
+ if (!textRange || textRange.collapsed)
1223
+ return {
1224
+ startOffset: 0,
1225
+ endOffset: body.dataStream.length - 2,
1226
+ collapsed: body.dataStream.length - 2 === 0,
1227
+ label: getPlainTextFormBody(body)
1228
+ };
1229
+ const links = BuildTextUtils.customRange.getCustomRangesInterestsWithRange(textRange, (_c = (_b = body.customRanges) == null ? void 0 : _b.filter((i) => i.rangeType === CustomRangeType.HYPERLINK)) != null ? _c : []);
1230
+ let start = textRange.startOffset, end = textRange.endOffset;
1231
+ return links.forEach((link) => {
1232
+ start = Math.min(start, link.startIndex), end = Math.max(end, link.endIndex + 1);
1233
+ }), {
1234
+ startOffset: start,
1235
+ endOffset: end,
1236
+ collapsed: start === end,
1237
+ label: getPlainText(body.dataStream.slice(start, end))
1238
+ };
1239
+ }
1240
+ return null;
1241
+ }
1242
+ get _editPopup() {
1243
+ return {
1244
+ componentKey: CellLinkEdit.componentKey,
1245
+ direction: "bottom",
1246
+ onClickOutside: /* @__PURE__ */ __name(() => {
1247
+ const hyperLinkRangeSelectorId = createInternalEditorID("hyper-link-edit");
1248
+ this._editorService.getFocusId() !== hyperLinkRangeSelectorId && (this._rangeSelectorService.getCurrentSelectorId() === hyperLinkRangeSelectorId && this._rangeSelectorService.selectorModalVisible || this.endEditing());
1249
+ }, "onClickOutside"),
1250
+ hiddenType: "hide"
1251
+ };
1252
+ }
1253
+ startAddEditing(link) {
1254
+ var _a15, _b, _c;
1255
+ const { unitId, subUnitId, type } = link;
1256
+ if (type === HyperLinkEditSourceType.ZEN_EDITOR) {
1257
+ const document = this._univerInstanceService.getUnit(DOCS_ZEN_EDITOR_UNIT_ID_KEY, UniverInstanceType.UNIVER_DOC);
1258
+ if (!document)
1259
+ return;
1260
+ const range = this._textSelectionManagerService.getActiveTextRange();
1261
+ if (!range)
1262
+ return;
1263
+ this._currentEditingPopup = this._docCanvasPopManagerService.attachPopupToRange(
1264
+ range,
1265
+ this._editPopup,
1266
+ DOCS_ZEN_EDITOR_UNIT_ID_KEY
1267
+ );
1268
+ const label = (_a15 = document.getBody()) == null ? void 0 : _a15.dataStream.slice(range.startOffset, range.endOffset - 1);
1269
+ this._currentEditing$.next({
1270
+ ...link,
1271
+ label
1272
+ });
1273
+ } else if (type === HyperLinkEditSourceType.EDITING) {
1274
+ const range = this._getEditingRange();
1275
+ range && this._textSelectionManagerService.replaceTextRanges([{ ...range }]), this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToCell(
1276
+ link.row,
1277
+ link.col,
1278
+ this._editPopup,
1279
+ unitId,
1280
+ subUnitId
1281
+ ), this._currentEditing$.next({
1282
+ ...link,
1283
+ label: (_b = range == null ? void 0 : range.label) != null ? _b : ""
1284
+ });
1285
+ } else {
1286
+ this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToCell(
1287
+ link.row,
1288
+ link.col,
1289
+ this._editPopup,
1290
+ unitId,
1291
+ subUnitId
1292
+ );
1293
+ 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);
1294
+ this._currentEditing$.next({
1295
+ ...link,
1296
+ label: cell != null && cell.p ? getPlainTextFormDocument(cell.p) : ((_c = cell == null ? void 0 : cell.v) != null ? _c : "").toString()
1297
+ });
1298
+ }
944
1299
  }
945
1300
  startEditing(link) {
946
- this._currentEditing$.next(link);
1301
+ var _a15, _b, _c, _d, _e, _f;
1302
+ (_a15 = this._currentEditingPopup) == null || _a15.dispose(), this.hideCurrentPopup(void 0, !0);
1303
+ const { unitId, subUnitId } = link;
1304
+ let customRange, label;
1305
+ if (link.type === HyperLinkEditSourceType.ZEN_EDITOR) {
1306
+ const document = this._univerInstanceService.getUnit(DOCS_ZEN_EDITOR_UNIT_ID_KEY, UniverInstanceType.UNIVER_DOC);
1307
+ if (customRange = (_c = (_b = document == null ? void 0 : document.getBody()) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((range) => range.rangeId === link.customRangeId), label = customRange ? (_d = document == null ? void 0 : document.getBody()) == null ? void 0 : _d.dataStream.slice(customRange.startIndex + 1, customRange.endIndex) : "", !customRange || !label)
1308
+ return;
1309
+ this._textSelectionManagerService.replaceTextRanges([
1310
+ {
1311
+ startOffset: customRange.startIndex,
1312
+ endOffset: customRange.endIndex + 1
1313
+ }
1314
+ ]), this._currentEditingPopup = this._docCanvasPopManagerService.attachPopupToRange(
1315
+ {
1316
+ startOffset: customRange.startIndex,
1317
+ endOffset: customRange.endIndex,
1318
+ collapsed: !1
1319
+ },
1320
+ this._editPopup,
1321
+ DOCS_ZEN_EDITOR_UNIT_ID_KEY
1322
+ );
1323
+ } else if (link.type === HyperLinkEditSourceType.EDITING) {
1324
+ const customRangeInfo = getEditingCustomRangePosition(this._injector, link.unitId, link.subUnitId, link.row, link.col, link.customRangeId);
1325
+ if (!customRangeInfo || !((_e = customRangeInfo.rects) != null && _e.length))
1326
+ return;
1327
+ customRange = customRangeInfo.customRange, label = customRangeInfo.label, this._textSelectionManagerService.replaceTextRanges([
1328
+ {
1329
+ startOffset: customRange.startIndex,
1330
+ endOffset: customRange.endIndex + 1
1331
+ }
1332
+ ]), this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(
1333
+ customRangeInfo.rects.pop(),
1334
+ this._editPopup,
1335
+ unitId,
1336
+ subUnitId
1337
+ );
1338
+ } else {
1339
+ const customRangeInfo = getCustomRangePosition(this._injector, link.unitId, link.subUnitId, link.row, link.col, link.customRangeId);
1340
+ if (!customRangeInfo || !((_f = customRangeInfo.rects) != null && _f.length))
1341
+ return;
1342
+ customRange = customRangeInfo.customRange, label = customRangeInfo.label, this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupByPosition(
1343
+ customRangeInfo.rects.pop(),
1344
+ this._editPopup,
1345
+ unitId,
1346
+ subUnitId
1347
+ );
1348
+ }
1349
+ this._currentEditing$.next({
1350
+ ...link,
1351
+ customRange,
1352
+ label
1353
+ });
1354
+ }
1355
+ endEditing(type) {
1356
+ var _a15;
1357
+ const current = this._currentEditing$.getValue();
1358
+ current && (!type || type === current.type) && ((_a15 = this._currentEditingPopup) == null || _a15.dispose(), this._currentEditing$.next(null));
1359
+ }
1360
+ }, __name(_a2, "SheetsHyperLinkPopupService"), _a2);
1361
+ SheetsHyperLinkPopupService = __decorateClass$b([
1362
+ __decorateParam$b(0, Inject(SheetCanvasPopManagerService)),
1363
+ __decorateParam$b(1, Inject(Injector)),
1364
+ __decorateParam$b(2, IUniverInstanceService),
1365
+ __decorateParam$b(3, IEditorBridgeService),
1366
+ __decorateParam$b(4, Inject(DocSelectionManagerService)),
1367
+ __decorateParam$b(5, Inject(DocCanvasPopManagerService)),
1368
+ __decorateParam$b(6, IEditorService),
1369
+ __decorateParam$b(7, IRangeSelectorService),
1370
+ __decorateParam$b(8, IZenZoneService)
1371
+ ], SheetsHyperLinkPopupService);
1372
+ const OpenHyperLinkEditPanelOperation = {
1373
+ type: CommandType.OPERATION,
1374
+ id: "sheet.operation.open-hyper-link-edit-panel",
1375
+ handler(accessor, params) {
1376
+ if (!params)
1377
+ return !1;
1378
+ const popupService = accessor.get(SheetsHyperLinkPopupService);
1379
+ return params.customRangeId ? popupService.startEditing(params) : popupService.startAddEditing(params), !0;
1380
+ }
1381
+ }, CloseHyperLinkPopupOperation = {
1382
+ type: CommandType.OPERATION,
1383
+ id: "sheet.operation.close-hyper-link-popup",
1384
+ handler(accessor) {
1385
+ return accessor.get(SheetsHyperLinkPopupService).endEditing(), !0;
947
1386
  }
948
- endEditing() {
949
- this._currentEditing$.next(null);
1387
+ }, InsertHyperLinkOperation = {
1388
+ type: CommandType.OPERATION,
1389
+ id: "sheet.operation.insert-hyper-link",
1390
+ handler(accessor) {
1391
+ var _a15;
1392
+ const univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService), editorBridgeService = accessor.get(IEditorBridgeService);
1393
+ if (!target)
1394
+ return !1;
1395
+ const commandService = accessor.get(ICommandService), selection = accessor.get(SheetsSelectionsService).getCurrentLastSelection();
1396
+ if (!selection)
1397
+ return !1;
1398
+ const row = selection.range.startRow, col = selection.range.startColumn, visible = editorBridgeService.isVisible(), isZenEditor = ((_a15 = univerInstanceService.getFocusedUnit()) == null ? void 0 : _a15.getUnitId()) === DOCS_ZEN_EDITOR_UNIT_ID_KEY;
1399
+ return commandService.executeCommand(OpenHyperLinkEditPanelOperation.id, {
1400
+ unitId: target.unitId,
1401
+ subUnitId: target.subUnitId,
1402
+ row,
1403
+ col,
1404
+ type: isZenEditor ? HyperLinkEditSourceType.ZEN_EDITOR : visible.visible ? HyperLinkEditSourceType.EDITING : HyperLinkEditSourceType.VIEWING
1405
+ });
1406
+ }
1407
+ }, InsertHyperLinkToolbarOperation = {
1408
+ type: CommandType.OPERATION,
1409
+ id: "sheet.operation.insert-hyper-link-toolbar",
1410
+ handler(accessor) {
1411
+ const commandService = accessor.get(ICommandService);
1412
+ return accessor.get(SheetsHyperLinkPopupService).currentEditing ? commandService.executeCommand(CloseHyperLinkPopupOperation.id) : commandService.executeCommand(InsertHyperLinkOperation.id);
950
1413
  }
951
- }, __name(_a2, "SheetsHyperLinkPopupService"), _a2);
952
- SheetsHyperLinkPopupService = __decorateClass$a([
953
- __decorateParam$a(0, Inject(HyperLinkModel)),
954
- __decorateParam$a(1, Inject(SheetCanvasPopManagerService))
955
- ], SheetsHyperLinkPopupService);
956
- const SHEET_HYPER_LINK_UI_PLUGIN = "SHEET_HYPER_LINK_UI_PLUGIN";
957
- var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
958
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1414
+ }, SHEET_HYPER_LINK_UI_PLUGIN = "SHEET_HYPER_LINK_UI_PLUGIN";
1415
+ var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1416
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
959
1417
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
960
- return kind && result && __defProp$9(target, key, result), result;
961
- }, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9"), _a3;
1418
+ return kind && result && __defProp$a(target, key, result), result;
1419
+ }, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a"), _a3;
962
1420
  let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
963
1421
  constructor(_sheetClipboardService, _hyperLinkModel, _injector, _resolverService) {
964
1422
  super();
@@ -989,7 +1447,7 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
989
1447
  onPastePlainText: /* @__PURE__ */ __name((pasteTo, clipText) => {
990
1448
  const filterResult = this._filterPlainText(clipText);
991
1449
  if (isLegalLink(clipText) && filterResult) {
992
- const text = serializeUrl(clipText), { range, unitId, subUnitId } = pasteTo, { ranges: [pasteToRange], mapFunc } = virtualizeDiscreteRanges([range]), redos = [], undos = [];
1450
+ const { range, unitId, subUnitId } = pasteTo, { ranges: [pasteToRange], mapFunc } = virtualizeDiscreteRanges([range]), redos = [], undos = [];
993
1451
  return Range.foreach(pasteToRange, (originRow, originCol) => {
994
1452
  const { row, col: column } = mapFunc(originRow, originCol), link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
995
1453
  link && redos.push({
@@ -999,27 +1457,6 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
999
1457
  subUnitId,
1000
1458
  id: link.id
1001
1459
  }
1002
- });
1003
- const newId = Tools.generateRandomId();
1004
- redos.push({
1005
- id: AddHyperLinkMutation.id,
1006
- params: {
1007
- unitId,
1008
- subUnitId,
1009
- link: {
1010
- id: newId,
1011
- row,
1012
- column,
1013
- payload: text
1014
- }
1015
- }
1016
- }), undos.push({
1017
- id: RemoveHyperLinkMutation.id,
1018
- params: {
1019
- unitId,
1020
- subUnitId,
1021
- id: newId
1022
- }
1023
1460
  }), link && undos.push({
1024
1461
  id: AddHyperLinkMutation.id,
1025
1462
  params: {
@@ -1048,9 +1485,9 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
1048
1485
  const { rows, cols } = discreteRange;
1049
1486
  rows.forEach((row, rowIndex) => {
1050
1487
  cols.forEach((col, colIndex) => {
1051
- var _a14;
1488
+ var _a15;
1052
1489
  const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1053
- matrix.setValue(rowIndex, colIndex, (_a14 = link == null ? void 0 : link.id) != null ? _a14 : "");
1490
+ matrix.setValue(rowIndex, colIndex, (_a15 = link == null ? void 0 : link.id) != null ? _a15 : "");
1054
1491
  });
1055
1492
  });
1056
1493
  }
@@ -1071,8 +1508,8 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
1071
1508
  return { redos: [], undos: [] };
1072
1509
  const { unitId, subUnitId } = this._copyInfo, redos = [], undos = [], { ranges: [vCopyRange, vPastedRange], mapFunc } = virtualizeDiscreteRanges([copyInfo.copyRange, pastedRange]);
1073
1510
  return getRepeatRange(vCopyRange, vPastedRange, !0).forEach(({ startRange }) => {
1074
- var _a14;
1075
- (_a14 = this._copyInfo) == null || _a14.matrix.forValue((row, col, ruleId) => {
1511
+ var _a15;
1512
+ (_a15 = this._copyInfo) == null || _a15.matrix.forValue((row, col, ruleId) => {
1076
1513
  const range = Rectangle.getPositionRange(
1077
1514
  {
1078
1515
  startRow: row,
@@ -1120,18 +1557,104 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
1120
1557
  }), { redos, undos };
1121
1558
  }
1122
1559
  }, __name(_a3, "SheetsHyperLinkCopyPasteController"), _a3);
1123
- SheetsHyperLinkCopyPasteController = __decorateClass$9([
1560
+ SheetsHyperLinkCopyPasteController = __decorateClass$a([
1124
1561
  OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkCopyPasteController),
1125
- __decorateParam$9(0, ISheetClipboardService),
1126
- __decorateParam$9(1, Inject(HyperLinkModel)),
1127
- __decorateParam$9(2, Inject(Injector)),
1128
- __decorateParam$9(3, Inject(SheetsHyperLinkResolverService))
1562
+ __decorateParam$a(0, ISheetClipboardService),
1563
+ __decorateParam$a(1, Inject(HyperLinkModel)),
1564
+ __decorateParam$a(2, Inject(Injector)),
1565
+ __decorateParam$a(3, Inject(SheetsHyperLinkResolverService))
1129
1566
  ], SheetsHyperLinkCopyPasteController);
1130
- var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1131
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1567
+ const getLinkDisable$ = /* @__PURE__ */ __name((accessor) => {
1568
+ const disableRange$ = getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }), univerInstanceService = accessor.get(IUniverInstanceService), sheetSelectionService = accessor.get(SheetsSelectionsService), disableCell$ = univerInstanceService.focused$.pipe(
1569
+ map((focused) => focused ? univerInstanceService.getUnit(focused, UniverInstanceType.UNIVER_SHEET) : null),
1570
+ mergeMap((unit) => unit ? unit.activeSheet$ : new Observable((sub) => {
1571
+ sub.next(null);
1572
+ })),
1573
+ mergeMap((sheet) => sheetSelectionService.selectionMoveEnd$.pipe(map((selections) => sheet && { selections, sheet }))),
1574
+ map((sheetWithSelection) => {
1575
+ if (!sheetWithSelection)
1576
+ return !0;
1577
+ const { selections, sheet } = sheetWithSelection;
1578
+ if (!selections.length)
1579
+ return !0;
1580
+ const row = selections[0].range.startRow, col = selections[0].range.startColumn, cell = sheet.getCell(row, col);
1581
+ if (cell != null && cell.f || cell != null && cell.si)
1582
+ return !0;
1583
+ const disables = [
1584
+ DataValidationType.CHECKBOX,
1585
+ DataValidationType.LIST,
1586
+ DataValidationType.LIST_MULTIPLE
1587
+ ];
1588
+ return !!(cell != null && cell.dataValidation && disables.includes(cell.dataValidation.rule.type));
1589
+ })
1590
+ );
1591
+ return disableRange$.pipe(mergeMap((disableRange) => disableCell$.pipe(map((disableCell) => disableRange || disableCell))));
1592
+ }, "getLinkDisable$"), shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
1593
+ var _a15;
1594
+ const textSelectionService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges = textSelectionService.getDocRanges();
1595
+ if (!textRanges.length || textRanges.length > 1)
1596
+ return !0;
1597
+ const activeRange = textRanges[0], doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
1598
+ if (!doc || !activeRange || activeRange.collapsed)
1599
+ return !0;
1600
+ const body = doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody(), paragraphs = body == null ? void 0 : body.paragraphs;
1601
+ if (!paragraphs)
1602
+ return !0;
1603
+ for (let i = 0, len = paragraphs.length; i < len; i++) {
1604
+ const p2 = paragraphs[i];
1605
+ if (activeRange.startOffset <= p2.startIndex && activeRange.endOffset > p2.startIndex)
1606
+ return !0;
1607
+ if (p2.startIndex > activeRange.endOffset)
1608
+ break;
1609
+ }
1610
+ return !BuildTextUtils.customRange.getCustomRangesInterestsWithRange(activeRange, (_a15 = body.customRanges) != null ? _a15 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
1611
+ }, "shouldDisableAddLink"), getZenLinkDisable$ = /* @__PURE__ */ __name((accessor) => accessor.get(IUniverInstanceService).focused$.pipe(
1612
+ mergeMap((focused) => !focused || focused !== DOCS_ZEN_EDITOR_UNIT_ID_KEY ? new Observable((sub) => sub.next(null)) : accessor.get(DocSelectionManagerService).textSelection$),
1613
+ map((selection) => !selection || selection.unitId !== DOCS_ZEN_EDITOR_UNIT_ID_KEY ? !0 : shouldDisableAddLink(accessor))
1614
+ ), "getZenLinkDisable$"), linkMenu = {
1615
+ commandId: InsertHyperLinkOperation.id,
1616
+ type: MenuItemType.BUTTON,
1617
+ positions: [MenuPosition.CONTEXT_MENU],
1618
+ title: "hyperLink.menu.add",
1619
+ icon: "LinkSingle"
1620
+ }, genZenEditorMenuId = /* @__PURE__ */ __name((id) => `${id}-zen-editor`, "genZenEditorMenuId"), insertLinkMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1621
+ ...linkMenu,
1622
+ id: linkMenu.commandId,
1623
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1624
+ disabled$: getLinkDisable$(accessor)
1625
+ // disabled$: getObservableWithExclusiveRange$(accessor, getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })),
1626
+ }), "insertLinkMenuFactory"), zenEditorInsertLinkMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1627
+ ...linkMenu,
1628
+ id: genZenEditorMenuId(linkMenu.commandId),
1629
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC, DOCS_ZEN_EDITOR_UNIT_ID_KEY),
1630
+ disabled$: getZenLinkDisable$(accessor)
1631
+ }), "zenEditorInsertLinkMenuFactory"), linkToolbarMenu = {
1632
+ tooltip: "hyperLink.form.addTitle",
1633
+ positions: MenuPosition.TOOLBAR_START,
1634
+ group: MenuGroup.TOOLBAR_OTHERS,
1635
+ commandId: InsertHyperLinkToolbarOperation.id,
1636
+ type: MenuItemType.BUTTON,
1637
+ icon: "LinkSingle"
1638
+ }, insertLinkMenuToolbarFactory = /* @__PURE__ */ __name((accessor) => ({
1639
+ ...linkToolbarMenu,
1640
+ id: linkToolbarMenu.commandId,
1641
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1642
+ disabled$: getLinkDisable$(accessor)
1643
+ }), "insertLinkMenuToolbarFactory"), zenEditorInsertLinkMenuToolbarFactory = /* @__PURE__ */ __name((accessor) => ({
1644
+ ...linkToolbarMenu,
1645
+ id: genZenEditorMenuId(linkToolbarMenu.commandId),
1646
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC, DOCS_ZEN_EDITOR_UNIT_ID_KEY),
1647
+ disabled$: getZenLinkDisable$(accessor)
1648
+ }), "zenEditorInsertLinkMenuToolbarFactory"), InsertLinkShortcut = {
1649
+ id: InsertHyperLinkToolbarOperation.id,
1650
+ binding: KeyCode.K | MetaKeys.CTRL_COMMAND,
1651
+ preconditions: whenSheetEditorFocused
1652
+ };
1653
+ var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1654
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1132
1655
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1133
- return kind && result && __defProp$8(target, key, result), result;
1134
- }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a4;
1656
+ return kind && result && __defProp$9(target, key, result), result;
1657
+ }, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9"), _a4;
1135
1658
  let SheetsHyperLinkRemoveSheetController = (_a4 = class extends Disposable {
1136
1659
  constructor(_sheetInterceptorService, _univerInstanceService, _hyperLinkModel) {
1137
1660
  super(), this._sheetInterceptorService = _sheetInterceptorService, this._univerInstanceService = _univerInstanceService, this._hyperLinkModel = _hyperLinkModel, this._initSheetChange();
@@ -1140,12 +1663,12 @@ let SheetsHyperLinkRemoveSheetController = (_a4 = class extends Disposable {
1140
1663
  this.disposeWithMe(
1141
1664
  this._sheetInterceptorService.interceptCommand({
1142
1665
  getMutations: /* @__PURE__ */ __name((commandInfo) => {
1143
- var _a14;
1666
+ var _a15;
1144
1667
  if (commandInfo.id === RemoveSheetCommand.id) {
1145
1668
  const params = commandInfo.params, workbook = params.unitId ? this._univerInstanceService.getUnit(params.unitId) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
1146
1669
  if (!workbook)
1147
1670
  return { redos: [], undos: [] };
1148
- const unitId = workbook.getUnitId(), subUnitId = params.subUnitId || ((_a14 = workbook.getActiveSheet()) == null ? void 0 : _a14.getSheetId());
1671
+ const unitId = workbook.getUnitId(), subUnitId = params.subUnitId || ((_a15 = workbook.getActiveSheet()) == null ? void 0 : _a15.getSheetId());
1149
1672
  if (!subUnitId)
1150
1673
  return { redos: [], undos: [] };
1151
1674
  const links = this._hyperLinkModel.getSubUnit(unitId, subUnitId), redos = links.map((link) => ({
@@ -1171,25 +1694,25 @@ let SheetsHyperLinkRemoveSheetController = (_a4 = class extends Disposable {
1171
1694
  );
1172
1695
  }
1173
1696
  }, __name(_a4, "SheetsHyperLinkRemoveSheetController"), _a4);
1174
- SheetsHyperLinkRemoveSheetController = __decorateClass$8([
1697
+ SheetsHyperLinkRemoveSheetController = __decorateClass$9([
1175
1698
  OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkRemoveSheetController),
1176
- __decorateParam$8(0, Inject(SheetInterceptorService)),
1177
- __decorateParam$8(1, IUniverInstanceService),
1178
- __decorateParam$8(2, Inject(HyperLinkModel))
1699
+ __decorateParam$9(0, Inject(SheetInterceptorService)),
1700
+ __decorateParam$9(1, IUniverInstanceService),
1701
+ __decorateParam$9(2, Inject(HyperLinkModel))
1179
1702
  ], SheetsHyperLinkRemoveSheetController);
1180
- var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1181
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1703
+ var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1704
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1182
1705
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1183
- return kind && result && __defProp$7(target, key, result), result;
1184
- }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a5;
1706
+ return kind && result && __defProp$8(target, key, result), result;
1707
+ }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a5;
1185
1708
  let SheetsHyperLinkRenderController = (_a5 = class extends Disposable {
1186
1709
  constructor(_context, _hyperLinkModel, _sheetSkeletonManagerService, _renderManagerService) {
1187
1710
  super(), this._context = _context, this._hyperLinkModel = _hyperLinkModel, this._sheetSkeletonManagerService = _sheetSkeletonManagerService, this._renderManagerService = _renderManagerService, this._initSkeletonChange();
1188
1711
  }
1189
1712
  _initSkeletonChange() {
1190
1713
  const markSkeletonDirty = /* @__PURE__ */ __name(() => {
1191
- var _a14;
1192
- const workbook = this._context.unit, unitId = workbook.getUnitId(), subUnitId = (_a14 = workbook.getActiveSheet()) == null ? void 0 : _a14.getSheetId();
1714
+ var _a15;
1715
+ const workbook = this._context.unit, unitId = workbook.getUnitId(), subUnitId = (_a15 = workbook.getActiveSheet()) == null ? void 0 : _a15.getSheetId();
1193
1716
  if (!subUnitId) {
1194
1717
  console.warn("No active sheet found");
1195
1718
  return;
@@ -1202,10 +1725,10 @@ let SheetsHyperLinkRenderController = (_a5 = class extends Disposable {
1202
1725
  }));
1203
1726
  }
1204
1727
  }, __name(_a5, "SheetsHyperLinkRenderController"), _a5);
1205
- SheetsHyperLinkRenderController = __decorateClass$7([
1206
- __decorateParam$7(1, Inject(HyperLinkModel)),
1207
- __decorateParam$7(2, Inject(SheetSkeletonManagerService)),
1208
- __decorateParam$7(3, IRenderManagerService)
1728
+ SheetsHyperLinkRenderController = __decorateClass$8([
1729
+ __decorateParam$8(1, Inject(HyperLinkModel)),
1730
+ __decorateParam$8(2, Inject(SheetSkeletonManagerService)),
1731
+ __decorateParam$8(3, IRenderManagerService)
1209
1732
  ], SheetsHyperLinkRenderController);
1210
1733
  var _a6;
1211
1734
  let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
@@ -1218,17 +1741,11 @@ let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
1218
1741
  INTERCEPTOR_POINT.CELL_CONTENT,
1219
1742
  {
1220
1743
  handler: /* @__PURE__ */ __name((cell, pos, next) => {
1221
- const { row, col, unitId, subUnitId } = pos, link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col), styleSheet = this._themeService.getCurrentTheme();
1744
+ const { row, col, unitId, subUnitId } = pos, link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1222
1745
  return next(link ? {
1223
1746
  ...cell,
1224
- interceptorStyle: {
1225
- ul: {
1226
- s: BooleanNumber.TRUE
1227
- },
1228
- cl: {
1229
- rgb: styleSheet.blue500
1230
- }
1231
- }
1747
+ linkUrl: link.payload,
1748
+ linkId: link.id
1232
1749
  } : cell);
1233
1750
  }, "handler"),
1234
1751
  priority: 100
@@ -1237,140 +1754,32 @@ let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
1237
1754
  );
1238
1755
  }
1239
1756
  }, __name(_a6, "SheetsHyperLinkRenderManagerController"), _a6);
1240
- SheetsHyperLinkRenderManagerController = __decorateClass$7([
1757
+ SheetsHyperLinkRenderManagerController = __decorateClass$8([
1241
1758
  OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkRenderManagerController),
1242
- __decorateParam$7(0, Inject(SheetInterceptorService)),
1243
- __decorateParam$7(1, Inject(HyperLinkModel)),
1244
- __decorateParam$7(2, Inject(ThemeService))
1759
+ __decorateParam$8(0, Inject(SheetInterceptorService)),
1760
+ __decorateParam$8(1, Inject(HyperLinkModel)),
1761
+ __decorateParam$8(2, Inject(ThemeService))
1245
1762
  ], SheetsHyperLinkRenderManagerController);
1246
- var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1247
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1763
+ var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1764
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1248
1765
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1249
- return kind && result && __defProp$6(target, key, result), result;
1250
- }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a7;
1766
+ return kind && result && __defProp$7(target, key, result), result;
1767
+ }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a7;
1251
1768
  let SheetHyperLinkSetRangeController = (_a7 = class extends Disposable {
1252
- constructor(_sheetInterceptorService, _injector, _hyperLinkModel, _selectionManagerService, _univerInstanceService, _editorBridgeService) {
1253
- super(), this._sheetInterceptorService = _sheetInterceptorService, this._injector = _injector, this._hyperLinkModel = _hyperLinkModel, this._selectionManagerService = _selectionManagerService, this._univerInstanceService = _univerInstanceService, this._editorBridgeService = _editorBridgeService, this._initCommandInterceptor();
1769
+ constructor(_sheetInterceptorService, _hyperLinkModel, _selectionManagerService, _univerInstanceService, _editorBridgeService, _renderManagerService) {
1770
+ super(), this._sheetInterceptorService = _sheetInterceptorService, this._hyperLinkModel = _hyperLinkModel, this._selectionManagerService = _selectionManagerService, this._univerInstanceService = _univerInstanceService, this._editorBridgeService = _editorBridgeService, this._renderManagerService = _renderManagerService, this._initCommandInterceptor(), this._initAfterEditor();
1254
1771
  }
1255
1772
  _initCommandInterceptor() {
1256
- this._initAddHyperLinkCommandInterceptor(), this._initSetRangeValuesCommandInterceptor(), this._initUpdateHyperLinkCommandInterceptor(), this._initClearSelectionCommandInterceptor(), this._initRichTextEditorInterceptor();
1257
- }
1258
- _getCurrentCell(unitId, subUnitId, row, col) {
1259
- var _a14, _b;
1260
- return (_b = (_a14 = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET)) == null ? void 0 : _a14.getSheetBySheetId(subUnitId)) == null ? void 0 : _b.getCell(row, col);
1261
- }
1262
- _initAddHyperLinkCommandInterceptor() {
1263
- this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
1264
- getMutations: /* @__PURE__ */ __name((command) => {
1265
- var _a14;
1266
- if (command.id === AddHyperLinkCommand.id) {
1267
- const params = command.params, { unitId, subUnitId, link } = params, currentCell = this._getCurrentCell(unitId, subUnitId, link.row, link.column), redoParams = {
1268
- unitId,
1269
- subUnitId,
1270
- cellValue: {
1271
- [link.row]: {
1272
- [link.column]: {
1273
- v: link.display,
1274
- // t: CellValueType.STRING, // Setting a link to a number is still a number
1275
- p: null,
1276
- t: (_a14 = currentCell == null ? void 0 : currentCell.t) != null ? _a14 : void 0
1277
- // Keep force string type
1278
- }
1279
- }
1280
- }
1281
- };
1282
- return {
1283
- redos: [{
1284
- id: SetRangeValuesMutation.id,
1285
- params: redoParams
1286
- }],
1287
- undos: [{
1288
- id: SetRangeValuesMutation.id,
1289
- params: SetRangeValuesUndoMutationFactory(this._injector, redoParams)
1290
- }]
1291
- };
1292
- }
1293
- return {
1294
- redos: [],
1295
- undos: []
1296
- };
1297
- }, "getMutations")
1298
- }));
1299
- }
1300
- _initUpdateHyperLinkCommandInterceptor() {
1301
- this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
1302
- getMutations: /* @__PURE__ */ __name((command) => {
1303
- if (command.id === UpdateHyperLinkCommand.id) {
1304
- const params = command.params, { unitId, subUnitId, id, payload } = params, current = this._hyperLinkModel.getHyperLink(unitId, subUnitId, id);
1305
- if (current && current.display !== payload.display) {
1306
- const redoParams = {
1307
- unitId,
1308
- subUnitId,
1309
- cellValue: {
1310
- [current.row]: {
1311
- [current.column]: {
1312
- v: payload.display,
1313
- t: CellValueType.STRING,
1314
- p: null
1315
- }
1316
- }
1317
- }
1318
- };
1319
- return {
1320
- redos: [{
1321
- id: SetRangeValuesMutation.id,
1322
- params: redoParams
1323
- }],
1324
- undos: [{
1325
- id: SetRangeValuesMutation.id,
1326
- params: SetRangeValuesUndoMutationFactory(this._injector, redoParams)
1327
- }]
1328
- };
1329
- }
1330
- }
1331
- return {
1332
- redos: [],
1333
- undos: []
1334
- };
1335
- }, "getMutations")
1336
- }));
1773
+ this._initSetRangeValuesCommandInterceptor(), this._initClearSelectionCommandInterceptor();
1337
1774
  }
1338
1775
  _initSetRangeValuesCommandInterceptor() {
1339
1776
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
1340
1777
  getMutations: /* @__PURE__ */ __name((command) => {
1341
1778
  if (command.id === SetRangeValuesCommand.id) {
1342
1779
  const params = command.params, { unitId, subUnitId } = params, redos = [], undos = [];
1343
- return params.cellValue && new ObjectMatrix(params.cellValue).forValue((row, col, cell) => {
1344
- var _a14, _b, _c, _d, _e, _f, _g;
1345
- const cellValueRaw = (_c = cell == null ? void 0 : cell.v) != null ? _c : (_b = (_a14 = cell == null ? void 0 : cell.p) == null ? void 0 : _a14.body) == null ? void 0 : _b.dataStream.slice(0, -2), cellValue = (cellValueRaw != null ? cellValueRaw : "").toString(), link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1346
- if (!link) {
1347
- if (isLegalLink(cellValue) || (_d = cell == null ? void 0 : cell.custom) != null && _d.__link_url) {
1348
- const url = (_f = (_e = cell == null ? void 0 : cell.custom) == null ? void 0 : _e.__link_url) != null ? _f : cellValue, id = Tools.generateRandomId();
1349
- undos.push({
1350
- id: RemoveHyperLinkMutation.id,
1351
- params: {
1352
- unitId,
1353
- subUnitId,
1354
- id
1355
- }
1356
- }), redos.push({
1357
- id: AddHyperLinkMutation.id,
1358
- params: {
1359
- unitId,
1360
- subUnitId,
1361
- link: {
1362
- id,
1363
- row,
1364
- column: col,
1365
- display: cellValue,
1366
- payload: serializeUrl(url)
1367
- }
1368
- }
1369
- });
1370
- }
1371
- return;
1372
- }
1373
- (cellValueRaw === "" || ((_g = cell == null ? void 0 : cell.custom) == null ? void 0 : _g.__link_url) === "") && (redos.push({
1780
+ return params.cellValue && new ObjectMatrix(params.cellValue).forValue((row, col) => {
1781
+ const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1782
+ link && (redos.push({
1374
1783
  id: RemoveHyperLinkMutation.id,
1375
1784
  params: {
1376
1785
  unitId,
@@ -1435,88 +1844,220 @@ let SheetHyperLinkSetRangeController = (_a7 = class extends Disposable {
1435
1844
  }, "getMutations")
1436
1845
  }));
1437
1846
  }
1438
- _initRichTextEditorInterceptor() {
1439
- this.disposeWithMe(
1440
- this._editorBridgeService.interceptor.intercept(
1441
- this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,
1442
- {
1443
- handler: /* @__PURE__ */ __name((data, context, next) => {
1444
- var _a14, _b, _c;
1445
- if (data != null && data.p) {
1446
- const range = (_b = (_a14 = data.p.body) == null ? void 0 : _a14.customRanges) == null ? void 0 : _b.find((i) => i.rangeType === CustomRangeType.HYPERLINK);
1447
- if (range) {
1448
- const url = (_c = range.properties) == null ? void 0 : _c.url;
1449
- return next({
1450
- ...data,
1451
- p: null,
1452
- v: getPlainTextFormDocument(data.p),
1453
- t: CellValueType.STRING,
1454
- custom: {
1455
- __link_url: url
1456
- }
1457
- });
1847
+ _initAfterEditor() {
1848
+ this.disposeWithMe(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT, {
1849
+ handler: /* @__PURE__ */ __name((cell, context, next) => {
1850
+ if (!cell || cell.p)
1851
+ return next(cell);
1852
+ if (typeof cell.v == "string" && Tools.isLegalUrl(cell.v) && cell.v[cell.v.length - 1] !== " ") {
1853
+ const { unitId, subUnitId } = context, renderer = this._renderManagerService.getRenderById(unitId), skeleton = renderer == null ? void 0 : renderer.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);
1854
+ if (!skeleton)
1855
+ return next(cell);
1856
+ const doc = skeleton.skeleton.getBlankCellDocumentModel(cell);
1857
+ if (!doc.documentModel)
1858
+ return next(cell);
1859
+ const textX = BuildTextUtils.selection.replace({
1860
+ selection: {
1861
+ startOffset: 0,
1862
+ endOffset: cell.v.length,
1863
+ collapsed: !1
1864
+ },
1865
+ body: {
1866
+ dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${cell.v}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
1867
+ customRanges: [{
1868
+ startIndex: 0,
1869
+ endIndex: cell.v.length,
1870
+ rangeId: generateRandomId(),
1871
+ rangeType: CustomRangeType.HYPERLINK,
1872
+ properties: {
1873
+ url: cell.v
1874
+ }
1875
+ }]
1876
+ },
1877
+ doc: doc.documentModel
1878
+ });
1879
+ if (!textX)
1880
+ return next(cell);
1881
+ const body = doc.documentModel.getBody();
1882
+ return TextX.apply(body, textX.serialize()), next({
1883
+ ...cell,
1884
+ p: {
1885
+ id: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
1886
+ body,
1887
+ documentStyle: {
1888
+ pageSize: {
1889
+ width: 1 / 0,
1890
+ height: 1 / 0
1891
+ }
1458
1892
  }
1459
1893
  }
1460
- return next(data);
1461
- }, "handler")
1894
+ });
1462
1895
  }
1463
- )
1464
- );
1896
+ return next(cell);
1897
+ }, "handler")
1898
+ }));
1465
1899
  }
1466
1900
  }, __name(_a7, "SheetHyperLinkSetRangeController"), _a7);
1467
- SheetHyperLinkSetRangeController = __decorateClass$6([
1901
+ SheetHyperLinkSetRangeController = __decorateClass$7([
1468
1902
  OnLifecycle(LifecycleStages.Starting, SheetHyperLinkSetRangeController),
1469
- __decorateParam$6(0, Inject(SheetInterceptorService)),
1470
- __decorateParam$6(1, Inject(Injector)),
1471
- __decorateParam$6(2, Inject(HyperLinkModel)),
1472
- __decorateParam$6(3, Inject(SheetsSelectionsService)),
1473
- __decorateParam$6(4, IUniverInstanceService),
1474
- __decorateParam$6(5, IEditorBridgeService)
1903
+ __decorateParam$7(0, Inject(SheetInterceptorService)),
1904
+ __decorateParam$7(1, Inject(HyperLinkModel)),
1905
+ __decorateParam$7(2, Inject(SheetsSelectionsService)),
1906
+ __decorateParam$7(3, IUniverInstanceService),
1907
+ __decorateParam$7(4, IEditorBridgeService),
1908
+ __decorateParam$7(5, IRenderManagerService)
1475
1909
  ], SheetHyperLinkSetRangeController);
1476
- var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1477
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1910
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1911
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1478
1912
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1479
- return kind && result && __defProp$5(target, key, result), result;
1480
- }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a8;
1913
+ return kind && result && __defProp$6(target, key, result), result;
1914
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a8;
1481
1915
  let SheetsHyperLinkPopupController = (_a8 = class extends Disposable {
1482
- constructor(_hoverManagerService, _sheetsHyperLinkPopupService, _renderManagerService, _permissionService, _sheetPermissionInterceptorBaseController, _commandService) {
1483
- super(), this._hoverManagerService = _hoverManagerService, this._sheetsHyperLinkPopupService = _sheetsHyperLinkPopupService, this._renderManagerService = _renderManagerService, this._permissionService = _permissionService, this._sheetPermissionInterceptorBaseController = _sheetPermissionInterceptorBaseController, this._commandService = _commandService, this._initHoverListener(), this._initCommandListener();
1916
+ constructor(_hoverManagerService, _sheetsHyperLinkPopupService, _renderManagerService, _permissionService, _sheetPermissionInterceptorBaseController, _commandService, _editorBridgeService, _textSelectionManagerService, _univerInstanceService, _zenZoneService) {
1917
+ 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();
1918
+ }
1919
+ _getLinkPermission(location2) {
1920
+ const { unitId, subUnitId, row: currentRow, col: currentCol } = location2, viewPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
1921
+ workbookTypes: [WorkbookViewPermission],
1922
+ worksheetTypes: [WorksheetViewPermission],
1923
+ rangeTypes: [RangeProtectionPermissionViewPoint]
1924
+ }, [{ startRow: currentRow, startColumn: currentCol, endRow: currentRow, endColumn: currentCol }]), editPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
1925
+ workbookTypes: [WorkbookEditablePermission],
1926
+ worksheetTypes: [WorksheetEditPermission, WorksheetInsertHyperlinkPermission],
1927
+ rangeTypes: [RangeProtectionPermissionEditPoint]
1928
+ }, [{ startRow: currentRow, startColumn: currentCol, endRow: currentRow, endColumn: currentCol }]), copyPermission = this._permissionService.composePermission([new WorkbookCopyPermission(unitId).id, new WorksheetCopyPermission(unitId, subUnitId).id]).every((permission) => permission.value);
1929
+ return {
1930
+ viewPermission,
1931
+ editPermission,
1932
+ copyPermission
1933
+ };
1484
1934
  }
1485
1935
  _initHoverListener() {
1486
1936
  this.disposeWithMe(
1487
- this._hoverManagerService.currentCell$.pipe(debounceTime(200)).subscribe((currentCell) => {
1488
- var _a14, _b;
1937
+ // hover over not editing cell
1938
+ this._hoverManagerService.currentRichText$.pipe(debounceTime(200)).subscribe((currentCell) => {
1939
+ var _a15;
1489
1940
  if (!currentCell) {
1490
1941
  this._sheetsHyperLinkPopupService.hideCurrentPopup();
1491
1942
  return;
1492
1943
  }
1493
- const skeleton = (_b = (_a14 = this._renderManagerService.getRenderById(currentCell.location.unitId)) == null ? void 0 : _a14.with(SheetSkeletonManagerService).getWorksheetSkeleton(currentCell.location.subUnitId)) == null ? void 0 : _b.skeleton, currentCol = currentCell.location.col, currentRow = currentCell.location.row;
1944
+ const { unitId, subUnitId, row, col } = currentCell, renderer = this._renderManagerService.getRenderById(unitId);
1945
+ if (!renderer)
1946
+ return;
1947
+ if (!renderer.with(HoverRenderController).active) {
1948
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.VIEWING);
1949
+ return;
1950
+ }
1951
+ const skeleton = (_a15 = renderer == null ? void 0 : renderer.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId)) == null ? void 0 : _a15.skeleton, currentCol = col, currentRow = row;
1494
1952
  let targetRow = currentRow, targetCol = currentCol;
1495
- if (skeleton && skeleton.overflowCache.forValue((row, col, value) => {
1496
- Rectangle.contains(value, { startColumn: currentCol, endColumn: currentCol, startRow: currentRow, endRow: currentRow }) && (targetRow = row, targetCol = col);
1497
- }), !this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
1498
- workbookTypes: [WorkbookViewPermission],
1499
- worksheetTypes: [WorksheetViewPermission],
1500
- rangeTypes: [RangeProtectionPermissionViewPoint]
1501
- }, [{ startRow: currentRow, startColumn: currentCol, endRow: currentRow, endColumn: currentCol }])) {
1953
+ skeleton && skeleton.overflowCache.forValue((row2, col2, value) => {
1954
+ Rectangle.contains(value, { startColumn: currentCol, endColumn: currentCol, startRow: currentRow, endRow: currentRow }) && (targetRow = row2, targetCol = col2);
1955
+ });
1956
+ const { viewPermission, editPermission, copyPermission } = this._getLinkPermission(currentCell);
1957
+ if (!viewPermission || !currentCell.customRange) {
1502
1958
  this._sheetsHyperLinkPopupService.hideCurrentPopup();
1503
1959
  return;
1504
1960
  }
1505
- const editPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
1506
- workbookTypes: [WorkbookEditablePermission],
1507
- worksheetTypes: [WorksheetEditPermission, WorksheetInsertHyperlinkPermission],
1508
- rangeTypes: [RangeProtectionPermissionEditPoint]
1509
- }, [{ startRow: currentRow, startColumn: currentCol, endRow: currentRow, endColumn: currentCol }]), unitId = currentCell.location.unitId, subUnitId = currentCell.location.subUnitId, copyPermission = this._permissionService.composePermission([new WorkbookCopyPermission(unitId).id, new WorksheetCopyPermission(unitId, subUnitId).id]).every((permission) => permission.value);
1510
1961
  this._sheetsHyperLinkPopupService.showPopup({
1511
- ...currentCell.location,
1512
1962
  row: targetRow,
1513
1963
  col: targetCol,
1514
1964
  editPermission,
1515
- copyPermission
1965
+ copyPermission,
1966
+ customRange: currentCell.customRange,
1967
+ customRangeRect: currentCell.rect,
1968
+ type: HyperLinkEditSourceType.VIEWING,
1969
+ unitId,
1970
+ subUnitId
1516
1971
  });
1517
1972
  })
1518
1973
  );
1519
1974
  }
1975
+ _initHoverEditingListener() {
1976
+ let subscribe = null;
1977
+ this.disposeWithMe(
1978
+ this._editorBridgeService.currentEditCellState$.pipe(mergeMap((state) => this._editorBridgeService.visible$.pipe(map((visible) => ({ visible, state }))))).subscribe(({ visible, state }) => {
1979
+ if (!state || state.editorUnitId !== DOCS_NORMAL_EDITOR_UNIT_ID_KEY)
1980
+ return;
1981
+ if (!visible.visible) {
1982
+ subscribe == null || subscribe.unsubscribe(), this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.EDITING), this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.EDITING);
1983
+ return;
1984
+ }
1985
+ const { editorUnitId, unitId, sheetId, row, column } = state, renderer = this._renderManagerService.getRenderById(editorUnitId);
1986
+ if (!renderer)
1987
+ return;
1988
+ const { editPermission, viewPermission, copyPermission } = this._getLinkPermission({ unitId, subUnitId: sheetId, row, col: column }), docEventService = renderer.with(DocEventManagerService);
1989
+ viewPermission && (subscribe == null || subscribe.unsubscribe(), subscribe = docEventService.hoverCustomRanges$.pipe(debounceTime(200)).subscribe((customRanges) => {
1990
+ var _a15, _b;
1991
+ const customRange = customRanges.find((customRange2) => customRange2.range.rangeType === CustomRangeType.HYPERLINK);
1992
+ if (!customRange) {
1993
+ this._sheetsHyperLinkPopupService.hideCurrentPopup();
1994
+ return;
1995
+ }
1996
+ const rect = customRange.rects[customRange.rects.length - 1];
1997
+ if (!((_b = (_a15 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a15.with(SheetSkeletonManagerService).getWorksheetSkeleton(sheetId)) == null ? void 0 : _b.skeleton) || !rect)
1998
+ return;
1999
+ const canvasClientRect = renderer.engine.getCanvasElement().getBoundingClientRect();
2000
+ this._sheetsHyperLinkPopupService.showPopup({
2001
+ unitId,
2002
+ subUnitId: sheetId,
2003
+ row,
2004
+ col: column,
2005
+ customRange: customRange.range,
2006
+ customRangeRect: {
2007
+ left: rect.left + canvasClientRect.left,
2008
+ top: rect.top + canvasClientRect.top,
2009
+ bottom: rect.bottom + canvasClientRect.top,
2010
+ right: rect.right + canvasClientRect.left
2011
+ },
2012
+ editPermission,
2013
+ copyPermission,
2014
+ type: HyperLinkEditSourceType.EDITING
2015
+ });
2016
+ }));
2017
+ })
2018
+ ), this.disposeWithMe(() => {
2019
+ subscribe == null || subscribe.unsubscribe();
2020
+ });
2021
+ }
2022
+ _initZenEditor() {
2023
+ this.disposeWithMe(
2024
+ this._zenZoneService.visible$.subscribe((visible) => {
2025
+ visible && (this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.VIEWING), this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.EDITING), this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.EDITING), this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.VIEWING));
2026
+ })
2027
+ ), this.disposeWithMe(
2028
+ this._univerInstanceService.focused$.pipe(
2029
+ mergeMap((id) => {
2030
+ const render2 = id === DOCS_ZEN_EDITOR_UNIT_ID_KEY ? this._renderManagerService.getRenderById(id) : null;
2031
+ return render2 ? render2.with(DocEventManagerService).hoverCustomRanges$.pipe(debounceTime(200)) : new Observable((sub) => {
2032
+ sub.next(null);
2033
+ });
2034
+ })
2035
+ ).subscribe((value) => {
2036
+ const range = value == null ? void 0 : value.find((range2) => range2.range.rangeType === CustomRangeType.HYPERLINK), state = this._editorBridgeService.getEditCellState();
2037
+ if (range && state) {
2038
+ const { unitId, sheetId, row, column } = state, { editPermission, viewPermission, copyPermission } = this._getLinkPermission({ unitId, subUnitId: sheetId, row, col: column });
2039
+ viewPermission && this._sheetsHyperLinkPopupService.showPopup({
2040
+ type: HyperLinkEditSourceType.ZEN_EDITOR,
2041
+ unitId,
2042
+ subUnitId: sheetId,
2043
+ row,
2044
+ col: column,
2045
+ customRange: range.range,
2046
+ editPermission,
2047
+ copyPermission
2048
+ });
2049
+ } else
2050
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.ZEN_EDITOR);
2051
+ })
2052
+ );
2053
+ }
2054
+ _initTextSelectionListener() {
2055
+ this.disposeWithMe(
2056
+ this._textSelectionManagerService.textSelection$.subscribe((selection) => {
2057
+ selection && selection.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY && this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.EDITING);
2058
+ })
2059
+ );
2060
+ }
1520
2061
  _initCommandListener() {
1521
2062
  const HIDE_COMMAND_LIST = [ClearSelectionContentCommand.id, ClearSelectionAllCommand.id, ClearSelectionFormatCommand.id];
1522
2063
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
@@ -1524,38 +2065,28 @@ let SheetsHyperLinkPopupController = (_a8 = class extends Disposable {
1524
2065
  }));
1525
2066
  }
1526
2067
  }, __name(_a8, "SheetsHyperLinkPopupController"), _a8);
1527
- SheetsHyperLinkPopupController = __decorateClass$5([
2068
+ SheetsHyperLinkPopupController = __decorateClass$6([
1528
2069
  OnLifecycle(LifecycleStages.Rendered, SheetsHyperLinkPopupController),
1529
- __decorateParam$5(0, Inject(HoverManagerService)),
1530
- __decorateParam$5(1, Inject(SheetsHyperLinkPopupService)),
1531
- __decorateParam$5(2, Inject(IRenderManagerService)),
1532
- __decorateParam$5(3, Inject(IPermissionService)),
1533
- __decorateParam$5(4, Inject(SheetPermissionInterceptorBaseController)),
1534
- __decorateParam$5(5, ICommandService)
2070
+ __decorateParam$6(0, Inject(HoverManagerService)),
2071
+ __decorateParam$6(1, Inject(SheetsHyperLinkPopupService)),
2072
+ __decorateParam$6(2, Inject(IRenderManagerService)),
2073
+ __decorateParam$6(3, Inject(IPermissionService)),
2074
+ __decorateParam$6(4, Inject(SheetPermissionInterceptorBaseController)),
2075
+ __decorateParam$6(5, ICommandService),
2076
+ __decorateParam$6(6, IEditorBridgeService),
2077
+ __decorateParam$6(7, Inject(DocSelectionManagerService)),
2078
+ __decorateParam$6(8, IUniverInstanceService),
2079
+ __decorateParam$6(9, IZenZoneService)
1535
2080
  ], SheetsHyperLinkPopupController);
1536
- const insertLinkMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1537
- id: InsertHyperLinkOperation.id,
1538
- type: MenuItemType.BUTTON,
1539
- title: "hyperLink.menu.add",
1540
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1541
- icon: "LinkSingle",
1542
- disabled$: getObservableWithExclusiveRange$(accessor, getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }))
1543
- }), "insertLinkMenuFactory"), insertLinkMenuToolbarFactory = /* @__PURE__ */ __name((accessor) => ({
1544
- tooltip: "hyperLink.form.addTitle",
1545
- id: InsertHyperLinkToolbarOperation.id,
1546
- type: MenuItemType.BUTTON,
1547
- icon: "LinkSingle",
1548
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1549
- disabled$: getObservableWithExclusiveRange$(accessor, getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }))
1550
- }), "insertLinkMenuToolbarFactory"), InsertLinkShortcut = {
1551
- id: InsertHyperLinkToolbarOperation.id,
1552
- binding: KeyCode.K | MetaKeys.CTRL_COMMAND,
1553
- preconditions: whenSheetEditorFocused
1554
- }, menuSchema = {
2081
+ const menuSchema = {
1555
2082
  [RibbonStartGroup.OTHERS]: {
1556
2083
  [InsertHyperLinkToolbarOperation.id]: {
1557
2084
  order: 2,
1558
2085
  menuItemFactory: insertLinkMenuToolbarFactory
2086
+ },
2087
+ [genZenEditorMenuId(InsertHyperLinkToolbarOperation.id)]: {
2088
+ order: 2,
2089
+ menuItemFactory: zenEditorInsertLinkMenuToolbarFactory
1559
2090
  }
1560
2091
  },
1561
2092
  [ContextMenuPosition.MAIN_AREA]: {
@@ -1564,15 +2095,19 @@ const insertLinkMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1564
2095
  [InsertHyperLinkToolbarOperation.id]: {
1565
2096
  order: 0,
1566
2097
  menuItemFactory: insertLinkMenuFactory
2098
+ },
2099
+ [genZenEditorMenuId(InsertHyperLinkToolbarOperation.id)]: {
2100
+ order: 0,
2101
+ menuItemFactory: zenEditorInsertLinkMenuFactory
1567
2102
  }
1568
2103
  }
1569
2104
  }
1570
2105
  };
1571
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1572
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2106
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2107
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1573
2108
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1574
- return kind && result && __defProp$4(target, key, result), result;
1575
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a9;
2109
+ return kind && result && __defProp$5(target, key, result), result;
2110
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a9;
1576
2111
  let SheetsHyperLinkUIController = (_a9 = class extends Disposable {
1577
2112
  constructor(_componentManager, _commandService, _menuManagerService, _injector, _shortcutService) {
1578
2113
  super(), this._componentManager = _componentManager, this._commandService = _commandService, this._menuManagerService = _menuManagerService, this._injector = _injector, this._shortcutService = _shortcutService, this._initComponents(), this._initCommands(), this._initMenus(), this._initShortCut();
@@ -1588,14 +2123,16 @@ let SheetsHyperLinkUIController = (_a9 = class extends Disposable {
1588
2123
  }
1589
2124
  _initCommands() {
1590
2125
  [
1591
- OpenHyperLinkSidebarOperation,
1592
- CloseHyperLinkSidebarOperation,
2126
+ OpenHyperLinkEditPanelOperation,
2127
+ CloseHyperLinkPopupOperation,
1593
2128
  InsertHyperLinkOperation,
1594
2129
  InsertHyperLinkToolbarOperation,
1595
2130
  AddHyperLinkCommand,
1596
2131
  UpdateHyperLinkCommand,
1597
- RemoveHyperLinkCommand,
1598
- CancelHyperLinkCommand
2132
+ CancelHyperLinkCommand,
2133
+ UpdateRichHyperLinkCommand,
2134
+ CancelRichHyperLinkCommand,
2135
+ AddRichHyperLinkCommand
1599
2136
  ].forEach((command) => {
1600
2137
  this._commandService.registerCommand(command);
1601
2138
  });
@@ -1607,19 +2144,19 @@ let SheetsHyperLinkUIController = (_a9 = class extends Disposable {
1607
2144
  this._shortcutService.registerShortcut(InsertLinkShortcut);
1608
2145
  }
1609
2146
  }, __name(_a9, "SheetsHyperLinkUIController"), _a9);
1610
- SheetsHyperLinkUIController = __decorateClass$4([
2147
+ SheetsHyperLinkUIController = __decorateClass$5([
1611
2148
  OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkUIController),
1612
- __decorateParam$4(0, Inject(ComponentManager)),
1613
- __decorateParam$4(1, ICommandService),
1614
- __decorateParam$4(2, IMenuManagerService),
1615
- __decorateParam$4(3, Inject(Injector)),
1616
- __decorateParam$4(4, Inject(IShortcutService))
2149
+ __decorateParam$5(0, Inject(ComponentManager)),
2150
+ __decorateParam$5(1, ICommandService),
2151
+ __decorateParam$5(2, IMenuManagerService),
2152
+ __decorateParam$5(3, Inject(Injector)),
2153
+ __decorateParam$5(4, Inject(IShortcutService))
1617
2154
  ], SheetsHyperLinkUIController);
1618
- var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1619
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2155
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2156
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1620
2157
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1621
- return kind && result && __defProp$3(target, key, result), result;
1622
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a10;
2158
+ return kind && result && __defProp$4(target, key, result), result;
2159
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a10;
1623
2160
  let SheetsHyperLinkAutoFillController = (_a10 = class extends Disposable {
1624
2161
  constructor(_autoFillService, _hyperLinkModel) {
1625
2162
  super(), this._autoFillService = _autoFillService, this._hyperLinkModel = _hyperLinkModel, this._initAutoFill();
@@ -1707,16 +2244,16 @@ let SheetsHyperLinkAutoFillController = (_a10 = class extends Disposable {
1707
2244
  this.disposeWithMe(this._autoFillService.addHook(hook));
1708
2245
  }
1709
2246
  }, __name(_a10, "SheetsHyperLinkAutoFillController"), _a10);
1710
- SheetsHyperLinkAutoFillController = __decorateClass$3([
2247
+ SheetsHyperLinkAutoFillController = __decorateClass$4([
1711
2248
  OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkAutoFillController),
1712
- __decorateParam$3(0, IAutoFillService),
1713
- __decorateParam$3(1, Inject(HyperLinkModel))
2249
+ __decorateParam$4(0, IAutoFillService),
2250
+ __decorateParam$4(1, Inject(HyperLinkModel))
1714
2251
  ], SheetsHyperLinkAutoFillController);
1715
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1716
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2252
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2253
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1717
2254
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1718
- return kind && result && __defProp$2(target, key, result), result;
1719
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a11;
2255
+ return kind && result && __defProp$3(target, key, result), result;
2256
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a11;
1720
2257
  let SheetHyperLinkUrlController = (_a11 = class extends Disposable {
1721
2258
  constructor(_resolverService) {
1722
2259
  super(), this._resolverService = _resolverService, this._handleInitUrl();
@@ -1726,15 +2263,15 @@ let SheetHyperLinkUrlController = (_a11 = class extends Disposable {
1726
2263
  hash && this._resolverService.parseHyperLink(hash).handler();
1727
2264
  }
1728
2265
  }, __name(_a11, "SheetHyperLinkUrlController"), _a11);
1729
- SheetHyperLinkUrlController = __decorateClass$2([
2266
+ SheetHyperLinkUrlController = __decorateClass$3([
1730
2267
  OnLifecycle(LifecycleStages.Rendered, SheetHyperLinkUrlController),
1731
- __decorateParam$2(0, Inject(SheetsHyperLinkResolverService))
2268
+ __decorateParam$3(0, Inject(SheetsHyperLinkResolverService))
1732
2269
  ], SheetHyperLinkUrlController);
1733
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1734
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2270
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2271
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1735
2272
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1736
- return kind && result && __defProp$1(target, key, result), result;
1737
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a12;
2273
+ return kind && result && __defProp$2(target, key, result), result;
2274
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a12;
1738
2275
  let SheetsHyperLinkPermissionController = (_a12 = class extends Disposable {
1739
2276
  constructor(_localeService, _commandService, _sheetPermissionInterceptorBaseController) {
1740
2277
  super(), this._localeService = _localeService, this._commandService = _commandService, this._sheetPermissionInterceptorBaseController = _sheetPermissionInterceptorBaseController, this._commandExecutedListener();
@@ -1751,18 +2288,175 @@ let SheetsHyperLinkPermissionController = (_a12 = class extends Disposable {
1751
2288
  );
1752
2289
  }
1753
2290
  }, __name(_a12, "SheetsHyperLinkPermissionController"), _a12);
1754
- SheetsHyperLinkPermissionController = __decorateClass$1([
2291
+ SheetsHyperLinkPermissionController = __decorateClass$2([
1755
2292
  OnLifecycle(LifecycleStages.Rendered, SheetsHyperLinkPermissionController),
1756
- __decorateParam$1(0, Inject(LocaleService)),
1757
- __decorateParam$1(1, ICommandService),
1758
- __decorateParam$1(2, Inject(SheetPermissionInterceptorBaseController))
2293
+ __decorateParam$2(0, Inject(LocaleService)),
2294
+ __decorateParam$2(1, ICommandService),
2295
+ __decorateParam$2(2, Inject(SheetPermissionInterceptorBaseController))
1759
2296
  ], SheetsHyperLinkPermissionController);
2297
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2298
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2299
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2300
+ return kind && result && __defProp$1(target, key, result), result;
2301
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a13;
2302
+ let SheetsHyperLinkRichTextRefRangeController = (_a13 = class extends Disposable {
2303
+ constructor(_commandService, _univerInstanceService, _refRangeService) {
2304
+ super();
2305
+ __publicField(this, "_refRangeMap", /* @__PURE__ */ new Map());
2306
+ this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._refRangeService = _refRangeService, this._initWorkbookLoad(), this._initWorkbookUnload(), this._initSetRangesListener();
2307
+ }
2308
+ _enusreMap(unitId, subUnitId) {
2309
+ let unitMap = this._refRangeMap.get(unitId);
2310
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._refRangeMap.set(unitId, unitMap));
2311
+ let subUnitMap = unitMap.get(subUnitId);
2312
+ return subUnitMap || (subUnitMap = new ObjectMatrix(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
2313
+ }
2314
+ _isLegalRangeUrl(unitId, payload) {
2315
+ var _a15, _b, _c;
2316
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
2317
+ if (!workbook)
2318
+ return null;
2319
+ if (payload && payload.startsWith("#")) {
2320
+ const search = new URLSearchParams(payload.slice(1)), searchObj = {
2321
+ gid: (_a15 = search.get("gid")) != null ? _a15 : "",
2322
+ range: (_b = search.get("range")) != null ? _b : "",
2323
+ rangeid: (_c = search.get("rangeid")) != null ? _c : ""
2324
+ };
2325
+ if (searchObj.range && searchObj.gid) {
2326
+ const subUnitId = searchObj.gid, worksheet = workbook.getSheetBySheetId(subUnitId);
2327
+ if (!worksheet)
2328
+ return null;
2329
+ const range = deserializeRangeWithSheet(searchObj.range).range;
2330
+ if (isValidRange(range, worksheet) && searchObj.range !== ERROR_RANGE)
2331
+ return range;
2332
+ }
2333
+ }
2334
+ return null;
2335
+ }
2336
+ _registerRange(unitId, subUnitId, row, col, p2) {
2337
+ var _a15, _b, _c, _d;
2338
+ const map2 = this._enusreMap(unitId, subUnitId), data = Tools.deepClone(p2), handleRangeChange = /* @__PURE__ */ __name((commandInfo) => {
2339
+ var _a16, _b2;
2340
+ const dataCopy = Tools.deepClone(data);
2341
+ (_b2 = (_a16 = dataCopy.body) == null ? void 0 : _a16.customRanges) == null || _b2.forEach((customRange) => {
2342
+ var _a17;
2343
+ if (customRange.rangeType === CustomRangeType.HYPERLINK) {
2344
+ const payload = (_a17 = customRange.properties) == null ? void 0 : _a17.url, range = this._isLegalRangeUrl(unitId, payload);
2345
+ if (range) {
2346
+ const resultRange = handleDefaultRangeChangeWithEffectRefCommands(range, commandInfo), newPayload = `#gid=${subUnitId}&range=${resultRange ? serializeRange(resultRange) : ERROR_RANGE}`;
2347
+ customRange.properties.url = newPayload;
2348
+ }
2349
+ }
2350
+ });
2351
+ const position = handleDefaultRangeChangeWithEffectRefCommands({ startRow: row, endRow: row, startColumn: col, endColumn: col }, commandInfo);
2352
+ return position ? {
2353
+ redos: [{
2354
+ id: SetRangeValuesMutation.id,
2355
+ params: {
2356
+ unitId,
2357
+ subUnitId,
2358
+ cellValue: {
2359
+ [position.startRow]: {
2360
+ [position.startColumn]: {
2361
+ p: dataCopy
2362
+ }
2363
+ }
2364
+ }
2365
+ }
2366
+ }],
2367
+ undos: [
2368
+ {
2369
+ id: SetRangeValuesMutation.id,
2370
+ params: {
2371
+ unitId,
2372
+ subUnitId,
2373
+ cellValue: {
2374
+ [row]: {
2375
+ [col]: {
2376
+ p: data
2377
+ }
2378
+ }
2379
+ }
2380
+ }
2381
+ }
2382
+ ]
2383
+ } : {
2384
+ redos: [],
2385
+ undos: []
2386
+ };
2387
+ }, "handleRangeChange");
2388
+ if ((_b = (_a15 = p2.body) == null ? void 0 : _a15.customRanges) != null && _b.some((customRange) => {
2389
+ var _a16;
2390
+ return customRange.rangeType === CustomRangeType.HYPERLINK && this._isLegalRangeUrl(unitId, (_a16 = customRange.properties) == null ? void 0 : _a16.url);
2391
+ })) {
2392
+ const disposableCollection = new DisposableCollection();
2393
+ (_d = (_c = p2.body) == null ? void 0 : _c.customRanges) == null || _d.forEach((customRange) => {
2394
+ var _a16;
2395
+ if (customRange.rangeType === CustomRangeType.HYPERLINK) {
2396
+ const payload = (_a16 = customRange.properties) == null ? void 0 : _a16.url, range = this._isLegalRangeUrl(unitId, payload);
2397
+ range && disposableCollection.add(this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId));
2398
+ }
2399
+ }), map2.setValue(row, col, disposableCollection);
2400
+ }
2401
+ }
2402
+ _initWorkbookLoad() {
2403
+ const handleWorkbook = /* @__PURE__ */ __name((workbook) => {
2404
+ const unitId = workbook.getUnitId();
2405
+ workbook.getSheets().forEach((sheet) => {
2406
+ const subUnitId = sheet.getSheetId(), map2 = this._enusreMap(unitId, subUnitId);
2407
+ sheet.getCellMatrix().forValue((row, col, cell) => {
2408
+ const dispose = map2.getValue(row, col);
2409
+ dispose && dispose.dispose(), cell && cell.p && this._registerRange(unitId, subUnitId, row, col, cell.p);
2410
+ });
2411
+ });
2412
+ }, "handleWorkbook");
2413
+ this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
2414
+ handleWorkbook(workbook);
2415
+ }), this.disposeWithMe(
2416
+ this._univerInstanceService.unitAdded$.subscribe((unit) => {
2417
+ unit.type === UniverInstanceType.UNIVER_SHEET && handleWorkbook(unit);
2418
+ })
2419
+ );
2420
+ }
2421
+ _initWorkbookUnload() {
2422
+ this._univerInstanceService.unitDisposed$.subscribe((unit) => {
2423
+ if (unit.type === UniverInstanceType.UNIVER_SHEET) {
2424
+ const workbook = unit, unitId = workbook.getUnitId();
2425
+ workbook.getSheets().forEach((sheet) => {
2426
+ const subUnitId = sheet.getSheetId();
2427
+ this._enusreMap(unitId, subUnitId).forValue((row, col, dispose) => {
2428
+ dispose && dispose.dispose();
2429
+ });
2430
+ }), this._refRangeMap.delete(unitId);
2431
+ }
2432
+ });
2433
+ }
2434
+ _initSetRangesListener() {
2435
+ this.disposeWithMe(
2436
+ this._commandService.onCommandExecuted((commandInfo) => {
2437
+ if (commandInfo.id === SetRangeValuesMutation.id) {
2438
+ const params = commandInfo.params, { unitId, subUnitId, cellValue } = params, map2 = this._enusreMap(unitId, subUnitId);
2439
+ cellValue && new ObjectMatrix(cellValue).forValue((row, col, cell) => {
2440
+ const dispose = map2.getValue(row, col);
2441
+ dispose && dispose.dispose(), cell && cell.p && this._registerRange(unitId, subUnitId, row, col, cell.p);
2442
+ });
2443
+ }
2444
+ })
2445
+ );
2446
+ }
2447
+ }, __name(_a13, "SheetsHyperLinkRichTextRefRangeController"), _a13);
2448
+ SheetsHyperLinkRichTextRefRangeController = __decorateClass$1([
2449
+ OnLifecycle(LifecycleStages.Starting, SheetsHyperLinkRichTextRefRangeController),
2450
+ __decorateParam$1(0, ICommandService),
2451
+ __decorateParam$1(1, IUniverInstanceService),
2452
+ __decorateParam$1(2, Inject(RefRangeService))
2453
+ ], SheetsHyperLinkRichTextRefRangeController);
1760
2454
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1761
2455
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1762
2456
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1763
2457
  return kind && result && __defProp2(target, key, result), result;
1764
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a13;
1765
- let UniverSheetsHyperLinkUIPlugin = (_a13 = class extends Plugin {
2458
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a14;
2459
+ let UniverSheetsHyperLinkUIPlugin = (_a14 = class extends Plugin {
1766
2460
  constructor(_config = defaultPluginConfig, _injector, _renderManagerService, _configService) {
1767
2461
  super(), this._config = _config, this._injector = _injector, this._renderManagerService = _renderManagerService, this._configService = _configService;
1768
2462
  const { menu, ...rest } = this._config;
@@ -1781,7 +2475,8 @@ let UniverSheetsHyperLinkUIPlugin = (_a13 = class extends Plugin {
1781
2475
  [SheetsHyperLinkAutoFillController],
1782
2476
  [SheetsHyperLinkCopyPasteController],
1783
2477
  [SheetsHyperLinkPermissionController],
1784
- [SheetHyperLinkUrlController]
2478
+ [SheetHyperLinkUrlController],
2479
+ [SheetsHyperLinkRichTextRefRangeController]
1785
2480
  ].forEach((dep) => this._injector.add(dep));
1786
2481
  }
1787
2482
  onReady() {
@@ -1789,11 +2484,11 @@ let UniverSheetsHyperLinkUIPlugin = (_a13 = class extends Plugin {
1789
2484
  [SheetsHyperLinkRenderController]
1790
2485
  ].forEach((d) => this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, d));
1791
2486
  }
1792
- }, __name(_a13, "UniverSheetsHyperLinkUIPlugin"), _a13);
2487
+ }, __name(_a14, "UniverSheetsHyperLinkUIPlugin"), _a14);
1793
2488
  __publicField2(UniverSheetsHyperLinkUIPlugin, "pluginName", SHEET_HYPER_LINK_UI_PLUGIN);
1794
2489
  __publicField2(UniverSheetsHyperLinkUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
1795
2490
  UniverSheetsHyperLinkUIPlugin = __decorateClass([
1796
- DependentOn(UniverSheetsHyperLinkPlugin),
2491
+ DependentOn(UniverSheetsHyperLinkPlugin, UniverDocsUIPlugin),
1797
2492
  __decorateParam(1, Inject(Injector)),
1798
2493
  __decorateParam(2, IRenderManagerService),
1799
2494
  __decorateParam(3, IConfigService)
@@ -1801,11 +2496,10 @@ UniverSheetsHyperLinkUIPlugin = __decorateClass([
1801
2496
  export {
1802
2497
  AddHyperLinkCommand,
1803
2498
  CancelHyperLinkCommand,
1804
- CloseHyperLinkSidebarOperation,
2499
+ CloseHyperLinkPopupOperation,
1805
2500
  InsertHyperLinkOperation,
1806
2501
  InsertLinkShortcut,
1807
- OpenHyperLinkSidebarOperation,
1808
- RemoveHyperLinkCommand,
2502
+ OpenHyperLinkEditPanelOperation,
1809
2503
  SheetsHyperLinkCopyPasteController,
1810
2504
  SheetsHyperLinkPopupService,
1811
2505
  SheetsHyperLinkResolverService,