@univerjs/docs-hyper-link-ui 1.0.0-insiders.20260813-7c9aa50 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +0 -1
  3. package/lib/cjs/index.js +767 -232
  4. package/lib/cjs/locale/ar-SA.js +0 -3
  5. package/lib/cjs/locale/ca-ES.js +0 -3
  6. package/lib/cjs/locale/de-DE.js +0 -3
  7. package/lib/cjs/locale/en-US.js +0 -3
  8. package/lib/cjs/locale/es-ES.js +0 -3
  9. package/lib/cjs/locale/fa-IR.js +0 -3
  10. package/lib/cjs/locale/fr-FR.js +0 -3
  11. package/lib/cjs/locale/id-ID.js +0 -3
  12. package/lib/cjs/locale/it-IT.js +0 -3
  13. package/lib/cjs/locale/ja-JP.js +0 -3
  14. package/lib/cjs/locale/ko-KR.js +0 -3
  15. package/lib/cjs/locale/pl-PL.js +0 -3
  16. package/lib/cjs/locale/pt-BR.js +0 -3
  17. package/lib/cjs/locale/ru-RU.js +0 -3
  18. package/lib/cjs/locale/sk-SK.js +0 -3
  19. package/lib/cjs/locale/vi-VN.js +0 -3
  20. package/lib/cjs/locale/zh-CN.js +0 -3
  21. package/lib/cjs/locale/zh-HK.js +0 -3
  22. package/lib/cjs/locale/zh-TW.js +0 -3
  23. package/lib/es/index.js +769 -240
  24. package/lib/es/locale/ar-SA.js +0 -2
  25. package/lib/es/locale/ca-ES.js +0 -2
  26. package/lib/es/locale/de-DE.js +0 -2
  27. package/lib/es/locale/en-US.js +0 -2
  28. package/lib/es/locale/es-ES.js +0 -2
  29. package/lib/es/locale/fa-IR.js +0 -2
  30. package/lib/es/locale/fr-FR.js +0 -2
  31. package/lib/es/locale/id-ID.js +0 -2
  32. package/lib/es/locale/it-IT.js +0 -2
  33. package/lib/es/locale/ja-JP.js +0 -2
  34. package/lib/es/locale/ko-KR.js +0 -2
  35. package/lib/es/locale/pl-PL.js +0 -2
  36. package/lib/es/locale/pt-BR.js +0 -2
  37. package/lib/es/locale/ru-RU.js +0 -2
  38. package/lib/es/locale/sk-SK.js +0 -2
  39. package/lib/es/locale/vi-VN.js +0 -2
  40. package/lib/es/locale/zh-CN.js +0 -2
  41. package/lib/es/locale/zh-HK.js +0 -2
  42. package/lib/es/locale/zh-TW.js +0 -2
  43. package/lib/index.css +80 -4
  44. package/lib/index.js +769 -240
  45. package/lib/locale/ar-SA.js +0 -2
  46. package/lib/locale/ca-ES.js +0 -2
  47. package/lib/locale/de-DE.js +0 -2
  48. package/lib/locale/en-US.js +0 -2
  49. package/lib/locale/es-ES.js +0 -2
  50. package/lib/locale/fa-IR.js +0 -2
  51. package/lib/locale/fr-FR.js +0 -2
  52. package/lib/locale/id-ID.js +0 -2
  53. package/lib/locale/it-IT.js +0 -2
  54. package/lib/locale/ja-JP.js +0 -2
  55. package/lib/locale/ko-KR.js +0 -2
  56. package/lib/locale/pl-PL.js +0 -2
  57. package/lib/locale/pt-BR.js +0 -2
  58. package/lib/locale/ru-RU.js +0 -2
  59. package/lib/locale/sk-SK.js +0 -2
  60. package/lib/locale/vi-VN.js +0 -2
  61. package/lib/locale/zh-CN.js +0 -2
  62. package/lib/locale/zh-HK.js +0 -2
  63. package/lib/locale/zh-TW.js +0 -2
  64. package/lib/types/commands/operations/popup.operation.d.ts +1 -0
  65. package/lib/types/controllers/doc-hyper-link-selection.controller.d.ts +1 -0
  66. package/lib/types/controllers/mobile/components.controller.d.ts +24 -0
  67. package/lib/types/controllers/render-controllers/hyper-link-event.render-controller.d.ts +2 -0
  68. package/lib/types/controllers/render-controllers/mobile/hyper-link-event.render-controller.d.ts +33 -0
  69. package/lib/types/controllers/render-controllers/render.controller.d.ts +1 -5
  70. package/lib/types/index.d.ts +1 -0
  71. package/lib/types/locale/en-US.d.ts +0 -2
  72. package/lib/types/mobile-plugin.d.ts +32 -0
  73. package/lib/types/services/hyper-link-popup.service.d.ts +33 -10
  74. package/lib/types/services/mobile/hyper-link-popup.service.d.ts +22 -0
  75. package/lib/types/views/MobileDocHyperLinkEdit.d.ts +19 -0
  76. package/lib/types/views/MobileDocLinkPopup.d.ts +19 -0
  77. package/lib/types/views/hyper-link-edit/index.d.ts +19 -0
  78. package/lib/types/views/hyper-link-edit/use-doc-hyper-link-edit.d.ts +28 -0
  79. package/lib/types/views/hyper-link-popup/index.d.ts +19 -0
  80. package/lib/umd/index.js +1 -1
  81. package/lib/umd/locale/ar-SA.js +1 -1
  82. package/lib/umd/locale/ca-ES.js +1 -1
  83. package/lib/umd/locale/de-DE.js +1 -1
  84. package/lib/umd/locale/en-US.js +1 -1
  85. package/lib/umd/locale/es-ES.js +1 -1
  86. package/lib/umd/locale/fa-IR.js +1 -1
  87. package/lib/umd/locale/fr-FR.js +1 -1
  88. package/lib/umd/locale/id-ID.js +1 -1
  89. package/lib/umd/locale/it-IT.js +1 -1
  90. package/lib/umd/locale/ja-JP.js +1 -1
  91. package/lib/umd/locale/ko-KR.js +1 -1
  92. package/lib/umd/locale/pl-PL.js +1 -1
  93. package/lib/umd/locale/pt-BR.js +1 -1
  94. package/lib/umd/locale/ru-RU.js +1 -1
  95. package/lib/umd/locale/sk-SK.js +1 -1
  96. package/lib/umd/locale/vi-VN.js +1 -1
  97. package/lib/umd/locale/zh-CN.js +1 -1
  98. package/lib/umd/locale/zh-HK.js +1 -1
  99. package/lib/umd/locale/zh-TW.js +1 -1
  100. package/package.json +13 -12
package/lib/es/index.js CHANGED
@@ -1,25 +1,46 @@
1
- import { DocCanvasPopManagerService, DocEventManagerService, DocRenderController, EMPTY_PARAGRAPH_MENU_ID, FLOAT_TOOLBAR_MENU_POSITION, INSERT_BELLOW_MENU_ID, UniverDocsUIPlugin, whenDocAndEditorFocused } from "@univerjs/docs-ui";
2
- import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IMessageService, IShortcutService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
3
- import { BuildTextUtils, CommandType, CustomRangeType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Disposable, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, generateRandomId, getBodySlice, isSafeUrl, merge } from "@univerjs/core";
4
- import { DOC_INTERCEPTOR_POINT, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, SetTextSelectionsOperation, UniverDocsPlugin, addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory } from "@univerjs/docs";
5
- import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, pairwise } from "rxjs";
6
- import { Button, FormLayout, Input, MessageType, Tooltip, borderClassName, clsx } from "@univerjs/design";
1
+ import { DocBackScrollRenderController, DocCanvasPopManagerService, DocEventManagerService, DocMobileElementMenuService, EMPTY_PARAGRAPH_MENU_ID, FLOAT_TOOLBAR_MENU_POSITION, INSERT_BELLOW_MENU_ID, MOBILE_DOC_ELEMENT_MENU, UniverDocsMobileUIPlugin, UniverDocsUIPlugin, whenDocAndEditorFocused } from "@univerjs/docs-ui";
2
+ import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IDialogService, IMenuManagerService, IMessageService, IShortcutService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
3
+ import { BuildTextUtils, CommandType, CustomRangeType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Disposable, DocumentDataModel, ICommandService, IConfigService, IPermissionService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, generateRandomId, getBodySlice, isSafeUrl, merge } from "@univerjs/core";
4
+ import { DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation, SetTextSelectionsOperation, UniverDocsPlugin, addCustomRangeBySelectionFactory, canEditDocumentTargets, deleteCustomRangeFactory, getDocumentEntityParentPermissionObjectIds, getDocumentEntityPermissionObjectId, getDocumentPermissionValue, replaceSelectionFactory } from "@univerjs/docs";
5
+ import { IRenderManagerService, UniverRenderEnginePlugin } from "@univerjs/engine-render";
6
+ import { BehaviorSubject, Observable, debounceTime } from "rxjs";
7
+ import { DocHyperLinkCommandId, UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
8
+ import { Button, FormLayout, Input, MessageType, MobileActionRow, Tooltip, borderClassName, clsx } from "@univerjs/design";
7
9
  import { useEffect, useState } from "react";
8
- import { jsx, jsxs } from "react/jsx-runtime";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
11
  import { CopyIcon, LinkIcon, UnlinkIcon, WriteIcon } from "@univerjs/icons";
10
- import { UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
11
- import { IRenderManagerService, UniverRenderEnginePlugin } from "@univerjs/engine-render";
12
+ import { UnitAction } from "@univerjs/protocol";
13
+
14
+ //#region src/commands/commands/delete-link.command.ts
15
+ const DeleteDocHyperLinkCommand = {
16
+ type: CommandType.COMMAND,
17
+ id: DocHyperLinkCommandId.Delete,
18
+ async handler(accessor, params) {
19
+ if (!params) return false;
20
+ const { unitId, linkId, segmentId } = params;
21
+ const commandService = accessor.get(ICommandService);
22
+ const doMutation = deleteCustomRangeFactory(accessor, {
23
+ unitId,
24
+ rangeId: linkId,
25
+ segmentId
26
+ });
27
+ if (!doMutation) return false;
28
+ return await commandService.syncExecuteCommand(doMutation.id, doMutation.params);
29
+ }
30
+ };
12
31
 
32
+ //#endregion
13
33
  //#region src/commands/commands/add-link.command.ts
14
34
  const AddDocHyperLinkCommand = {
15
35
  type: CommandType.COMMAND,
16
- id: "docs.command.add-hyper-link",
36
+ id: DocHyperLinkCommandId.Add,
17
37
  async handler(accessor, params) {
18
38
  if (!params) return false;
19
39
  const { payload, unitId, selections } = params;
20
40
  const commandService = accessor.get(ICommandService);
41
+ const id = generateRandomId();
21
42
  const doMutation = addCustomRangeBySelectionFactory(accessor, {
22
- rangeId: generateRandomId(),
43
+ rangeId: id,
23
44
  rangeType: CustomRangeType.HYPERLINK,
24
45
  properties: { url: payload },
25
46
  unitId,
@@ -33,10 +54,10 @@ const AddDocHyperLinkCommand = {
33
54
  //#endregion
34
55
  //#region src/commands/commands/update-link.command.ts
35
56
  const UpdateDocHyperLinkCommand = {
36
- id: "docs.command.update-hyper-link",
57
+ id: DocHyperLinkCommandId.Update,
37
58
  type: CommandType.COMMAND,
38
59
  handler(accessor, params) {
39
- var _doc$getSelfOrHeaderF, _getBodySlice$textRun;
60
+ var _doc$getSelfOrHeaderF, _oldBody$customRanges, _getBodySlice$textRun, _oldLink$properties, _oldLink$properties2;
40
61
  if (!params) return false;
41
62
  const { unitId, payload, segmentId, linkId } = params;
42
63
  const commandService = accessor.get(ICommandService);
@@ -46,6 +67,7 @@ const UpdateDocHyperLinkCommand = {
46
67
  if (!currentSelection || !doc) return false;
47
68
  const oldBody = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
48
69
  if (!oldBody) return false;
70
+ const oldLink = (_oldBody$customRanges = oldBody.customRanges) === null || _oldBody$customRanges === void 0 ? void 0 : _oldBody$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK);
49
71
  const textRun = (_getBodySlice$textRun = getBodySlice(oldBody, currentSelection.startOffset, currentSelection.endOffset).textRuns) === null || _getBodySlice$textRun === void 0 ? void 0 : _getBodySlice$textRun[0];
50
72
  if (textRun) textRun.ed = params.label.length + 1;
51
73
  const replaceSelection = replaceSelectionFactory(accessor, {
@@ -57,7 +79,11 @@ const UpdateDocHyperLinkCommand = {
57
79
  rangeType: CustomRangeType.HYPERLINK,
58
80
  startIndex: 0,
59
81
  endIndex: params.label.length + 1,
60
- properties: { url: payload }
82
+ properties: {
83
+ url: payload,
84
+ ...(oldLink === null || oldLink === void 0 || (_oldLink$properties = oldLink.properties) === null || _oldLink$properties === void 0 ? void 0 : _oldLink$properties.textStyleMode) ? { textStyleMode: oldLink.properties.textStyleMode } : null,
85
+ ...(oldLink === null || oldLink === void 0 || (_oldLink$properties2 = oldLink.properties) === null || _oldLink$properties2 === void 0 ? void 0 : _oldLink$properties2.textColorMode) ? { textColorMode: oldLink.properties.textColorMode } : null
86
+ }
61
87
  }],
62
88
  textRuns: textRun ? [textRun] : void 0
63
89
  },
@@ -95,20 +121,19 @@ function isBlankInput(value) {
95
121
  }
96
122
 
97
123
  //#endregion
98
- //#region src/views/DocHyperLinkEdit.tsx
99
- function hasProtocol(urlString) {
100
- return /^[a-zA-Z]+:\/\//.test(urlString);
124
+ //#region src/views/hyper-link-edit/use-doc-hyper-link-edit.ts
125
+ function hasProtocol(url) {
126
+ return /^[a-zA-Z]+:\/\//.test(url);
101
127
  }
102
128
  function isEmail(url) {
103
- return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
129
+ return /^[\w.-]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
104
130
  }
105
- function transformUrl(urlStr) {
106
- return hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `https://${urlStr}`;
131
+ function transformUrl(url) {
132
+ return hasProtocol(url) ? url : isEmail(url) ? `mailto://${url}` : `https://${url}`;
107
133
  }
108
- const DocHyperLinkEdit = () => {
134
+ function useDocHyperLinkEdit() {
109
135
  const hyperLinkService = useDependency(DocHyperLinkPopupService);
110
- const localeService = useDependency(LocaleService);
111
- const editing = useObservable(hyperLinkService.editingLink$);
136
+ const editing = useObservable(hyperLinkService.editingLink$, hyperLinkService.editing);
112
137
  const commandService = useDependency(ICommandService);
113
138
  const univerInstanceService = useDependency(IUniverInstanceService);
114
139
  const docSelectionManagerService = useDependency(DocSelectionManagerService);
@@ -124,7 +149,7 @@ const DocHyperLinkEdit = () => {
124
149
  if (editing) {
125
150
  var _doc$getSelfOrHeaderF, _body$customRanges;
126
151
  const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
127
- const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((i) => (editing === null || editing === void 0 ? void 0 : editing.linkId) === i.rangeId && i.startIndex === editing.startIndex && i.endIndex === editing.endIndex);
152
+ const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => editing.linkId === range.rangeId && range.startIndex === editing.startIndex && range.endIndex === editing.endIndex);
128
153
  if (doc && matchedRange) {
129
154
  var _matchedRange$propert;
130
155
  setLink(((_matchedRange$propert = matchedRange.properties) === null || _matchedRange$propert === void 0 ? void 0 : _matchedRange$propert.url) ?? "");
@@ -137,40 +162,55 @@ const DocHyperLinkEdit = () => {
137
162
  const matchedRange = selection && ((_BuildTextUtils$custo = BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (body === null || body === void 0 ? void 0 : body.customRanges) ?? [])) === null || _BuildTextUtils$custo === void 0 ? void 0 : _BuildTextUtils$custo[0]);
138
163
  if (doc && matchedRange) {
139
164
  var _matchedRange$propert2;
140
- setLink((matchedRange === null || matchedRange === void 0 || (_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) ?? "");
165
+ setLink(((_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) ?? "");
141
166
  }
142
167
  }, [
143
168
  doc,
144
- editing,
145
169
  docSelectionManagerService,
146
- univerInstanceService
170
+ editing
147
171
  ]);
148
- const handleCancel = () => {
149
- hyperLinkService.hideEditPopup();
150
- };
172
+ const handleCancel = () => hyperLinkService.hideEditPopup();
151
173
  const handleConfirm = () => {
152
174
  setShowError(true);
153
175
  if (!isLegal || !doc) return;
154
- const linkFinal = transformUrl(link);
155
- if (!editing) commandService.executeCommand(AddDocHyperLinkCommand.id, {
156
- unitId: doc.getUnitId(),
157
- payload: linkFinal
158
- });
159
- else {
176
+ const payload = transformUrl(link);
177
+ if (editing) {
160
178
  if (isBlankInput(label)) return;
161
179
  commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
162
180
  unitId: doc.getUnitId(),
163
- payload: linkFinal,
181
+ payload,
164
182
  linkId: editing.linkId,
165
183
  label,
166
184
  segmentId: editing.segmentId
167
- });
168
- }
185
+ }).catch(() => void 0);
186
+ } else commandService.executeCommand(AddDocHyperLinkCommand.id, {
187
+ unitId: doc.getUnitId(),
188
+ payload
189
+ }).catch(() => void 0);
169
190
  hyperLinkService.hideEditPopup();
170
191
  };
192
+ return {
193
+ doc,
194
+ editing,
195
+ handleCancel,
196
+ handleConfirm,
197
+ isLegal,
198
+ label,
199
+ link,
200
+ setLabel,
201
+ setLink,
202
+ showError
203
+ };
204
+ }
205
+
206
+ //#endregion
207
+ //#region src/views/DocHyperLinkEdit.tsx
208
+ const DocHyperLinkEdit = () => {
209
+ const localeService = useDependency(LocaleService);
210
+ const { doc, editing, handleCancel, handleConfirm, isLegal, label, link, setLabel, setLink, showError } = useDocHyperLinkEdit();
171
211
  if (!doc) return;
172
212
  return /* @__PURE__ */ jsxs("div", {
173
- className: clsx("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900", borderClassName),
213
+ className: clsx("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-gray-0 univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900", borderClassName),
174
214
  children: [/* @__PURE__ */ jsxs("div", { children: [editing ? /* @__PURE__ */ jsx(FormLayout, {
175
215
  label: localeService.t("docs-hyper-link-ui.edit.label"),
176
216
  error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
@@ -178,8 +218,8 @@ const DocHyperLinkEdit = () => {
178
218
  value: label,
179
219
  onChange: setLabel,
180
220
  autoFocus: true,
181
- onKeyDown: (evt) => {
182
- if (evt.keyCode === KeyCode.ENTER) handleConfirm();
221
+ onKeyDown: (event) => {
222
+ if (event.keyCode === KeyCode.ENTER) handleConfirm();
183
223
  }
184
224
  })
185
225
  }) : null, /* @__PURE__ */ jsx(FormLayout, {
@@ -189,8 +229,8 @@ const DocHyperLinkEdit = () => {
189
229
  value: link,
190
230
  onChange: setLink,
191
231
  autoFocus: true,
192
- onKeyDown: (evt) => {
193
- if (evt.keyCode === KeyCode.ENTER) handleConfirm();
232
+ onKeyDown: (event) => {
233
+ if (event.keyCode === KeyCode.ENTER) handleConfirm();
194
234
  }
195
235
  })
196
236
  })] }), /* @__PURE__ */ jsxs("div", {
@@ -209,113 +249,108 @@ const DocHyperLinkEdit = () => {
209
249
  };
210
250
  DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
211
251
 
212
- //#endregion
213
- //#region src/commands/commands/delete-link.command.ts
214
- const DeleteDocHyperLinkCommand = {
215
- type: CommandType.COMMAND,
216
- id: "docs.command.delete-hyper-link",
217
- async handler(accessor, params) {
218
- if (!params) return false;
219
- const { unitId, linkId, segmentId } = params;
220
- const commandService = accessor.get(ICommandService);
221
- const doMutation = deleteCustomRangeFactory(accessor, {
222
- unitId,
223
- rangeId: linkId,
224
- segmentId
225
- });
226
- if (!doMutation) return false;
227
- return await commandService.syncExecuteCommand(doMutation.id, doMutation.params);
228
- }
229
- };
230
-
231
252
  //#endregion
232
253
  //#region src/views/DocLinkPopup.tsx
233
254
  const DocLinkPopup = () => {
234
- var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties;
255
+ var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties, _link$properties2, _link$properties3;
235
256
  const hyperLinkService = useDependency(DocHyperLinkPopupService);
236
257
  const commandService = useDependency(ICommandService);
237
258
  const messageService = useDependency(IMessageService);
238
259
  const localeService = useDependency(LocaleService);
239
- const currentPopup = useObservable(hyperLinkService.showingLink$);
260
+ const currentPopup = useObservable(hyperLinkService.showingLink$, hyperLinkService.showing);
240
261
  const univerInstanceService = useDependency(IUniverInstanceService);
262
+ const permissionService = useDependency(IPermissionService);
241
263
  if (!currentPopup) return null;
242
264
  const { unitId, linkId, segmentId, startIndex, endIndex } = currentPopup;
243
265
  const doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
244
- const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
266
+ const body = doc instanceof DocumentDataModel ? (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody() : void 0;
245
267
  const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK && range.startIndex === startIndex && range.endIndex === endIndex);
246
268
  if (!link) return null;
247
- const url = (_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.url;
269
+ const target = ((_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.url) ?? `#${((_link$properties2 = link.properties) === null || _link$properties2 === void 0 ? void 0 : _link$properties2.bookmarkId) ?? ((_link$properties3 = link.properties) === null || _link$properties3 === void 0 ? void 0 : _link$properties3.headingId) ?? ""}`;
270
+ const canEdit = hyperLinkService.canEditLink(unitId, currentPopup);
271
+ const canCopy = getDocumentPermissionValue(permissionService, unitId, unitId, UnitAction.Copy);
248
272
  return /* @__PURE__ */ jsxs("div", {
249
- className: clsx("univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow dark:!univer-bg-gray-900", borderClassName),
273
+ className: clsx("univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-gray-0 univer-p-3 univer-shadow dark:!univer-bg-gray-900", borderClassName),
274
+ onPointerEnter: () => {
275
+ hyperLinkService.cancelScheduledHideInfoPopup();
276
+ },
277
+ onPointerLeave: () => {
278
+ hyperLinkService.scheduleHideInfoPopup();
279
+ },
250
280
  onClick: () => {
251
281
  hyperLinkService.hideInfoPopup();
252
282
  },
253
283
  children: [/* @__PURE__ */ jsxs("div", {
254
284
  className: "univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500",
255
- onClick: () => window.open(url, void 0, "noopener noreferrer"),
285
+ onClick: () => commandService.executeCommand(ClickDocHyperLinkOperation.id, {
286
+ unitId,
287
+ linkId,
288
+ segmentId
289
+ }),
256
290
  children: [/* @__PURE__ */ jsx("div", {
257
- className: "univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",
291
+ className: "univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-gray-0",
258
292
  children: /* @__PURE__ */ jsx(LinkIcon, {})
259
293
  }), /* @__PURE__ */ jsx(Tooltip, {
260
294
  showIfEllipsis: true,
261
- title: url,
295
+ title: target,
262
296
  children: /* @__PURE__ */ jsx("span", {
263
297
  className: "univer-flex-1 univer-truncate",
264
- children: url
298
+ children: target
265
299
  })
266
300
  })]
267
301
  }), /* @__PURE__ */ jsxs("div", {
268
302
  className: "univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center",
269
- children: [
270
- /* @__PURE__ */ jsx("div", {
271
- className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
272
- onClick: () => {
273
- navigator.clipboard.writeText(url);
274
- messageService.show({
275
- content: localeService.t("docs-hyper-link-ui.info.coped"),
276
- type: MessageType.Info
277
- });
278
- },
279
- children: /* @__PURE__ */ jsx(Tooltip, {
280
- placement: "bottom",
281
- title: localeService.t("docs-hyper-link-ui.info.copy"),
282
- children: /* @__PURE__ */ jsx(CopyIcon, {})
283
- })
284
- }),
285
- /* @__PURE__ */ jsx("div", {
286
- className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
287
- onClick: () => {
288
- commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, { link: currentPopup });
289
- },
290
- children: /* @__PURE__ */ jsx(Tooltip, {
291
- placement: "bottom",
292
- title: localeService.t("docs-hyper-link-ui.info.edit"),
293
- children: /* @__PURE__ */ jsx(WriteIcon, {})
294
- })
295
- }),
296
- /* @__PURE__ */ jsx("div", {
297
- className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
298
- onClick: () => {
299
- commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
300
- unitId,
301
- linkId: link.rangeId,
302
- segmentId
303
- });
304
- },
305
- children: /* @__PURE__ */ jsx(Tooltip, {
306
- placement: "bottom",
307
- title: localeService.t("docs-hyper-link-ui.info.cancel"),
308
- children: /* @__PURE__ */ jsx(UnlinkIcon, {})
309
- })
303
+ children: [/* @__PURE__ */ jsx(Button, {
304
+ type: "button",
305
+ variant: "text",
306
+ size: "small",
307
+ "aria-label": localeService.t("docs-hyper-link-ui.info.copy"),
308
+ className: "univer-ml-2 !univer-flex univer-size-6 !univer-rounded !univer-border-0 !univer-bg-transparent !univer-p-0 !univer-text-base !univer-font-normal hover:!univer-bg-transparent active:!univer-bg-transparent disabled:!univer-pointer-events-auto disabled:!univer-opacity-40",
309
+ disabled: !canCopy,
310
+ onClick: () => {
311
+ navigator.clipboard.writeText(target);
312
+ messageService.show({
313
+ content: localeService.t("docs-hyper-link-ui.info.coped"),
314
+ type: MessageType.Info
315
+ });
316
+ },
317
+ children: /* @__PURE__ */ jsx(Tooltip, {
318
+ placement: "bottom",
319
+ title: localeService.t("docs-hyper-link-ui.info.copy"),
320
+ children: /* @__PURE__ */ jsx(CopyIcon, {})
321
+ })
322
+ }), canEdit && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
323
+ className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
324
+ onClick: () => {
325
+ commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, { link: currentPopup });
326
+ },
327
+ children: /* @__PURE__ */ jsx(Tooltip, {
328
+ placement: "bottom",
329
+ title: localeService.t("docs-hyper-link-ui.info.edit"),
330
+ children: /* @__PURE__ */ jsx(WriteIcon, {})
310
331
  })
311
- ]
332
+ }), /* @__PURE__ */ jsx("div", {
333
+ className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
334
+ onClick: () => {
335
+ commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
336
+ unitId,
337
+ linkId: link.rangeId,
338
+ segmentId
339
+ });
340
+ },
341
+ children: /* @__PURE__ */ jsx(Tooltip, {
342
+ placement: "bottom",
343
+ title: localeService.t("docs-hyper-link-ui.info.cancel"),
344
+ children: /* @__PURE__ */ jsx(UnlinkIcon, {})
345
+ })
346
+ })] })]
312
347
  })]
313
348
  });
314
349
  };
315
350
  DocLinkPopup.componentKey = "univer.doc.link-info-popup";
316
351
 
317
352
  //#endregion
318
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
353
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
319
354
  function _typeof(o) {
320
355
  "@babel/helpers - typeof";
321
356
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -326,7 +361,7 @@ function _typeof(o) {
326
361
  }
327
362
 
328
363
  //#endregion
329
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
364
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
330
365
  function toPrimitive(t, r) {
331
366
  if ("object" != _typeof(t) || !t) return t;
332
367
  var e = t[Symbol.toPrimitive];
@@ -339,14 +374,14 @@ function toPrimitive(t, r) {
339
374
  }
340
375
 
341
376
  //#endregion
342
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
377
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
343
378
  function toPropertyKey(t) {
344
379
  var i = toPrimitive(t, "string");
345
380
  return "symbol" == _typeof(i) ? i : i + "";
346
381
  }
347
382
 
348
383
  //#endregion
349
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
384
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
350
385
  function _defineProperty(e, r, t) {
351
386
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
352
387
  value: t,
@@ -357,7 +392,7 @@ function _defineProperty(e, r, t) {
357
392
  }
358
393
 
359
394
  //#endregion
360
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
395
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
361
396
  function __decorateParam(paramIndex, decorator) {
362
397
  return function(target, key) {
363
398
  decorator(target, key, paramIndex);
@@ -365,7 +400,7 @@ function __decorateParam(paramIndex, decorator) {
365
400
  }
366
401
 
367
402
  //#endregion
368
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
403
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
369
404
  function __decorate(decorators, target, key, desc) {
370
405
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
371
406
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -375,22 +410,54 @@ function __decorate(decorators, target, key, desc) {
375
410
 
376
411
  //#endregion
377
412
  //#region src/services/hyper-link-popup.service.ts
413
+ const INFO_POPUP_HIDE_DELAY = 150;
414
+ function isSameLinkInfo(current, next) {
415
+ return (current === null || current === void 0 ? void 0 : current.linkId) === next.linkId && current.unitId === next.unitId && (current.segmentId ?? "") === (next.segmentId ?? "") && current.segmentPage === next.segmentPage && current.startIndex === next.startIndex && current.endIndex === next.endIndex;
416
+ }
378
417
  let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable {
379
- constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService) {
418
+ constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService, _permissionService, _renderManagerService, _dialogService, _localeService, _commandService) {
380
419
  super();
381
420
  this._docCanvasPopupManagerService = _docCanvasPopupManagerService;
382
421
  this._textSelectionManagerService = _textSelectionManagerService;
383
422
  this._univerInstanceService = _univerInstanceService;
423
+ this._permissionService = _permissionService;
424
+ this._renderManagerService = _renderManagerService;
425
+ this._dialogService = _dialogService;
426
+ this._localeService = _localeService;
427
+ this._commandService = _commandService;
384
428
  _defineProperty(this, "_editingLink$", new BehaviorSubject(null));
385
429
  _defineProperty(this, "_showingLink$", new BehaviorSubject(null));
386
430
  _defineProperty(this, "editingLink$", this._editingLink$.asObservable());
387
431
  _defineProperty(this, "showingLink$", this._showingLink$.asObservable());
388
432
  _defineProperty(this, "_editPopup", null);
433
+ _defineProperty(this, "_editPopupUnitId", null);
389
434
  _defineProperty(this, "_infoPopup", null);
435
+ _defineProperty(this, "_infoPopupPinned", false);
436
+ _defineProperty(this, "_infoPopupHideTimer", null);
437
+ _defineProperty(this, "_infoPopupSuppressed", false);
438
+ _defineProperty(this, "_infoPopupSuppressionTimer", null);
390
439
  this.disposeWithMe(() => {
440
+ this.cancelScheduledHideInfoPopup();
441
+ if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
391
442
  this._editingLink$.complete();
392
443
  this._showingLink$.complete();
393
444
  });
445
+ this.disposeWithMe(this._permissionService.permissionPointUpdate$.subscribe(() => {
446
+ const editing = this.editing;
447
+ if (editing && !this.canEditLink(editing.unitId, editing)) this.hideEditPopup();
448
+ const showing = this.showing;
449
+ if (showing) this._showingLink$.next({ ...showing });
450
+ }));
451
+ this.disposeWithMe(this._renderManagerService.disposed$.subscribe((unitId) => {
452
+ var _this$showing;
453
+ if (this._editPopupUnitId === unitId) this.hideEditPopup();
454
+ if (((_this$showing = this.showing) === null || _this$showing === void 0 ? void 0 : _this$showing.unitId) === unitId) this.hideInfoPopup();
455
+ }));
456
+ }
457
+ dispose() {
458
+ this.hideEditPopup();
459
+ this.hideInfoPopup();
460
+ super.dispose();
394
461
  }
395
462
  get editing() {
396
463
  return this._editingLink$.value;
@@ -398,8 +465,16 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
398
465
  get showing() {
399
466
  return this._showingLink$.value;
400
467
  }
468
+ get infoPopupPinned() {
469
+ return this._infoPopupPinned;
470
+ }
401
471
  showEditPopup(unitId, linkInfo) {
402
- if (this._editPopup) this._editPopup.dispose();
472
+ if (!this.canEditLink(unitId, linkInfo)) return null;
473
+ if (this._editPopup) {
474
+ this._editPopup.dispose();
475
+ this._editPopup = null;
476
+ this._editPopupUnitId = null;
477
+ }
403
478
  this._editingLink$.next(linkInfo);
404
479
  const textRanges = this._textSelectionManagerService.getTextRanges({
405
480
  unitId,
@@ -421,25 +496,33 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
421
496
  }]);
422
497
  }
423
498
  if (activeRange) {
424
- this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(activeRange, {
425
- componentKey: DocHyperLinkEdit.componentKey,
426
- direction: "bottom"
427
- }, unitId);
499
+ this._editPopup = this._openEditSurface(activeRange, unitId);
500
+ this._editPopupUnitId = unitId;
428
501
  return this._editPopup;
429
502
  }
430
503
  return null;
431
504
  }
432
505
  hideEditPopup() {
433
- var _this$_editPopup;
434
506
  this._editingLink$.next(null);
435
- (_this$_editPopup = this._editPopup) === null || _this$_editPopup === void 0 || _this$_editPopup.dispose();
507
+ const popup = this._editPopup;
508
+ this._editPopup = null;
509
+ popup === null || popup === void 0 || popup.dispose();
510
+ this._editPopupUnitId = null;
436
511
  }
437
- showInfoPopup(info) {
438
- var _this$showing, _this$showing2, _this$showing3, _this$showing4, _this$showing5, _this$showing6;
512
+ showInfoPopup(info, options) {
513
+ this.cancelScheduledHideInfoPopup();
514
+ if (this._infoPopupSuppressed) return;
439
515
  const { linkId, unitId, segmentId, segmentPage, startIndex, endIndex } = info;
440
- if (((_this$showing = this.showing) === null || _this$showing === void 0 ? void 0 : _this$showing.linkId) === linkId && ((_this$showing2 = this.showing) === null || _this$showing2 === void 0 ? void 0 : _this$showing2.unitId) === unitId && ((_this$showing3 = this.showing) === null || _this$showing3 === void 0 ? void 0 : _this$showing3.segmentId) === segmentId && ((_this$showing4 = this.showing) === null || _this$showing4 === void 0 ? void 0 : _this$showing4.segmentPage) === segmentPage && ((_this$showing5 = this.showing) === null || _this$showing5 === void 0 ? void 0 : _this$showing5.startIndex) === startIndex && ((_this$showing6 = this.showing) === null || _this$showing6 === void 0 ? void 0 : _this$showing6.endIndex) === endIndex) return;
441
- if (this._infoPopup) this._infoPopup.dispose();
442
- if (!this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC)) return;
516
+ if (isSameLinkInfo(this.showing, info)) {
517
+ if (options === null || options === void 0 ? void 0 : options.pinned) this._infoPopupPinned = true;
518
+ return;
519
+ }
520
+ if (this._infoPopup) {
521
+ this._infoPopup.dispose();
522
+ this._infoPopup = null;
523
+ }
524
+ if (!(this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC) instanceof DocumentDataModel)) return;
525
+ this._infoPopupPinned = (options === null || options === void 0 ? void 0 : options.pinned) ?? false;
443
526
  this._showingLink$.next({
444
527
  unitId,
445
528
  linkId,
@@ -448,32 +531,100 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
448
531
  startIndex,
449
532
  endIndex
450
533
  });
451
- this._infoPopup = this._docCanvasPopupManagerService.attachPopupToRange({
534
+ this._infoPopup = this._openInfoSurface(info);
535
+ return this._infoPopup;
536
+ }
537
+ _openEditSurface(activeRange, unitId) {
538
+ return this._docCanvasPopupManagerService.attachPopupToRange(activeRange, {
539
+ componentKey: DocHyperLinkEdit.componentKey,
540
+ direction: "bottom",
541
+ offset: [0, 10]
542
+ }, unitId);
543
+ }
544
+ _openInfoSurface(info, componentKey = DocLinkPopup.componentKey) {
545
+ const { unitId, linkId, segmentId, segmentPage, startIndex, endIndex } = info;
546
+ return this._docCanvasPopupManagerService.attachPopupToRange({
452
547
  collapsed: false,
453
548
  startOffset: startIndex,
454
549
  endOffset: endIndex + 1,
455
550
  segmentId,
456
551
  segmentPage
457
552
  }, {
458
- componentKey: DocLinkPopup.componentKey,
553
+ componentKey,
554
+ extraProps: {
555
+ onEdit: () => {
556
+ this.hideInfoPopup();
557
+ this.showEditPopup(unitId, info);
558
+ },
559
+ onDelete: async () => {
560
+ if (await this._commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
561
+ unitId,
562
+ linkId,
563
+ segmentId
564
+ })) this.hideInfoPopup();
565
+ }
566
+ },
459
567
  direction: "top-center",
460
568
  multipleDirection: "top",
569
+ offset: [0, 10],
461
570
  onClickOutside: () => {
462
571
  this.hideInfoPopup();
463
572
  }
464
573
  }, unitId);
465
- return this._infoPopup;
574
+ }
575
+ showInfoPopupFromHover(info) {
576
+ this.cancelScheduledHideInfoPopup();
577
+ if (this._infoPopupPinned || this._infoPopupSuppressed) return;
578
+ if (!this.showing) this.showInfoPopup(info);
466
579
  }
467
580
  hideInfoPopup() {
468
- var _this$_infoPopup;
581
+ this.cancelScheduledHideInfoPopup();
582
+ this._infoPopupPinned = false;
469
583
  this._showingLink$.next(null);
470
- (_this$_infoPopup = this._infoPopup) === null || _this$_infoPopup === void 0 || _this$_infoPopup.dispose();
584
+ const popup = this._infoPopup;
585
+ this._infoPopup = null;
586
+ popup === null || popup === void 0 || popup.dispose();
587
+ }
588
+ scheduleHideInfoPopup() {
589
+ if (this._infoPopupPinned || !this.showing) return;
590
+ this.cancelScheduledHideInfoPopup();
591
+ this._infoPopupHideTimer = setTimeout(() => {
592
+ this._infoPopupHideTimer = null;
593
+ if (!this._infoPopupPinned) this.hideInfoPopup();
594
+ }, INFO_POPUP_HIDE_DELAY);
595
+ }
596
+ cancelScheduledHideInfoPopup() {
597
+ if (this._infoPopupHideTimer !== null) {
598
+ clearTimeout(this._infoPopupHideTimer);
599
+ this._infoPopupHideTimer = null;
600
+ }
601
+ }
602
+ hideInfoPopupOnPointerDown() {
603
+ this._infoPopupSuppressed = true;
604
+ if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
605
+ this.hideInfoPopup();
606
+ this._infoPopupSuppressionTimer = setTimeout(() => {
607
+ this._infoPopupSuppressed = false;
608
+ this._infoPopupSuppressionTimer = null;
609
+ }, 0);
610
+ }
611
+ canEditLink(unitId, linkInfo) {
612
+ const document = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
613
+ if (!(document instanceof DocumentDataModel)) return false;
614
+ if (!linkInfo) return canEditDocumentTargets(this._permissionService, unitId, []);
615
+ const segmentId = linkInfo.segmentId ?? "";
616
+ return canEditDocumentTargets(this._permissionService, unitId, [...getDocumentEntityParentPermissionObjectIds(document, segmentId, "custom-range", linkInfo.linkId), getDocumentEntityPermissionObjectId(segmentId, "custom-range", linkInfo.linkId)]);
471
617
  }
472
618
  };
473
619
  DocHyperLinkPopupService = __decorate([
474
620
  __decorateParam(0, Inject(DocCanvasPopManagerService)),
475
621
  __decorateParam(1, Inject(DocSelectionManagerService)),
476
- __decorateParam(2, IUniverInstanceService)
622
+ __decorateParam(2, IUniverInstanceService),
623
+ __decorateParam(3, IPermissionService),
624
+ __decorateParam(4, IRenderManagerService),
625
+ __decorateParam(5, IDialogService),
626
+ __decorateParam(6, Inject(LocaleService)),
627
+ __decorateParam(7, ICommandService)
477
628
  ], DocHyperLinkPopupService);
478
629
 
479
630
  //#endregion
@@ -498,7 +649,7 @@ const ShowDocHyperLinkEditPopupOperation = {
498
649
  const hyperLinkService = accessor.get(DocHyperLinkPopupService);
499
650
  const unitId = (linkInfo === null || linkInfo === void 0 ? void 0 : linkInfo.unitId) || ((_univerInstanceServic = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId());
500
651
  if (!unitId) return false;
501
- hyperLinkService.showEditPopup(unitId, linkInfo);
652
+ hyperLinkService.showEditPopup(unitId, linkInfo ?? null);
502
653
  return true;
503
654
  }
504
655
  };
@@ -511,7 +662,8 @@ const ToggleDocHyperLinkInfoPopupOperation = {
511
662
  hyperLinkService.hideInfoPopup();
512
663
  return true;
513
664
  }
514
- hyperLinkService.showInfoPopup(params);
665
+ if (params.fromHover) hyperLinkService.showInfoPopupFromHover(params);
666
+ else hyperLinkService.showInfoPopup(params);
515
667
  return true;
516
668
  }
517
669
  };
@@ -519,17 +671,57 @@ const ClickDocHyperLinkOperation = {
519
671
  type: CommandType.OPERATION,
520
672
  id: "doc.operation.click-hyper-link",
521
673
  handler(accessor, params) {
522
- var _doc$getSelfOrHeaderF, _body$customRanges;
674
+ var _doc$getSelfOrHeaderF, _sourceBody$customRan;
523
675
  if (!params) return false;
524
676
  const { unitId, linkId, segmentId } = params;
525
677
  const doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
526
- const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
527
- const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.properties) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.url;
528
- if (!isSafeUrl(link)) return false;
529
- window.open(link, "_blank", "noopener noreferrer");
678
+ const sourceBody = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
679
+ const link = sourceBody === null || sourceBody === void 0 || (_sourceBody$customRan = sourceBody.customRanges) === null || _sourceBody$customRan === void 0 || (_sourceBody$customRan = _sourceBody$customRan.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)) === null || _sourceBody$customRan === void 0 ? void 0 : _sourceBody$customRan.properties;
680
+ if ((link === null || link === void 0 ? void 0 : link.bookmarkId) || (link === null || link === void 0 ? void 0 : link.headingId)) {
681
+ var _render$getInjector;
682
+ const targetOffset = findInternalLinkTarget(doc === null || doc === void 0 ? void 0 : doc.getBody(), link.bookmarkId, link.headingId);
683
+ if (targetOffset == null) return false;
684
+ const range = {
685
+ startOffset: targetOffset,
686
+ endOffset: targetOffset,
687
+ collapsed: true
688
+ };
689
+ const selectionManager = accessor.get(DocSelectionManagerService);
690
+ const selectTarget = () => selectionManager.replaceDocRanges([range], {
691
+ unitId,
692
+ subUnitId: unitId
693
+ }, false, { [DOC_SELECTION_OPTION_PRESERVE_CARET]: true });
694
+ const render = accessor.get(IRenderManagerService).getRenderUnitById(unitId);
695
+ const renderInjector = render === null || render === void 0 || (_render$getInjector = render.getInjector) === null || _render$getInjector === void 0 ? void 0 : _render$getInjector.call(render);
696
+ const backScrollController = (renderInjector === null || renderInjector === void 0 ? void 0 : renderInjector.has(DocBackScrollRenderController)) ? render === null || render === void 0 ? void 0 : render.with(DocBackScrollRenderController) : null;
697
+ if (backScrollController) backScrollController.scrollToRange(range, selectTarget);
698
+ else selectTarget();
699
+ return true;
700
+ }
701
+ if (!(link === null || link === void 0 ? void 0 : link.url) || !isSafeUrl(link.url)) return false;
702
+ window.open(link.url, "_blank", "noopener noreferrer");
530
703
  return true;
531
704
  }
532
705
  };
706
+ function findInternalLinkTarget(body, bookmarkId, headingId) {
707
+ if (!body) return;
708
+ if (bookmarkId) {
709
+ var _body$customRanges;
710
+ const bookmark = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => {
711
+ var _range$properties;
712
+ return range.rangeType === CustomRangeType.BOOKMARK && (range.rangeId === bookmarkId || ((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.bookmarkId) === bookmarkId);
713
+ });
714
+ if (bookmark) return bookmark.startIndex;
715
+ }
716
+ if (headingId) {
717
+ var _body$paragraphs;
718
+ const paragraphIndex = ((_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.findIndex((paragraph) => {
719
+ var _paragraph$paragraphS;
720
+ return ((_paragraph$paragraphS = paragraph.paragraphStyle) === null || _paragraph$paragraphS === void 0 ? void 0 : _paragraph$paragraphS.headingId) === headingId;
721
+ })) ?? -1;
722
+ if (paragraphIndex >= 0) return paragraphIndex === 0 ? 0 : body.paragraphs[paragraphIndex - 1].startIndex + 1;
723
+ }
724
+ }
533
725
 
534
726
  //#endregion
535
727
  //#region src/menu/menu.ts
@@ -563,6 +755,10 @@ const addLinkShortcut = {
563
755
  const menuSchema = {
564
756
  [RibbonInsertGroup.MEDIA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
565
757
  order: 1,
758
+ gridLayout: {
759
+ row: 1,
760
+ column: 5
761
+ },
566
762
  menuItemFactory: AddHyperLinkMenuItemFactory
567
763
  } },
568
764
  [FLOAT_TOOLBAR_MENU_POSITION]: { [ShowDocHyperLinkEditPopupOperation.id]: {
@@ -588,7 +784,7 @@ const menuSchema = {
588
784
  //#endregion
589
785
  //#region package.json
590
786
  var name = "@univerjs/docs-hyper-link-ui";
591
- var version = "1.0.0-insiders.20260813-7c9aa50";
787
+ var version = "1.0.0";
592
788
 
593
789
  //#endregion
594
790
  //#region src/config/config.ts
@@ -597,7 +793,199 @@ const configSymbol = Symbol(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
597
793
  const defaultPluginConfig = {};
598
794
 
599
795
  //#endregion
600
- //#region src/controllers/components.controller.ts
796
+ //#region src/controllers/doc-hyper-link-selection.controller.ts
797
+ let DocHyperLinkSelectionController = class DocHyperLinkSelectionController extends Disposable {
798
+ constructor(_commandService, _univerInstanceService, _docHyperLinkService) {
799
+ super();
800
+ this._commandService = _commandService;
801
+ this._univerInstanceService = _univerInstanceService;
802
+ this._docHyperLinkService = _docHyperLinkService;
803
+ _defineProperty(this, "_selection", null);
804
+ this._initSelectionChange();
805
+ this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((unit) => {
806
+ var _this$_selection;
807
+ if (((_this$_selection = this._selection) === null || _this$_selection === void 0 ? void 0 : _this$_selection.unitId) === unit.getUnitId()) this._selection = null;
808
+ }));
809
+ }
810
+ _initSelectionChange() {
811
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
812
+ if (commandInfo.id === RichTextEditingMutation.id) {
813
+ var _this$_docHyperLinkSe;
814
+ if (commandInfo.params.unitId === ((_this$_docHyperLinkSe = this._docHyperLinkService.showing) === null || _this$_docHyperLinkSe === void 0 ? void 0 : _this$_docHyperLinkSe.unitId)) this._docHyperLinkService.hideInfoPopup();
815
+ return;
816
+ }
817
+ if (commandInfo.id === SetTextSelectionsOperation.id) {
818
+ var _this$_selection2;
819
+ const params = commandInfo.params;
820
+ const { unitId, ranges, segmentId } = params;
821
+ const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
822
+ const primary = ranges[0];
823
+ const selectionKey = JSON.stringify([
824
+ unitId,
825
+ segmentId ?? "",
826
+ primary === null || primary === void 0 ? void 0 : primary.startOffset,
827
+ primary === null || primary === void 0 ? void 0 : primary.endOffset,
828
+ primary === null || primary === void 0 ? void 0 : primary.segmentPage
829
+ ]);
830
+ const sameSelection = selectionKey === ((_this$_selection2 = this._selection) === null || _this$_selection2 === void 0 ? void 0 : _this$_selection2.key);
831
+ this._selection = {
832
+ unitId,
833
+ key: selectionKey
834
+ };
835
+ const editing = this._docHyperLinkService.editing;
836
+ if ((editing === null || editing === void 0 ? void 0 : editing.unitId) === unitId && (editing.segmentId ?? "") === (segmentId ?? "") && (primary === null || primary === void 0 ? void 0 : primary.startOffset) === editing.startIndex && primary.endOffset === editing.endIndex + 1) return;
837
+ if (params.isEditing) {
838
+ this._docHyperLinkService.hideInfoPopup();
839
+ return;
840
+ }
841
+ if (sameSelection) return;
842
+ if ((primary === null || primary === void 0 ? void 0 : primary.collapsed) && doc) {
843
+ var _doc$getSelfOrHeaderF;
844
+ const { startOffset, endOffset, segmentPage } = primary;
845
+ const customRanges = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.customRanges;
846
+ const showing = this._docHyperLinkService.showing;
847
+ const customRange = ((showing === null || showing === void 0 ? void 0 : showing.unitId) === unitId && (showing.segmentId ?? "") === segmentId && showing.segmentPage === segmentPage && showing.endIndex === endOffset - 1 ? customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.rangeId === showing.linkId && value.rangeType === CustomRangeType.HYPERLINK && value.startIndex <= startOffset && value.endIndex === endOffset - 1) : void 0) ?? (customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.rangeType === CustomRangeType.HYPERLINK && value.startIndex <= startOffset && value.endIndex > endOffset - 1));
848
+ if (customRange) {
849
+ this._docHyperLinkService.showInfoPopup({
850
+ unitId,
851
+ linkId: customRange.rangeId,
852
+ segmentId,
853
+ segmentPage,
854
+ startIndex: customRange.startIndex,
855
+ endIndex: customRange.endIndex
856
+ });
857
+ return;
858
+ }
859
+ }
860
+ this._docHyperLinkService.hideInfoPopup();
861
+ this._docHyperLinkService.hideEditPopup();
862
+ }
863
+ }));
864
+ }
865
+ };
866
+ DocHyperLinkSelectionController = __decorate([
867
+ __decorateParam(0, ICommandService),
868
+ __decorateParam(1, IUniverInstanceService),
869
+ __decorateParam(2, Inject(DocHyperLinkPopupService))
870
+ ], DocHyperLinkSelectionController);
871
+
872
+ //#endregion
873
+ //#region src/views/MobileDocHyperLinkEdit.tsx
874
+ function MobileDocHyperLinkEdit() {
875
+ const localeService = useDependency(LocaleService);
876
+ const { doc, editing, handleCancel, handleConfirm, isLegal, label, link, setLabel, setLink, showError } = useDocHyperLinkEdit();
877
+ if (!doc) return;
878
+ return /* @__PURE__ */ jsxs("div", {
879
+ className: "univer-box-border univer-w-full univer-bg-gray-0 univer-py-2 dark:!univer-bg-gray-900",
880
+ children: [/* @__PURE__ */ jsxs("div", { children: [editing ? /* @__PURE__ */ jsx(FormLayout, {
881
+ label: localeService.t("docs-hyper-link-ui.edit.label"),
882
+ error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
883
+ children: /* @__PURE__ */ jsx(Input, {
884
+ value: label,
885
+ onChange: setLabel,
886
+ autoFocus: true,
887
+ onKeyDown: (event) => {
888
+ if (event.keyCode === KeyCode.ENTER) handleConfirm();
889
+ }
890
+ })
891
+ }) : null, /* @__PURE__ */ jsx(FormLayout, {
892
+ label: localeService.t("docs-hyper-link-ui.edit.address"),
893
+ error: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : "",
894
+ children: /* @__PURE__ */ jsx(Input, {
895
+ value: link,
896
+ onChange: setLink,
897
+ autoFocus: !editing,
898
+ onKeyDown: (event) => {
899
+ if (event.keyCode === KeyCode.ENTER) handleConfirm();
900
+ }
901
+ })
902
+ })] }), /* @__PURE__ */ jsxs("div", {
903
+ className: "univer-mt-5 univer-flex univer-gap-3",
904
+ children: [/* @__PURE__ */ jsx(Button, {
905
+ className: "univer-h-12 univer-flex-1",
906
+ onClick: handleCancel,
907
+ children: localeService.t("docs-hyper-link-ui.edit.cancel")
908
+ }), /* @__PURE__ */ jsx(Button, {
909
+ variant: "primary",
910
+ className: "univer-h-12 univer-flex-1",
911
+ disabled: isBlankInput(link),
912
+ onClick: handleConfirm,
913
+ children: localeService.t("docs-hyper-link-ui.edit.confirm")
914
+ })]
915
+ })]
916
+ });
917
+ }
918
+ MobileDocHyperLinkEdit.componentKey = "univer.doc.mobile-hyper-link-edit";
919
+
920
+ //#endregion
921
+ //#region src/views/MobileDocLinkPopup.tsx
922
+ function MobileDocLinkPopup() {
923
+ var _document$getSelfOrHe, _body$customRanges, _link$properties;
924
+ const commandService = useDependency(ICommandService);
925
+ const hyperLinkService = useDependency(DocHyperLinkPopupService);
926
+ const localeService = useDependency(LocaleService);
927
+ const messageService = useDependency(IMessageService);
928
+ const permissionService = useDependency(IPermissionService);
929
+ const univerInstanceService = useDependency(IUniverInstanceService);
930
+ const currentPopup = useObservable(hyperLinkService.showingLink$, hyperLinkService.showing);
931
+ if (!currentPopup) return null;
932
+ const { unitId, linkId, segmentId, startIndex, endIndex } = currentPopup;
933
+ const document = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
934
+ const body = document instanceof DocumentDataModel ? (_document$getSelfOrHe = document.getSelfOrHeaderFooterModel(segmentId)) === null || _document$getSelfOrHe === void 0 ? void 0 : _document$getSelfOrHe.getBody() : void 0;
935
+ const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK && range.startIndex === startIndex && range.endIndex === endIndex);
936
+ if (!link) return null;
937
+ const url = (_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.url;
938
+ const canEdit = hyperLinkService.canEditLink(unitId, currentPopup);
939
+ const canCopy = getDocumentPermissionValue(permissionService, unitId, unitId, UnitAction.Copy);
940
+ return /* @__PURE__ */ jsxs("div", {
941
+ className: "univer-flex univer-flex-col univer-gap-2 univer-py-2",
942
+ children: [
943
+ /* @__PURE__ */ jsx(MobileActionRow, {
944
+ title: /* @__PURE__ */ jsx("span", {
945
+ className: "univer-truncate univer-text-primary-600",
946
+ children: url
947
+ }),
948
+ "aria-label": url,
949
+ variant: "subtle",
950
+ onClick: () => window.open(url, void 0, "noopener noreferrer")
951
+ }),
952
+ canCopy && /* @__PURE__ */ jsx(MobileActionRow, {
953
+ title: localeService.t("docs-hyper-link-ui.info.copy"),
954
+ "aria-label": localeService.t("docs-hyper-link-ui.info.copy"),
955
+ variant: "subtle",
956
+ onClick: () => navigator.clipboard.writeText(url).then(() => {
957
+ messageService.show({
958
+ content: localeService.t("docs-hyper-link-ui.info.coped"),
959
+ type: MessageType.Info
960
+ });
961
+ }).catch(() => void 0)
962
+ }),
963
+ canEdit && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(MobileActionRow, {
964
+ title: localeService.t("docs-hyper-link-ui.info.edit"),
965
+ "aria-label": localeService.t("docs-hyper-link-ui.info.edit"),
966
+ variant: "subtle",
967
+ onClick: () => {
968
+ commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, { link: currentPopup }).catch(() => void 0);
969
+ }
970
+ }), /* @__PURE__ */ jsx(MobileActionRow, {
971
+ title: localeService.t("docs-hyper-link-ui.info.cancel"),
972
+ "aria-label": localeService.t("docs-hyper-link-ui.info.cancel"),
973
+ variant: "subtle",
974
+ onClick: () => {
975
+ commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
976
+ unitId,
977
+ linkId: link.rangeId,
978
+ segmentId
979
+ }).catch(() => void 0);
980
+ }
981
+ })] })
982
+ ]
983
+ });
984
+ }
985
+ MobileDocLinkPopup.componentKey = "univer.doc.mobile-link-info-popup";
986
+
987
+ //#endregion
988
+ //#region src/controllers/mobile/components.controller.ts
601
989
  /**
602
990
  * Copyright 2023-present DreamNum Co., Ltd.
603
991
  *
@@ -613,7 +1001,7 @@ const defaultPluginConfig = {};
613
1001
  * See the License for the specific language governing permissions and
614
1002
  * limitations under the License.
615
1003
  */
616
- let ComponentsController = class ComponentsController extends Disposable {
1004
+ let MobileComponentsController = class MobileComponentsController extends Disposable {
617
1005
  constructor(_componentManager, _iconManager) {
618
1006
  super();
619
1007
  this._componentManager = _componentManager;
@@ -622,7 +1010,7 @@ let ComponentsController = class ComponentsController extends Disposable {
622
1010
  this._registerIcons();
623
1011
  }
624
1012
  _registerComponents() {
625
- [[DocHyperLinkEdit.componentKey, DocHyperLinkEdit], [DocLinkPopup.componentKey, DocLinkPopup]].forEach(([key, comp]) => {
1013
+ [[MobileDocHyperLinkEdit.componentKey, MobileDocHyperLinkEdit], [MobileDocLinkPopup.componentKey, MobileDocLinkPopup]].forEach(([key, comp]) => {
626
1014
  this.disposeWithMe(this._componentManager.register(key, comp));
627
1015
  });
628
1016
  }
@@ -630,103 +1018,66 @@ let ComponentsController = class ComponentsController extends Disposable {
630
1018
  this.disposeWithMe(this._iconManager.register({ LinkIcon }));
631
1019
  }
632
1020
  };
633
- ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
634
-
635
- //#endregion
636
- //#region src/controllers/doc-hyper-link-selection.controller.ts
637
- let DocHyperLinkSelectionController = class DocHyperLinkSelectionController extends Disposable {
638
- constructor(_commandService, _univerInstanceService, _docHyperLinkService) {
639
- super();
640
- this._commandService = _commandService;
641
- this._univerInstanceService = _univerInstanceService;
642
- this._docHyperLinkService = _docHyperLinkService;
643
- this._initSelectionChange();
644
- }
645
- _initSelectionChange() {
646
- this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
647
- if (commandInfo.id === SetTextSelectionsOperation.id) {
648
- const { unitId, ranges, segmentId } = commandInfo.params;
649
- const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
650
- const primary = ranges[0];
651
- if (primary && doc) {
652
- var _doc$getSelfOrHeaderF;
653
- const { startOffset, endOffset, collapsed, segmentPage } = primary;
654
- const customRanges = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.customRanges;
655
- if (collapsed) {
656
- const index = (customRanges === null || customRanges === void 0 ? void 0 : customRanges.findIndex((value) => value.startIndex < startOffset && value.endIndex > endOffset - 1)) ?? -1;
657
- if (index > -1) {
658
- const customRange = customRanges[index];
659
- this._docHyperLinkService.showInfoPopup({
660
- unitId,
661
- linkId: customRange.rangeId,
662
- segmentId,
663
- segmentPage,
664
- startIndex: customRange.startIndex,
665
- endIndex: customRange.endIndex
666
- });
667
- return;
668
- }
669
- } else if (customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1)) return;
670
- }
671
- this._docHyperLinkService.hideInfoPopup();
672
- this._docHyperLinkService.hideEditPopup();
673
- }
674
- }));
675
- }
676
- };
677
- DocHyperLinkSelectionController = __decorate([
678
- __decorateParam(0, ICommandService),
679
- __decorateParam(1, IUniverInstanceService),
680
- __decorateParam(2, Inject(DocHyperLinkPopupService))
681
- ], DocHyperLinkSelectionController);
1021
+ MobileComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], MobileComponentsController);
682
1022
 
683
1023
  //#endregion
684
- //#region src/controllers/render-controllers/hyper-link-event.render-controller.ts
685
- let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController extends Disposable {
1024
+ //#region src/controllers/render-controllers/mobile/hyper-link-event.render-controller.ts
1025
+ let MobileDocHyperLinkEventRenderController = class MobileDocHyperLinkEventRenderController extends Disposable {
686
1026
  get _skeleton() {
687
1027
  return this._docSkeletonManagerService.getSkeleton();
688
1028
  }
689
- constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _docSelectionManagerService) {
1029
+ constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _mobileElementMenuService) {
690
1030
  super();
691
1031
  this._context = _context;
692
1032
  this._docEventManagerService = _docEventManagerService;
693
1033
  this._commandService = _commandService;
694
1034
  this._hyperLinkPopupService = _hyperLinkPopupService;
695
1035
  this._docSkeletonManagerService = _docSkeletonManagerService;
696
- this._docSelectionManagerService = _docSelectionManagerService;
1036
+ this._mobileElementMenuService = _mobileElementMenuService;
697
1037
  if (this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
698
- this._initHover();
1038
+ this._initPointerDown();
699
1039
  this._initClick();
700
1040
  }
701
- _hideInfoPopup() {
702
- if (this._hyperLinkPopupService.showing) this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id);
703
- }
704
- _initHover() {
705
- this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
706
- var _activeRanges$;
1041
+ _initPointerDown() {
1042
+ this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe((ranges) => {
707
1043
  const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK);
708
- const activeRanges = this._docSelectionManagerService.getTextRanges();
709
- const currentSegmentId = activeRanges === null || activeRanges === void 0 || (_activeRanges$ = activeRanges[0]) === null || _activeRanges$ === void 0 ? void 0 : _activeRanges$.segmentId;
710
- if (((link === null || link === void 0 ? void 0 : link.segmentId) ?? "") !== currentSegmentId) {
711
- this._hideInfoPopup();
1044
+ if (!link) {
1045
+ this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
712
1046
  return;
713
1047
  }
714
- if (link) this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id, {
1048
+ const info = {
715
1049
  unitId: this._context.unitId,
716
1050
  linkId: link.range.rangeId,
717
1051
  segmentId: link.segmentId,
718
1052
  segmentPage: link.segmentPageIndex,
719
- rangeId: link.range.rangeId,
720
1053
  startIndex: link.range.startIndex,
721
1054
  endIndex: link.range.endIndex
1055
+ };
1056
+ const rect = link.rects[0];
1057
+ if (rect && this._hyperLinkPopupService.canEditLink(info.unitId, info)) this._mobileElementMenuService.capture({
1058
+ unitId: info.unitId,
1059
+ rect,
1060
+ onEdit: () => this._hyperLinkPopupService.showEditPopup(info.unitId, info),
1061
+ onDelete: () => this._commandService.executeCommand(DeleteDocHyperLinkCommand.id, info)
722
1062
  });
723
- else this._hideInfoPopup();
724
1063
  }));
725
1064
  }
726
1065
  _initClick() {
727
1066
  this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
728
1067
  const link = range.range;
729
- if (link) this._commandService.executeCommand(ClickDocHyperLinkOperation.id, {
1068
+ if (link.rangeType !== CustomRangeType.HYPERLINK) return;
1069
+ if (!range.ctrlKey && !range.metaKey) {
1070
+ this._hyperLinkPopupService.showInfoPopup({
1071
+ unitId: this._context.unitId,
1072
+ linkId: link.rangeId,
1073
+ segmentId: range.segmentId,
1074
+ segmentPage: range.segmentPageIndex,
1075
+ startIndex: link.startIndex,
1076
+ endIndex: link.endIndex
1077
+ }, { pinned: true });
1078
+ return;
1079
+ }
1080
+ this._commandService.executeCommand(ClickDocHyperLinkOperation.id, {
730
1081
  unitId: this._context.unitId,
731
1082
  linkId: link.rangeId,
732
1083
  segmentId: range.segmentId
@@ -734,25 +1085,22 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
734
1085
  }));
735
1086
  }
736
1087
  };
737
- DocHyperLinkEventRenderController = __decorate([
1088
+ MobileDocHyperLinkEventRenderController = __decorate([
738
1089
  __decorateParam(1, Inject(DocEventManagerService)),
739
1090
  __decorateParam(2, ICommandService),
740
1091
  __decorateParam(3, Inject(DocHyperLinkPopupService)),
741
1092
  __decorateParam(4, Inject(DocSkeletonManagerService)),
742
- __decorateParam(5, Inject(DocSelectionManagerService))
743
- ], DocHyperLinkEventRenderController);
1093
+ __decorateParam(5, Inject(DocMobileElementMenuService))
1094
+ ], MobileDocHyperLinkEventRenderController);
744
1095
 
745
1096
  //#endregion
746
1097
  //#region src/controllers/render-controllers/render.controller.ts
747
1098
  let DocHyperLinkRenderController = class DocHyperLinkRenderController extends Disposable {
748
- constructor(_context, _docInterceptorService, _hyperLinkService, _docRenderController) {
1099
+ constructor(_context, _docInterceptorService, _hyperLinkService) {
749
1100
  super();
750
- this._context = _context;
751
1101
  this._docInterceptorService = _docInterceptorService;
752
1102
  this._hyperLinkService = _hyperLinkService;
753
- this._docRenderController = _docRenderController;
754
1103
  this._init();
755
- this._initReRender();
756
1104
  }
757
1105
  _init() {
758
1106
  this._docInterceptorService.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, { handler: (data, pos, next) => {
@@ -771,19 +1119,8 @@ let DocHyperLinkRenderController = class DocHyperLinkRenderController extends Di
771
1119
  });
772
1120
  } });
773
1121
  }
774
- _initReRender() {
775
- this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(distinctUntilChanged((prev, aft) => (prev === null || prev === void 0 ? void 0 : prev.linkId) === (aft === null || aft === void 0 ? void 0 : aft.linkId) && (prev === null || prev === void 0 ? void 0 : prev.unitId) === (aft === null || aft === void 0 ? void 0 : aft.unitId) && (prev === null || prev === void 0 ? void 0 : prev.startIndex) === (aft === null || aft === void 0 ? void 0 : aft.startIndex)), pairwise()).subscribe(([preLink, link]) => {
776
- if (link) {
777
- if (link.unitId === this._context.unitId) this._docRenderController.reRender(link.unitId);
778
- } else if (preLink && preLink.unitId === this._context.unitId) this._docRenderController.reRender(preLink.unitId);
779
- }));
780
- }
781
1122
  };
782
- DocHyperLinkRenderController = __decorate([
783
- __decorateParam(1, Inject(DocInterceptorService)),
784
- __decorateParam(2, Inject(DocHyperLinkPopupService)),
785
- __decorateParam(3, Inject(DocRenderController))
786
- ], DocHyperLinkRenderController);
1123
+ DocHyperLinkRenderController = __decorate([__decorateParam(1, Inject(DocInterceptorService)), __decorateParam(2, Inject(DocHyperLinkPopupService))], DocHyperLinkRenderController);
787
1124
 
788
1125
  //#endregion
789
1126
  //#region src/controllers/ui.controller.ts
@@ -825,6 +1162,29 @@ DocHyperLinkUIController = __decorate([
825
1162
  __decorateParam(2, IShortcutService)
826
1163
  ], DocHyperLinkUIController);
827
1164
 
1165
+ //#endregion
1166
+ //#region src/services/mobile/hyper-link-popup.service.ts
1167
+ var MobileDocHyperLinkPopupService = class extends DocHyperLinkPopupService {
1168
+ _openEditSurface(_activeRange, _unitId) {
1169
+ return this._dialogService.open({
1170
+ id: "doc-mobile-hyper-link-editor",
1171
+ title: { title: this._localeService.t("docs-hyper-link-ui.menu.tooltip") },
1172
+ children: { label: MobileDocHyperLinkEdit.componentKey },
1173
+ maskClosable: false,
1174
+ onClose: () => this.hideEditPopup()
1175
+ });
1176
+ }
1177
+ _openInfoSurface(info) {
1178
+ if (this.canEditLink(info.unitId, info)) return super._openInfoSurface(info, MOBILE_DOC_ELEMENT_MENU);
1179
+ return this._dialogService.open({
1180
+ id: "doc-mobile-hyper-link-viewer",
1181
+ title: { title: this._localeService.t("docs-hyper-link-ui.menu.tooltip") },
1182
+ children: { label: MobileDocLinkPopup.componentKey },
1183
+ onClose: () => this.hideInfoPopup()
1184
+ });
1185
+ }
1186
+ };
1187
+
828
1188
  //#endregion
829
1189
  //#region src/types/const/index.ts
830
1190
  /**
@@ -844,6 +1204,175 @@ DocHyperLinkUIController = __decorate([
844
1204
  */
845
1205
  const DOC_HYPER_LINK_UI_PLUGIN = "DOC_HYPER_LINK_UI_PLUGIN";
846
1206
 
1207
+ //#endregion
1208
+ //#region src/mobile-plugin.ts
1209
+ let UniverDocsHyperLinkMobileUIPlugin = class UniverDocsHyperLinkMobileUIPlugin extends Plugin {
1210
+ constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
1211
+ super();
1212
+ this._config = _config;
1213
+ this._injector = _injector;
1214
+ this._renderManagerSrv = _renderManagerSrv;
1215
+ this._configService = _configService;
1216
+ const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
1217
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
1218
+ this._configService.setConfig(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
1219
+ }
1220
+ onStarting() {
1221
+ [
1222
+ [MobileComponentsController],
1223
+ [DocHyperLinkPopupService, { useClass: MobileDocHyperLinkPopupService }],
1224
+ [DocHyperLinkUIController],
1225
+ [DocHyperLinkSelectionController]
1226
+ ].forEach((dep) => this._injector.add(dep));
1227
+ this._injector.get(MobileComponentsController);
1228
+ this._injector.get(DocHyperLinkUIController);
1229
+ }
1230
+ onReady() {
1231
+ this._injector.get(DocHyperLinkSelectionController);
1232
+ }
1233
+ onRendered() {
1234
+ [[DocHyperLinkRenderController], [MobileDocHyperLinkEventRenderController]].forEach((dep) => {
1235
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, dep);
1236
+ });
1237
+ }
1238
+ };
1239
+ _defineProperty(UniverDocsHyperLinkMobileUIPlugin, "pluginName", DOC_HYPER_LINK_UI_PLUGIN);
1240
+ _defineProperty(UniverDocsHyperLinkMobileUIPlugin, "packageName", name);
1241
+ _defineProperty(UniverDocsHyperLinkMobileUIPlugin, "version", version);
1242
+ _defineProperty(UniverDocsHyperLinkMobileUIPlugin, "type", UniverInstanceType.UNIVER_DOC);
1243
+ UniverDocsHyperLinkMobileUIPlugin = __decorate([
1244
+ DependentOn(UniverDocsPlugin, UniverRenderEnginePlugin, UniverDocsHyperLinkPlugin, UniverDocsMobileUIPlugin),
1245
+ __decorateParam(1, Inject(Injector)),
1246
+ __decorateParam(2, IRenderManagerService),
1247
+ __decorateParam(3, IConfigService)
1248
+ ], UniverDocsHyperLinkMobileUIPlugin);
1249
+
1250
+ //#endregion
1251
+ //#region src/controllers/components.controller.ts
1252
+ /**
1253
+ * Copyright 2023-present DreamNum Co., Ltd.
1254
+ *
1255
+ * Licensed under the Apache License, Version 2.0 (the "License");
1256
+ * you may not use this file except in compliance with the License.
1257
+ * You may obtain a copy of the License at
1258
+ *
1259
+ * http://www.apache.org/licenses/LICENSE-2.0
1260
+ *
1261
+ * Unless required by applicable law or agreed to in writing, software
1262
+ * distributed under the License is distributed on an "AS IS" BASIS,
1263
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1264
+ * See the License for the specific language governing permissions and
1265
+ * limitations under the License.
1266
+ */
1267
+ let ComponentsController = class ComponentsController extends Disposable {
1268
+ constructor(_componentManager, _iconManager) {
1269
+ super();
1270
+ this._componentManager = _componentManager;
1271
+ this._iconManager = _iconManager;
1272
+ this._registerComponents();
1273
+ this._registerIcons();
1274
+ }
1275
+ _registerComponents() {
1276
+ [[DocHyperLinkEdit.componentKey, DocHyperLinkEdit], [DocLinkPopup.componentKey, DocLinkPopup]].forEach(([key, comp]) => {
1277
+ this.disposeWithMe(this._componentManager.register(key, comp));
1278
+ });
1279
+ }
1280
+ _registerIcons() {
1281
+ this.disposeWithMe(this._iconManager.register({ LinkIcon }));
1282
+ }
1283
+ };
1284
+ ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
1285
+
1286
+ //#endregion
1287
+ //#region src/controllers/render-controllers/hyper-link-event.render-controller.ts
1288
+ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController extends Disposable {
1289
+ get _skeleton() {
1290
+ return this._docSkeletonManagerService.getSkeleton();
1291
+ }
1292
+ constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _docSelectionManagerService) {
1293
+ super();
1294
+ this._context = _context;
1295
+ this._docEventManagerService = _docEventManagerService;
1296
+ this._commandService = _commandService;
1297
+ this._hyperLinkPopupService = _hyperLinkPopupService;
1298
+ this._docSkeletonManagerService = _docSkeletonManagerService;
1299
+ this._docSelectionManagerService = _docSelectionManagerService;
1300
+ if (this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
1301
+ this._initPointerDown();
1302
+ this._initHover();
1303
+ this._initClick();
1304
+ }
1305
+ _hideInfoPopup() {
1306
+ if (this._hyperLinkPopupService.infoPopupPinned) return;
1307
+ if (this._hyperLinkPopupService.showing) this._hyperLinkPopupService.scheduleHideInfoPopup();
1308
+ }
1309
+ _normalizeSegmentId(segmentId) {
1310
+ var _this$_context$unit$g;
1311
+ if (!segmentId) return "";
1312
+ return ((_this$_context$unit$g = this._context.unit.getBody()) === null || _this$_context$unit$g === void 0 || (_this$_context$unit$g = _this$_context$unit$g.tables) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.some((table) => table.tableId === segmentId)) ? "" : segmentId;
1313
+ }
1314
+ _initPointerDown() {
1315
+ this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe((ranges) => {
1316
+ if (!ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK)) this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
1317
+ }));
1318
+ }
1319
+ _initHover() {
1320
+ this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
1321
+ var _activeRanges$;
1322
+ const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK);
1323
+ const activeRanges = this._docSelectionManagerService.getTextRanges();
1324
+ const currentSegmentId = activeRanges === null || activeRanges === void 0 || (_activeRanges$ = activeRanges[0]) === null || _activeRanges$ === void 0 ? void 0 : _activeRanges$.segmentId;
1325
+ if (this._normalizeSegmentId(link === null || link === void 0 ? void 0 : link.segmentId) !== this._normalizeSegmentId(currentSegmentId)) {
1326
+ this._hideInfoPopup();
1327
+ return;
1328
+ }
1329
+ if (link) {
1330
+ const info = {
1331
+ unitId: this._context.unitId,
1332
+ linkId: link.range.rangeId,
1333
+ segmentId: link.segmentId,
1334
+ segmentPage: link.segmentPageIndex,
1335
+ startIndex: link.range.startIndex,
1336
+ endIndex: link.range.endIndex
1337
+ };
1338
+ this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id, {
1339
+ ...info,
1340
+ fromHover: true
1341
+ });
1342
+ } else this._hideInfoPopup();
1343
+ }));
1344
+ }
1345
+ _initClick() {
1346
+ this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
1347
+ const link = range.range;
1348
+ if (link.rangeType !== CustomRangeType.HYPERLINK) return;
1349
+ if (!range.ctrlKey && !range.metaKey) {
1350
+ this._hyperLinkPopupService.showInfoPopup({
1351
+ unitId: this._context.unitId,
1352
+ linkId: link.rangeId,
1353
+ segmentId: range.segmentId,
1354
+ segmentPage: range.segmentPageIndex,
1355
+ startIndex: link.startIndex,
1356
+ endIndex: link.endIndex
1357
+ }, { pinned: true });
1358
+ return;
1359
+ }
1360
+ this._commandService.executeCommand(ClickDocHyperLinkOperation.id, {
1361
+ unitId: this._context.unitId,
1362
+ linkId: link.rangeId,
1363
+ segmentId: range.segmentId
1364
+ });
1365
+ }));
1366
+ }
1367
+ };
1368
+ DocHyperLinkEventRenderController = __decorate([
1369
+ __decorateParam(1, Inject(DocEventManagerService)),
1370
+ __decorateParam(2, ICommandService),
1371
+ __decorateParam(3, Inject(DocHyperLinkPopupService)),
1372
+ __decorateParam(4, Inject(DocSkeletonManagerService)),
1373
+ __decorateParam(5, Inject(DocSelectionManagerService))
1374
+ ], DocHyperLinkEventRenderController);
1375
+
847
1376
  //#endregion
848
1377
  //#region src/plugin.ts
849
1378
  let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends Plugin {
@@ -858,15 +1387,15 @@ let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends Plug
858
1387
  this._configService.setConfig(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
859
1388
  }
860
1389
  onStarting() {
861
- this._injector.add([ComponentsController]);
862
- this._injector.get(ComponentsController);
863
1390
  [
1391
+ [ComponentsController],
864
1392
  [DocHyperLinkPopupService],
865
1393
  [DocHyperLinkUIController],
866
1394
  [DocHyperLinkSelectionController]
867
1395
  ].forEach((dep) => {
868
1396
  this._injector.add(dep);
869
1397
  });
1398
+ this._injector.get(ComponentsController);
870
1399
  this._injector.get(DocHyperLinkUIController);
871
1400
  }
872
1401
  onReady() {
@@ -893,4 +1422,4 @@ UniverDocsHyperLinkUIPlugin = __decorate([
893
1422
  ], UniverDocsHyperLinkUIPlugin);
894
1423
 
895
1424
  //#endregion
896
- export { menuSchema as DocsHyperLinkUIMenuSchema, UniverDocsHyperLinkUIPlugin };
1425
+ export { menuSchema as DocsHyperLinkUIMenuSchema, UniverDocsHyperLinkMobileUIPlugin, UniverDocsHyperLinkUIPlugin };