@univerjs/docs-hyper-link-ui 0.2.7 → 0.2.9
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/cjs/index.js +1 -1
- package/lib/es/index.js +290 -146
- package/lib/index.css +1 -1
- package/lib/locale/en-US.json +4 -2
- package/lib/locale/ru-RU.json +3 -1
- package/lib/locale/vi-VN.json +3 -1
- package/lib/locale/zh-CN.json +3 -1
- package/lib/locale/zh-TW.json +3 -1
- package/lib/types/commands/commands/add-link.command.d.ts +0 -1
- package/lib/types/commands/commands/delete-link.command.d.ts +1 -1
- package/lib/types/commands/commands/update-link.command.d.ts +2 -1
- package/lib/types/commands/operations/popup.operation.d.ts +13 -2
- package/lib/types/controllers/doc-hyper-link-clipboard.controller.d.ts +0 -1
- package/lib/types/controllers/doc-hyper-link-custom-range.controller.d.ts +0 -1
- package/lib/types/controllers/doc-hyper-link-selection.controller.d.ts +0 -1
- package/lib/types/controllers/menu.d.ts +0 -1
- package/lib/types/controllers/render-controllers/hyper-link-event.render-controller.d.ts +17 -0
- package/lib/types/controllers/render-controllers/render.controller.d.ts +0 -1
- package/lib/types/controllers/ui.controller.d.ts +0 -1
- package/lib/types/locale/en-US.d.ts +0 -1
- package/lib/types/locale/ru-RU.d.ts +0 -1
- package/lib/types/locale/vi-VN.d.ts +0 -1
- package/lib/types/locale/zh-CN.d.ts +2 -0
- package/lib/types/locale/zh-TW.d.ts +0 -1
- package/lib/types/plugin.d.ts +0 -1
- package/lib/types/services/hyper-link-popup.service.d.ts +4 -5
- package/lib/types/views/hyper-link-edit/index.d.ts +0 -1
- package/lib/types/views/hyper-link-popup/index.d.ts +0 -1
- package/lib/umd/index.js +1 -1
- package/package.json +17 -17
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, useDependency, LocaleService, Disposable, Inject, generateRandomId,
|
|
6
|
-
import { DocHyperLinkModel, AddDocHyperLinkMutation,
|
|
7
|
-
import { IRenderManagerService, DocumentEditArea
|
|
8
|
-
import { IMessageService, useObservable,
|
|
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";
|
|
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,
|
|
12
|
-
import { DocCanvasPopManagerService, whenDocAndEditorFocused, DocRenderController, IDocClipboardService } from "@univerjs/docs-ui";
|
|
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";
|
|
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(
|
|
46
|
-
var key =
|
|
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];
|
|
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
|
|
53
|
-
return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((
|
|
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) {
|
|
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
|
}
|
|
@@ -60,14 +60,6 @@ function generateShortUuid() {
|
|
|
60
60
|
}
|
|
61
61
|
__name(generateShortUuid, "generateShortUuid");
|
|
62
62
|
IconBase.displayName = "UniverIcon";
|
|
63
|
-
var element$4 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z" } }] }, CloseSingle = forwardRef(function(props, ref) {
|
|
64
|
-
return createElement(IconBase, Object.assign({}, props, {
|
|
65
|
-
id: "close-single",
|
|
66
|
-
ref,
|
|
67
|
-
icon: element$4
|
|
68
|
-
}));
|
|
69
|
-
});
|
|
70
|
-
CloseSingle.displayName = "CloseSingle";
|
|
71
63
|
var element$3 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, CopySingle = forwardRef(function(props, ref) {
|
|
72
64
|
return createElement(IconBase, Object.assign({}, props, {
|
|
73
65
|
id: "copy-single",
|
|
@@ -106,21 +98,21 @@ const DeleteDocHyperLinkCommand = {
|
|
|
106
98
|
async handler(accessor, params) {
|
|
107
99
|
if (!params)
|
|
108
100
|
return !1;
|
|
109
|
-
const { unitId, linkId } = params, commandService = accessor.get(ICommandService);
|
|
101
|
+
const { unitId, linkId, segmentId } = params, commandService = accessor.get(ICommandService);
|
|
110
102
|
if (!accessor.get(DocHyperLinkModel).getLink(unitId, linkId))
|
|
111
103
|
return !1;
|
|
112
|
-
const doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId });
|
|
104
|
+
const doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId, segmentId });
|
|
113
105
|
return doMutation ? await commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
|
|
114
106
|
}
|
|
115
107
|
}, shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
|
|
116
|
-
var
|
|
117
|
-
const textSelectionService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges =
|
|
118
|
-
if (
|
|
108
|
+
var _a9;
|
|
109
|
+
const textSelectionService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges = textSelectionService.getDocRanges();
|
|
110
|
+
if (!textRanges.length || textRanges.length > 1)
|
|
119
111
|
return !0;
|
|
120
112
|
const activeRange = textRanges[0], doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
121
113
|
if (!doc || !activeRange || activeRange.collapsed)
|
|
122
114
|
return !0;
|
|
123
|
-
const
|
|
115
|
+
const body = doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody(), paragraphs = body == null ? void 0 : body.paragraphs;
|
|
124
116
|
if (!paragraphs)
|
|
125
117
|
return !0;
|
|
126
118
|
for (let i = 0, len = paragraphs.length; i < len; i++) {
|
|
@@ -130,14 +122,30 @@ const DeleteDocHyperLinkCommand = {
|
|
|
130
122
|
if (p.startIndex > activeRange.endOffset)
|
|
131
123
|
break;
|
|
132
124
|
}
|
|
133
|
-
return !
|
|
125
|
+
return !getCustomRangesInterestsWithRange(activeRange, (_a9 = body.customRanges) != null ? _a9 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
|
|
134
126
|
}, "shouldDisableAddLink"), ShowDocHyperLinkEditPopupOperation = {
|
|
135
127
|
type: CommandType.OPERATION,
|
|
136
|
-
id: "
|
|
128
|
+
id: "doc.operation.show-hyper-link-edit-popup",
|
|
137
129
|
handler(accessor, params) {
|
|
138
130
|
const linkInfo = params == null ? void 0 : params.link;
|
|
139
131
|
return shouldDisableAddLink(accessor) && !linkInfo ? !1 : (accessor.get(DocHyperLinkPopupService).showEditPopup(linkInfo), !0);
|
|
140
132
|
}
|
|
133
|
+
}, ToggleDocHyperLinkInfoPopupOperation = {
|
|
134
|
+
type: CommandType.OPERATION,
|
|
135
|
+
id: "doc.operation.toggle-hyper-link-info-popup",
|
|
136
|
+
handler(accessor, params) {
|
|
137
|
+
const hyperLinkService = accessor.get(DocHyperLinkPopupService);
|
|
138
|
+
return params ? (hyperLinkService.showInfoPopup(params), !0) : (hyperLinkService.hideInfoPopup(), !0);
|
|
139
|
+
}
|
|
140
|
+
}, ClickDocHyperLinkOperation = {
|
|
141
|
+
type: CommandType.OPERATION,
|
|
142
|
+
id: "doc.operation.click-hyper-link",
|
|
143
|
+
handler(accessor, params) {
|
|
144
|
+
if (!params)
|
|
145
|
+
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
|
+
}
|
|
141
149
|
}, 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 = {
|
|
142
150
|
docLink,
|
|
143
151
|
docLinkType,
|
|
@@ -151,7 +159,7 @@ const DeleteDocHyperLinkCommand = {
|
|
|
151
159
|
const hyperLinkService = useDependency(DocHyperLinkPopupService), hyperLinkModel = useDependency(DocHyperLinkModel), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService), currentPopup = useObservable(hyperLinkService.showingLink$);
|
|
152
160
|
if (!currentPopup)
|
|
153
161
|
return null;
|
|
154
|
-
const { unitId, linkId } = currentPopup, link = hyperLinkModel.getLink(unitId, linkId);
|
|
162
|
+
const { unitId, linkId, segmentId } = currentPopup, link = hyperLinkModel.getLink(unitId, linkId);
|
|
155
163
|
return link ? /* @__PURE__ */ React.createElement(
|
|
156
164
|
"div",
|
|
157
165
|
{
|
|
@@ -191,7 +199,8 @@ const DeleteDocHyperLinkCommand = {
|
|
|
191
199
|
onClick: /* @__PURE__ */ __name(() => {
|
|
192
200
|
commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
|
|
193
201
|
unitId,
|
|
194
|
-
linkId: link.id
|
|
202
|
+
linkId: link.id,
|
|
203
|
+
segmentId
|
|
195
204
|
});
|
|
196
205
|
}, "onClick")
|
|
197
206
|
},
|
|
@@ -200,15 +209,15 @@ const DeleteDocHyperLinkCommand = {
|
|
|
200
209
|
) : null;
|
|
201
210
|
}, "DocLinkPopup");
|
|
202
211
|
DocLinkPopup.componentKey = "univer.doc.link-info-popup";
|
|
203
|
-
var __defProp$
|
|
204
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
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--)
|
|
205
214
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
206
|
-
return kind && result && __defProp$
|
|
207
|
-
}, "__decorateClass$
|
|
208
|
-
const SKIT_PLACEHOLDER =
|
|
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");
|
|
217
|
+
const SKIT_PLACEHOLDER = 0;
|
|
209
218
|
var _a;
|
|
210
219
|
let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
211
|
-
constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _docHyperLinkModel, _univerInstanceService
|
|
220
|
+
constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _docHyperLinkModel, _univerInstanceService) {
|
|
212
221
|
super();
|
|
213
222
|
__publicField(this, "_editingLink$", new BehaviorSubject(null));
|
|
214
223
|
__publicField(this, "_showingLink$", new BehaviorSubject(null));
|
|
@@ -216,7 +225,7 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
216
225
|
__publicField(this, "showingLink$", this._showingLink$.asObservable());
|
|
217
226
|
__publicField(this, "_editPopup", null);
|
|
218
227
|
__publicField(this, "_infoPopup", null);
|
|
219
|
-
this._docCanvasPopupManagerService = _docCanvasPopupManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._docHyperLinkModel = _docHyperLinkModel, this._univerInstanceService = _univerInstanceService, this.
|
|
228
|
+
this._docCanvasPopupManagerService = _docCanvasPopupManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._docHyperLinkModel = _docHyperLinkModel, this._univerInstanceService = _univerInstanceService, this.disposeWithMe(() => {
|
|
220
229
|
this._editingLink$.complete(), this._showingLink$.complete();
|
|
221
230
|
});
|
|
222
231
|
}
|
|
@@ -227,21 +236,23 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
227
236
|
return this._showingLink$.value;
|
|
228
237
|
}
|
|
229
238
|
showEditPopup(linkInfo) {
|
|
230
|
-
var
|
|
239
|
+
var _a9, _b, _c;
|
|
231
240
|
this._editPopup && this._editPopup.dispose(), this._editingLink$.next(linkInfo);
|
|
232
241
|
let activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
233
242
|
if (linkInfo) {
|
|
234
|
-
const { unitId,
|
|
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);
|
|
235
244
|
range && (activeRange = {
|
|
236
245
|
collapsed: !1,
|
|
237
|
-
startOffset: range.startIndex,
|
|
238
|
-
endOffset: range.endIndex + 1
|
|
246
|
+
startOffset: range.startIndex + SKIT_PLACEHOLDER,
|
|
247
|
+
endOffset: range.endIndex + 1,
|
|
248
|
+
segmentId,
|
|
249
|
+
segmentPage
|
|
239
250
|
}, this._textSelectionManagerService.replaceTextRanges([{
|
|
240
251
|
startOffset: range.startIndex,
|
|
241
252
|
endOffset: range.endIndex + 1
|
|
242
253
|
}]));
|
|
243
254
|
}
|
|
244
|
-
return activeRange ? (
|
|
255
|
+
return activeRange ? (this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(
|
|
245
256
|
activeRange,
|
|
246
257
|
{
|
|
247
258
|
componentKey: DocHyperLinkEdit.componentKey,
|
|
@@ -250,25 +261,27 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
250
261
|
), this._editPopup) : null;
|
|
251
262
|
}
|
|
252
263
|
hideEditPopup() {
|
|
253
|
-
var
|
|
254
|
-
this._editingLink$.next(null), (
|
|
264
|
+
var _a9;
|
|
265
|
+
this._editingLink$.next(null), (_a9 = this._editPopup) == null || _a9.dispose();
|
|
255
266
|
}
|
|
256
267
|
showInfoPopup(info) {
|
|
257
|
-
var
|
|
258
|
-
const { linkId, unitId,
|
|
259
|
-
if (((
|
|
268
|
+
var _a9, _b, _c, _d, _e, _f;
|
|
269
|
+
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)
|
|
260
271
|
return;
|
|
261
272
|
this._infoPopup && this._infoPopup.dispose();
|
|
262
273
|
const link = this._docHyperLinkModel.getLink(unitId, linkId), doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
263
274
|
if (!doc || !link)
|
|
264
275
|
return;
|
|
265
|
-
const range = (
|
|
266
|
-
if (this._showingLink$.next({ unitId, linkId,
|
|
276
|
+
const range = (_f = (_e = doc.getSelfOrHeaderFooterModel(info.segmentId).getBody()) == null ? void 0 : _e.customRanges) == null ? void 0 : _f.find((i) => i.rangeId === linkId);
|
|
277
|
+
if (this._showingLink$.next({ unitId, linkId, segmentId, segmentPage }), !!range)
|
|
267
278
|
return this._infoPopup = this._docCanvasPopupManagerService.attachPopupToRange(
|
|
268
279
|
{
|
|
269
280
|
collapsed: !1,
|
|
270
281
|
startOffset: range.startIndex + SKIT_PLACEHOLDER,
|
|
271
|
-
endOffset: range.endIndex + 1
|
|
282
|
+
endOffset: range.endIndex + 1,
|
|
283
|
+
segmentId: info.segmentId,
|
|
284
|
+
segmentPage: info.segmentPage
|
|
272
285
|
},
|
|
273
286
|
{
|
|
274
287
|
componentKey: DocLinkPopup.componentKey,
|
|
@@ -281,16 +294,15 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
281
294
|
), this._infoPopup;
|
|
282
295
|
}
|
|
283
296
|
hideInfoPopup() {
|
|
284
|
-
var
|
|
285
|
-
this._showingLink$.next(null), (
|
|
297
|
+
var _a9;
|
|
298
|
+
this._showingLink$.next(null), (_a9 = this._infoPopup) == null || _a9.dispose();
|
|
286
299
|
}
|
|
287
300
|
}, __name(_a, "DocHyperLinkPopupService"), _a);
|
|
288
|
-
DocHyperLinkPopupService = __decorateClass$
|
|
289
|
-
__decorateParam$
|
|
290
|
-
__decorateParam$
|
|
291
|
-
__decorateParam$
|
|
292
|
-
__decorateParam$
|
|
293
|
-
__decorateParam$6(4, ICommandService)
|
|
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)
|
|
294
306
|
], DocHyperLinkPopupService);
|
|
295
307
|
const AddDocHyperLinkCommand = {
|
|
296
308
|
type: CommandType.COMMAND,
|
|
@@ -310,7 +322,7 @@ const AddDocHyperLinkCommand = {
|
|
|
310
322
|
id: AddDocHyperLinkMutation.id,
|
|
311
323
|
params: { unitId, link: { payload, id } }
|
|
312
324
|
};
|
|
313
|
-
return (await
|
|
325
|
+
return (await sequenceExecute([hyperLinkMutation, doMutation], commandService)).result;
|
|
314
326
|
}
|
|
315
327
|
return !1;
|
|
316
328
|
}
|
|
@@ -318,7 +330,42 @@ const AddDocHyperLinkCommand = {
|
|
|
318
330
|
id: "docs.command.update-hyper-link",
|
|
319
331
|
type: CommandType.COMMAND,
|
|
320
332
|
handler(accessor, params) {
|
|
321
|
-
|
|
333
|
+
if (!params)
|
|
334
|
+
return !1;
|
|
335
|
+
const { unitId, payload, segmentId } = params, commandService = accessor.get(ICommandService), currentSelection = accessor.get(TextSelectionManagerService).getActiveTextRange();
|
|
336
|
+
if (!currentSelection)
|
|
337
|
+
return !1;
|
|
338
|
+
const newId = generateRandomId(), replaceSelection = replaceSelectionFactory(accessor, {
|
|
339
|
+
unitId: params.unitId,
|
|
340
|
+
body: {
|
|
341
|
+
dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
|
|
342
|
+
customRanges: [{
|
|
343
|
+
rangeId: newId,
|
|
344
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
345
|
+
startIndex: 0,
|
|
346
|
+
endIndex: params.label.length + 1
|
|
347
|
+
}]
|
|
348
|
+
},
|
|
349
|
+
selection: {
|
|
350
|
+
startOffset: currentSelection.startOffset,
|
|
351
|
+
endOffset: currentSelection.endOffset,
|
|
352
|
+
collapsed: !1,
|
|
353
|
+
segmentId
|
|
354
|
+
}
|
|
355
|
+
});
|
|
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;
|
|
322
369
|
}
|
|
323
370
|
}, 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 = {
|
|
324
371
|
docsLinkEdit,
|
|
@@ -340,23 +387,25 @@ function transformUrl(urlStr) {
|
|
|
340
387
|
}
|
|
341
388
|
__name(transformUrl, "transformUrl");
|
|
342
389
|
const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
|
|
343
|
-
const hyperLinkService = useDependency(DocHyperLinkPopupService), localeService = useDependency(LocaleService), hyperLinkModel = useDependency(DocHyperLinkModel),
|
|
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);
|
|
344
391
|
useEffect(() => {
|
|
345
|
-
var
|
|
346
|
-
if (editingId) {
|
|
347
|
-
const linkDetail = editingId ? hyperLinkModel.getLink(editingId.unitId, editingId.linkId) : null;
|
|
348
|
-
setLink((_a8 = linkDetail == null ? void 0 : linkDetail.payload) != null ? _a8 : "");
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
392
|
+
var _a9, _b, _c, _d, _e, _f, _g;
|
|
351
393
|
const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
352
394
|
if (!activeRange)
|
|
353
395
|
return;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
396
|
+
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)));
|
|
401
|
+
return;
|
|
358
402
|
}
|
|
359
|
-
|
|
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(), () => {
|
|
360
409
|
textSelectionRenderManager.focusEditor();
|
|
361
410
|
}), [textSelectionRenderManager]);
|
|
362
411
|
const handleCancel = /* @__PURE__ */ __name(() => {
|
|
@@ -365,23 +414,59 @@ const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
|
|
|
365
414
|
if (setShowError(!0), !isLegal || !doc)
|
|
366
415
|
return;
|
|
367
416
|
const linkFinal = transformUrl(link);
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
417
|
+
if (!editing)
|
|
418
|
+
commandService.executeCommand(AddDocHyperLinkCommand.id, {
|
|
419
|
+
unitId: doc.getUnitId(),
|
|
420
|
+
payload: linkFinal
|
|
421
|
+
});
|
|
422
|
+
else {
|
|
423
|
+
if (!label)
|
|
424
|
+
return;
|
|
425
|
+
commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
|
|
426
|
+
unitId: doc.getUnitId(),
|
|
427
|
+
payload: linkFinal,
|
|
428
|
+
linkId: editing.linkId,
|
|
429
|
+
label,
|
|
430
|
+
segmentId: editing.segmentId
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
hyperLinkService.hideEditPopup();
|
|
376
434
|
}, "handleConfirm");
|
|
377
435
|
if (doc)
|
|
378
|
-
return /* @__PURE__ */ React.createElement("div", { className: styles.docsLinkEdit }, /* @__PURE__ */ React.createElement("div",
|
|
436
|
+
return /* @__PURE__ */ React.createElement("div", { className: styles.docsLinkEdit }, /* @__PURE__ */ React.createElement("div", null, editing ? /* @__PURE__ */ React.createElement(
|
|
437
|
+
FormLayout,
|
|
438
|
+
{
|
|
439
|
+
label: localeService.t("docLink.edit.label"),
|
|
440
|
+
error: showError && !isLegal ? localeService.t("docLink.edit.labelError") : ""
|
|
441
|
+
},
|
|
442
|
+
/* @__PURE__ */ React.createElement(
|
|
443
|
+
Input,
|
|
444
|
+
{
|
|
445
|
+
value: label,
|
|
446
|
+
onChange: setLabel,
|
|
447
|
+
autoFocus: !0,
|
|
448
|
+
onKeyDown: /* @__PURE__ */ __name((evt) => {
|
|
449
|
+
evt.keyCode === KeyCode.ENTER && handleConfirm();
|
|
450
|
+
}, "onKeyDown")
|
|
451
|
+
}
|
|
452
|
+
)
|
|
453
|
+
) : null, /* @__PURE__ */ React.createElement(
|
|
379
454
|
FormLayout,
|
|
380
455
|
{
|
|
381
456
|
label: localeService.t("docLink.edit.address"),
|
|
382
457
|
error: showError && !isLegal ? localeService.t("docLink.edit.addressError") : ""
|
|
383
458
|
},
|
|
384
|
-
/* @__PURE__ */ React.createElement(
|
|
459
|
+
/* @__PURE__ */ React.createElement(
|
|
460
|
+
Input,
|
|
461
|
+
{
|
|
462
|
+
value: link,
|
|
463
|
+
onChange: setLink,
|
|
464
|
+
autoFocus: !0,
|
|
465
|
+
onKeyDown: /* @__PURE__ */ __name((evt) => {
|
|
466
|
+
evt.keyCode === KeyCode.ENTER && handleConfirm();
|
|
467
|
+
}, "onKeyDown")
|
|
468
|
+
}
|
|
469
|
+
)
|
|
385
470
|
)), /* @__PURE__ */ React.createElement("div", { className: styles.docsLinkEditButtons }, /* @__PURE__ */ React.createElement(
|
|
386
471
|
Button,
|
|
387
472
|
{
|
|
@@ -429,11 +514,11 @@ const addLinkShortcut = {
|
|
|
429
514
|
description: "docLink.menu.tooltip",
|
|
430
515
|
preconditions: whenDocAndEditorFocused
|
|
431
516
|
};
|
|
432
|
-
var __defProp$
|
|
433
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
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--)
|
|
434
519
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
435
|
-
return kind && result && __defProp$
|
|
436
|
-
}, "__decorateClass$
|
|
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;
|
|
437
522
|
let DocHyperLinkUIController = (_a2 = class extends Disposable {
|
|
438
523
|
constructor(_config, _componentManager, _commandService, _menuService, _injector, _shortcutService) {
|
|
439
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();
|
|
@@ -452,7 +537,9 @@ let DocHyperLinkUIController = (_a2 = class extends Disposable {
|
|
|
452
537
|
AddDocHyperLinkCommand,
|
|
453
538
|
UpdateDocHyperLinkCommand,
|
|
454
539
|
DeleteDocHyperLinkCommand,
|
|
455
|
-
ShowDocHyperLinkEditPopupOperation
|
|
540
|
+
ShowDocHyperLinkEditPopupOperation,
|
|
541
|
+
ToggleDocHyperLinkInfoPopupOperation,
|
|
542
|
+
ClickDocHyperLinkOperation
|
|
456
543
|
].forEach((command) => {
|
|
457
544
|
this._commandService.registerCommand(command);
|
|
458
545
|
});
|
|
@@ -468,19 +555,19 @@ let DocHyperLinkUIController = (_a2 = class extends Disposable {
|
|
|
468
555
|
});
|
|
469
556
|
}
|
|
470
557
|
}, __name(_a2, "DocHyperLinkUIController"), _a2);
|
|
471
|
-
DocHyperLinkUIController = __decorateClass$
|
|
558
|
+
DocHyperLinkUIController = __decorateClass$6([
|
|
472
559
|
OnLifecycle(LifecycleStages.Starting, DocHyperLinkUIController),
|
|
473
|
-
__decorateParam$
|
|
474
|
-
__decorateParam$
|
|
475
|
-
__decorateParam$
|
|
476
|
-
__decorateParam$
|
|
477
|
-
__decorateParam$
|
|
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)
|
|
478
565
|
], DocHyperLinkUIController);
|
|
479
|
-
var __defProp$
|
|
480
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
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--)
|
|
481
568
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
482
|
-
return kind && result && __defProp$
|
|
483
|
-
}, "__decorateClass$
|
|
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;
|
|
484
571
|
let DocHyperLinkSelectionController = (_a3 = class extends Disposable {
|
|
485
572
|
constructor(_commandService, _univerInstanceService, _docHyperLinkService, _renderMangerService) {
|
|
486
573
|
super(), this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._docHyperLinkService = _docHyperLinkService, this._renderMangerService = _renderMangerService, this._initSelectionChange();
|
|
@@ -488,24 +575,19 @@ let DocHyperLinkSelectionController = (_a3 = class extends Disposable {
|
|
|
488
575
|
_initSelectionChange() {
|
|
489
576
|
this.disposeWithMe(
|
|
490
577
|
this._commandService.onCommandExecuted((commandInfo) => {
|
|
491
|
-
var
|
|
578
|
+
var _a9, _b, _c;
|
|
492
579
|
if (commandInfo.id === SetTextSelectionsOperation.id) {
|
|
493
|
-
const params = commandInfo.params, { unitId, ranges } = params,
|
|
494
|
-
if ((skeleton == null ? void 0 : skeleton.getViewModel().getEditArea()) !== DocumentEditArea.BODY) {
|
|
495
|
-
this._docHyperLinkService.hideInfoPopup(), this._docHyperLinkService.hideEditPopup();
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), primary = ranges[0];
|
|
580
|
+
const params = commandInfo.params, { unitId, ranges, segmentId } = params, doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), primary = ranges[0];
|
|
499
581
|
if (primary && doc) {
|
|
500
|
-
const { startOffset, endOffset, collapsed } = primary, customRanges = (
|
|
582
|
+
const { startOffset, endOffset, collapsed, segmentPage } = primary, customRanges = (_b = (_a9 = doc.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a9.getBody()) == null ? void 0 : _b.customRanges;
|
|
501
583
|
if (collapsed) {
|
|
502
|
-
const index = (
|
|
584
|
+
const index = (_c = customRanges == null ? void 0 : customRanges.findIndex((value) => value.startIndex < startOffset && value.endIndex > endOffset - 1)) != null ? _c : -1;
|
|
503
585
|
if (index > -1) {
|
|
504
586
|
const customRange = customRanges[index];
|
|
505
|
-
this._docHyperLinkService.showInfoPopup({ unitId, linkId: customRange.rangeId,
|
|
587
|
+
this._docHyperLinkService.showInfoPopup({ unitId, linkId: customRange.rangeId, segmentId, segmentPage });
|
|
506
588
|
return;
|
|
507
589
|
}
|
|
508
|
-
} else if (customRanges
|
|
590
|
+
} else if (customRanges == null ? void 0 : customRanges.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1))
|
|
509
591
|
return;
|
|
510
592
|
}
|
|
511
593
|
this._docHyperLinkService.hideInfoPopup(), this._docHyperLinkService.hideEditPopup();
|
|
@@ -514,18 +596,18 @@ let DocHyperLinkSelectionController = (_a3 = class extends Disposable {
|
|
|
514
596
|
);
|
|
515
597
|
}
|
|
516
598
|
}, __name(_a3, "DocHyperLinkSelectionController"), _a3);
|
|
517
|
-
DocHyperLinkSelectionController = __decorateClass$
|
|
599
|
+
DocHyperLinkSelectionController = __decorateClass$5([
|
|
518
600
|
OnLifecycle(LifecycleStages.Ready, DocHyperLinkSelectionController),
|
|
519
|
-
__decorateParam$
|
|
520
|
-
__decorateParam$
|
|
521
|
-
__decorateParam$
|
|
522
|
-
__decorateParam$
|
|
601
|
+
__decorateParam$5(0, ICommandService),
|
|
602
|
+
__decorateParam$5(1, IUniverInstanceService),
|
|
603
|
+
__decorateParam$5(2, Inject(DocHyperLinkPopupService)),
|
|
604
|
+
__decorateParam$5(3, IRenderManagerService)
|
|
523
605
|
], DocHyperLinkSelectionController);
|
|
524
|
-
var __defProp$
|
|
525
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
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--)
|
|
526
608
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
527
|
-
return kind && result && __defProp$
|
|
528
|
-
}, "__decorateClass$
|
|
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;
|
|
529
611
|
let DocHyperLinkRenderController = (_a4 = class extends Disposable {
|
|
530
612
|
constructor(_context, _docInterceptorService, _hyperLinkService, _docRenderController) {
|
|
531
613
|
super(), this._context = _context, this._docInterceptorService = _docInterceptorService, this._hyperLinkService = _hyperLinkService, this._docRenderController = _docRenderController, this._init(), this._initReRender();
|
|
@@ -552,16 +634,16 @@ let DocHyperLinkRenderController = (_a4 = class extends Disposable {
|
|
|
552
634
|
}));
|
|
553
635
|
}
|
|
554
636
|
}, __name(_a4, "DocHyperLinkRenderController"), _a4);
|
|
555
|
-
DocHyperLinkRenderController = __decorateClass$
|
|
556
|
-
__decorateParam$
|
|
557
|
-
__decorateParam$
|
|
558
|
-
__decorateParam$
|
|
637
|
+
DocHyperLinkRenderController = __decorateClass$4([
|
|
638
|
+
__decorateParam$4(1, Inject(DocInterceptorService)),
|
|
639
|
+
__decorateParam$4(2, Inject(DocHyperLinkPopupService)),
|
|
640
|
+
__decorateParam$4(3, Inject(DocRenderController))
|
|
559
641
|
], DocHyperLinkRenderController);
|
|
560
|
-
var __defProp$
|
|
561
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
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--)
|
|
562
644
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
563
|
-
return kind && result && __defProp$
|
|
564
|
-
}, "__decorateClass$
|
|
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;
|
|
565
647
|
let DocHyperLinkClipboardController = (_a5 = class extends Disposable {
|
|
566
648
|
constructor(_docClipboardService, _univerInstanceService, _hyperLinkModel, _textSelectionManagerService, _commandService) {
|
|
567
649
|
super(), this._docClipboardService = _docClipboardService, this._univerInstanceService = _univerInstanceService, this._hyperLinkModel = _hyperLinkModel, this._textSelectionManagerService = _textSelectionManagerService, this._commandService = _commandService, this._initClipboard();
|
|
@@ -569,13 +651,13 @@ let DocHyperLinkClipboardController = (_a5 = class extends Disposable {
|
|
|
569
651
|
_initClipboard() {
|
|
570
652
|
this.disposeWithMe(this._docClipboardService.addClipboardHook({
|
|
571
653
|
onBeforePaste: /* @__PURE__ */ __name((body) => {
|
|
572
|
-
var
|
|
654
|
+
var _a9, _b;
|
|
573
655
|
const doc = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
574
656
|
if (!doc)
|
|
575
657
|
return body;
|
|
576
|
-
const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), customRanges = (
|
|
658
|
+
const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), customRanges = (_a9 = doc.getBody()) == null ? void 0 : _a9.customRanges;
|
|
577
659
|
if (activeRange ? customRanges == null ? void 0 : customRanges.find(
|
|
578
|
-
(range) => range.rangeType === CustomRangeType.HYPERLINK && range.startIndex
|
|
660
|
+
(range) => range.rangeType === CustomRangeType.HYPERLINK && range.startIndex < activeRange.startOffset && range.endIndex > activeRange.endOffset - 1
|
|
579
661
|
) : null) {
|
|
580
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 = {
|
|
581
663
|
...extBody,
|
|
@@ -587,7 +669,7 @@ let DocHyperLinkClipboardController = (_a5 = class extends Disposable {
|
|
|
587
669
|
} else {
|
|
588
670
|
const unitId = doc.getUnitId(), customRangeIds = new Set(customRanges == null ? void 0 : customRanges.map((i) => i.rangeType === CustomRangeType.HYPERLINK && i.rangeId));
|
|
589
671
|
(_b = body.customRanges) == null || _b.forEach((range) => {
|
|
590
|
-
var
|
|
672
|
+
var _a10;
|
|
591
673
|
if (range.rangeType === CustomRangeType.HYPERLINK) {
|
|
592
674
|
if (customRangeIds.has(range.rangeId)) {
|
|
593
675
|
const link = this._hyperLinkModel.getLink(unitId, range.rangeId);
|
|
@@ -604,7 +686,7 @@ let DocHyperLinkClipboardController = (_a5 = class extends Disposable {
|
|
|
604
686
|
}
|
|
605
687
|
), range.rangeId = newId;
|
|
606
688
|
}
|
|
607
|
-
} else if ((
|
|
689
|
+
} else if ((_a10 = body.payloads) != null && _a10[range.rangeId]) {
|
|
608
690
|
const url = body.payloads[range.rangeId];
|
|
609
691
|
this._commandService.executeCommand(
|
|
610
692
|
AddDocHyperLinkMutation.id,
|
|
@@ -625,19 +707,19 @@ let DocHyperLinkClipboardController = (_a5 = class extends Disposable {
|
|
|
625
707
|
}));
|
|
626
708
|
}
|
|
627
709
|
}, __name(_a5, "DocHyperLinkClipboardController"), _a5);
|
|
628
|
-
DocHyperLinkClipboardController = __decorateClass$
|
|
710
|
+
DocHyperLinkClipboardController = __decorateClass$3([
|
|
629
711
|
OnLifecycle(LifecycleStages.Ready, DocHyperLinkClipboardController),
|
|
630
|
-
__decorateParam$
|
|
631
|
-
__decorateParam$
|
|
632
|
-
__decorateParam$
|
|
633
|
-
__decorateParam$
|
|
634
|
-
__decorateParam$
|
|
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)
|
|
635
717
|
], DocHyperLinkClipboardController);
|
|
636
|
-
var __defProp$
|
|
637
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
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--)
|
|
638
720
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
639
|
-
return kind && result && __defProp$
|
|
640
|
-
}, "__decorateClass$
|
|
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;
|
|
641
723
|
let DocHyperLinkCustomRangeController = (_a6 = class extends Disposable {
|
|
642
724
|
constructor(_docCustomRangeService, _docHyperLinkModel, _commandService) {
|
|
643
725
|
super(), this._docCustomRangeService = _docCustomRangeService, this._docHyperLinkModel = _docHyperLinkModel, this._commandService = _commandService, this._initCustomRangeHooks();
|
|
@@ -689,18 +771,77 @@ let DocHyperLinkCustomRangeController = (_a6 = class extends Disposable {
|
|
|
689
771
|
);
|
|
690
772
|
}
|
|
691
773
|
}, __name(_a6, "DocHyperLinkCustomRangeController"), _a6);
|
|
692
|
-
DocHyperLinkCustomRangeController = __decorateClass$
|
|
774
|
+
DocHyperLinkCustomRangeController = __decorateClass$2([
|
|
693
775
|
OnLifecycle(LifecycleStages.Ready, DocHyperLinkCustomRangeController),
|
|
694
|
-
__decorateParam$
|
|
695
|
-
__decorateParam$
|
|
696
|
-
__decorateParam$
|
|
776
|
+
__decorateParam$2(0, Inject(DocCustomRangeService)),
|
|
777
|
+
__decorateParam$2(1, Inject(DocHyperLinkModel)),
|
|
778
|
+
__decorateParam$2(2, ICommandService)
|
|
697
779
|
], DocHyperLinkCustomRangeController);
|
|
780
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
781
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
782
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
783
|
+
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();
|
|
788
|
+
}
|
|
789
|
+
get _skeleton() {
|
|
790
|
+
return this._docSkeletonManagerService.getSkeleton();
|
|
791
|
+
}
|
|
792
|
+
_hideInfoPopup() {
|
|
793
|
+
this._hyperLinkPopupService.showing && this._commandService.executeCommand(
|
|
794
|
+
ToggleDocHyperLinkInfoPopupOperation.id
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
_initHover() {
|
|
798
|
+
this.disposeWithMe(
|
|
799
|
+
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) {
|
|
802
|
+
this._hideInfoPopup();
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
link ? this._commandService.executeCommand(
|
|
806
|
+
ToggleDocHyperLinkInfoPopupOperation.id,
|
|
807
|
+
{
|
|
808
|
+
unitId: this._context.unitId,
|
|
809
|
+
linkId: link.range.rangeId,
|
|
810
|
+
segmentId: link.segmentId,
|
|
811
|
+
segmentPage: link.segmentPageIndex,
|
|
812
|
+
rangeId: link.range.rangeId
|
|
813
|
+
}
|
|
814
|
+
) : this._hideInfoPopup();
|
|
815
|
+
})
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
_initClick() {
|
|
819
|
+
this.disposeWithMe(
|
|
820
|
+
this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
|
|
821
|
+
const link = range.range;
|
|
822
|
+
link && this._commandService.executeCommand(
|
|
823
|
+
ClickDocHyperLinkOperation.id,
|
|
824
|
+
{
|
|
825
|
+
unitId: this._context.unitId,
|
|
826
|
+
linkId: link.rangeId
|
|
827
|
+
}
|
|
828
|
+
);
|
|
829
|
+
})
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
}, __name(_a7, "DocHyperLinkEventRenderController"), _a7);
|
|
833
|
+
DocHyperLinkEventRenderController = __decorateClass$1([
|
|
834
|
+
__decorateParam$1(1, Inject(DocEventManagerService)),
|
|
835
|
+
__decorateParam$1(2, ICommandService),
|
|
836
|
+
__decorateParam$1(3, Inject(DocHyperLinkPopupService)),
|
|
837
|
+
__decorateParam$1(4, Inject(DocSkeletonManagerService))
|
|
838
|
+
], DocHyperLinkEventRenderController);
|
|
698
839
|
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) => {
|
|
699
840
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
700
841
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
701
842
|
return kind && result && __defProp2(target, key, result), result;
|
|
702
|
-
}, "__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"),
|
|
703
|
-
let UniverDocsHyperLinkUIPlugin = (
|
|
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 {
|
|
704
845
|
constructor(_config = { menu: {} }, _injector, _renderManagerSrv) {
|
|
705
846
|
super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv;
|
|
706
847
|
}
|
|
@@ -724,11 +865,14 @@ let UniverDocsHyperLinkUIPlugin = (_a7 = class extends Plugin {
|
|
|
724
865
|
this._initRenderModule();
|
|
725
866
|
}
|
|
726
867
|
_initRenderModule() {
|
|
727
|
-
[
|
|
868
|
+
[
|
|
869
|
+
[DocHyperLinkRenderController],
|
|
870
|
+
[DocHyperLinkEventRenderController]
|
|
871
|
+
].forEach((dep) => {
|
|
728
872
|
this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, dep);
|
|
729
873
|
});
|
|
730
874
|
}
|
|
731
|
-
}, __name(
|
|
875
|
+
}, __name(_a8, "UniverDocsHyperLinkUIPlugin"), _a8);
|
|
732
876
|
__publicField2(UniverDocsHyperLinkUIPlugin, "pluginName", DOC_HYPER_LINK_UI_PLUGIN);
|
|
733
877
|
__publicField2(UniverDocsHyperLinkUIPlugin, "type", UniverInstanceType.UNIVER_DOC);
|
|
734
878
|
UniverDocsHyperLinkUIPlugin = __decorateClass([
|