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

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, KeyCode, RangeSelector, IEditorService, IRangeSelectorService, MenuItemType, MenuPosition, MenuGroup, MetaKeys, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IShortcutService, IMenuManagerService } from "@univerjs/ui";
14
+ import require$$0, { forwardRef, useRef, createElement, useState, useEffect, useMemo } from "react";
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,220 @@ 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 (showLabel && !display || !payload || type === SheetHyperLinkType.URL && !isLegalLink(payload)) {
959
+ setShowError(!0);
960
+ return;
961
+ }
962
+ if (editing)
963
+ if (id) {
964
+ const commandId = editing.type === HyperLinkEditSourceType.ZEN_EDITOR || editing.type === HyperLinkEditSourceType.EDITING ? UpdateRichHyperLinkCommand.id : UpdateHyperLinkCommand.id;
965
+ await commandService.executeCommand(commandId, {
966
+ id,
967
+ unitId: editing.unitId,
968
+ subUnitId: editing.subUnitId,
969
+ payload: {
970
+ display: showLabel ? display : "",
971
+ payload: formatUrl(type, payload)
972
+ },
973
+ row: editing.row,
974
+ column: editing.col,
975
+ documentId: editing.type === HyperLinkEditSourceType.ZEN_EDITOR ? DOCS_ZEN_EDITOR_UNIT_ID_KEY : editorBridgeService.getCurrentEditorId()
976
+ });
977
+ } else {
978
+ const commandId = editing.type === HyperLinkEditSourceType.ZEN_EDITOR || editing.type === HyperLinkEditSourceType.EDITING ? AddRichHyperLinkCommand.id : AddHyperLinkCommand.id;
979
+ await commandService.executeCommand(commandId, {
980
+ unitId: editing.unitId,
981
+ subUnitId: editing.subUnitId,
982
+ link: {
983
+ id: generateRandomId(),
984
+ row: editing.row,
985
+ column: editing.col,
986
+ payload: formatUrl(type, payload),
987
+ display: showLabel ? display : ""
988
+ },
989
+ documentId: editing.type === HyperLinkEditSourceType.ZEN_EDITOR ? DOCS_ZEN_EDITOR_UNIT_ID_KEY : editorBridgeService.getCurrentEditorId()
990
+ });
555
991
  }
556
- })), editing) {
992
+ if ((editing == null ? void 0 : editing.type) === HyperLinkEditSourceType.VIEWING) {
557
993
  await commandService.executeCommand(SetWorksheetActiveOperation.id, {
558
994
  unitId: editing.unitId,
559
995
  subUnitId: editing.subUnitId
@@ -563,15 +999,15 @@ const UpdateHyperLinkCommand = {
563
999
  range: {
564
1000
  startRow: Math.max(editing.row - GAP, 0),
565
1001
  endRow: editing.row + GAP,
566
- startColumn: Math.max(editing.column - GAP, 0),
567
- endColumn: editing.column + GAP
1002
+ startColumn: Math.max(editing.col - GAP, 0),
1003
+ endColumn: editing.col + GAP
568
1004
  }
569
1005
  });
570
1006
  }
571
- commandService.executeCommand(CloseHyperLinkSidebarOperation.id);
1007
+ commandService.executeCommand(CloseHyperLinkPopupOperation.id);
572
1008
  }, "handleSubmit");
573
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
574
- /* @__PURE__ */ jsxRuntimeExports.jsx(
1009
+ return editing ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLinkEdit, style: { display: hide ? "none" : "block" }, children: [
1010
+ showLabel ? /* @__PURE__ */ jsxRuntimeExports.jsx(
575
1011
  FormLayout,
576
1012
  {
577
1013
  label: localeService.t("hyperLink.form.label"),
@@ -583,12 +1019,16 @@ const UpdateHyperLinkCommand = {
583
1019
  onChange: /* @__PURE__ */ __name((v) => {
584
1020
  setDisplay(v), setByPayload.current = !1;
585
1021
  }, "onChange"),
586
- placeholder: localeService.t("hyperLink.form.labelPlaceholder")
1022
+ placeholder: localeService.t("hyperLink.form.labelPlaceholder"),
1023
+ autoFocus: !0,
1024
+ onKeyDown: /* @__PURE__ */ __name((e) => {
1025
+ e.keyCode === KeyCode.ENTER && handleSubmit();
1026
+ }, "onKeyDown")
587
1027
  }
588
1028
  )
589
1029
  }
590
- ),
591
- /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("hyperLink.form.type"), children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1030
+ ) : null,
1031
+ /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { label: localeService.t("hyperLink.form.type"), contentStyle: { marginBottom: 0 }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
592
1032
  Select,
593
1033
  {
594
1034
  options: linkTypeOptions,
@@ -598,7 +1038,7 @@ const UpdateHyperLinkCommand = {
598
1038
  }, "onChange")
599
1039
  }
600
1040
  ) }),
601
- type === LinkType.link && /* @__PURE__ */ jsxRuntimeExports.jsx(
1041
+ type === SheetHyperLinkType.URL && /* @__PURE__ */ jsxRuntimeExports.jsx(
602
1042
  FormLayout,
603
1043
  {
604
1044
  error: showError ? payload ? isLegalLink(payload) ? "" : localeService.t("hyperLink.form.linkError") : localeService.t("hyperLink.form.inputError") : "",
@@ -609,43 +1049,55 @@ const UpdateHyperLinkCommand = {
609
1049
  onChange: /* @__PURE__ */ __name((newLink) => {
610
1050
  setPayload(newLink), newLink && (setByPayload.current || !display || display === payload) && (setDisplay(newLink), setByPayload.current = !0);
611
1051
  }, "onChange"),
612
- placeholder: localeService.t("hyperLink.form.linkPlaceholder")
1052
+ placeholder: localeService.t("hyperLink.form.linkPlaceholder"),
1053
+ autoFocus: !showLabel,
1054
+ onKeyDown: /* @__PURE__ */ __name((e) => {
1055
+ e.keyCode === KeyCode.ENTER && handleSubmit();
1056
+ }, "onKeyDown")
613
1057
  }
614
1058
  )
615
1059
  }
616
1060
  ),
617
- type === LinkType.range && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.inputError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1061
+ type === SheetHyperLinkType.RANGE && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.inputError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
618
1062
  RangeSelector,
619
1063
  {
620
1064
  openForSheetUnitId: workbook.getUnitId(),
621
1065
  id: createInternalEditorID("hyper-link-edit"),
622
1066
  isSingleChoice: !0,
623
1067
  value: payloadInitial,
624
- onChange: handleRangeChange
1068
+ onChange: handleRangeChange,
1069
+ disableInput: editing.type === HyperLinkEditSourceType.ZEN_EDITOR,
1070
+ onSelectorVisibleChange: /* @__PURE__ */ __name(async (visible) => {
1071
+ 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, {
1072
+ unitId: editing.unitId,
1073
+ subUnitId: editing.subUnitId,
1074
+ selections: [{ range: { startRow: editing.row, endRow: editing.row, startColumn: editing.col, endColumn: editing.col } }]
1075
+ }), zenZoneService.show(), contextService.setContextValue(FOCUSING_SHEET, !1)), editorBridgeService.disableForceKeepVisible(), setHide(!1));
1076
+ }, "onSelectorVisibleChange")
625
1077
  }
626
1078
  ) }),
627
- type === LinkType.sheet && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1079
+ type === SheetHyperLinkType.SHEET && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
628
1080
  Select,
629
1081
  {
630
1082
  options: sheetsOption,
631
1083
  value: payload,
632
1084
  onChange: /* @__PURE__ */ __name((newPayload) => {
633
- var _a15, _b;
1085
+ var _a16, _b;
634
1086
  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;
1087
+ 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
1088
  label && (setByPayload.current || !display || display === oldLabel) && (setDisplay(label), setByPayload.current = !0);
637
1089
  }, "onChange")
638
1090
  }
639
1091
  ) }),
640
- type === LinkType.definedName && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1092
+ type === SheetHyperLinkType.DEFINE_NAME && /* @__PURE__ */ jsxRuntimeExports.jsx(FormLayout, { error: showError && !payload ? localeService.t("hyperLink.form.selectError") : "", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
641
1093
  Select,
642
1094
  {
643
1095
  options: definedNames,
644
1096
  value: payload,
645
1097
  onChange: /* @__PURE__ */ __name((newValue) => {
646
- var _a15, _b;
1098
+ var _a16, _b;
647
1099
  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;
1100
+ 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
1101
  label && (setByPayload.current || !display || display === oldLabel) && (setDisplay(label), setByPayload.current = !0);
650
1102
  }, "onChange")
651
1103
  }
@@ -664,15 +1116,12 @@ const UpdateHyperLinkCommand = {
664
1116
  setPayload
665
1117
  }
666
1118
  ),
667
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles$1.cellLinkEditButtons, children: [
1119
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.cellLinkEditButtons, children: [
668
1120
  /* @__PURE__ */ jsxRuntimeExports.jsx(
669
1121
  Button,
670
1122
  {
671
1123
  onClick: /* @__PURE__ */ __name(() => {
672
- editing && commandService.executeCommand(SetWorksheetActiveOperation.id, {
673
- unitId: editing.unitId,
674
- subUnitId: editing.subUnitId
675
- }), commandService.executeCommand(CloseHyperLinkSidebarOperation.id);
1124
+ editing && resolverService.navigateToRange(editing.unitId, editing.subUnitId, { startRow: editing.row, endRow: editing.row, startColumn: editing.col, endColumn: editing.col }), commandService.executeCommand(CloseHyperLinkPopupOperation.id);
676
1125
  }, "onClick"),
677
1126
  children: localeService.t("hyperLink.form.cancel")
678
1127
  }
@@ -683,226 +1132,35 @@ const UpdateHyperLinkCommand = {
683
1132
  type: "primary",
684
1133
  style: { marginLeft: 8 },
685
1134
  onClick: /* @__PURE__ */ __name(async () => {
686
- if (!display || !payload || type === LinkType.link && !isLegalLink(payload)) {
687
- setShowError(!0);
688
- return;
689
- }
690
1135
  handleSubmit();
691
1136
  }, "onClick"),
692
1137
  children: localeService.t("hyperLink.form.ok")
693
1138
  }
694
1139
  )
695
1140
  ] })
696
- ] });
1141
+ ] }) : null;
697
1142
  }, "CellLinkEdit");
698
1143
  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--)
1144
+ var __defProp$b = Object.defineProperty, __getOwnPropDesc$b = Object.getOwnPropertyDescriptor, __decorateClass$b = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1145
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
892
1146
  (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");
1147
+ return kind && result && __defProp$b(target, key, result), result;
1148
+ }, "__decorateClass$b"), __decorateParam$b = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$b");
1149
+ const isEqualLink = /* @__PURE__ */ __name((a, b) => {
1150
+ var _a15, _b;
1151
+ return a.unitId === b.unitId && a.subUnitId === b.subUnitId && a.row === b.row && a.col === b.col && ((_a15 = a.customRange) == null ? void 0 : _a15.rangeId) === ((_b = b.customRange) == null ? void 0 : _b.rangeId) && a.type === b.type;
1152
+ }, "isEqualLink");
896
1153
  var _a2;
897
1154
  let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
898
- constructor(_hyperLinkModel, _sheetCanvasPopManagerService) {
1155
+ constructor(_sheetCanvasPopManagerService, _injector, _univerInstanceService, _editorBridgeService, _textSelectionManagerService, _docCanvasPopManagerService, _editorService, _rangeSelectorService, _zenZoneService) {
899
1156
  super();
900
1157
  __publicField(this, "_currentPopup", null);
901
1158
  __publicField(this, "_currentPopup$", new Subject());
902
1159
  __publicField(this, "currentPopup$", this._currentPopup$.asObservable());
1160
+ __publicField(this, "_currentEditingPopup", null);
903
1161
  __publicField(this, "_currentEditing$", new BehaviorSubject(null));
904
1162
  __publicField(this, "currentEditing$", this._currentEditing$.asObservable());
905
- this._hyperLinkModel = _hyperLinkModel, this._sheetCanvasPopManagerService = _sheetCanvasPopManagerService, this.disposeWithMe(() => {
1163
+ 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
1164
  this.hideCurrentPopup(), this.endEditing(), this._currentEditing$.complete(), this._currentPopup$.complete();
907
1165
  });
908
1166
  }
@@ -913,52 +1171,260 @@ let SheetsHyperLinkPopupService = (_a2 = class extends Disposable {
913
1171
  return this._currentEditing$.getValue();
914
1172
  }
915
1173
  showPopup(location2) {
916
- if (this._currentPopup && isEqualLink(location2, this._currentPopup))
1174
+ if (this._currentPopup && isEqualLink(location2, this._currentPopup) || (this.hideCurrentPopup(void 0, !0), location2.type !== HyperLinkEditSourceType.ZEN_EDITOR && this._zenZoneService.visible))
1175
+ return;
1176
+ const currentEditing = this._currentEditing$.getValue();
1177
+ if (currentEditing && isEqualLink(location2, currentEditing))
917
1178
  return;
918
- this.hideCurrentPopup();
919
- const { unitId, subUnitId, row, col } = location2, link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
920
- if (!link)
1179
+ const { unitId, subUnitId, row, col, customRangeRect, customRange } = location2;
1180
+ if (!customRange)
921
1181
  return;
922
- const disposable = this._sheetCanvasPopManagerService.attachPopupToCell(row, col, {
1182
+ let disposable;
1183
+ const popup = {
923
1184
  componentKey: CellLinkPopup.componentKey,
924
1185
  direction: "bottom",
925
- closeOnSelfTarget: !0,
926
1186
  onClickOutside: /* @__PURE__ */ __name(() => {
927
1187
  this.hideCurrentPopup();
928
- }, "onClickOutside")
929
- });
930
- disposable && (this._currentPopup = {
1188
+ }, "onClickOutside"),
1189
+ onClick: /* @__PURE__ */ __name(() => {
1190
+ this.hideCurrentPopup(location2.type, !0);
1191
+ }, "onClick")
1192
+ };
1193
+ location2.type === HyperLinkEditSourceType.EDITING ? disposable = customRangeRect && this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(
1194
+ customRangeRect,
1195
+ popup
1196
+ ) : location2.type === HyperLinkEditSourceType.ZEN_EDITOR ? disposable = this._docCanvasPopManagerService.attachPopupToRange(
1197
+ {
1198
+ startOffset: customRange.startIndex,
1199
+ endOffset: customRange.endIndex + 1,
1200
+ collapsed: !1
1201
+ },
1202
+ popup,
1203
+ DOCS_ZEN_EDITOR_UNIT_ID_KEY
1204
+ ) : disposable = customRangeRect && this._sheetCanvasPopManagerService.attachPopupByPosition(
1205
+ customRangeRect,
1206
+ popup
1207
+ ), disposable && (this._currentPopup = {
931
1208
  unitId,
932
1209
  subUnitId,
933
- id: link.id,
934
1210
  disposable,
935
1211
  row,
936
1212
  col,
937
1213
  editPermission: !!location2.editPermission,
938
- copyPermission: !!location2.copyPermission
1214
+ copyPermission: !!location2.copyPermission,
1215
+ customRange,
1216
+ type: location2.type
939
1217
  }, this._currentPopup$.next(this._currentPopup));
940
1218
  }
941
- hideCurrentPopup() {
942
- var _a14;
943
- this._currentPopup && ((_a14 = this._currentPopup.disposable) == null || _a14.dispose(), this._currentPopup = null, this._currentPopup$.next(null));
1219
+ hideCurrentPopup(type, force) {
1220
+ var _a15, _b;
1221
+ 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));
1222
+ }
1223
+ _getEditingRange() {
1224
+ var _a15, _b, _c;
1225
+ const visible = this._editorBridgeService.isVisible().visible, state = this._editorBridgeService.getEditCellState();
1226
+ if (visible && state) {
1227
+ const textRange = this._textSelectionManagerService.getActiveTextRange(), body = (_a15 = state.documentLayoutObject.documentModel) == null ? void 0 : _a15.getBody();
1228
+ if (!body)
1229
+ return null;
1230
+ if (!textRange || textRange.collapsed)
1231
+ return {
1232
+ startOffset: 0,
1233
+ endOffset: body.dataStream.length - 2,
1234
+ collapsed: body.dataStream.length - 2 === 0,
1235
+ label: getPlainTextFormBody(body)
1236
+ };
1237
+ const links = BuildTextUtils.customRange.getCustomRangesInterestsWithRange(textRange, (_c = (_b = body.customRanges) == null ? void 0 : _b.filter((i) => i.rangeType === CustomRangeType.HYPERLINK)) != null ? _c : []);
1238
+ let start = textRange.startOffset, end = textRange.endOffset;
1239
+ return links.forEach((link) => {
1240
+ start = Math.min(start, link.startIndex), end = Math.max(end, link.endIndex + 1);
1241
+ }), {
1242
+ startOffset: start,
1243
+ endOffset: end,
1244
+ collapsed: start === end,
1245
+ label: getPlainText(body.dataStream.slice(start, end))
1246
+ };
1247
+ }
1248
+ return null;
1249
+ }
1250
+ get _editPopup() {
1251
+ return {
1252
+ componentKey: CellLinkEdit.componentKey,
1253
+ direction: "bottom",
1254
+ onClickOutside: /* @__PURE__ */ __name(() => {
1255
+ const hyperLinkRangeSelectorId = createInternalEditorID("hyper-link-edit");
1256
+ this._editorService.getFocusId() !== hyperLinkRangeSelectorId && (this._rangeSelectorService.getCurrentSelectorId() === hyperLinkRangeSelectorId && this._rangeSelectorService.selectorModalVisible || this.endEditing());
1257
+ }, "onClickOutside"),
1258
+ hiddenType: "hide"
1259
+ };
1260
+ }
1261
+ startAddEditing(link) {
1262
+ var _a15, _b, _c;
1263
+ const { unitId, subUnitId, type } = link;
1264
+ if (type === HyperLinkEditSourceType.ZEN_EDITOR) {
1265
+ const document = this._univerInstanceService.getUnit(DOCS_ZEN_EDITOR_UNIT_ID_KEY, UniverInstanceType.UNIVER_DOC);
1266
+ if (!document)
1267
+ return;
1268
+ const range = this._textSelectionManagerService.getActiveTextRange();
1269
+ if (!range)
1270
+ return;
1271
+ this._currentEditingPopup = this._docCanvasPopManagerService.attachPopupToRange(
1272
+ range,
1273
+ this._editPopup,
1274
+ DOCS_ZEN_EDITOR_UNIT_ID_KEY
1275
+ );
1276
+ const label = (_a15 = document.getBody()) == null ? void 0 : _a15.dataStream.slice(range.startOffset, range.endOffset - 1);
1277
+ this._currentEditing$.next({
1278
+ ...link,
1279
+ label
1280
+ });
1281
+ } else if (type === HyperLinkEditSourceType.EDITING) {
1282
+ const range = this._getEditingRange();
1283
+ range && this._textSelectionManagerService.replaceTextRanges([{ ...range }]), this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToCell(
1284
+ link.row,
1285
+ link.col,
1286
+ this._editPopup,
1287
+ unitId,
1288
+ subUnitId
1289
+ ), this._currentEditing$.next({
1290
+ ...link,
1291
+ label: (_b = range == null ? void 0 : range.label) != null ? _b : ""
1292
+ });
1293
+ } else {
1294
+ this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToCell(
1295
+ link.row,
1296
+ link.col,
1297
+ this._editPopup,
1298
+ unitId,
1299
+ subUnitId
1300
+ );
1301
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId), cell = worksheet == null ? void 0 : worksheet.getCellRaw(link.row, link.col);
1302
+ this._currentEditing$.next({
1303
+ ...link,
1304
+ label: cell != null && cell.p ? getPlainTextFormDocument(cell.p) : ((_c = cell == null ? void 0 : cell.v) != null ? _c : "").toString()
1305
+ });
1306
+ }
944
1307
  }
945
1308
  startEditing(link) {
946
- this._currentEditing$.next(link);
1309
+ var _a15, _b, _c, _d, _e, _f;
1310
+ (_a15 = this._currentEditingPopup) == null || _a15.dispose(), this.hideCurrentPopup(void 0, !0);
1311
+ const { unitId, subUnitId } = link;
1312
+ let customRange, label;
1313
+ if (link.type === HyperLinkEditSourceType.ZEN_EDITOR) {
1314
+ const document = this._univerInstanceService.getUnit(DOCS_ZEN_EDITOR_UNIT_ID_KEY, UniverInstanceType.UNIVER_DOC);
1315
+ 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)
1316
+ return;
1317
+ this._textSelectionManagerService.replaceTextRanges([
1318
+ {
1319
+ startOffset: customRange.startIndex,
1320
+ endOffset: customRange.endIndex + 1
1321
+ }
1322
+ ]), this._currentEditingPopup = this._docCanvasPopManagerService.attachPopupToRange(
1323
+ {
1324
+ startOffset: customRange.startIndex,
1325
+ endOffset: customRange.endIndex,
1326
+ collapsed: !1
1327
+ },
1328
+ this._editPopup,
1329
+ DOCS_ZEN_EDITOR_UNIT_ID_KEY
1330
+ );
1331
+ } else if (link.type === HyperLinkEditSourceType.EDITING) {
1332
+ const customRangeInfo = getEditingCustomRangePosition(this._injector, link.unitId, link.subUnitId, link.row, link.col, link.customRangeId);
1333
+ if (!customRangeInfo || !((_e = customRangeInfo.rects) != null && _e.length))
1334
+ return;
1335
+ customRange = customRangeInfo.customRange, label = customRangeInfo.label, this._textSelectionManagerService.replaceTextRanges([
1336
+ {
1337
+ startOffset: customRange.startIndex,
1338
+ endOffset: customRange.endIndex + 1
1339
+ }
1340
+ ]), this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(
1341
+ customRangeInfo.rects.pop(),
1342
+ this._editPopup,
1343
+ unitId,
1344
+ subUnitId
1345
+ );
1346
+ } else {
1347
+ const customRangeInfo = getCustomRangePosition(this._injector, link.unitId, link.subUnitId, link.row, link.col, link.customRangeId);
1348
+ if (!customRangeInfo || !((_f = customRangeInfo.rects) != null && _f.length))
1349
+ return;
1350
+ customRange = customRangeInfo.customRange, label = customRangeInfo.label, this._currentEditingPopup = this._sheetCanvasPopManagerService.attachPopupByPosition(
1351
+ customRangeInfo.rects.pop(),
1352
+ this._editPopup,
1353
+ unitId,
1354
+ subUnitId
1355
+ );
1356
+ }
1357
+ this._currentEditing$.next({
1358
+ ...link,
1359
+ customRange,
1360
+ label
1361
+ });
1362
+ }
1363
+ endEditing(type) {
1364
+ var _a15;
1365
+ const current = this._currentEditing$.getValue();
1366
+ current && (!type || type === current.type) && ((_a15 = this._currentEditingPopup) == null || _a15.dispose(), this._currentEditing$.next(null));
1367
+ }
1368
+ }, __name(_a2, "SheetsHyperLinkPopupService"), _a2);
1369
+ SheetsHyperLinkPopupService = __decorateClass$b([
1370
+ __decorateParam$b(0, Inject(SheetCanvasPopManagerService)),
1371
+ __decorateParam$b(1, Inject(Injector)),
1372
+ __decorateParam$b(2, IUniverInstanceService),
1373
+ __decorateParam$b(3, IEditorBridgeService),
1374
+ __decorateParam$b(4, Inject(DocSelectionManagerService)),
1375
+ __decorateParam$b(5, Inject(DocCanvasPopManagerService)),
1376
+ __decorateParam$b(6, IEditorService),
1377
+ __decorateParam$b(7, IRangeSelectorService),
1378
+ __decorateParam$b(8, IZenZoneService)
1379
+ ], SheetsHyperLinkPopupService);
1380
+ const OpenHyperLinkEditPanelOperation = {
1381
+ type: CommandType.OPERATION,
1382
+ id: "sheet.operation.open-hyper-link-edit-panel",
1383
+ handler(accessor, params) {
1384
+ if (!params)
1385
+ return !1;
1386
+ const popupService = accessor.get(SheetsHyperLinkPopupService);
1387
+ return params.customRangeId ? popupService.startEditing(params) : popupService.startAddEditing(params), !0;
1388
+ }
1389
+ }, CloseHyperLinkPopupOperation = {
1390
+ type: CommandType.OPERATION,
1391
+ id: "sheet.operation.close-hyper-link-popup",
1392
+ handler(accessor) {
1393
+ return accessor.get(SheetsHyperLinkPopupService).endEditing(), !0;
1394
+ }
1395
+ }, InsertHyperLinkOperation = {
1396
+ type: CommandType.OPERATION,
1397
+ id: "sheet.operation.insert-hyper-link",
1398
+ handler(accessor) {
1399
+ var _a15;
1400
+ const univerInstanceService = accessor.get(IUniverInstanceService), target = getSheetCommandTarget(univerInstanceService), editorBridgeService = accessor.get(IEditorBridgeService);
1401
+ if (!target)
1402
+ return !1;
1403
+ const commandService = accessor.get(ICommandService), selection = accessor.get(SheetsSelectionsService).getCurrentLastSelection();
1404
+ if (!selection)
1405
+ return !1;
1406
+ 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;
1407
+ return commandService.executeCommand(OpenHyperLinkEditPanelOperation.id, {
1408
+ unitId: target.unitId,
1409
+ subUnitId: target.subUnitId,
1410
+ row,
1411
+ col,
1412
+ type: isZenEditor ? HyperLinkEditSourceType.ZEN_EDITOR : visible.visible ? HyperLinkEditSourceType.EDITING : HyperLinkEditSourceType.VIEWING
1413
+ });
947
1414
  }
948
- endEditing() {
949
- this._currentEditing$.next(null);
1415
+ }, InsertHyperLinkToolbarOperation = {
1416
+ type: CommandType.OPERATION,
1417
+ id: "sheet.operation.insert-hyper-link-toolbar",
1418
+ handler(accessor) {
1419
+ const commandService = accessor.get(ICommandService);
1420
+ return accessor.get(SheetsHyperLinkPopupService).currentEditing ? commandService.executeCommand(CloseHyperLinkPopupOperation.id) : commandService.executeCommand(InsertHyperLinkOperation.id);
950
1421
  }
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--)
1422
+ }, SHEET_HYPER_LINK_UI_PLUGIN = "SHEET_HYPER_LINK_UI_PLUGIN";
1423
+ var __defProp$a = Object.defineProperty, __getOwnPropDesc$a = Object.getOwnPropertyDescriptor, __decorateClass$a = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1424
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
959
1425
  (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;
1426
+ return kind && result && __defProp$a(target, key, result), result;
1427
+ }, "__decorateClass$a"), __decorateParam$a = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$a"), _a3;
962
1428
  let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
963
1429
  constructor(_sheetClipboardService, _hyperLinkModel, _injector, _resolverService) {
964
1430
  super();
@@ -989,7 +1455,7 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
989
1455
  onPastePlainText: /* @__PURE__ */ __name((pasteTo, clipText) => {
990
1456
  const filterResult = this._filterPlainText(clipText);
991
1457
  if (isLegalLink(clipText) && filterResult) {
992
- const text = serializeUrl(clipText), { range, unitId, subUnitId } = pasteTo, { ranges: [pasteToRange], mapFunc } = virtualizeDiscreteRanges([range]), redos = [], undos = [];
1458
+ const { range, unitId, subUnitId } = pasteTo, { ranges: [pasteToRange], mapFunc } = virtualizeDiscreteRanges([range]), redos = [], undos = [];
993
1459
  return Range.foreach(pasteToRange, (originRow, originCol) => {
994
1460
  const { row, col: column } = mapFunc(originRow, originCol), link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
995
1461
  link && redos.push({
@@ -999,27 +1465,6 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
999
1465
  subUnitId,
1000
1466
  id: link.id
1001
1467
  }
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
1468
  }), link && undos.push({
1024
1469
  id: AddHyperLinkMutation.id,
1025
1470
  params: {
@@ -1048,9 +1493,9 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
1048
1493
  const { rows, cols } = discreteRange;
1049
1494
  rows.forEach((row, rowIndex) => {
1050
1495
  cols.forEach((col, colIndex) => {
1051
- var _a14;
1496
+ var _a15;
1052
1497
  const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1053
- matrix.setValue(rowIndex, colIndex, (_a14 = link == null ? void 0 : link.id) != null ? _a14 : "");
1498
+ matrix.setValue(rowIndex, colIndex, (_a15 = link == null ? void 0 : link.id) != null ? _a15 : "");
1054
1499
  });
1055
1500
  });
1056
1501
  }
@@ -1071,8 +1516,8 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
1071
1516
  return { redos: [], undos: [] };
1072
1517
  const { unitId, subUnitId } = this._copyInfo, redos = [], undos = [], { ranges: [vCopyRange, vPastedRange], mapFunc } = virtualizeDiscreteRanges([copyInfo.copyRange, pastedRange]);
1073
1518
  return getRepeatRange(vCopyRange, vPastedRange, !0).forEach(({ startRange }) => {
1074
- var _a14;
1075
- (_a14 = this._copyInfo) == null || _a14.matrix.forValue((row, col, ruleId) => {
1519
+ var _a15;
1520
+ (_a15 = this._copyInfo) == null || _a15.matrix.forValue((row, col, ruleId) => {
1076
1521
  const range = Rectangle.getPositionRange(
1077
1522
  {
1078
1523
  startRow: row,
@@ -1120,18 +1565,104 @@ let SheetsHyperLinkCopyPasteController = (_a3 = class extends Disposable {
1120
1565
  }), { redos, undos };
1121
1566
  }
1122
1567
  }, __name(_a3, "SheetsHyperLinkCopyPasteController"), _a3);
1123
- SheetsHyperLinkCopyPasteController = __decorateClass$9([
1568
+ SheetsHyperLinkCopyPasteController = __decorateClass$a([
1124
1569
  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))
1570
+ __decorateParam$a(0, ISheetClipboardService),
1571
+ __decorateParam$a(1, Inject(HyperLinkModel)),
1572
+ __decorateParam$a(2, Inject(Injector)),
1573
+ __decorateParam$a(3, Inject(SheetsHyperLinkResolverService))
1129
1574
  ], 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--)
1575
+ const getLinkDisable$ = /* @__PURE__ */ __name((accessor) => {
1576
+ const disableRange$ = getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }), univerInstanceService = accessor.get(IUniverInstanceService), sheetSelectionService = accessor.get(SheetsSelectionsService), disableCell$ = univerInstanceService.focused$.pipe(
1577
+ map((focused) => focused ? univerInstanceService.getUnit(focused, UniverInstanceType.UNIVER_SHEET) : null),
1578
+ mergeMap((unit) => unit ? unit.activeSheet$ : new Observable((sub) => {
1579
+ sub.next(null);
1580
+ })),
1581
+ mergeMap((sheet) => sheetSelectionService.selectionMoveEnd$.pipe(map((selections) => sheet && { selections, sheet }))),
1582
+ map((sheetWithSelection) => {
1583
+ if (!sheetWithSelection)
1584
+ return !0;
1585
+ const { selections, sheet } = sheetWithSelection;
1586
+ if (!selections.length)
1587
+ return !0;
1588
+ const row = selections[0].range.startRow, col = selections[0].range.startColumn, cell = sheet.getCell(row, col);
1589
+ if (cell != null && cell.f || cell != null && cell.si)
1590
+ return !0;
1591
+ const disables = [
1592
+ DataValidationType.CHECKBOX,
1593
+ DataValidationType.LIST,
1594
+ DataValidationType.LIST_MULTIPLE
1595
+ ];
1596
+ return !!(cell != null && cell.dataValidation && disables.includes(cell.dataValidation.rule.type));
1597
+ })
1598
+ );
1599
+ return disableRange$.pipe(mergeMap((disableRange) => disableCell$.pipe(map((disableCell) => disableRange || disableCell))));
1600
+ }, "getLinkDisable$"), shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
1601
+ var _a15;
1602
+ const textSelectionService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges = textSelectionService.getDocRanges();
1603
+ if (!textRanges.length || textRanges.length > 1)
1604
+ return !0;
1605
+ const activeRange = textRanges[0], doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
1606
+ if (!doc || !activeRange || activeRange.collapsed)
1607
+ return !0;
1608
+ const body = doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody(), paragraphs = body == null ? void 0 : body.paragraphs;
1609
+ if (!paragraphs)
1610
+ return !0;
1611
+ for (let i = 0, len = paragraphs.length; i < len; i++) {
1612
+ const p2 = paragraphs[i];
1613
+ if (activeRange.startOffset <= p2.startIndex && activeRange.endOffset > p2.startIndex)
1614
+ return !0;
1615
+ if (p2.startIndex > activeRange.endOffset)
1616
+ break;
1617
+ }
1618
+ return !BuildTextUtils.customRange.getCustomRangesInterestsWithRange(activeRange, (_a15 = body.customRanges) != null ? _a15 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
1619
+ }, "shouldDisableAddLink"), getZenLinkDisable$ = /* @__PURE__ */ __name((accessor) => accessor.get(IUniverInstanceService).focused$.pipe(
1620
+ mergeMap((focused) => !focused || focused !== DOCS_ZEN_EDITOR_UNIT_ID_KEY ? new Observable((sub) => sub.next(null)) : accessor.get(DocSelectionManagerService).textSelection$),
1621
+ map((selection) => !selection || selection.unitId !== DOCS_ZEN_EDITOR_UNIT_ID_KEY ? !0 : shouldDisableAddLink(accessor))
1622
+ ), "getZenLinkDisable$"), linkMenu = {
1623
+ commandId: InsertHyperLinkOperation.id,
1624
+ type: MenuItemType.BUTTON,
1625
+ positions: [MenuPosition.CONTEXT_MENU],
1626
+ title: "hyperLink.menu.add",
1627
+ icon: "LinkSingle"
1628
+ }, genZenEditorMenuId = /* @__PURE__ */ __name((id) => `${id}-zen-editor`, "genZenEditorMenuId"), insertLinkMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1629
+ ...linkMenu,
1630
+ id: linkMenu.commandId,
1631
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1632
+ disabled$: getLinkDisable$(accessor)
1633
+ // disabled$: getObservableWithExclusiveRange$(accessor, getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })),
1634
+ }), "insertLinkMenuFactory"), zenEditorInsertLinkMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1635
+ ...linkMenu,
1636
+ id: genZenEditorMenuId(linkMenu.commandId),
1637
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC, DOCS_ZEN_EDITOR_UNIT_ID_KEY),
1638
+ disabled$: getZenLinkDisable$(accessor)
1639
+ }), "zenEditorInsertLinkMenuFactory"), linkToolbarMenu = {
1640
+ tooltip: "hyperLink.form.addTitle",
1641
+ positions: MenuPosition.TOOLBAR_START,
1642
+ group: MenuGroup.TOOLBAR_OTHERS,
1643
+ commandId: InsertHyperLinkToolbarOperation.id,
1644
+ type: MenuItemType.BUTTON,
1645
+ icon: "LinkSingle"
1646
+ }, insertLinkMenuToolbarFactory = /* @__PURE__ */ __name((accessor) => ({
1647
+ ...linkToolbarMenu,
1648
+ id: linkToolbarMenu.commandId,
1649
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
1650
+ disabled$: getLinkDisable$(accessor)
1651
+ }), "insertLinkMenuToolbarFactory"), zenEditorInsertLinkMenuToolbarFactory = /* @__PURE__ */ __name((accessor) => ({
1652
+ ...linkToolbarMenu,
1653
+ id: genZenEditorMenuId(linkToolbarMenu.commandId),
1654
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC, DOCS_ZEN_EDITOR_UNIT_ID_KEY),
1655
+ disabled$: getZenLinkDisable$(accessor)
1656
+ }), "zenEditorInsertLinkMenuToolbarFactory"), InsertLinkShortcut = {
1657
+ id: InsertHyperLinkToolbarOperation.id,
1658
+ binding: KeyCode.K | MetaKeys.CTRL_COMMAND,
1659
+ preconditions: whenSheetEditorFocused
1660
+ };
1661
+ var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1662
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1132
1663
  (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;
1664
+ return kind && result && __defProp$9(target, key, result), result;
1665
+ }, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9"), _a4;
1135
1666
  let SheetsHyperLinkRemoveSheetController = (_a4 = class extends Disposable {
1136
1667
  constructor(_sheetInterceptorService, _univerInstanceService, _hyperLinkModel) {
1137
1668
  super(), this._sheetInterceptorService = _sheetInterceptorService, this._univerInstanceService = _univerInstanceService, this._hyperLinkModel = _hyperLinkModel, this._initSheetChange();
@@ -1140,12 +1671,12 @@ let SheetsHyperLinkRemoveSheetController = (_a4 = class extends Disposable {
1140
1671
  this.disposeWithMe(
1141
1672
  this._sheetInterceptorService.interceptCommand({
1142
1673
  getMutations: /* @__PURE__ */ __name((commandInfo) => {
1143
- var _a14;
1674
+ var _a15;
1144
1675
  if (commandInfo.id === RemoveSheetCommand.id) {
1145
1676
  const params = commandInfo.params, workbook = params.unitId ? this._univerInstanceService.getUnit(params.unitId) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
1146
1677
  if (!workbook)
1147
1678
  return { redos: [], undos: [] };
1148
- const unitId = workbook.getUnitId(), subUnitId = params.subUnitId || ((_a14 = workbook.getActiveSheet()) == null ? void 0 : _a14.getSheetId());
1679
+ const unitId = workbook.getUnitId(), subUnitId = params.subUnitId || ((_a15 = workbook.getActiveSheet()) == null ? void 0 : _a15.getSheetId());
1149
1680
  if (!subUnitId)
1150
1681
  return { redos: [], undos: [] };
1151
1682
  const links = this._hyperLinkModel.getSubUnit(unitId, subUnitId), redos = links.map((link) => ({
@@ -1171,25 +1702,25 @@ let SheetsHyperLinkRemoveSheetController = (_a4 = class extends Disposable {
1171
1702
  );
1172
1703
  }
1173
1704
  }, __name(_a4, "SheetsHyperLinkRemoveSheetController"), _a4);
1174
- SheetsHyperLinkRemoveSheetController = __decorateClass$8([
1705
+ SheetsHyperLinkRemoveSheetController = __decorateClass$9([
1175
1706
  OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkRemoveSheetController),
1176
- __decorateParam$8(0, Inject(SheetInterceptorService)),
1177
- __decorateParam$8(1, IUniverInstanceService),
1178
- __decorateParam$8(2, Inject(HyperLinkModel))
1707
+ __decorateParam$9(0, Inject(SheetInterceptorService)),
1708
+ __decorateParam$9(1, IUniverInstanceService),
1709
+ __decorateParam$9(2, Inject(HyperLinkModel))
1179
1710
  ], 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--)
1711
+ var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1712
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1182
1713
  (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;
1714
+ return kind && result && __defProp$8(target, key, result), result;
1715
+ }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a5;
1185
1716
  let SheetsHyperLinkRenderController = (_a5 = class extends Disposable {
1186
1717
  constructor(_context, _hyperLinkModel, _sheetSkeletonManagerService, _renderManagerService) {
1187
1718
  super(), this._context = _context, this._hyperLinkModel = _hyperLinkModel, this._sheetSkeletonManagerService = _sheetSkeletonManagerService, this._renderManagerService = _renderManagerService, this._initSkeletonChange();
1188
1719
  }
1189
1720
  _initSkeletonChange() {
1190
1721
  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();
1722
+ var _a15;
1723
+ const workbook = this._context.unit, unitId = workbook.getUnitId(), subUnitId = (_a15 = workbook.getActiveSheet()) == null ? void 0 : _a15.getSheetId();
1193
1724
  if (!subUnitId) {
1194
1725
  console.warn("No active sheet found");
1195
1726
  return;
@@ -1202,10 +1733,10 @@ let SheetsHyperLinkRenderController = (_a5 = class extends Disposable {
1202
1733
  }));
1203
1734
  }
1204
1735
  }, __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)
1736
+ SheetsHyperLinkRenderController = __decorateClass$8([
1737
+ __decorateParam$8(1, Inject(HyperLinkModel)),
1738
+ __decorateParam$8(2, Inject(SheetSkeletonManagerService)),
1739
+ __decorateParam$8(3, IRenderManagerService)
1209
1740
  ], SheetsHyperLinkRenderController);
1210
1741
  var _a6;
1211
1742
  let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
@@ -1218,17 +1749,11 @@ let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
1218
1749
  INTERCEPTOR_POINT.CELL_CONTENT,
1219
1750
  {
1220
1751
  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();
1752
+ const { row, col, unitId, subUnitId } = pos, link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1222
1753
  return next(link ? {
1223
1754
  ...cell,
1224
- interceptorStyle: {
1225
- ul: {
1226
- s: BooleanNumber.TRUE
1227
- },
1228
- cl: {
1229
- rgb: styleSheet.blue500
1230
- }
1231
- }
1755
+ linkUrl: link.payload,
1756
+ linkId: link.id
1232
1757
  } : cell);
1233
1758
  }, "handler"),
1234
1759
  priority: 100
@@ -1237,140 +1762,32 @@ let SheetsHyperLinkRenderManagerController = (_a6 = class extends Disposable {
1237
1762
  );
1238
1763
  }
1239
1764
  }, __name(_a6, "SheetsHyperLinkRenderManagerController"), _a6);
1240
- SheetsHyperLinkRenderManagerController = __decorateClass$7([
1765
+ SheetsHyperLinkRenderManagerController = __decorateClass$8([
1241
1766
  OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkRenderManagerController),
1242
- __decorateParam$7(0, Inject(SheetInterceptorService)),
1243
- __decorateParam$7(1, Inject(HyperLinkModel)),
1244
- __decorateParam$7(2, Inject(ThemeService))
1767
+ __decorateParam$8(0, Inject(SheetInterceptorService)),
1768
+ __decorateParam$8(1, Inject(HyperLinkModel)),
1769
+ __decorateParam$8(2, Inject(ThemeService))
1245
1770
  ], 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--)
1771
+ var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1772
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1248
1773
  (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;
1774
+ return kind && result && __defProp$7(target, key, result), result;
1775
+ }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a7;
1251
1776
  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();
1777
+ constructor(_sheetInterceptorService, _hyperLinkModel, _selectionManagerService, _univerInstanceService, _editorBridgeService, _renderManagerService) {
1778
+ super(), this._sheetInterceptorService = _sheetInterceptorService, this._hyperLinkModel = _hyperLinkModel, this._selectionManagerService = _selectionManagerService, this._univerInstanceService = _univerInstanceService, this._editorBridgeService = _editorBridgeService, this._renderManagerService = _renderManagerService, this._initCommandInterceptor(), this._initAfterEditor();
1254
1779
  }
1255
1780
  _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
- }));
1781
+ this._initSetRangeValuesCommandInterceptor(), this._initClearSelectionCommandInterceptor();
1337
1782
  }
1338
1783
  _initSetRangeValuesCommandInterceptor() {
1339
1784
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
1340
1785
  getMutations: /* @__PURE__ */ __name((command) => {
1341
1786
  if (command.id === SetRangeValuesCommand.id) {
1342
1787
  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({
1788
+ return params.cellValue && new ObjectMatrix(params.cellValue).forValue((row, col) => {
1789
+ const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1790
+ link && (redos.push({
1374
1791
  id: RemoveHyperLinkMutation.id,
1375
1792
  params: {
1376
1793
  unitId,
@@ -1435,88 +1852,220 @@ let SheetHyperLinkSetRangeController = (_a7 = class extends Disposable {
1435
1852
  }, "getMutations")
1436
1853
  }));
1437
1854
  }
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
- });
1855
+ _initAfterEditor() {
1856
+ this.disposeWithMe(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT, {
1857
+ handler: /* @__PURE__ */ __name((cell, context, next) => {
1858
+ if (!cell || cell.p)
1859
+ return next(cell);
1860
+ if (typeof cell.v == "string" && Tools.isLegalUrl(cell.v) && cell.v[cell.v.length - 1] !== " ") {
1861
+ const { unitId, subUnitId } = context, renderer = this._renderManagerService.getRenderById(unitId), skeleton = renderer == null ? void 0 : renderer.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);
1862
+ if (!skeleton)
1863
+ return next(cell);
1864
+ const doc = skeleton.skeleton.getBlankCellDocumentModel(cell);
1865
+ if (!doc.documentModel)
1866
+ return next(cell);
1867
+ const textX = BuildTextUtils.selection.replace({
1868
+ selection: {
1869
+ startOffset: 0,
1870
+ endOffset: cell.v.length,
1871
+ collapsed: !1
1872
+ },
1873
+ body: {
1874
+ dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${cell.v}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
1875
+ customRanges: [{
1876
+ startIndex: 0,
1877
+ endIndex: cell.v.length,
1878
+ rangeId: generateRandomId(),
1879
+ rangeType: CustomRangeType.HYPERLINK,
1880
+ properties: {
1881
+ url: cell.v
1882
+ }
1883
+ }]
1884
+ },
1885
+ doc: doc.documentModel
1886
+ });
1887
+ if (!textX)
1888
+ return next(cell);
1889
+ const body = doc.documentModel.getBody();
1890
+ return TextX.apply(body, textX.serialize()), next({
1891
+ ...cell,
1892
+ p: {
1893
+ id: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
1894
+ body,
1895
+ documentStyle: {
1896
+ pageSize: {
1897
+ width: 1 / 0,
1898
+ height: 1 / 0
1899
+ }
1458
1900
  }
1459
1901
  }
1460
- return next(data);
1461
- }, "handler")
1902
+ });
1462
1903
  }
1463
- )
1464
- );
1904
+ return next(cell);
1905
+ }, "handler")
1906
+ }));
1465
1907
  }
1466
1908
  }, __name(_a7, "SheetHyperLinkSetRangeController"), _a7);
1467
- SheetHyperLinkSetRangeController = __decorateClass$6([
1909
+ SheetHyperLinkSetRangeController = __decorateClass$7([
1468
1910
  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)
1911
+ __decorateParam$7(0, Inject(SheetInterceptorService)),
1912
+ __decorateParam$7(1, Inject(HyperLinkModel)),
1913
+ __decorateParam$7(2, Inject(SheetsSelectionsService)),
1914
+ __decorateParam$7(3, IUniverInstanceService),
1915
+ __decorateParam$7(4, IEditorBridgeService),
1916
+ __decorateParam$7(5, IRenderManagerService)
1475
1917
  ], 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--)
1918
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1919
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1478
1920
  (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;
1921
+ return kind && result && __defProp$6(target, key, result), result;
1922
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a8;
1481
1923
  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();
1924
+ constructor(_hoverManagerService, _sheetsHyperLinkPopupService, _renderManagerService, _permissionService, _sheetPermissionInterceptorBaseController, _commandService, _editorBridgeService, _textSelectionManagerService, _univerInstanceService, _zenZoneService) {
1925
+ super(), this._hoverManagerService = _hoverManagerService, this._sheetsHyperLinkPopupService = _sheetsHyperLinkPopupService, this._renderManagerService = _renderManagerService, this._permissionService = _permissionService, this._sheetPermissionInterceptorBaseController = _sheetPermissionInterceptorBaseController, this._commandService = _commandService, this._editorBridgeService = _editorBridgeService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this._zenZoneService = _zenZoneService, this._initHoverListener(), this._initCommandListener(), this._initHoverEditingListener(), this._initTextSelectionListener(), this._initZenEditor();
1926
+ }
1927
+ _getLinkPermission(location2) {
1928
+ const { unitId, subUnitId, row: currentRow, col: currentCol } = location2, viewPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
1929
+ workbookTypes: [WorkbookViewPermission],
1930
+ worksheetTypes: [WorksheetViewPermission],
1931
+ rangeTypes: [RangeProtectionPermissionViewPoint]
1932
+ }, [{ startRow: currentRow, startColumn: currentCol, endRow: currentRow, endColumn: currentCol }]), editPermission = this._sheetPermissionInterceptorBaseController.permissionCheckWithRanges({
1933
+ workbookTypes: [WorkbookEditablePermission],
1934
+ worksheetTypes: [WorksheetEditPermission, WorksheetInsertHyperlinkPermission],
1935
+ rangeTypes: [RangeProtectionPermissionEditPoint]
1936
+ }, [{ 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);
1937
+ return {
1938
+ viewPermission,
1939
+ editPermission,
1940
+ copyPermission
1941
+ };
1484
1942
  }
1485
1943
  _initHoverListener() {
1486
1944
  this.disposeWithMe(
1487
- this._hoverManagerService.currentCell$.pipe(debounceTime(200)).subscribe((currentCell) => {
1488
- var _a14, _b;
1945
+ // hover over not editing cell
1946
+ this._hoverManagerService.currentRichText$.pipe(debounceTime(200)).subscribe((currentCell) => {
1947
+ var _a15;
1489
1948
  if (!currentCell) {
1490
1949
  this._sheetsHyperLinkPopupService.hideCurrentPopup();
1491
1950
  return;
1492
1951
  }
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;
1952
+ const { unitId, subUnitId, row, col } = currentCell, renderer = this._renderManagerService.getRenderById(unitId);
1953
+ if (!renderer)
1954
+ return;
1955
+ if (!renderer.with(HoverRenderController).active) {
1956
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.VIEWING);
1957
+ return;
1958
+ }
1959
+ const skeleton = (_a15 = renderer == null ? void 0 : renderer.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId)) == null ? void 0 : _a15.skeleton, currentCol = col, currentRow = row;
1494
1960
  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 }])) {
1961
+ skeleton && skeleton.overflowCache.forValue((row2, col2, value) => {
1962
+ Rectangle.contains(value, { startColumn: currentCol, endColumn: currentCol, startRow: currentRow, endRow: currentRow }) && (targetRow = row2, targetCol = col2);
1963
+ });
1964
+ const { viewPermission, editPermission, copyPermission } = this._getLinkPermission(currentCell);
1965
+ if (!viewPermission || !currentCell.customRange) {
1502
1966
  this._sheetsHyperLinkPopupService.hideCurrentPopup();
1503
1967
  return;
1504
1968
  }
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
1969
  this._sheetsHyperLinkPopupService.showPopup({
1511
- ...currentCell.location,
1512
1970
  row: targetRow,
1513
1971
  col: targetCol,
1514
1972
  editPermission,
1515
- copyPermission
1973
+ copyPermission,
1974
+ customRange: currentCell.customRange,
1975
+ customRangeRect: currentCell.rect,
1976
+ type: HyperLinkEditSourceType.VIEWING,
1977
+ unitId,
1978
+ subUnitId
1516
1979
  });
1517
1980
  })
1518
1981
  );
1519
1982
  }
1983
+ _initHoverEditingListener() {
1984
+ let subscribe = null;
1985
+ this.disposeWithMe(
1986
+ this._editorBridgeService.currentEditCellState$.pipe(mergeMap((state) => this._editorBridgeService.visible$.pipe(map((visible) => ({ visible, state }))))).subscribe(({ visible, state }) => {
1987
+ if (!state || state.editorUnitId !== DOCS_NORMAL_EDITOR_UNIT_ID_KEY)
1988
+ return;
1989
+ if (!visible.visible) {
1990
+ subscribe == null || subscribe.unsubscribe(), this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.EDITING), this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.EDITING);
1991
+ return;
1992
+ }
1993
+ const { editorUnitId, unitId, sheetId, row, column } = state, renderer = this._renderManagerService.getRenderById(editorUnitId);
1994
+ if (!renderer)
1995
+ return;
1996
+ const { editPermission, viewPermission, copyPermission } = this._getLinkPermission({ unitId, subUnitId: sheetId, row, col: column }), docEventService = renderer.with(DocEventManagerService);
1997
+ viewPermission && (subscribe == null || subscribe.unsubscribe(), subscribe = docEventService.hoverCustomRanges$.pipe(debounceTime(200)).subscribe((customRanges) => {
1998
+ var _a15, _b;
1999
+ const customRange = customRanges.find((customRange2) => customRange2.range.rangeType === CustomRangeType.HYPERLINK);
2000
+ if (!customRange) {
2001
+ this._sheetsHyperLinkPopupService.hideCurrentPopup();
2002
+ return;
2003
+ }
2004
+ const rect = customRange.rects[customRange.rects.length - 1];
2005
+ if (!((_b = (_a15 = this._renderManagerService.getRenderById(unitId)) == null ? void 0 : _a15.with(SheetSkeletonManagerService).getWorksheetSkeleton(sheetId)) == null ? void 0 : _b.skeleton) || !rect)
2006
+ return;
2007
+ const canvasClientRect = renderer.engine.getCanvasElement().getBoundingClientRect();
2008
+ this._sheetsHyperLinkPopupService.showPopup({
2009
+ unitId,
2010
+ subUnitId: sheetId,
2011
+ row,
2012
+ col: column,
2013
+ customRange: customRange.range,
2014
+ customRangeRect: {
2015
+ left: rect.left + canvasClientRect.left,
2016
+ top: rect.top + canvasClientRect.top,
2017
+ bottom: rect.bottom + canvasClientRect.top,
2018
+ right: rect.right + canvasClientRect.left
2019
+ },
2020
+ editPermission,
2021
+ copyPermission,
2022
+ type: HyperLinkEditSourceType.EDITING
2023
+ });
2024
+ }));
2025
+ })
2026
+ ), this.disposeWithMe(() => {
2027
+ subscribe == null || subscribe.unsubscribe();
2028
+ });
2029
+ }
2030
+ _initZenEditor() {
2031
+ this.disposeWithMe(
2032
+ this._zenZoneService.visible$.subscribe((visible) => {
2033
+ visible && (this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.VIEWING), this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.EDITING), this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.EDITING), this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.VIEWING));
2034
+ })
2035
+ ), this.disposeWithMe(
2036
+ this._univerInstanceService.focused$.pipe(
2037
+ mergeMap((id) => {
2038
+ const render2 = id === DOCS_ZEN_EDITOR_UNIT_ID_KEY ? this._renderManagerService.getRenderById(id) : null;
2039
+ return render2 ? render2.with(DocEventManagerService).hoverCustomRanges$.pipe(debounceTime(200)) : new Observable((sub) => {
2040
+ sub.next(null);
2041
+ });
2042
+ })
2043
+ ).subscribe((value) => {
2044
+ const range = value == null ? void 0 : value.find((range2) => range2.range.rangeType === CustomRangeType.HYPERLINK), state = this._editorBridgeService.getEditCellState();
2045
+ if (range && state) {
2046
+ const { unitId, sheetId, row, column } = state, { editPermission, viewPermission, copyPermission } = this._getLinkPermission({ unitId, subUnitId: sheetId, row, col: column });
2047
+ viewPermission && this._sheetsHyperLinkPopupService.showPopup({
2048
+ type: HyperLinkEditSourceType.ZEN_EDITOR,
2049
+ unitId,
2050
+ subUnitId: sheetId,
2051
+ row,
2052
+ col: column,
2053
+ customRange: range.range,
2054
+ editPermission,
2055
+ copyPermission
2056
+ });
2057
+ } else
2058
+ this._sheetsHyperLinkPopupService.hideCurrentPopup(HyperLinkEditSourceType.ZEN_EDITOR);
2059
+ })
2060
+ );
2061
+ }
2062
+ _initTextSelectionListener() {
2063
+ this.disposeWithMe(
2064
+ this._textSelectionManagerService.textSelection$.subscribe((selection) => {
2065
+ selection && selection.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY && this._sheetsHyperLinkPopupService.endEditing(HyperLinkEditSourceType.EDITING);
2066
+ })
2067
+ );
2068
+ }
1520
2069
  _initCommandListener() {
1521
2070
  const HIDE_COMMAND_LIST = [ClearSelectionContentCommand.id, ClearSelectionAllCommand.id, ClearSelectionFormatCommand.id];
1522
2071
  this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
@@ -1524,38 +2073,28 @@ let SheetsHyperLinkPopupController = (_a8 = class extends Disposable {
1524
2073
  }));
1525
2074
  }
1526
2075
  }, __name(_a8, "SheetsHyperLinkPopupController"), _a8);
1527
- SheetsHyperLinkPopupController = __decorateClass$5([
2076
+ SheetsHyperLinkPopupController = __decorateClass$6([
1528
2077
  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)
2078
+ __decorateParam$6(0, Inject(HoverManagerService)),
2079
+ __decorateParam$6(1, Inject(SheetsHyperLinkPopupService)),
2080
+ __decorateParam$6(2, Inject(IRenderManagerService)),
2081
+ __decorateParam$6(3, Inject(IPermissionService)),
2082
+ __decorateParam$6(4, Inject(SheetPermissionInterceptorBaseController)),
2083
+ __decorateParam$6(5, ICommandService),
2084
+ __decorateParam$6(6, IEditorBridgeService),
2085
+ __decorateParam$6(7, Inject(DocSelectionManagerService)),
2086
+ __decorateParam$6(8, IUniverInstanceService),
2087
+ __decorateParam$6(9, IZenZoneService)
1535
2088
  ], 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 = {
2089
+ const menuSchema = {
1555
2090
  [RibbonStartGroup.OTHERS]: {
1556
2091
  [InsertHyperLinkToolbarOperation.id]: {
1557
2092
  order: 2,
1558
2093
  menuItemFactory: insertLinkMenuToolbarFactory
2094
+ },
2095
+ [genZenEditorMenuId(InsertHyperLinkToolbarOperation.id)]: {
2096
+ order: 2,
2097
+ menuItemFactory: zenEditorInsertLinkMenuToolbarFactory
1559
2098
  }
1560
2099
  },
1561
2100
  [ContextMenuPosition.MAIN_AREA]: {
@@ -1564,15 +2103,19 @@ const insertLinkMenuFactory = /* @__PURE__ */ __name((accessor) => ({
1564
2103
  [InsertHyperLinkToolbarOperation.id]: {
1565
2104
  order: 0,
1566
2105
  menuItemFactory: insertLinkMenuFactory
2106
+ },
2107
+ [genZenEditorMenuId(InsertHyperLinkToolbarOperation.id)]: {
2108
+ order: 0,
2109
+ menuItemFactory: zenEditorInsertLinkMenuFactory
1567
2110
  }
1568
2111
  }
1569
2112
  }
1570
2113
  };
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--)
2114
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2115
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1573
2116
  (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;
2117
+ return kind && result && __defProp$5(target, key, result), result;
2118
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a9;
1576
2119
  let SheetsHyperLinkUIController = (_a9 = class extends Disposable {
1577
2120
  constructor(_componentManager, _commandService, _menuManagerService, _injector, _shortcutService) {
1578
2121
  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 +2131,16 @@ let SheetsHyperLinkUIController = (_a9 = class extends Disposable {
1588
2131
  }
1589
2132
  _initCommands() {
1590
2133
  [
1591
- OpenHyperLinkSidebarOperation,
1592
- CloseHyperLinkSidebarOperation,
2134
+ OpenHyperLinkEditPanelOperation,
2135
+ CloseHyperLinkPopupOperation,
1593
2136
  InsertHyperLinkOperation,
1594
2137
  InsertHyperLinkToolbarOperation,
1595
2138
  AddHyperLinkCommand,
1596
2139
  UpdateHyperLinkCommand,
1597
- RemoveHyperLinkCommand,
1598
- CancelHyperLinkCommand
2140
+ CancelHyperLinkCommand,
2141
+ UpdateRichHyperLinkCommand,
2142
+ CancelRichHyperLinkCommand,
2143
+ AddRichHyperLinkCommand
1599
2144
  ].forEach((command) => {
1600
2145
  this._commandService.registerCommand(command);
1601
2146
  });
@@ -1607,19 +2152,19 @@ let SheetsHyperLinkUIController = (_a9 = class extends Disposable {
1607
2152
  this._shortcutService.registerShortcut(InsertLinkShortcut);
1608
2153
  }
1609
2154
  }, __name(_a9, "SheetsHyperLinkUIController"), _a9);
1610
- SheetsHyperLinkUIController = __decorateClass$4([
2155
+ SheetsHyperLinkUIController = __decorateClass$5([
1611
2156
  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))
2157
+ __decorateParam$5(0, Inject(ComponentManager)),
2158
+ __decorateParam$5(1, ICommandService),
2159
+ __decorateParam$5(2, IMenuManagerService),
2160
+ __decorateParam$5(3, Inject(Injector)),
2161
+ __decorateParam$5(4, Inject(IShortcutService))
1617
2162
  ], 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--)
2163
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2164
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1620
2165
  (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;
2166
+ return kind && result && __defProp$4(target, key, result), result;
2167
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a10;
1623
2168
  let SheetsHyperLinkAutoFillController = (_a10 = class extends Disposable {
1624
2169
  constructor(_autoFillService, _hyperLinkModel) {
1625
2170
  super(), this._autoFillService = _autoFillService, this._hyperLinkModel = _hyperLinkModel, this._initAutoFill();
@@ -1707,16 +2252,16 @@ let SheetsHyperLinkAutoFillController = (_a10 = class extends Disposable {
1707
2252
  this.disposeWithMe(this._autoFillService.addHook(hook));
1708
2253
  }
1709
2254
  }, __name(_a10, "SheetsHyperLinkAutoFillController"), _a10);
1710
- SheetsHyperLinkAutoFillController = __decorateClass$3([
2255
+ SheetsHyperLinkAutoFillController = __decorateClass$4([
1711
2256
  OnLifecycle(LifecycleStages.Ready, SheetsHyperLinkAutoFillController),
1712
- __decorateParam$3(0, IAutoFillService),
1713
- __decorateParam$3(1, Inject(HyperLinkModel))
2257
+ __decorateParam$4(0, IAutoFillService),
2258
+ __decorateParam$4(1, Inject(HyperLinkModel))
1714
2259
  ], 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--)
2260
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2261
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1717
2262
  (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;
2263
+ return kind && result && __defProp$3(target, key, result), result;
2264
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a11;
1720
2265
  let SheetHyperLinkUrlController = (_a11 = class extends Disposable {
1721
2266
  constructor(_resolverService) {
1722
2267
  super(), this._resolverService = _resolverService, this._handleInitUrl();
@@ -1726,15 +2271,15 @@ let SheetHyperLinkUrlController = (_a11 = class extends Disposable {
1726
2271
  hash && this._resolverService.parseHyperLink(hash).handler();
1727
2272
  }
1728
2273
  }, __name(_a11, "SheetHyperLinkUrlController"), _a11);
1729
- SheetHyperLinkUrlController = __decorateClass$2([
2274
+ SheetHyperLinkUrlController = __decorateClass$3([
1730
2275
  OnLifecycle(LifecycleStages.Rendered, SheetHyperLinkUrlController),
1731
- __decorateParam$2(0, Inject(SheetsHyperLinkResolverService))
2276
+ __decorateParam$3(0, Inject(SheetsHyperLinkResolverService))
1732
2277
  ], 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--)
2278
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2279
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1735
2280
  (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;
2281
+ return kind && result && __defProp$2(target, key, result), result;
2282
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a12;
1738
2283
  let SheetsHyperLinkPermissionController = (_a12 = class extends Disposable {
1739
2284
  constructor(_localeService, _commandService, _sheetPermissionInterceptorBaseController) {
1740
2285
  super(), this._localeService = _localeService, this._commandService = _commandService, this._sheetPermissionInterceptorBaseController = _sheetPermissionInterceptorBaseController, this._commandExecutedListener();
@@ -1751,18 +2296,175 @@ let SheetsHyperLinkPermissionController = (_a12 = class extends Disposable {
1751
2296
  );
1752
2297
  }
1753
2298
  }, __name(_a12, "SheetsHyperLinkPermissionController"), _a12);
1754
- SheetsHyperLinkPermissionController = __decorateClass$1([
2299
+ SheetsHyperLinkPermissionController = __decorateClass$2([
1755
2300
  OnLifecycle(LifecycleStages.Rendered, SheetsHyperLinkPermissionController),
1756
- __decorateParam$1(0, Inject(LocaleService)),
1757
- __decorateParam$1(1, ICommandService),
1758
- __decorateParam$1(2, Inject(SheetPermissionInterceptorBaseController))
2301
+ __decorateParam$2(0, Inject(LocaleService)),
2302
+ __decorateParam$2(1, ICommandService),
2303
+ __decorateParam$2(2, Inject(SheetPermissionInterceptorBaseController))
1759
2304
  ], SheetsHyperLinkPermissionController);
2305
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2306
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2307
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2308
+ return kind && result && __defProp$1(target, key, result), result;
2309
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a13;
2310
+ let SheetsHyperLinkRichTextRefRangeController = (_a13 = class extends Disposable {
2311
+ constructor(_commandService, _univerInstanceService, _refRangeService) {
2312
+ super();
2313
+ __publicField(this, "_refRangeMap", /* @__PURE__ */ new Map());
2314
+ this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._refRangeService = _refRangeService, this._initWorkbookLoad(), this._initWorkbookUnload(), this._initSetRangesListener();
2315
+ }
2316
+ _enusreMap(unitId, subUnitId) {
2317
+ let unitMap = this._refRangeMap.get(unitId);
2318
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._refRangeMap.set(unitId, unitMap));
2319
+ let subUnitMap = unitMap.get(subUnitId);
2320
+ return subUnitMap || (subUnitMap = new ObjectMatrix(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
2321
+ }
2322
+ _isLegalRangeUrl(unitId, payload) {
2323
+ var _a15, _b, _c;
2324
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
2325
+ if (!workbook)
2326
+ return null;
2327
+ if (payload && payload.startsWith("#")) {
2328
+ const search = new URLSearchParams(payload.slice(1)), searchObj = {
2329
+ gid: (_a15 = search.get("gid")) != null ? _a15 : "",
2330
+ range: (_b = search.get("range")) != null ? _b : "",
2331
+ rangeid: (_c = search.get("rangeid")) != null ? _c : ""
2332
+ };
2333
+ if (searchObj.range && searchObj.gid) {
2334
+ const subUnitId = searchObj.gid, worksheet = workbook.getSheetBySheetId(subUnitId);
2335
+ if (!worksheet)
2336
+ return null;
2337
+ const range = deserializeRangeWithSheet(searchObj.range).range;
2338
+ if (isValidRange(range, worksheet) && searchObj.range !== ERROR_RANGE)
2339
+ return range;
2340
+ }
2341
+ }
2342
+ return null;
2343
+ }
2344
+ _registerRange(unitId, subUnitId, row, col, p2) {
2345
+ var _a15, _b, _c, _d;
2346
+ const map2 = this._enusreMap(unitId, subUnitId), data = Tools.deepClone(p2), handleRangeChange = /* @__PURE__ */ __name((commandInfo) => {
2347
+ var _a16, _b2;
2348
+ const dataCopy = Tools.deepClone(data);
2349
+ (_b2 = (_a16 = dataCopy.body) == null ? void 0 : _a16.customRanges) == null || _b2.forEach((customRange) => {
2350
+ var _a17;
2351
+ if (customRange.rangeType === CustomRangeType.HYPERLINK) {
2352
+ const payload = (_a17 = customRange.properties) == null ? void 0 : _a17.url, range = this._isLegalRangeUrl(unitId, payload);
2353
+ if (range) {
2354
+ const resultRange = handleDefaultRangeChangeWithEffectRefCommands(range, commandInfo), newPayload = `#gid=${subUnitId}&range=${resultRange ? serializeRange(resultRange) : ERROR_RANGE}`;
2355
+ customRange.properties.url = newPayload;
2356
+ }
2357
+ }
2358
+ });
2359
+ const position = handleDefaultRangeChangeWithEffectRefCommands({ startRow: row, endRow: row, startColumn: col, endColumn: col }, commandInfo);
2360
+ return position ? {
2361
+ redos: [{
2362
+ id: SetRangeValuesMutation.id,
2363
+ params: {
2364
+ unitId,
2365
+ subUnitId,
2366
+ cellValue: {
2367
+ [position.startRow]: {
2368
+ [position.startColumn]: {
2369
+ p: dataCopy
2370
+ }
2371
+ }
2372
+ }
2373
+ }
2374
+ }],
2375
+ undos: [
2376
+ {
2377
+ id: SetRangeValuesMutation.id,
2378
+ params: {
2379
+ unitId,
2380
+ subUnitId,
2381
+ cellValue: {
2382
+ [row]: {
2383
+ [col]: {
2384
+ p: data
2385
+ }
2386
+ }
2387
+ }
2388
+ }
2389
+ }
2390
+ ]
2391
+ } : {
2392
+ redos: [],
2393
+ undos: []
2394
+ };
2395
+ }, "handleRangeChange");
2396
+ if ((_b = (_a15 = p2.body) == null ? void 0 : _a15.customRanges) != null && _b.some((customRange) => {
2397
+ var _a16;
2398
+ return customRange.rangeType === CustomRangeType.HYPERLINK && this._isLegalRangeUrl(unitId, (_a16 = customRange.properties) == null ? void 0 : _a16.url);
2399
+ })) {
2400
+ const disposableCollection = new DisposableCollection();
2401
+ (_d = (_c = p2.body) == null ? void 0 : _c.customRanges) == null || _d.forEach((customRange) => {
2402
+ var _a16;
2403
+ if (customRange.rangeType === CustomRangeType.HYPERLINK) {
2404
+ const payload = (_a16 = customRange.properties) == null ? void 0 : _a16.url, range = this._isLegalRangeUrl(unitId, payload);
2405
+ range && disposableCollection.add(this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId));
2406
+ }
2407
+ }), map2.setValue(row, col, disposableCollection);
2408
+ }
2409
+ }
2410
+ _initWorkbookLoad() {
2411
+ const handleWorkbook = /* @__PURE__ */ __name((workbook) => {
2412
+ const unitId = workbook.getUnitId();
2413
+ workbook.getSheets().forEach((sheet) => {
2414
+ const subUnitId = sheet.getSheetId(), map2 = this._enusreMap(unitId, subUnitId);
2415
+ sheet.getCellMatrix().forValue((row, col, cell) => {
2416
+ const dispose = map2.getValue(row, col);
2417
+ dispose && dispose.dispose(), cell && cell.p && this._registerRange(unitId, subUnitId, row, col, cell.p);
2418
+ });
2419
+ });
2420
+ }, "handleWorkbook");
2421
+ this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
2422
+ handleWorkbook(workbook);
2423
+ }), this.disposeWithMe(
2424
+ this._univerInstanceService.unitAdded$.subscribe((unit) => {
2425
+ unit.type === UniverInstanceType.UNIVER_SHEET && handleWorkbook(unit);
2426
+ })
2427
+ );
2428
+ }
2429
+ _initWorkbookUnload() {
2430
+ this._univerInstanceService.unitDisposed$.subscribe((unit) => {
2431
+ if (unit.type === UniverInstanceType.UNIVER_SHEET) {
2432
+ const workbook = unit, unitId = workbook.getUnitId();
2433
+ workbook.getSheets().forEach((sheet) => {
2434
+ const subUnitId = sheet.getSheetId();
2435
+ this._enusreMap(unitId, subUnitId).forValue((row, col, dispose) => {
2436
+ dispose && dispose.dispose();
2437
+ });
2438
+ }), this._refRangeMap.delete(unitId);
2439
+ }
2440
+ });
2441
+ }
2442
+ _initSetRangesListener() {
2443
+ this.disposeWithMe(
2444
+ this._commandService.onCommandExecuted((commandInfo) => {
2445
+ if (commandInfo.id === SetRangeValuesMutation.id) {
2446
+ const params = commandInfo.params, { unitId, subUnitId, cellValue } = params, map2 = this._enusreMap(unitId, subUnitId);
2447
+ cellValue && new ObjectMatrix(cellValue).forValue((row, col, cell) => {
2448
+ const dispose = map2.getValue(row, col);
2449
+ dispose && dispose.dispose(), cell && cell.p && this._registerRange(unitId, subUnitId, row, col, cell.p);
2450
+ });
2451
+ }
2452
+ })
2453
+ );
2454
+ }
2455
+ }, __name(_a13, "SheetsHyperLinkRichTextRefRangeController"), _a13);
2456
+ SheetsHyperLinkRichTextRefRangeController = __decorateClass$1([
2457
+ OnLifecycle(LifecycleStages.Starting, SheetsHyperLinkRichTextRefRangeController),
2458
+ __decorateParam$1(0, ICommandService),
2459
+ __decorateParam$1(1, IUniverInstanceService),
2460
+ __decorateParam$1(2, Inject(RefRangeService))
2461
+ ], SheetsHyperLinkRichTextRefRangeController);
1760
2462
  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
2463
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1762
2464
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1763
2465
  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 {
2466
+ }, "__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;
2467
+ let UniverSheetsHyperLinkUIPlugin = (_a14 = class extends Plugin {
1766
2468
  constructor(_config = defaultPluginConfig, _injector, _renderManagerService, _configService) {
1767
2469
  super(), this._config = _config, this._injector = _injector, this._renderManagerService = _renderManagerService, this._configService = _configService;
1768
2470
  const { menu, ...rest } = this._config;
@@ -1781,7 +2483,8 @@ let UniverSheetsHyperLinkUIPlugin = (_a13 = class extends Plugin {
1781
2483
  [SheetsHyperLinkAutoFillController],
1782
2484
  [SheetsHyperLinkCopyPasteController],
1783
2485
  [SheetsHyperLinkPermissionController],
1784
- [SheetHyperLinkUrlController]
2486
+ [SheetHyperLinkUrlController],
2487
+ [SheetsHyperLinkRichTextRefRangeController]
1785
2488
  ].forEach((dep) => this._injector.add(dep));
1786
2489
  }
1787
2490
  onReady() {
@@ -1789,11 +2492,11 @@ let UniverSheetsHyperLinkUIPlugin = (_a13 = class extends Plugin {
1789
2492
  [SheetsHyperLinkRenderController]
1790
2493
  ].forEach((d) => this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, d));
1791
2494
  }
1792
- }, __name(_a13, "UniverSheetsHyperLinkUIPlugin"), _a13);
2495
+ }, __name(_a14, "UniverSheetsHyperLinkUIPlugin"), _a14);
1793
2496
  __publicField2(UniverSheetsHyperLinkUIPlugin, "pluginName", SHEET_HYPER_LINK_UI_PLUGIN);
1794
2497
  __publicField2(UniverSheetsHyperLinkUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
1795
2498
  UniverSheetsHyperLinkUIPlugin = __decorateClass([
1796
- DependentOn(UniverSheetsHyperLinkPlugin),
2499
+ DependentOn(UniverSheetsHyperLinkPlugin, UniverDocsUIPlugin),
1797
2500
  __decorateParam(1, Inject(Injector)),
1798
2501
  __decorateParam(2, IRenderManagerService),
1799
2502
  __decorateParam(3, IConfigService)
@@ -1801,11 +2504,10 @@ UniverSheetsHyperLinkUIPlugin = __decorateClass([
1801
2504
  export {
1802
2505
  AddHyperLinkCommand,
1803
2506
  CancelHyperLinkCommand,
1804
- CloseHyperLinkSidebarOperation,
2507
+ CloseHyperLinkPopupOperation,
1805
2508
  InsertHyperLinkOperation,
1806
2509
  InsertLinkShortcut,
1807
- OpenHyperLinkSidebarOperation,
1808
- RemoveHyperLinkCommand,
2510
+ OpenHyperLinkEditPanelOperation,
1809
2511
  SheetsHyperLinkCopyPasteController,
1810
2512
  SheetsHyperLinkPopupService,
1811
2513
  SheetsHyperLinkResolverService,