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

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