@univerjs/docs-hyper-link-ui 1.0.0-rc.0 → 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 (39) hide show
  1. package/lib/cjs/index.js +586 -165
  2. package/lib/cjs/locale/ar-SA.js +0 -1
  3. package/lib/cjs/locale/ca-ES.js +0 -1
  4. package/lib/cjs/locale/de-DE.js +0 -1
  5. package/lib/cjs/locale/en-US.js +0 -1
  6. package/lib/cjs/locale/es-ES.js +0 -1
  7. package/lib/cjs/locale/fa-IR.js +0 -1
  8. package/lib/cjs/locale/fr-FR.js +0 -1
  9. package/lib/cjs/locale/id-ID.js +0 -1
  10. package/lib/cjs/locale/it-IT.js +0 -1
  11. package/lib/cjs/locale/ja-JP.js +0 -1
  12. package/lib/cjs/locale/ko-KR.js +0 -1
  13. package/lib/cjs/locale/pl-PL.js +0 -1
  14. package/lib/cjs/locale/pt-BR.js +0 -1
  15. package/lib/cjs/locale/ru-RU.js +0 -1
  16. package/lib/cjs/locale/sk-SK.js +0 -1
  17. package/lib/cjs/locale/vi-VN.js +0 -1
  18. package/lib/cjs/locale/zh-CN.js +0 -1
  19. package/lib/cjs/locale/zh-HK.js +0 -1
  20. package/lib/cjs/locale/zh-TW.js +0 -1
  21. package/lib/es/index.js +585 -170
  22. package/lib/index.css +29 -0
  23. package/lib/index.js +585 -170
  24. package/lib/types/commands/operations/popup.operation.d.ts +1 -0
  25. package/lib/types/controllers/doc-hyper-link-selection.controller.d.ts +1 -0
  26. package/lib/types/controllers/mobile/components.controller.d.ts +24 -0
  27. package/lib/types/controllers/render-controllers/hyper-link-event.render-controller.d.ts +1 -0
  28. package/lib/types/controllers/render-controllers/mobile/hyper-link-event.render-controller.d.ts +33 -0
  29. package/lib/types/index.d.ts +1 -0
  30. package/lib/types/mobile-plugin.d.ts +32 -0
  31. package/lib/types/services/hyper-link-popup.service.d.ts +13 -7
  32. package/lib/types/services/mobile/hyper-link-popup.service.d.ts +22 -0
  33. package/lib/types/views/MobileDocHyperLinkEdit.d.ts +19 -0
  34. package/lib/types/views/MobileDocLinkPopup.d.ts +19 -0
  35. package/lib/types/views/hyper-link-edit/index.d.ts +19 -0
  36. package/lib/types/views/hyper-link-edit/use-doc-hyper-link-edit.d.ts +28 -0
  37. package/lib/types/views/hyper-link-popup/index.d.ts +19 -0
  38. package/lib/umd/index.js +1 -1
  39. package/package.json +13 -13
package/lib/index.js CHANGED
@@ -1,16 +1,35 @@
1
- import { DocCanvasPopManagerService, DocEventManagerService, 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";
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
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, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, SetTextSelectionsOperation, UniverDocsPlugin, addCustomRangeBySelectionFactory, canEditDocumentTargets, deleteCustomRangeFactory, getDocumentEntityParentPermissionObjectIds, getDocumentEntityPermissionObjectId, getDocumentPermissionValue, replaceSelectionFactory } from "@univerjs/docs";
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
5
  import { IRenderManagerService, UniverRenderEnginePlugin } from "@univerjs/engine-render";
6
6
  import { BehaviorSubject, Observable, debounceTime } from "rxjs";
7
- import { Button, FormLayout, Input, MessageType, Tooltip, borderClassName, clsx } from "@univerjs/design";
8
- import { useEffect, useState } from "react";
9
7
  import { DocHyperLinkCommandId, UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
8
+ import { Button, FormLayout, Input, MessageType, MobileActionRow, Tooltip, borderClassName, clsx } from "@univerjs/design";
9
+ import { useEffect, useState } from "react";
10
10
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
11
11
  import { CopyIcon, LinkIcon, UnlinkIcon, WriteIcon } from "@univerjs/icons";
12
12
  import { UnitAction } from "@univerjs/protocol";
13
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
+ };
31
+
32
+ //#endregion
14
33
  //#region src/commands/commands/add-link.command.ts
15
34
  const AddDocHyperLinkCommand = {
16
35
  type: CommandType.COMMAND,
@@ -19,8 +38,9 @@ const AddDocHyperLinkCommand = {
19
38
  if (!params) return false;
20
39
  const { payload, unitId, selections } = params;
21
40
  const commandService = accessor.get(ICommandService);
41
+ const id = generateRandomId();
22
42
  const doMutation = addCustomRangeBySelectionFactory(accessor, {
23
- rangeId: generateRandomId(),
43
+ rangeId: id,
24
44
  rangeType: CustomRangeType.HYPERLINK,
25
45
  properties: { url: payload },
26
46
  unitId,
@@ -37,7 +57,7 @@ const UpdateDocHyperLinkCommand = {
37
57
  id: DocHyperLinkCommandId.Update,
38
58
  type: CommandType.COMMAND,
39
59
  handler(accessor, params) {
40
- var _doc$getSelfOrHeaderF, _getBodySlice$textRun;
60
+ var _doc$getSelfOrHeaderF, _oldBody$customRanges, _getBodySlice$textRun, _oldLink$properties, _oldLink$properties2;
41
61
  if (!params) return false;
42
62
  const { unitId, payload, segmentId, linkId } = params;
43
63
  const commandService = accessor.get(ICommandService);
@@ -47,6 +67,7 @@ const UpdateDocHyperLinkCommand = {
47
67
  if (!currentSelection || !doc) return false;
48
68
  const oldBody = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
49
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);
50
71
  const textRun = (_getBodySlice$textRun = getBodySlice(oldBody, currentSelection.startOffset, currentSelection.endOffset).textRuns) === null || _getBodySlice$textRun === void 0 ? void 0 : _getBodySlice$textRun[0];
51
72
  if (textRun) textRun.ed = params.label.length + 1;
52
73
  const replaceSelection = replaceSelectionFactory(accessor, {
@@ -58,7 +79,11 @@ const UpdateDocHyperLinkCommand = {
58
79
  rangeType: CustomRangeType.HYPERLINK,
59
80
  startIndex: 0,
60
81
  endIndex: params.label.length + 1,
61
- 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
+ }
62
87
  }],
63
88
  textRuns: textRun ? [textRun] : void 0
64
89
  },
@@ -96,20 +121,19 @@ function isBlankInput(value) {
96
121
  }
97
122
 
98
123
  //#endregion
99
- //#region src/views/DocHyperLinkEdit.tsx
100
- function hasProtocol(urlString) {
101
- 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);
102
127
  }
103
128
  function isEmail(url) {
104
- return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
129
+ return /^[\w.-]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
105
130
  }
106
- function transformUrl(urlStr) {
107
- 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}`;
108
133
  }
109
- const DocHyperLinkEdit = () => {
134
+ function useDocHyperLinkEdit() {
110
135
  const hyperLinkService = useDependency(DocHyperLinkPopupService);
111
- const localeService = useDependency(LocaleService);
112
- const editing = useObservable(hyperLinkService.editingLink$);
136
+ const editing = useObservable(hyperLinkService.editingLink$, hyperLinkService.editing);
113
137
  const commandService = useDependency(ICommandService);
114
138
  const univerInstanceService = useDependency(IUniverInstanceService);
115
139
  const docSelectionManagerService = useDependency(DocSelectionManagerService);
@@ -125,7 +149,7 @@ const DocHyperLinkEdit = () => {
125
149
  if (editing) {
126
150
  var _doc$getSelfOrHeaderF, _body$customRanges;
127
151
  const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
128
- 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);
129
153
  if (doc && matchedRange) {
130
154
  var _matchedRange$propert;
131
155
  setLink(((_matchedRange$propert = matchedRange.properties) === null || _matchedRange$propert === void 0 ? void 0 : _matchedRange$propert.url) ?? "");
@@ -138,37 +162,52 @@ const DocHyperLinkEdit = () => {
138
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]);
139
163
  if (doc && matchedRange) {
140
164
  var _matchedRange$propert2;
141
- 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) ?? "");
142
166
  }
143
167
  }, [
144
168
  doc,
145
- editing,
146
169
  docSelectionManagerService,
147
- univerInstanceService
170
+ editing
148
171
  ]);
149
- const handleCancel = () => {
150
- hyperLinkService.hideEditPopup();
151
- };
172
+ const handleCancel = () => hyperLinkService.hideEditPopup();
152
173
  const handleConfirm = () => {
153
174
  setShowError(true);
154
175
  if (!isLegal || !doc) return;
155
- const linkFinal = transformUrl(link);
156
- if (!editing) commandService.executeCommand(AddDocHyperLinkCommand.id, {
157
- unitId: doc.getUnitId(),
158
- payload: linkFinal
159
- });
160
- else {
176
+ const payload = transformUrl(link);
177
+ if (editing) {
161
178
  if (isBlankInput(label)) return;
162
179
  commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
163
180
  unitId: doc.getUnitId(),
164
- payload: linkFinal,
181
+ payload,
165
182
  linkId: editing.linkId,
166
183
  label,
167
184
  segmentId: editing.segmentId
168
- });
169
- }
185
+ }).catch(() => void 0);
186
+ } else commandService.executeCommand(AddDocHyperLinkCommand.id, {
187
+ unitId: doc.getUnitId(),
188
+ payload
189
+ }).catch(() => void 0);
170
190
  hyperLinkService.hideEditPopup();
171
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();
172
211
  if (!doc) return;
173
212
  return /* @__PURE__ */ jsxs("div", {
174
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),
@@ -179,8 +218,8 @@ const DocHyperLinkEdit = () => {
179
218
  value: label,
180
219
  onChange: setLabel,
181
220
  autoFocus: true,
182
- onKeyDown: (evt) => {
183
- if (evt.keyCode === KeyCode.ENTER) handleConfirm();
221
+ onKeyDown: (event) => {
222
+ if (event.keyCode === KeyCode.ENTER) handleConfirm();
184
223
  }
185
224
  })
186
225
  }) : null, /* @__PURE__ */ jsx(FormLayout, {
@@ -190,8 +229,8 @@ const DocHyperLinkEdit = () => {
190
229
  value: link,
191
230
  onChange: setLink,
192
231
  autoFocus: true,
193
- onKeyDown: (evt) => {
194
- if (evt.keyCode === KeyCode.ENTER) handleConfirm();
232
+ onKeyDown: (event) => {
233
+ if (event.keyCode === KeyCode.ENTER) handleConfirm();
195
234
  }
196
235
  })
197
236
  })] }), /* @__PURE__ */ jsxs("div", {
@@ -210,34 +249,15 @@ const DocHyperLinkEdit = () => {
210
249
  };
211
250
  DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
212
251
 
213
- //#endregion
214
- //#region src/commands/commands/delete-link.command.ts
215
- const DeleteDocHyperLinkCommand = {
216
- type: CommandType.COMMAND,
217
- id: DocHyperLinkCommandId.Delete,
218
- async handler(accessor, params) {
219
- if (!params) return false;
220
- const { unitId, linkId, segmentId } = params;
221
- const commandService = accessor.get(ICommandService);
222
- const doMutation = deleteCustomRangeFactory(accessor, {
223
- unitId,
224
- rangeId: linkId,
225
- segmentId
226
- });
227
- if (!doMutation) return false;
228
- return await commandService.syncExecuteCommand(doMutation.id, doMutation.params);
229
- }
230
- };
231
-
232
252
  //#endregion
233
253
  //#region src/views/DocLinkPopup.tsx
234
254
  const DocLinkPopup = () => {
235
- var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties;
255
+ var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties, _link$properties2, _link$properties3;
236
256
  const hyperLinkService = useDependency(DocHyperLinkPopupService);
237
257
  const commandService = useDependency(ICommandService);
238
258
  const messageService = useDependency(IMessageService);
239
259
  const localeService = useDependency(LocaleService);
240
- const currentPopup = useObservable(hyperLinkService.showingLink$);
260
+ const currentPopup = useObservable(hyperLinkService.showingLink$, hyperLinkService.showing);
241
261
  const univerInstanceService = useDependency(IUniverInstanceService);
242
262
  const permissionService = useDependency(IPermissionService);
243
263
  if (!currentPopup) return null;
@@ -246,7 +266,7 @@ const DocLinkPopup = () => {
246
266
  const body = doc instanceof DocumentDataModel ? (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody() : void 0;
247
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);
248
268
  if (!link) return null;
249
- 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) ?? ""}`;
250
270
  const canEdit = hyperLinkService.canEditLink(unitId, currentPopup);
251
271
  const canCopy = getDocumentPermissionValue(permissionService, unitId, unitId, UnitAction.Copy);
252
272
  return /* @__PURE__ */ jsxs("div", {
@@ -262,16 +282,20 @@ const DocLinkPopup = () => {
262
282
  },
263
283
  children: [/* @__PURE__ */ jsxs("div", {
264
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",
265
- onClick: () => window.open(url, void 0, "noopener noreferrer"),
285
+ onClick: () => commandService.executeCommand(ClickDocHyperLinkOperation.id, {
286
+ unitId,
287
+ linkId,
288
+ segmentId
289
+ }),
266
290
  children: [/* @__PURE__ */ jsx("div", {
267
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",
268
292
  children: /* @__PURE__ */ jsx(LinkIcon, {})
269
293
  }), /* @__PURE__ */ jsx(Tooltip, {
270
294
  showIfEllipsis: true,
271
- title: url,
295
+ title: target,
272
296
  children: /* @__PURE__ */ jsx("span", {
273
297
  className: "univer-flex-1 univer-truncate",
274
- children: url
298
+ children: target
275
299
  })
276
300
  })]
277
301
  }), /* @__PURE__ */ jsxs("div", {
@@ -284,7 +308,7 @@ const DocLinkPopup = () => {
284
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",
285
309
  disabled: !canCopy,
286
310
  onClick: () => {
287
- navigator.clipboard.writeText(url);
311
+ navigator.clipboard.writeText(target);
288
312
  messageService.show({
289
313
  content: localeService.t("docs-hyper-link-ui.info.coped"),
290
314
  type: MessageType.Info
@@ -326,7 +350,7 @@ const DocLinkPopup = () => {
326
350
  DocLinkPopup.componentKey = "univer.doc.link-info-popup";
327
351
 
328
352
  //#endregion
329
- //#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
330
354
  function _typeof(o) {
331
355
  "@babel/helpers - typeof";
332
356
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -337,7 +361,7 @@ function _typeof(o) {
337
361
  }
338
362
 
339
363
  //#endregion
340
- //#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
341
365
  function toPrimitive(t, r) {
342
366
  if ("object" != _typeof(t) || !t) return t;
343
367
  var e = t[Symbol.toPrimitive];
@@ -350,14 +374,14 @@ function toPrimitive(t, r) {
350
374
  }
351
375
 
352
376
  //#endregion
353
- //#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
354
378
  function toPropertyKey(t) {
355
379
  var i = toPrimitive(t, "string");
356
380
  return "symbol" == _typeof(i) ? i : i + "";
357
381
  }
358
382
 
359
383
  //#endregion
360
- //#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
361
385
  function _defineProperty(e, r, t) {
362
386
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
363
387
  value: t,
@@ -368,7 +392,7 @@ function _defineProperty(e, r, t) {
368
392
  }
369
393
 
370
394
  //#endregion
371
- //#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
372
396
  function __decorateParam(paramIndex, decorator) {
373
397
  return function(target, key) {
374
398
  decorator(target, key, paramIndex);
@@ -376,7 +400,7 @@ function __decorateParam(paramIndex, decorator) {
376
400
  }
377
401
 
378
402
  //#endregion
379
- //#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
380
404
  function __decorate(decorators, target, key, desc) {
381
405
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
382
406
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -386,33 +410,21 @@ function __decorate(decorators, target, key, desc) {
386
410
 
387
411
  //#endregion
388
412
  //#region src/services/hyper-link-popup.service.ts
389
- /**
390
- * Copyright 2023-present DreamNum Co., Ltd.
391
- *
392
- * Licensed under the Apache License, Version 2.0 (the "License");
393
- * you may not use this file except in compliance with the License.
394
- * You may obtain a copy of the License at
395
- *
396
- * http://www.apache.org/licenses/LICENSE-2.0
397
- *
398
- * Unless required by applicable law or agreed to in writing, software
399
- * distributed under the License is distributed on an "AS IS" BASIS,
400
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
401
- * See the License for the specific language governing permissions and
402
- * limitations under the License.
403
- */
404
413
  const INFO_POPUP_HIDE_DELAY = 150;
405
414
  function isSameLinkInfo(current, next) {
406
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;
407
416
  }
408
417
  let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable {
409
- constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService, _permissionService, _renderManagerService) {
418
+ constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService, _permissionService, _renderManagerService, _dialogService, _localeService, _commandService) {
410
419
  super();
411
420
  this._docCanvasPopupManagerService = _docCanvasPopupManagerService;
412
421
  this._textSelectionManagerService = _textSelectionManagerService;
413
422
  this._univerInstanceService = _univerInstanceService;
414
423
  this._permissionService = _permissionService;
415
424
  this._renderManagerService = _renderManagerService;
425
+ this._dialogService = _dialogService;
426
+ this._localeService = _localeService;
427
+ this._commandService = _commandService;
416
428
  _defineProperty(this, "_editingLink$", new BehaviorSubject(null));
417
429
  _defineProperty(this, "_showingLink$", new BehaviorSubject(null));
418
430
  _defineProperty(this, "editingLink$", this._editingLink$.asObservable());
@@ -484,21 +496,17 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
484
496
  }]);
485
497
  }
486
498
  if (activeRange) {
487
- this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(activeRange, {
488
- componentKey: DocHyperLinkEdit.componentKey,
489
- direction: "bottom",
490
- offset: [0, 10]
491
- }, unitId);
499
+ this._editPopup = this._openEditSurface(activeRange, unitId);
492
500
  this._editPopupUnitId = unitId;
493
501
  return this._editPopup;
494
502
  }
495
503
  return null;
496
504
  }
497
505
  hideEditPopup() {
498
- var _this$_editPopup;
499
506
  this._editingLink$.next(null);
500
- (_this$_editPopup = this._editPopup) === null || _this$_editPopup === void 0 || _this$_editPopup.dispose();
507
+ const popup = this._editPopup;
501
508
  this._editPopup = null;
509
+ popup === null || popup === void 0 || popup.dispose();
502
510
  this._editPopupUnitId = null;
503
511
  }
504
512
  showInfoPopup(info, options) {
@@ -523,14 +531,39 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
523
531
  startIndex,
524
532
  endIndex
525
533
  });
526
- 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({
527
547
  collapsed: false,
528
548
  startOffset: startIndex,
529
549
  endOffset: endIndex + 1,
530
550
  segmentId,
531
551
  segmentPage
532
552
  }, {
533
- 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
+ },
534
567
  direction: "top-center",
535
568
  multipleDirection: "top",
536
569
  offset: [0, 10],
@@ -538,15 +571,19 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
538
571
  this.hideInfoPopup();
539
572
  }
540
573
  }, unitId);
541
- return this._infoPopup;
574
+ }
575
+ showInfoPopupFromHover(info) {
576
+ this.cancelScheduledHideInfoPopup();
577
+ if (this._infoPopupPinned || this._infoPopupSuppressed) return;
578
+ if (!this.showing) this.showInfoPopup(info);
542
579
  }
543
580
  hideInfoPopup() {
544
- var _this$_infoPopup;
545
581
  this.cancelScheduledHideInfoPopup();
546
582
  this._infoPopupPinned = false;
547
583
  this._showingLink$.next(null);
548
- (_this$_infoPopup = this._infoPopup) === null || _this$_infoPopup === void 0 || _this$_infoPopup.dispose();
584
+ const popup = this._infoPopup;
549
585
  this._infoPopup = null;
586
+ popup === null || popup === void 0 || popup.dispose();
550
587
  }
551
588
  scheduleHideInfoPopup() {
552
589
  if (this._infoPopupPinned || !this.showing) return;
@@ -584,7 +621,10 @@ DocHyperLinkPopupService = __decorate([
584
621
  __decorateParam(1, Inject(DocSelectionManagerService)),
585
622
  __decorateParam(2, IUniverInstanceService),
586
623
  __decorateParam(3, IPermissionService),
587
- __decorateParam(4, IRenderManagerService)
624
+ __decorateParam(4, IRenderManagerService),
625
+ __decorateParam(5, IDialogService),
626
+ __decorateParam(6, Inject(LocaleService)),
627
+ __decorateParam(7, ICommandService)
588
628
  ], DocHyperLinkPopupService);
589
629
 
590
630
  //#endregion
@@ -622,7 +662,8 @@ const ToggleDocHyperLinkInfoPopupOperation = {
622
662
  hyperLinkService.hideInfoPopup();
623
663
  return true;
624
664
  }
625
- hyperLinkService.showInfoPopup(params);
665
+ if (params.fromHover) hyperLinkService.showInfoPopupFromHover(params);
666
+ else hyperLinkService.showInfoPopup(params);
626
667
  return true;
627
668
  }
628
669
  };
@@ -630,17 +671,57 @@ const ClickDocHyperLinkOperation = {
630
671
  type: CommandType.OPERATION,
631
672
  id: "doc.operation.click-hyper-link",
632
673
  handler(accessor, params) {
633
- var _doc$getSelfOrHeaderF, _body$customRanges;
674
+ var _doc$getSelfOrHeaderF, _sourceBody$customRan;
634
675
  if (!params) return false;
635
676
  const { unitId, linkId, segmentId } = params;
636
677
  const doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
637
- const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
638
- 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;
639
- if (!isSafeUrl(link)) return false;
640
- 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");
641
703
  return true;
642
704
  }
643
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
+ }
644
725
 
645
726
  //#endregion
646
727
  //#region src/menu/menu.ts
@@ -674,6 +755,10 @@ const addLinkShortcut = {
674
755
  const menuSchema = {
675
756
  [RibbonInsertGroup.MEDIA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
676
757
  order: 1,
758
+ gridLayout: {
759
+ row: 1,
760
+ column: 5
761
+ },
677
762
  menuItemFactory: AddHyperLinkMenuItemFactory
678
763
  } },
679
764
  [FLOAT_TOOLBAR_MENU_POSITION]: { [ShowDocHyperLinkEditPopupOperation.id]: {
@@ -699,7 +784,7 @@ const menuSchema = {
699
784
  //#endregion
700
785
  //#region package.json
701
786
  var name = "@univerjs/docs-hyper-link-ui";
702
- var version = "1.0.0-rc.0";
787
+ var version = "1.0.0";
703
788
 
704
789
  //#endregion
705
790
  //#region src/config/config.ts
@@ -707,42 +792,6 @@ const DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config";
707
792
  const configSymbol = Symbol(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
708
793
  const defaultPluginConfig = {};
709
794
 
710
- //#endregion
711
- //#region src/controllers/components.controller.ts
712
- /**
713
- * Copyright 2023-present DreamNum Co., Ltd.
714
- *
715
- * Licensed under the Apache License, Version 2.0 (the "License");
716
- * you may not use this file except in compliance with the License.
717
- * You may obtain a copy of the License at
718
- *
719
- * http://www.apache.org/licenses/LICENSE-2.0
720
- *
721
- * Unless required by applicable law or agreed to in writing, software
722
- * distributed under the License is distributed on an "AS IS" BASIS,
723
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
724
- * See the License for the specific language governing permissions and
725
- * limitations under the License.
726
- */
727
- let ComponentsController = class ComponentsController extends Disposable {
728
- constructor(_componentManager, _iconManager) {
729
- super();
730
- this._componentManager = _componentManager;
731
- this._iconManager = _iconManager;
732
- this._registerComponents();
733
- this._registerIcons();
734
- }
735
- _registerComponents() {
736
- [[DocHyperLinkEdit.componentKey, DocHyperLinkEdit], [DocLinkPopup.componentKey, DocLinkPopup]].forEach(([key, comp]) => {
737
- this.disposeWithMe(this._componentManager.register(key, comp));
738
- });
739
- }
740
- _registerIcons() {
741
- this.disposeWithMe(this._iconManager.register({ LinkIcon }));
742
- }
743
- };
744
- ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
745
-
746
795
  //#endregion
747
796
  //#region src/controllers/doc-hyper-link-selection.controller.ts
748
797
  let DocHyperLinkSelectionController = class DocHyperLinkSelectionController extends Disposable {
@@ -751,14 +800,45 @@ let DocHyperLinkSelectionController = class DocHyperLinkSelectionController exte
751
800
  this._commandService = _commandService;
752
801
  this._univerInstanceService = _univerInstanceService;
753
802
  this._docHyperLinkService = _docHyperLinkService;
803
+ _defineProperty(this, "_selection", null);
754
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
+ }));
755
809
  }
756
810
  _initSelectionChange() {
757
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
+ }
758
817
  if (commandInfo.id === SetTextSelectionsOperation.id) {
759
- const { unitId, ranges, segmentId } = commandInfo.params;
818
+ var _this$_selection2;
819
+ const params = commandInfo.params;
820
+ const { unitId, ranges, segmentId } = params;
760
821
  const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
761
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;
762
842
  if ((primary === null || primary === void 0 ? void 0 : primary.collapsed) && doc) {
763
843
  var _doc$getSelfOrHeaderF;
764
844
  const { startOffset, endOffset, segmentPage } = primary;
@@ -790,53 +870,196 @@ DocHyperLinkSelectionController = __decorate([
790
870
  ], DocHyperLinkSelectionController);
791
871
 
792
872
  //#endregion
793
- //#region src/controllers/render-controllers/hyper-link-event.render-controller.ts
794
- let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController extends Disposable {
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
989
+ /**
990
+ * Copyright 2023-present DreamNum Co., Ltd.
991
+ *
992
+ * Licensed under the Apache License, Version 2.0 (the "License");
993
+ * you may not use this file except in compliance with the License.
994
+ * You may obtain a copy of the License at
995
+ *
996
+ * http://www.apache.org/licenses/LICENSE-2.0
997
+ *
998
+ * Unless required by applicable law or agreed to in writing, software
999
+ * distributed under the License is distributed on an "AS IS" BASIS,
1000
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1001
+ * See the License for the specific language governing permissions and
1002
+ * limitations under the License.
1003
+ */
1004
+ let MobileComponentsController = class MobileComponentsController extends Disposable {
1005
+ constructor(_componentManager, _iconManager) {
1006
+ super();
1007
+ this._componentManager = _componentManager;
1008
+ this._iconManager = _iconManager;
1009
+ this._registerComponents();
1010
+ this._registerIcons();
1011
+ }
1012
+ _registerComponents() {
1013
+ [[MobileDocHyperLinkEdit.componentKey, MobileDocHyperLinkEdit], [MobileDocLinkPopup.componentKey, MobileDocLinkPopup]].forEach(([key, comp]) => {
1014
+ this.disposeWithMe(this._componentManager.register(key, comp));
1015
+ });
1016
+ }
1017
+ _registerIcons() {
1018
+ this.disposeWithMe(this._iconManager.register({ LinkIcon }));
1019
+ }
1020
+ };
1021
+ MobileComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], MobileComponentsController);
1022
+
1023
+ //#endregion
1024
+ //#region src/controllers/render-controllers/mobile/hyper-link-event.render-controller.ts
1025
+ let MobileDocHyperLinkEventRenderController = class MobileDocHyperLinkEventRenderController extends Disposable {
795
1026
  get _skeleton() {
796
1027
  return this._docSkeletonManagerService.getSkeleton();
797
1028
  }
798
- constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _docSelectionManagerService) {
1029
+ constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _mobileElementMenuService) {
799
1030
  super();
800
1031
  this._context = _context;
801
1032
  this._docEventManagerService = _docEventManagerService;
802
1033
  this._commandService = _commandService;
803
1034
  this._hyperLinkPopupService = _hyperLinkPopupService;
804
1035
  this._docSkeletonManagerService = _docSkeletonManagerService;
805
- this._docSelectionManagerService = _docSelectionManagerService;
1036
+ this._mobileElementMenuService = _mobileElementMenuService;
806
1037
  if (this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
807
1038
  this._initPointerDown();
808
- this._initHover();
809
1039
  this._initClick();
810
1040
  }
811
- _hideInfoPopup() {
812
- if (this._hyperLinkPopupService.infoPopupPinned) return;
813
- if (this._hyperLinkPopupService.showing) this._hyperLinkPopupService.scheduleHideInfoPopup();
814
- }
815
1041
  _initPointerDown() {
816
1042
  this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe((ranges) => {
817
- if (!ranges.some((range) => range.range.rangeType === CustomRangeType.HYPERLINK)) this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
818
- }));
819
- }
820
- _initHover() {
821
- this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
822
- var _activeRanges$;
823
1043
  const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK);
824
- const activeRanges = this._docSelectionManagerService.getTextRanges();
825
- const currentSegmentId = activeRanges === null || activeRanges === void 0 || (_activeRanges$ = activeRanges[0]) === null || _activeRanges$ === void 0 ? void 0 : _activeRanges$.segmentId;
826
- if (((link === null || link === void 0 ? void 0 : link.segmentId) ?? "") !== currentSegmentId) {
827
- this._hideInfoPopup();
1044
+ if (!link) {
1045
+ this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
828
1046
  return;
829
1047
  }
830
- if (link) this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id, {
1048
+ const info = {
831
1049
  unitId: this._context.unitId,
832
1050
  linkId: link.range.rangeId,
833
1051
  segmentId: link.segmentId,
834
1052
  segmentPage: link.segmentPageIndex,
835
- rangeId: link.range.rangeId,
836
1053
  startIndex: link.range.startIndex,
837
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)
838
1062
  });
839
- else this._hideInfoPopup();
840
1063
  }));
841
1064
  }
842
1065
  _initClick() {
@@ -862,13 +1085,13 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
862
1085
  }));
863
1086
  }
864
1087
  };
865
- DocHyperLinkEventRenderController = __decorate([
1088
+ MobileDocHyperLinkEventRenderController = __decorate([
866
1089
  __decorateParam(1, Inject(DocEventManagerService)),
867
1090
  __decorateParam(2, ICommandService),
868
1091
  __decorateParam(3, Inject(DocHyperLinkPopupService)),
869
1092
  __decorateParam(4, Inject(DocSkeletonManagerService)),
870
- __decorateParam(5, Inject(DocSelectionManagerService))
871
- ], DocHyperLinkEventRenderController);
1093
+ __decorateParam(5, Inject(DocMobileElementMenuService))
1094
+ ], MobileDocHyperLinkEventRenderController);
872
1095
 
873
1096
  //#endregion
874
1097
  //#region src/controllers/render-controllers/render.controller.ts
@@ -939,6 +1162,29 @@ DocHyperLinkUIController = __decorate([
939
1162
  __decorateParam(2, IShortcutService)
940
1163
  ], DocHyperLinkUIController);
941
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
+
942
1188
  //#endregion
943
1189
  //#region src/types/const/index.ts
944
1190
  /**
@@ -958,6 +1204,175 @@ DocHyperLinkUIController = __decorate([
958
1204
  */
959
1205
  const DOC_HYPER_LINK_UI_PLUGIN = "DOC_HYPER_LINK_UI_PLUGIN";
960
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
+
961
1376
  //#endregion
962
1377
  //#region src/plugin.ts
963
1378
  let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends Plugin {
@@ -972,15 +1387,15 @@ let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends Plug
972
1387
  this._configService.setConfig(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
973
1388
  }
974
1389
  onStarting() {
975
- this._injector.add([ComponentsController]);
976
- this._injector.get(ComponentsController);
977
1390
  [
1391
+ [ComponentsController],
978
1392
  [DocHyperLinkPopupService],
979
1393
  [DocHyperLinkUIController],
980
1394
  [DocHyperLinkSelectionController]
981
1395
  ].forEach((dep) => {
982
1396
  this._injector.add(dep);
983
1397
  });
1398
+ this._injector.get(ComponentsController);
984
1399
  this._injector.get(DocHyperLinkUIController);
985
1400
  }
986
1401
  onReady() {
@@ -1007,4 +1422,4 @@ UniverDocsHyperLinkUIPlugin = __decorate([
1007
1422
  ], UniverDocsHyperLinkUIPlugin);
1008
1423
 
1009
1424
  //#endregion
1010
- export { menuSchema as DocsHyperLinkUIMenuSchema, UniverDocsHyperLinkUIPlugin };
1425
+ export { menuSchema as DocsHyperLinkUIMenuSchema, UniverDocsHyperLinkMobileUIPlugin, UniverDocsHyperLinkUIPlugin };