@univerjs/docs-hyper-link-ui 0.2.10 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -2,14 +2,14 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { CommandType, ICommandService, IUniverInstanceService, UniverInstanceType, CustomRangeType, useDependency, LocaleService, Disposable, Inject, generateRandomId, sequenceExecute, DataStreamTreeTokenType, useObservable as useObservable$1, Tools, getBodySlice, OnLifecycle, LifecycleStages, Injector, updateAttributeByDelete, DependentOn, Plugin } from "@univerjs/core";
6
- import { DocHyperLinkModel, AddDocHyperLinkMutation, UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
7
- import { ITextSelectionRenderManager, IRenderManagerService, DocumentEditArea } from "@univerjs/engine-render";
8
- import { IMessageService, useObservable, KeyCode, MetaKeys, MenuGroup, MenuItemType, MenuPosition, getMenuHiddenObservable, ComponentManager, IMenuService, IShortcutService } from "@univerjs/ui";
5
+ import { CommandType, ICommandService, IUniverInstanceService, UniverInstanceType, CustomRangeType, useDependency, LocaleService, Disposable, Inject, generateRandomId, DataStreamTreeTokenType, useObservable as useObservable$1, Tools, getBodySlice, OnLifecycle, LifecycleStages, Injector, DependentOn, Plugin, IConfigService } from "@univerjs/core";
6
+ import { ITextSelectionRenderManager, IRenderManagerService } from "@univerjs/engine-render";
7
+ import { UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
8
+ import { IMessageService, useObservable, KeyCode, MetaKeys, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IMenuManagerService, IShortcutService } from "@univerjs/ui";
9
9
  import { Tooltip, MessageType, FormLayout, Input, Button } from "@univerjs/design";
10
10
  import React, { forwardRef, useRef, createElement, useState, useEffect } from "react";
11
- import { deleteCustomRangeFactory, TextSelectionManagerService, getCustomRangesInterestsWithRange, addCustomRangeBySelectionFactory, replaceSelectionFactory, getPlainTextFormBody, SetTextSelectionsOperation, DocInterceptorService, DOC_INTERCEPTOR_POINT, DocCustomRangeService, DocSkeletonManagerService } from "@univerjs/docs";
12
- import { DocCanvasPopManagerService, whenDocAndEditorFocused, DocRenderController, IDocClipboardService, DocEventManagerService } from "@univerjs/docs-ui";
11
+ import { deleteCustomRangeFactory, TextSelectionManagerService, getCustomRangesInterestsWithRange, addCustomRangeBySelectionFactory, replaceSelectionFactory, getPlainTextFormBody, SetTextSelectionsOperation, DocInterceptorService, DOC_INTERCEPTOR_POINT, DocSkeletonManagerService } from "@univerjs/docs";
12
+ import { DocCanvasPopManagerService, whenDocAndEditorFocused, DocRenderController, DocEventManagerService } from "@univerjs/docs-ui";
13
13
  import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, pairwise } from "rxjs";
14
14
  import cs from "clsx";
15
15
  const DOC_HYPER_LINK_UI_PLUGIN = "DOC_HYPER_LINK_UI_PLUGIN";
@@ -42,15 +42,15 @@ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
42
42
  var attrs = __assign({}, node.attrs);
43
43
  extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
44
44
  var defIds = runtimeProps.defIds;
45
- return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a9) {
46
- var key = _a9[0], value = _a9[1];
45
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a7) {
46
+ var key = _a7[0], value = _a7[1];
47
47
  typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
48
48
  })), attrs;
49
49
  }
50
50
  __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
51
51
  function replaceRuntimeIdsInDefs(node, runtimeProps) {
52
- var _a9, defIds = runtimeProps.defIds;
53
- return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a9 = node.children) === null || _a9 === void 0) && _a9.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
52
+ var _a7, defIds = runtimeProps.defIds;
53
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a7 = node.children) === null || _a7 === void 0) && _a7.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
54
54
  return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
55
55
  }) }) : node;
56
56
  }
@@ -98,14 +98,11 @@ const DeleteDocHyperLinkCommand = {
98
98
  async handler(accessor, params) {
99
99
  if (!params)
100
100
  return !1;
101
- const { unitId, linkId, segmentId } = params, commandService = accessor.get(ICommandService);
102
- if (!accessor.get(DocHyperLinkModel).getLink(unitId, linkId))
103
- return !1;
104
- const doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId, segmentId });
101
+ const { unitId, linkId, segmentId } = params, commandService = accessor.get(ICommandService), doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId, segmentId });
105
102
  return doMutation ? await commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
106
103
  }
107
104
  }, shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
108
- var _a9;
105
+ var _a7;
109
106
  const textSelectionService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges = textSelectionService.getDocRanges();
110
107
  if (!textRanges.length || textRanges.length > 1)
111
108
  return !0;
@@ -122,13 +119,17 @@ const DeleteDocHyperLinkCommand = {
122
119
  if (p.startIndex > activeRange.endOffset)
123
120
  break;
124
121
  }
125
- return !getCustomRangesInterestsWithRange(activeRange, (_a9 = body.customRanges) != null ? _a9 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
122
+ return !getCustomRangesInterestsWithRange(activeRange, (_a7 = body.customRanges) != null ? _a7 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
126
123
  }, "shouldDisableAddLink"), ShowDocHyperLinkEditPopupOperation = {
127
124
  type: CommandType.OPERATION,
128
125
  id: "doc.operation.show-hyper-link-edit-popup",
129
126
  handler(accessor, params) {
130
- const linkInfo = params == null ? void 0 : params.link;
131
- return shouldDisableAddLink(accessor) && !linkInfo ? !1 : (accessor.get(DocHyperLinkPopupService).showEditPopup(linkInfo), !0);
127
+ var _a7;
128
+ const linkInfo = params == null ? void 0 : params.link, univerInstanceService = accessor.get(IUniverInstanceService);
129
+ if (shouldDisableAddLink(accessor) && !linkInfo)
130
+ return !1;
131
+ const hyperLinkService = accessor.get(DocHyperLinkPopupService), unitId = (linkInfo == null ? void 0 : linkInfo.unitId) || ((_a7 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a7.getUnitId());
132
+ return unitId ? (hyperLinkService.showEditPopup(unitId, linkInfo), !0) : !1;
132
133
  }
133
134
  }, ToggleDocHyperLinkInfoPopupOperation = {
134
135
  type: CommandType.OPERATION,
@@ -141,10 +142,11 @@ const DeleteDocHyperLinkCommand = {
141
142
  type: CommandType.OPERATION,
142
143
  id: "doc.operation.click-hyper-link",
143
144
  handler(accessor, params) {
145
+ var _a7, _b, _c;
144
146
  if (!params)
145
147
  return !1;
146
- const { unitId, linkId } = params, link = accessor.get(DocHyperLinkModel).getLink(unitId, linkId);
147
- return link ? (window.open(link.payload, "_blank", "noopener noreferrer"), !0) : !1;
148
+ const { unitId, linkId, segmentId } = params, doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC), body = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(segmentId).getBody(), link = (_c = (_b = (_a7 = body == null ? void 0 : body.customRanges) == null ? void 0 : _a7.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)) == null ? void 0 : _b.properties) == null ? void 0 : _c.url;
149
+ return link && window.open(link, "_blank", "noopener noreferrer"), !0;
148
150
  }
149
151
  }, docLink = "univer-doc-link", docLinkType = "univer-doc-link-type", docLinkContent = "univer-doc-link-content", docLinkContentError = "univer-doc-link-content-error", docLinkUrl = "univer-doc-link-url", docLinkOperations = "univer-doc-link-operations", docLinkOperation = "univer-doc-link-operation", docLinkOperationError = "univer-doc-link-operation-error", styles$1 = {
150
152
  docLink,
@@ -156,11 +158,15 @@ const DeleteDocHyperLinkCommand = {
156
158
  docLinkOperation,
157
159
  docLinkOperationError
158
160
  }, DocLinkPopup = /* @__PURE__ */ __name(() => {
159
- const hyperLinkService = useDependency(DocHyperLinkPopupService), hyperLinkModel = useDependency(DocHyperLinkModel), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService), currentPopup = useObservable(hyperLinkService.showingLink$);
161
+ var _a7, _b;
162
+ const hyperLinkService = useDependency(DocHyperLinkPopupService), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService), currentPopup = useObservable(hyperLinkService.showingLink$), univerInstanceService = useDependency(IUniverInstanceService);
160
163
  if (!currentPopup)
161
164
  return null;
162
- const { unitId, linkId, segmentId } = currentPopup, link = hyperLinkModel.getLink(unitId, linkId);
163
- return link ? /* @__PURE__ */ React.createElement(
165
+ const { unitId, linkId, segmentId } = currentPopup, doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), body = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(segmentId).getBody(), link = (_a7 = body == null ? void 0 : body.customRanges) == null ? void 0 : _a7.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK);
166
+ if (!link)
167
+ return null;
168
+ const url = (_b = link.properties) == null ? void 0 : _b.url;
169
+ return /* @__PURE__ */ React.createElement(
164
170
  "div",
165
171
  {
166
172
  className: styles$1.docLink,
@@ -168,13 +174,13 @@ const DeleteDocHyperLinkCommand = {
168
174
  hyperLinkService.hideInfoPopup();
169
175
  }, "onClick")
170
176
  },
171
- /* @__PURE__ */ React.createElement("div", { className: cs(styles$1.docLinkContent), onClick: /* @__PURE__ */ __name(() => window.open(link.payload), "onClick") }, /* @__PURE__ */ React.createElement("div", { className: styles$1.docLinkType }, /* @__PURE__ */ React.createElement(LinkSingle, null)), /* @__PURE__ */ React.createElement(Tooltip, { showIfEllipsis: !0, title: link.payload }, /* @__PURE__ */ React.createElement("span", { className: styles$1.docLinkUrl }, link.payload))),
177
+ /* @__PURE__ */ React.createElement("div", { className: cs(styles$1.docLinkContent), onClick: /* @__PURE__ */ __name(() => window.open(url), "onClick") }, /* @__PURE__ */ React.createElement("div", { className: styles$1.docLinkType }, /* @__PURE__ */ React.createElement(LinkSingle, null)), /* @__PURE__ */ React.createElement(Tooltip, { showIfEllipsis: !0, title: url }, /* @__PURE__ */ React.createElement("span", { className: styles$1.docLinkUrl }, url))),
172
178
  /* @__PURE__ */ React.createElement("div", { className: styles$1.docLinkOperations }, /* @__PURE__ */ React.createElement(
173
179
  "div",
174
180
  {
175
181
  className: cs(styles$1.docLinkOperation),
176
182
  onClick: /* @__PURE__ */ __name(() => {
177
- navigator.clipboard.writeText(link.payload), messageService.show({
183
+ navigator.clipboard.writeText(url), messageService.show({
178
184
  content: localeService.t("docLink.info.coped"),
179
185
  type: MessageType.Info
180
186
  });
@@ -199,25 +205,25 @@ const DeleteDocHyperLinkCommand = {
199
205
  onClick: /* @__PURE__ */ __name(() => {
200
206
  commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
201
207
  unitId,
202
- linkId: link.id,
208
+ linkId: link.rangeId,
203
209
  segmentId
204
210
  });
205
211
  }, "onClick")
206
212
  },
207
213
  /* @__PURE__ */ React.createElement(Tooltip, { placement: "bottom", title: localeService.t("docLink.info.cancel") }, /* @__PURE__ */ React.createElement(UnlinkSingle, null))
208
214
  ))
209
- ) : null;
215
+ );
210
216
  }, "DocLinkPopup");
211
217
  DocLinkPopup.componentKey = "univer.doc.link-info-popup";
212
- var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
213
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
218
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
219
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
214
220
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
215
- return kind && result && __defProp$7(target, key, result), result;
216
- }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7");
221
+ return kind && result && __defProp$5(target, key, result), result;
222
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5");
217
223
  const SKIT_PLACEHOLDER = 0;
218
224
  var _a;
219
225
  let DocHyperLinkPopupService = (_a = class extends Disposable {
220
- constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _docHyperLinkModel, _univerInstanceService) {
226
+ constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService) {
221
227
  super();
222
228
  __publicField(this, "_editingLink$", new BehaviorSubject(null));
223
229
  __publicField(this, "_showingLink$", new BehaviorSubject(null));
@@ -225,7 +231,7 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
225
231
  __publicField(this, "showingLink$", this._showingLink$.asObservable());
226
232
  __publicField(this, "_editPopup", null);
227
233
  __publicField(this, "_infoPopup", null);
228
- this._docCanvasPopupManagerService = _docCanvasPopupManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._docHyperLinkModel = _docHyperLinkModel, this._univerInstanceService = _univerInstanceService, this.disposeWithMe(() => {
234
+ this._docCanvasPopupManagerService = _docCanvasPopupManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this.disposeWithMe(() => {
229
235
  this._editingLink$.complete(), this._showingLink$.complete();
230
236
  });
231
237
  }
@@ -235,12 +241,12 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
235
241
  get showing() {
236
242
  return this._showingLink$.value;
237
243
  }
238
- showEditPopup(linkInfo) {
239
- var _a9, _b, _c;
244
+ showEditPopup(unitId, linkInfo) {
245
+ var _a7, _b, _c;
240
246
  this._editPopup && this._editPopup.dispose(), this._editingLink$.next(linkInfo);
241
247
  let activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle();
242
248
  if (linkInfo) {
243
- const { unitId, linkId, segmentId, segmentPage } = linkInfo, doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), range = (_c = (_b = (_a9 = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a9.getBody()) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((i) => i.rangeId === linkId);
249
+ const { unitId: unitId2, linkId, segmentId, segmentPage } = linkInfo, doc = this._univerInstanceService.getUnit(unitId2, UniverInstanceType.UNIVER_DOC), range = (_c = (_b = (_a7 = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a7.getBody()) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((i) => i.rangeId === linkId);
244
250
  range && (activeRange = {
245
251
  collapsed: !1,
246
252
  startOffset: range.startIndex + SKIT_PLACEHOLDER,
@@ -257,21 +263,22 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
257
263
  {
258
264
  componentKey: DocHyperLinkEdit.componentKey,
259
265
  direction: "bottom"
260
- }
266
+ },
267
+ unitId
261
268
  ), this._editPopup) : null;
262
269
  }
263
270
  hideEditPopup() {
264
- var _a9;
265
- this._editingLink$.next(null), (_a9 = this._editPopup) == null || _a9.dispose();
271
+ var _a7;
272
+ this._editingLink$.next(null), (_a7 = this._editPopup) == null || _a7.dispose();
266
273
  }
267
274
  showInfoPopup(info) {
268
- var _a9, _b, _c, _d, _e, _f;
275
+ var _a7, _b, _c, _d, _e, _f;
269
276
  const { linkId, unitId, segmentId, segmentPage } = info;
270
- if (((_a9 = this.showing) == null ? void 0 : _a9.linkId) === linkId && ((_b = this.showing) == null ? void 0 : _b.unitId) === unitId && ((_c = this.showing) == null ? void 0 : _c.segmentId) === segmentId && ((_d = this.showing) == null ? void 0 : _d.segmentPage) === segmentPage)
277
+ if (((_a7 = this.showing) == null ? void 0 : _a7.linkId) === linkId && ((_b = this.showing) == null ? void 0 : _b.unitId) === unitId && ((_c = this.showing) == null ? void 0 : _c.segmentId) === segmentId && ((_d = this.showing) == null ? void 0 : _d.segmentPage) === segmentPage)
271
278
  return;
272
279
  this._infoPopup && this._infoPopup.dispose();
273
- const link = this._docHyperLinkModel.getLink(unitId, linkId), doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
274
- if (!doc || !link)
280
+ const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
281
+ if (!doc)
275
282
  return;
276
283
  const range = (_f = (_e = doc.getSelfOrHeaderFooterModel(info.segmentId).getBody()) == null ? void 0 : _e.customRanges) == null ? void 0 : _f.find((i) => i.rangeId === linkId);
277
284
  if (this._showingLink$.next({ unitId, linkId, segmentId, segmentPage }), !!range)
@@ -285,24 +292,25 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
285
292
  },
286
293
  {
287
294
  componentKey: DocLinkPopup.componentKey,
288
- direction: "top",
295
+ direction: "top-center",
296
+ multipleDirection: "top",
289
297
  closeOnSelfTarget: !0,
290
298
  onClickOutside: /* @__PURE__ */ __name(() => {
291
299
  this.hideInfoPopup();
292
300
  }, "onClickOutside")
293
- }
301
+ },
302
+ info.unitId
294
303
  ), this._infoPopup;
295
304
  }
296
305
  hideInfoPopup() {
297
- var _a9;
298
- this._showingLink$.next(null), (_a9 = this._infoPopup) == null || _a9.dispose();
306
+ var _a7;
307
+ this._showingLink$.next(null), (_a7 = this._infoPopup) == null || _a7.dispose();
299
308
  }
300
309
  }, __name(_a, "DocHyperLinkPopupService"), _a);
301
- DocHyperLinkPopupService = __decorateClass$7([
302
- __decorateParam$7(0, Inject(DocCanvasPopManagerService)),
303
- __decorateParam$7(1, Inject(TextSelectionManagerService)),
304
- __decorateParam$7(2, Inject(DocHyperLinkModel)),
305
- __decorateParam$7(3, IUniverInstanceService)
310
+ DocHyperLinkPopupService = __decorateClass$5([
311
+ __decorateParam$5(0, Inject(DocCanvasPopManagerService)),
312
+ __decorateParam$5(1, Inject(TextSelectionManagerService)),
313
+ __decorateParam$5(2, IUniverInstanceService)
306
314
  ], DocHyperLinkPopupService);
307
315
  const AddDocHyperLinkCommand = {
308
316
  type: CommandType.COMMAND,
@@ -314,17 +322,13 @@ const AddDocHyperLinkCommand = {
314
322
  accessor,
315
323
  {
316
324
  rangeId: id,
317
- rangeType: CustomRangeType.HYPERLINK
325
+ rangeType: CustomRangeType.HYPERLINK,
326
+ properties: {
327
+ url: payload
328
+ }
318
329
  }
319
330
  );
320
- if (doMutation) {
321
- const hyperLinkMutation = {
322
- id: AddDocHyperLinkMutation.id,
323
- params: { unitId, link: { payload, id } }
324
- };
325
- return (await sequenceExecute([hyperLinkMutation, doMutation], commandService)).result;
326
- }
327
- return !1;
331
+ return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
328
332
  }
329
333
  }, UpdateDocHyperLinkCommand = {
330
334
  id: "docs.command.update-hyper-link",
@@ -336,14 +340,17 @@ const AddDocHyperLinkCommand = {
336
340
  if (!currentSelection)
337
341
  return !1;
338
342
  const newId = generateRandomId(), replaceSelection = replaceSelectionFactory(accessor, {
339
- unitId: params.unitId,
343
+ unitId,
340
344
  body: {
341
345
  dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
342
346
  customRanges: [{
343
347
  rangeId: newId,
344
348
  rangeType: CustomRangeType.HYPERLINK,
345
349
  startIndex: 0,
346
- endIndex: params.label.length + 1
350
+ endIndex: params.label.length + 1,
351
+ properties: {
352
+ url: payload
353
+ }
347
354
  }]
348
355
  },
349
356
  selection: {
@@ -353,19 +360,7 @@ const AddDocHyperLinkCommand = {
353
360
  segmentId
354
361
  }
355
362
  });
356
- if (!replaceSelection)
357
- return !1;
358
- const addLinkMutation = {
359
- id: AddDocHyperLinkMutation.id,
360
- params: {
361
- unitId,
362
- link: {
363
- id: newId,
364
- payload
365
- }
366
- }
367
- };
368
- return sequenceExecute([addLinkMutation, replaceSelection], commandService).result;
363
+ return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
369
364
  }
370
365
  }, docsLinkEdit = "univer-docs-link-edit", docsLinkEditTitle = "univer-docs-link-edit-title", docsLinkEditClose = "univer-docs-link-edit-close", docsLinkEditButtons = "univer-docs-link-edit-buttons", docsLinkEditButton = "univer-docs-link-edit-button", styles = {
371
366
  docsLinkEdit,
@@ -387,25 +382,20 @@ function transformUrl(urlStr) {
387
382
  }
388
383
  __name(transformUrl, "transformUrl");
389
384
  const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
390
- const hyperLinkService = useDependency(DocHyperLinkPopupService), localeService = useDependency(LocaleService), hyperLinkModel = useDependency(DocHyperLinkModel), editing = useObservable$1(hyperLinkService.editingLink$), commandService = useDependency(ICommandService), univerInstanceService = useDependency(IUniverInstanceService), textSelectionRenderManager = useDependency(ITextSelectionRenderManager), textSelectionManagerService = useDependency(TextSelectionManagerService), [link, setLink] = useState(""), [label, setLabel] = useState(""), [showError, setShowError] = useState(!1), isLegal = Tools.isLegalUrl(link), doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
385
+ const hyperLinkService = useDependency(DocHyperLinkPopupService), localeService = useDependency(LocaleService), editing = useObservable$1(hyperLinkService.editingLink$), commandService = useDependency(ICommandService), univerInstanceService = useDependency(IUniverInstanceService), textSelectionRenderManager = useDependency(ITextSelectionRenderManager), textSelectionManagerService = useDependency(TextSelectionManagerService), [link, setLink] = useState(""), [label, setLabel] = useState(""), [showError, setShowError] = useState(!1), isLegal = Tools.isLegalUrl(link), doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
391
386
  useEffect(() => {
392
- var _a9, _b, _c, _d, _e, _f, _g;
387
+ var _a7, _b, _c, _d, _e, _f, _g, _h, _i;
393
388
  const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
394
389
  if (!activeRange)
395
390
  return;
396
391
  if (editing) {
397
- const linkDetail = editing ? hyperLinkModel.getLink(editing.unitId, editing.linkId) : null;
398
- setLink((_a9 = linkDetail == null ? void 0 : linkDetail.payload) != null ? _a9 : "");
399
- const body = (_b = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(editing.segmentId)) == null ? void 0 : _b.getBody(), matchedRange2 = (_c = body == null ? void 0 : body.customRanges) == null ? void 0 : _c.find((i) => (linkDetail == null ? void 0 : linkDetail.id) === i.rangeId);
400
- doc && matchedRange2 && setLabel(getPlainTextFormBody(getBodySlice(body, matchedRange2.startIndex, matchedRange2.endIndex)));
392
+ const body = (_a7 = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(editing.segmentId)) == null ? void 0 : _a7.getBody(), matchedRange2 = (_b = body == null ? void 0 : body.customRanges) == null ? void 0 : _b.find((i) => (editing == null ? void 0 : editing.linkId) === i.rangeId);
393
+ doc && matchedRange2 && (setLink((_d = (_c = matchedRange2.properties) == null ? void 0 : _c.url) != null ? _d : ""), setLabel(getPlainTextFormBody(getBodySlice(body, matchedRange2.startIndex, matchedRange2.endIndex))));
401
394
  return;
402
395
  }
403
- const matchedRange = (_f = (_e = (_d = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) == null ? void 0 : _d.getBody()) == null ? void 0 : _e.customRanges) == null ? void 0 : _f.find((i) => Math.max(activeRange.startOffset, i.startIndex) <= Math.min(activeRange.endOffset - 1, i.endIndex));
404
- if (doc && matchedRange) {
405
- const linkDetail = hyperLinkModel.getLink(doc.getUnitId(), matchedRange.rangeId);
406
- setLink((_g = linkDetail == null ? void 0 : linkDetail.payload) != null ? _g : "");
407
- }
408
- }, [doc, editing, hyperLinkModel, textSelectionManagerService, univerInstanceService]), useEffect(() => (textSelectionRenderManager.blurEditor(), () => {
396
+ const matchedRange = (_g = (_f = (_e = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) == null ? void 0 : _e.getBody()) == null ? void 0 : _f.customRanges) == null ? void 0 : _g.find((i) => Math.max(activeRange.startOffset, i.startIndex) <= Math.min(activeRange.endOffset - 1, i.endIndex));
397
+ doc && matchedRange && setLink((_i = (_h = matchedRange == null ? void 0 : matchedRange.properties) == null ? void 0 : _h.url) != null ? _i : "");
398
+ }, [doc, editing, textSelectionManagerService, univerInstanceService]), useEffect(() => (textSelectionRenderManager.blurEditor(), () => {
409
399
  textSelectionRenderManager.focusEditor();
410
400
  }), [textSelectionRenderManager]);
411
401
  const handleCancel = /* @__PURE__ */ __name(() => {
@@ -437,7 +427,7 @@ const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
437
427
  FormLayout,
438
428
  {
439
429
  label: localeService.t("docLink.edit.label"),
440
- error: showError && !isLegal ? localeService.t("docLink.edit.labelError") : ""
430
+ error: showError && !label ? localeService.t("docLink.edit.labelError") : ""
441
431
  },
442
432
  /* @__PURE__ */ React.createElement(
443
433
  Input,
@@ -490,12 +480,10 @@ const DOC_LINK_ICON = "doc-hyper-link-icon";
490
480
  function AddHyperLinkMenuItemFactory(accessor) {
491
481
  return {
492
482
  id: ShowDocHyperLinkEditPopupOperation.id,
493
- group: MenuGroup.CONTEXT_MENU_DATA,
494
483
  type: MenuItemType.BUTTON,
495
484
  icon: DOC_LINK_ICON,
496
485
  title: "docLink.menu.tooltip",
497
486
  tooltip: "docLink.menu.tooltip",
498
- positions: [MenuPosition.TOOLBAR_START, MenuPosition.CONTEXT_MENU],
499
487
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
500
488
  disabled$: new Observable(function(subscribe) {
501
489
  const observer = accessor.get(TextSelectionManagerService).textSelection$.pipe(debounceTime(16)).subscribe(() => {
@@ -513,15 +501,30 @@ const addLinkShortcut = {
513
501
  binding: MetaKeys.CTRL_COMMAND | KeyCode.K,
514
502
  description: "docLink.menu.tooltip",
515
503
  preconditions: whenDocAndEditorFocused
504
+ }, menuSchema = {
505
+ [RibbonStartGroup.OTHERS]: {
506
+ [ShowDocHyperLinkEditPopupOperation.id]: {
507
+ order: 0,
508
+ menuItemFactory: AddHyperLinkMenuItemFactory
509
+ }
510
+ },
511
+ [ContextMenuPosition.MAIN_AREA]: {
512
+ [ContextMenuGroup.DATA]: {
513
+ [ShowDocHyperLinkEditPopupOperation.id]: {
514
+ order: 0,
515
+ menuItemFactory: AddHyperLinkMenuItemFactory
516
+ }
517
+ }
518
+ }
516
519
  };
517
- var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
518
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
520
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
521
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
519
522
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
520
- return kind && result && __defProp$6(target, key, result), result;
521
- }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a2;
523
+ return kind && result && __defProp$4(target, key, result), result;
524
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a2;
522
525
  let DocHyperLinkUIController = (_a2 = class extends Disposable {
523
- constructor(_config, _componentManager, _commandService, _menuService, _injector, _shortcutService) {
524
- super(), this._config = _config, this._componentManager = _componentManager, this._commandService = _commandService, this._menuService = _menuService, this._injector = _injector, this._shortcutService = _shortcutService, this._initComponents(), this._initCommands(), this._initMenus(), this._initShortcut();
526
+ constructor(_componentManager, _commandService, _menuManagerService, _injector, _shortcutService) {
527
+ super(), this._componentManager = _componentManager, this._commandService = _commandService, this._menuManagerService = _menuManagerService, this._injector = _injector, this._shortcutService = _shortcutService, this._initComponents(), this._initCommands(), this._initMenus(), this._initShortcut();
525
528
  }
526
529
  _initComponents() {
527
530
  [
@@ -550,36 +553,34 @@ let DocHyperLinkUIController = (_a2 = class extends Disposable {
550
553
  });
551
554
  }
552
555
  _initMenus() {
553
- [AddHyperLinkMenuItemFactory].forEach((menuFactory) => {
554
- this.disposeWithMe(this._menuService.addMenuItem(menuFactory(this._injector), {}));
555
- });
556
+ this._menuManagerService.mergeMenu(menuSchema);
556
557
  }
557
558
  }, __name(_a2, "DocHyperLinkUIController"), _a2);
558
- DocHyperLinkUIController = __decorateClass$6([
559
+ DocHyperLinkUIController = __decorateClass$4([
559
560
  OnLifecycle(LifecycleStages.Starting, DocHyperLinkUIController),
560
- __decorateParam$6(1, Inject(ComponentManager)),
561
- __decorateParam$6(2, ICommandService),
562
- __decorateParam$6(3, IMenuService),
563
- __decorateParam$6(4, Inject(Injector)),
564
- __decorateParam$6(5, IShortcutService)
561
+ __decorateParam$4(0, Inject(ComponentManager)),
562
+ __decorateParam$4(1, ICommandService),
563
+ __decorateParam$4(2, IMenuManagerService),
564
+ __decorateParam$4(3, Inject(Injector)),
565
+ __decorateParam$4(4, IShortcutService)
565
566
  ], DocHyperLinkUIController);
566
- var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
567
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
567
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
568
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
568
569
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
569
- return kind && result && __defProp$5(target, key, result), result;
570
- }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a3;
570
+ return kind && result && __defProp$3(target, key, result), result;
571
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a3;
571
572
  let DocHyperLinkSelectionController = (_a3 = class extends Disposable {
572
- constructor(_commandService, _univerInstanceService, _docHyperLinkService, _renderMangerService) {
573
- super(), this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._docHyperLinkService = _docHyperLinkService, this._renderMangerService = _renderMangerService, this._initSelectionChange();
573
+ constructor(_commandService, _univerInstanceService, _docHyperLinkService) {
574
+ super(), this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._docHyperLinkService = _docHyperLinkService, this._initSelectionChange();
574
575
  }
575
576
  _initSelectionChange() {
576
577
  this.disposeWithMe(
577
578
  this._commandService.onCommandExecuted((commandInfo) => {
578
- var _a9, _b, _c;
579
+ var _a7, _b, _c;
579
580
  if (commandInfo.id === SetTextSelectionsOperation.id) {
580
581
  const params = commandInfo.params, { unitId, ranges, segmentId } = params, doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), primary = ranges[0];
581
582
  if (primary && doc) {
582
- const { startOffset, endOffset, collapsed, segmentPage } = primary, customRanges = (_b = (_a9 = doc.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a9.getBody()) == null ? void 0 : _b.customRanges;
583
+ const { startOffset, endOffset, collapsed, segmentPage } = primary, customRanges = (_b = (_a7 = doc.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a7.getBody()) == null ? void 0 : _b.customRanges;
583
584
  if (collapsed) {
584
585
  const index = (_c = customRanges == null ? void 0 : customRanges.findIndex((value) => value.startIndex < startOffset && value.endIndex > endOffset - 1)) != null ? _c : -1;
585
586
  if (index > -1) {
@@ -596,18 +597,17 @@ let DocHyperLinkSelectionController = (_a3 = class extends Disposable {
596
597
  );
597
598
  }
598
599
  }, __name(_a3, "DocHyperLinkSelectionController"), _a3);
599
- DocHyperLinkSelectionController = __decorateClass$5([
600
+ DocHyperLinkSelectionController = __decorateClass$3([
600
601
  OnLifecycle(LifecycleStages.Ready, DocHyperLinkSelectionController),
601
- __decorateParam$5(0, ICommandService),
602
- __decorateParam$5(1, IUniverInstanceService),
603
- __decorateParam$5(2, Inject(DocHyperLinkPopupService)),
604
- __decorateParam$5(3, IRenderManagerService)
602
+ __decorateParam$3(0, ICommandService),
603
+ __decorateParam$3(1, IUniverInstanceService),
604
+ __decorateParam$3(2, Inject(DocHyperLinkPopupService))
605
605
  ], DocHyperLinkSelectionController);
606
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
607
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
606
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
607
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
608
608
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
609
- return kind && result && __defProp$4(target, key, result), result;
610
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a4;
609
+ return kind && result && __defProp$2(target, key, result), result;
610
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a4;
611
611
  let DocHyperLinkRenderController = (_a4 = class extends Disposable {
612
612
  constructor(_context, _docInterceptorService, _hyperLinkService, _docRenderController) {
613
613
  super(), this._context = _context, this._docInterceptorService = _docInterceptorService, this._hyperLinkService = _hyperLinkService, this._docRenderController = _docRenderController, this._init(), this._initReRender();
@@ -634,157 +634,19 @@ let DocHyperLinkRenderController = (_a4 = class extends Disposable {
634
634
  }));
635
635
  }
636
636
  }, __name(_a4, "DocHyperLinkRenderController"), _a4);
637
- DocHyperLinkRenderController = __decorateClass$4([
638
- __decorateParam$4(1, Inject(DocInterceptorService)),
639
- __decorateParam$4(2, Inject(DocHyperLinkPopupService)),
640
- __decorateParam$4(3, Inject(DocRenderController))
637
+ DocHyperLinkRenderController = __decorateClass$2([
638
+ __decorateParam$2(1, Inject(DocInterceptorService)),
639
+ __decorateParam$2(2, Inject(DocHyperLinkPopupService)),
640
+ __decorateParam$2(3, Inject(DocRenderController))
641
641
  ], DocHyperLinkRenderController);
642
- var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
643
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
644
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
645
- return kind && result && __defProp$3(target, key, result), result;
646
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a5;
647
- let DocHyperLinkClipboardController = (_a5 = class extends Disposable {
648
- constructor(_docClipboardService, _univerInstanceService, _hyperLinkModel, _textSelectionManagerService, _commandService) {
649
- super(), this._docClipboardService = _docClipboardService, this._univerInstanceService = _univerInstanceService, this._hyperLinkModel = _hyperLinkModel, this._textSelectionManagerService = _textSelectionManagerService, this._commandService = _commandService, this._initClipboard();
650
- }
651
- _initClipboard() {
652
- this.disposeWithMe(this._docClipboardService.addClipboardHook({
653
- onBeforePaste: /* @__PURE__ */ __name((body) => {
654
- var _a9, _b;
655
- const doc = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
656
- if (!doc)
657
- return body;
658
- const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), customRanges = (_a9 = doc.getBody()) == null ? void 0 : _a9.customRanges;
659
- if (activeRange ? customRanges == null ? void 0 : customRanges.find(
660
- (range) => range.rangeType === CustomRangeType.HYPERLINK && range.startIndex < activeRange.startOffset && range.endIndex > activeRange.endOffset - 1
661
- ) : null) {
662
- const { customRanges: customRanges2 = [], ...extBody } = body, deleteIndexes = customRanges2.filter((range) => range.rangeType === CustomRangeType.HYPERLINK).map((i) => [i.startIndex, i.endIndex]).flat().sort((pre, aft) => pre - aft), bodyWithoutLink = {
663
- ...extBody,
664
- customRanges: customRanges2.filter((range) => range.rangeType !== CustomRangeType.HYPERLINK)
665
- };
666
- for (let i = 0; i < deleteIndexes.length; i++)
667
- updateAttributeByDelete(bodyWithoutLink, 1, deleteIndexes[i] - i);
668
- return bodyWithoutLink;
669
- } else {
670
- const unitId = doc.getUnitId(), customRangeIds = new Set(customRanges == null ? void 0 : customRanges.map((i) => i.rangeType === CustomRangeType.HYPERLINK && i.rangeId));
671
- (_b = body.customRanges) == null || _b.forEach((range) => {
672
- var _a10;
673
- if (range.rangeType === CustomRangeType.HYPERLINK) {
674
- if (customRangeIds.has(range.rangeId)) {
675
- const link = this._hyperLinkModel.getLink(unitId, range.rangeId);
676
- if (link) {
677
- const newId = Tools.generateRandomId();
678
- this._commandService.executeCommand(
679
- AddDocHyperLinkMutation.id,
680
- {
681
- unitId,
682
- link: {
683
- id: newId,
684
- payload: link.payload
685
- }
686
- }
687
- ), range.rangeId = newId;
688
- }
689
- } else if ((_a10 = body.payloads) != null && _a10[range.rangeId]) {
690
- const url = body.payloads[range.rangeId];
691
- this._commandService.executeCommand(
692
- AddDocHyperLinkMutation.id,
693
- {
694
- unitId,
695
- link: {
696
- id: range.rangeId,
697
- payload: url
698
- }
699
- }
700
- );
701
- }
702
- }
703
- });
704
- }
705
- return body;
706
- }, "onBeforePaste")
707
- }));
708
- }
709
- }, __name(_a5, "DocHyperLinkClipboardController"), _a5);
710
- DocHyperLinkClipboardController = __decorateClass$3([
711
- OnLifecycle(LifecycleStages.Ready, DocHyperLinkClipboardController),
712
- __decorateParam$3(0, Inject(IDocClipboardService)),
713
- __decorateParam$3(1, IUniverInstanceService),
714
- __decorateParam$3(2, Inject(DocHyperLinkModel)),
715
- __decorateParam$3(3, Inject(TextSelectionManagerService)),
716
- __decorateParam$3(4, ICommandService)
717
- ], DocHyperLinkClipboardController);
718
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
719
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
720
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
721
- return kind && result && __defProp$2(target, key, result), result;
722
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a6;
723
- let DocHyperLinkCustomRangeController = (_a6 = class extends Disposable {
724
- constructor(_docCustomRangeService, _docHyperLinkModel, _commandService) {
725
- super(), this._docCustomRangeService = _docCustomRangeService, this._docHyperLinkModel = _docHyperLinkModel, this._commandService = _commandService, this._initCustomRangeHooks();
726
- }
727
- _initCustomRangeHooks() {
728
- this.disposeWithMe(
729
- this._docCustomRangeService.addClipboardHook({
730
- onCopyCustomRange: /* @__PURE__ */ __name((unitId, range) => {
731
- const { rangeId, rangeType, data, ...ext } = range;
732
- if (rangeType === CustomRangeType.HYPERLINK) {
733
- if (data) {
734
- const id = Tools.generateRandomId();
735
- return this._commandService.executeCommand(
736
- AddDocHyperLinkMutation.id,
737
- {
738
- unitId,
739
- link: {
740
- id,
741
- payload: data
742
- }
743
- }
744
- ), {
745
- ...range,
746
- rangeId: id
747
- };
748
- }
749
- const link = this._docHyperLinkModel.getLink(unitId, rangeId);
750
- if (!link)
751
- return range;
752
- const newId = Tools.generateRandomId();
753
- return this._commandService.executeCommand(
754
- AddDocHyperLinkMutation.id,
755
- {
756
- unitId,
757
- link: {
758
- id: newId,
759
- payload: link.payload
760
- }
761
- }
762
- ), {
763
- ...ext,
764
- rangeId: newId,
765
- rangeType
766
- };
767
- }
768
- return range;
769
- }, "onCopyCustomRange")
770
- })
771
- );
772
- }
773
- }, __name(_a6, "DocHyperLinkCustomRangeController"), _a6);
774
- DocHyperLinkCustomRangeController = __decorateClass$2([
775
- OnLifecycle(LifecycleStages.Ready, DocHyperLinkCustomRangeController),
776
- __decorateParam$2(0, Inject(DocCustomRangeService)),
777
- __decorateParam$2(1, Inject(DocHyperLinkModel)),
778
- __decorateParam$2(2, ICommandService)
779
- ], DocHyperLinkCustomRangeController);
780
642
  var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
781
643
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
782
644
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
783
645
  return kind && result && __defProp$1(target, key, result), result;
784
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a7;
785
- let DocHyperLinkEventRenderController = (_a7 = class extends Disposable {
786
- constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService) {
787
- super(), this._context = _context, this._docEventManagerService = _docEventManagerService, this._commandService = _commandService, this._hyperLinkPopupService = _hyperLinkPopupService, this._docSkeletonManagerService = _docSkeletonManagerService, this._initHover(), this._initClick();
646
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a5;
647
+ let DocHyperLinkEventRenderController = (_a5 = class extends Disposable {
648
+ constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _textSelectionManagerService) {
649
+ super(), this._context = _context, this._docEventManagerService = _docEventManagerService, this._commandService = _commandService, this._hyperLinkPopupService = _hyperLinkPopupService, this._docSkeletonManagerService = _docSkeletonManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._initHover(), this._initClick();
788
650
  }
789
651
  get _skeleton() {
790
652
  return this._docSkeletonManagerService.getSkeleton();
@@ -797,8 +659,9 @@ let DocHyperLinkEventRenderController = (_a7 = class extends Disposable {
797
659
  _initHover() {
798
660
  this.disposeWithMe(
799
661
  this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
800
- const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK), editArea = this._skeleton.getViewModel().getEditArea();
801
- if (link != null && link.segmentId && editArea === DocumentEditArea.BODY || !(link != null && link.segmentId) && editArea !== DocumentEditArea.BODY) {
662
+ var _a7;
663
+ const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK), activeRanges = this._textSelectionManagerService.getCurrentTextRanges(), currentSegmentId = activeRanges == null ? void 0 : activeRanges[0].segmentId;
664
+ if (((_a7 = link == null ? void 0 : link.segmentId) != null ? _a7 : "") !== currentSegmentId) {
802
665
  this._hideInfoPopup();
803
666
  return;
804
667
  }
@@ -823,40 +686,38 @@ let DocHyperLinkEventRenderController = (_a7 = class extends Disposable {
823
686
  ClickDocHyperLinkOperation.id,
824
687
  {
825
688
  unitId: this._context.unitId,
826
- linkId: link.rangeId
689
+ linkId: link.rangeId,
690
+ segmentId: range.segmentId
827
691
  }
828
692
  );
829
693
  })
830
694
  );
831
695
  }
832
- }, __name(_a7, "DocHyperLinkEventRenderController"), _a7);
696
+ }, __name(_a5, "DocHyperLinkEventRenderController"), _a5);
833
697
  DocHyperLinkEventRenderController = __decorateClass$1([
834
698
  __decorateParam$1(1, Inject(DocEventManagerService)),
835
699
  __decorateParam$1(2, ICommandService),
836
700
  __decorateParam$1(3, Inject(DocHyperLinkPopupService)),
837
- __decorateParam$1(4, Inject(DocSkeletonManagerService))
701
+ __decorateParam$1(4, Inject(DocSkeletonManagerService)),
702
+ __decorateParam$1(5, Inject(TextSelectionManagerService))
838
703
  ], DocHyperLinkEventRenderController);
704
+ const PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config", defaultPluginConfig = {};
839
705
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
840
706
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
841
707
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
842
708
  return kind && result && __defProp2(target, key, result), result;
843
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a8;
844
- let UniverDocsHyperLinkUIPlugin = (_a8 = class extends Plugin {
845
- constructor(_config = { menu: {} }, _injector, _renderManagerSrv) {
846
- super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv;
709
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a6;
710
+ let UniverDocsHyperLinkUIPlugin = (_a6 = class extends Plugin {
711
+ constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
712
+ super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv, this._configService = _configService;
713
+ const { menu, ...rest } = this._config;
714
+ menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
847
715
  }
848
716
  onStarting() {
849
717
  [
850
718
  [DocHyperLinkPopupService],
851
- [
852
- DocHyperLinkUIController,
853
- {
854
- useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(DocHyperLinkUIController, this._config), "useFactory")
855
- }
856
- ],
857
- [DocHyperLinkSelectionController],
858
- [DocHyperLinkClipboardController],
859
- [DocHyperLinkCustomRangeController]
719
+ [DocHyperLinkUIController],
720
+ [DocHyperLinkSelectionController]
860
721
  ].forEach((dep) => {
861
722
  this._injector.add(dep);
862
723
  });
@@ -872,13 +733,14 @@ let UniverDocsHyperLinkUIPlugin = (_a8 = class extends Plugin {
872
733
  this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, dep);
873
734
  });
874
735
  }
875
- }, __name(_a8, "UniverDocsHyperLinkUIPlugin"), _a8);
736
+ }, __name(_a6, "UniverDocsHyperLinkUIPlugin"), _a6);
876
737
  __publicField2(UniverDocsHyperLinkUIPlugin, "pluginName", DOC_HYPER_LINK_UI_PLUGIN);
877
738
  __publicField2(UniverDocsHyperLinkUIPlugin, "type", UniverInstanceType.UNIVER_DOC);
878
739
  UniverDocsHyperLinkUIPlugin = __decorateClass([
879
740
  DependentOn(UniverDocsHyperLinkPlugin),
880
741
  __decorateParam(1, Inject(Injector)),
881
- __decorateParam(2, IRenderManagerService)
742
+ __decorateParam(2, IRenderManagerService),
743
+ __decorateParam(3, IConfigService)
882
744
  ], UniverDocsHyperLinkUIPlugin);
883
745
  export {
884
746
  UniverDocsHyperLinkUIPlugin