@univerjs/docs-hyper-link-ui 0.2.11 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +205 -337
- package/lib/locale/en-US.json +1 -1
- package/lib/locale/ru-RU.json +1 -1
- package/lib/locale/vi-VN.json +1 -1
- package/lib/locale/zh-CN.json +1 -1
- package/lib/locale/zh-TW.json +1 -1
- package/lib/types/commands/commands/add-link.command.d.ts +2 -1
- package/lib/types/commands/operations/popup.operation.d.ts +1 -0
- package/lib/types/controllers/config.schema.d.ts +7 -0
- package/lib/types/controllers/doc-hyper-link-selection.controller.d.ts +1 -3
- package/lib/types/controllers/menu.schema.d.ts +2 -0
- package/lib/types/controllers/render-controllers/hyper-link-event.render-controller.d.ts +4 -3
- package/lib/types/controllers/ui.controller.d.ts +3 -4
- package/lib/types/locale/zh-CN.d.ts +1 -1
- package/lib/types/plugin.d.ts +5 -4
- package/lib/types/services/hyper-link-popup.service.d.ts +4 -6
- package/lib/umd/index.js +1 -1
- package/package.json +19 -19
- package/lib/types/controllers/doc-hyper-link-clipboard.controller.d.ts +0 -13
- package/lib/types/controllers/doc-hyper-link-custom-range.controller.d.ts +0 -10
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,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { IMessageService, useObservable, KeyCode, MetaKeys,
|
|
5
|
+
import { CommandType, ICommandService, generateRandomId, CustomRangeType, IUniverInstanceService, UniverInstanceType, getBodySlice, DataStreamTreeTokenType, BuildTextUtils, useDependency, LocaleService, Disposable, Inject, useObservable as useObservable$1, Tools, OnLifecycle, LifecycleStages, Injector, DependentOn, Plugin, IConfigService } from "@univerjs/core";
|
|
6
|
+
import { 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
|
+
import { DocSelectionManagerService, SetTextSelectionsOperation, DocInterceptorService, DOC_INTERCEPTOR_POINT, DocSkeletonManagerService } from "@univerjs/docs";
|
|
11
|
+
import { addCustomRangeBySelectionFactory, replaceSelectionFactory, deleteCustomRangeFactory, DocCanvasPopManagerService, DocSelectionRenderService, getPlainTextFormBody, whenDocAndEditorFocused, DocRenderController, DocEventManagerService } from "@univerjs/docs-ui";
|
|
10
12
|
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";
|
|
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(_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
|
|
53
|
-
return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((
|
|
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
|
}
|
|
@@ -92,21 +92,74 @@ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 16", width:
|
|
|
92
92
|
}));
|
|
93
93
|
});
|
|
94
94
|
WriteSingle.displayName = "WriteSingle";
|
|
95
|
-
const
|
|
95
|
+
const AddDocHyperLinkCommand = {
|
|
96
96
|
type: CommandType.COMMAND,
|
|
97
|
-
id: "docs.command.
|
|
97
|
+
id: "docs.command.add-hyper-link",
|
|
98
98
|
async handler(accessor, params) {
|
|
99
99
|
if (!params)
|
|
100
100
|
return !1;
|
|
101
|
-
const {
|
|
102
|
-
|
|
101
|
+
const { payload, unitId, selection } = params, commandService = accessor.get(ICommandService), id = generateRandomId(), doMutation = addCustomRangeBySelectionFactory(
|
|
102
|
+
accessor,
|
|
103
|
+
{
|
|
104
|
+
rangeId: id,
|
|
105
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
106
|
+
properties: {
|
|
107
|
+
url: payload
|
|
108
|
+
},
|
|
109
|
+
unitId,
|
|
110
|
+
selection
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
|
|
114
|
+
}
|
|
115
|
+
}, UpdateDocHyperLinkCommand = {
|
|
116
|
+
id: "docs.command.update-hyper-link",
|
|
117
|
+
type: CommandType.COMMAND,
|
|
118
|
+
handler(accessor, params) {
|
|
119
|
+
var _a7;
|
|
120
|
+
if (!params)
|
|
121
|
+
return !1;
|
|
122
|
+
const { unitId, payload, segmentId } = params, commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), currentSelection = accessor.get(DocSelectionManagerService).getActiveTextRange(), doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
123
|
+
if (!currentSelection || !doc)
|
|
124
|
+
return !1;
|
|
125
|
+
const newId = generateRandomId(), textRun = (_a7 = getBodySlice(doc.getSelfOrHeaderFooterModel(segmentId).getBody(), currentSelection.startOffset, currentSelection.endOffset).textRuns) == null ? void 0 : _a7[0];
|
|
126
|
+
textRun && (textRun.ed = params.label.length + 1);
|
|
127
|
+
const replaceSelection = replaceSelectionFactory(accessor, {
|
|
128
|
+
unitId,
|
|
129
|
+
body: {
|
|
130
|
+
dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
|
|
131
|
+
customRanges: [{
|
|
132
|
+
rangeId: newId,
|
|
133
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
134
|
+
startIndex: 0,
|
|
135
|
+
endIndex: params.label.length + 1,
|
|
136
|
+
properties: {
|
|
137
|
+
url: payload
|
|
138
|
+
}
|
|
139
|
+
}],
|
|
140
|
+
textRuns: textRun ? [textRun] : void 0
|
|
141
|
+
},
|
|
142
|
+
selection: {
|
|
143
|
+
startOffset: currentSelection.startOffset,
|
|
144
|
+
endOffset: currentSelection.endOffset,
|
|
145
|
+
collapsed: !1,
|
|
146
|
+
segmentId
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
|
|
150
|
+
}
|
|
151
|
+
}, DeleteDocHyperLinkCommand = {
|
|
152
|
+
type: CommandType.COMMAND,
|
|
153
|
+
id: "docs.command.delete-hyper-link",
|
|
154
|
+
async handler(accessor, params) {
|
|
155
|
+
if (!params)
|
|
103
156
|
return !1;
|
|
104
|
-
const doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId, segmentId });
|
|
157
|
+
const { unitId, linkId, segmentId } = params, commandService = accessor.get(ICommandService), doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId, segmentId });
|
|
105
158
|
return doMutation ? await commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
|
|
106
159
|
}
|
|
107
160
|
}, shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
|
|
108
|
-
var
|
|
109
|
-
const textSelectionService = accessor.get(
|
|
161
|
+
var _a7;
|
|
162
|
+
const textSelectionService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges = textSelectionService.getDocRanges();
|
|
110
163
|
if (!textRanges.length || textRanges.length > 1)
|
|
111
164
|
return !0;
|
|
112
165
|
const activeRange = textRanges[0], doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
@@ -122,13 +175,17 @@ const DeleteDocHyperLinkCommand = {
|
|
|
122
175
|
if (p.startIndex > activeRange.endOffset)
|
|
123
176
|
break;
|
|
124
177
|
}
|
|
125
|
-
return !getCustomRangesInterestsWithRange(activeRange, (
|
|
178
|
+
return !BuildTextUtils.customRange.getCustomRangesInterestsWithRange(activeRange, (_a7 = body.customRanges) != null ? _a7 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
|
|
126
179
|
}, "shouldDisableAddLink"), ShowDocHyperLinkEditPopupOperation = {
|
|
127
180
|
type: CommandType.OPERATION,
|
|
128
181
|
id: "doc.operation.show-hyper-link-edit-popup",
|
|
129
182
|
handler(accessor, params) {
|
|
130
|
-
|
|
131
|
-
|
|
183
|
+
var _a7;
|
|
184
|
+
const linkInfo = params == null ? void 0 : params.link, univerInstanceService = accessor.get(IUniverInstanceService);
|
|
185
|
+
if (shouldDisableAddLink(accessor) && !linkInfo)
|
|
186
|
+
return !1;
|
|
187
|
+
const hyperLinkService = accessor.get(DocHyperLinkPopupService), unitId = (linkInfo == null ? void 0 : linkInfo.unitId) || ((_a7 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a7.getUnitId());
|
|
188
|
+
return unitId ? (hyperLinkService.showEditPopup(unitId, linkInfo), !0) : !1;
|
|
132
189
|
}
|
|
133
190
|
}, ToggleDocHyperLinkInfoPopupOperation = {
|
|
134
191
|
type: CommandType.OPERATION,
|
|
@@ -141,10 +198,11 @@ const DeleteDocHyperLinkCommand = {
|
|
|
141
198
|
type: CommandType.OPERATION,
|
|
142
199
|
id: "doc.operation.click-hyper-link",
|
|
143
200
|
handler(accessor, params) {
|
|
201
|
+
var _a7, _b, _c;
|
|
144
202
|
if (!params)
|
|
145
203
|
return !1;
|
|
146
|
-
const { unitId, linkId } = params,
|
|
147
|
-
return link
|
|
204
|
+
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;
|
|
205
|
+
return link && window.open(link, "_blank", "noopener noreferrer"), !0;
|
|
148
206
|
}
|
|
149
207
|
}, 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
208
|
docLink,
|
|
@@ -156,11 +214,15 @@ const DeleteDocHyperLinkCommand = {
|
|
|
156
214
|
docLinkOperation,
|
|
157
215
|
docLinkOperationError
|
|
158
216
|
}, DocLinkPopup = /* @__PURE__ */ __name(() => {
|
|
159
|
-
|
|
217
|
+
var _a7, _b;
|
|
218
|
+
const hyperLinkService = useDependency(DocHyperLinkPopupService), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService), currentPopup = useObservable(hyperLinkService.showingLink$), univerInstanceService = useDependency(IUniverInstanceService);
|
|
160
219
|
if (!currentPopup)
|
|
161
220
|
return null;
|
|
162
|
-
const { unitId, linkId, segmentId } = currentPopup,
|
|
163
|
-
|
|
221
|
+
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);
|
|
222
|
+
if (!link)
|
|
223
|
+
return null;
|
|
224
|
+
const url = (_b = link.properties) == null ? void 0 : _b.url;
|
|
225
|
+
return /* @__PURE__ */ React.createElement(
|
|
164
226
|
"div",
|
|
165
227
|
{
|
|
166
228
|
className: styles$1.docLink,
|
|
@@ -168,13 +230,13 @@ const DeleteDocHyperLinkCommand = {
|
|
|
168
230
|
hyperLinkService.hideInfoPopup();
|
|
169
231
|
}, "onClick")
|
|
170
232
|
},
|
|
171
|
-
/* @__PURE__ */ React.createElement("div", { className: cs(styles$1.docLinkContent), onClick: /* @__PURE__ */ __name(() => window.open(
|
|
233
|
+
/* @__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
234
|
/* @__PURE__ */ React.createElement("div", { className: styles$1.docLinkOperations }, /* @__PURE__ */ React.createElement(
|
|
173
235
|
"div",
|
|
174
236
|
{
|
|
175
237
|
className: cs(styles$1.docLinkOperation),
|
|
176
238
|
onClick: /* @__PURE__ */ __name(() => {
|
|
177
|
-
navigator.clipboard.writeText(
|
|
239
|
+
navigator.clipboard.writeText(url), messageService.show({
|
|
178
240
|
content: localeService.t("docLink.info.coped"),
|
|
179
241
|
type: MessageType.Info
|
|
180
242
|
});
|
|
@@ -199,25 +261,25 @@ const DeleteDocHyperLinkCommand = {
|
|
|
199
261
|
onClick: /* @__PURE__ */ __name(() => {
|
|
200
262
|
commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
|
|
201
263
|
unitId,
|
|
202
|
-
linkId: link.
|
|
264
|
+
linkId: link.rangeId,
|
|
203
265
|
segmentId
|
|
204
266
|
});
|
|
205
267
|
}, "onClick")
|
|
206
268
|
},
|
|
207
269
|
/* @__PURE__ */ React.createElement(Tooltip, { placement: "bottom", title: localeService.t("docLink.info.cancel") }, /* @__PURE__ */ React.createElement(UnlinkSingle, null))
|
|
208
270
|
))
|
|
209
|
-
)
|
|
271
|
+
);
|
|
210
272
|
}, "DocLinkPopup");
|
|
211
273
|
DocLinkPopup.componentKey = "univer.doc.link-info-popup";
|
|
212
|
-
var __defProp$
|
|
213
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
274
|
+
var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
275
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
214
276
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
215
|
-
return kind && result && __defProp$
|
|
216
|
-
}, "__decorateClass$
|
|
277
|
+
return kind && result && __defProp$5(target, key, result), result;
|
|
278
|
+
}, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5");
|
|
217
279
|
const SKIT_PLACEHOLDER = 0;
|
|
218
280
|
var _a;
|
|
219
281
|
let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
220
|
-
constructor(_docCanvasPopupManagerService, _textSelectionManagerService,
|
|
282
|
+
constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService) {
|
|
221
283
|
super();
|
|
222
284
|
__publicField(this, "_editingLink$", new BehaviorSubject(null));
|
|
223
285
|
__publicField(this, "_showingLink$", new BehaviorSubject(null));
|
|
@@ -225,7 +287,7 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
225
287
|
__publicField(this, "showingLink$", this._showingLink$.asObservable());
|
|
226
288
|
__publicField(this, "_editPopup", null);
|
|
227
289
|
__publicField(this, "_infoPopup", null);
|
|
228
|
-
this._docCanvasPopupManagerService = _docCanvasPopupManagerService, this._textSelectionManagerService = _textSelectionManagerService, this.
|
|
290
|
+
this._docCanvasPopupManagerService = _docCanvasPopupManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this.disposeWithMe(() => {
|
|
229
291
|
this._editingLink$.complete(), this._showingLink$.complete();
|
|
230
292
|
});
|
|
231
293
|
}
|
|
@@ -235,12 +297,12 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
235
297
|
get showing() {
|
|
236
298
|
return this._showingLink$.value;
|
|
237
299
|
}
|
|
238
|
-
showEditPopup(linkInfo) {
|
|
239
|
-
var
|
|
300
|
+
showEditPopup(unitId, linkInfo) {
|
|
301
|
+
var _a7, _b, _c;
|
|
240
302
|
this._editPopup && this._editPopup.dispose(), this._editingLink$.next(linkInfo);
|
|
241
|
-
let activeRange = this._textSelectionManagerService.
|
|
303
|
+
let activeRange = this._textSelectionManagerService.getActiveTextRange();
|
|
242
304
|
if (linkInfo) {
|
|
243
|
-
const { unitId, linkId, segmentId, segmentPage } = linkInfo, doc = this._univerInstanceService.getUnit(
|
|
305
|
+
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
306
|
range && (activeRange = {
|
|
245
307
|
collapsed: !1,
|
|
246
308
|
startOffset: range.startIndex + SKIT_PLACEHOLDER,
|
|
@@ -257,21 +319,22 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
257
319
|
{
|
|
258
320
|
componentKey: DocHyperLinkEdit.componentKey,
|
|
259
321
|
direction: "bottom"
|
|
260
|
-
}
|
|
322
|
+
},
|
|
323
|
+
unitId
|
|
261
324
|
), this._editPopup) : null;
|
|
262
325
|
}
|
|
263
326
|
hideEditPopup() {
|
|
264
|
-
var
|
|
265
|
-
this._editingLink$.next(null), (
|
|
327
|
+
var _a7;
|
|
328
|
+
this._editingLink$.next(null), (_a7 = this._editPopup) == null || _a7.dispose();
|
|
266
329
|
}
|
|
267
330
|
showInfoPopup(info) {
|
|
268
|
-
var
|
|
331
|
+
var _a7, _b, _c, _d, _e, _f;
|
|
269
332
|
const { linkId, unitId, segmentId, segmentPage } = info;
|
|
270
|
-
if (((
|
|
333
|
+
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
334
|
return;
|
|
272
335
|
this._infoPopup && this._infoPopup.dispose();
|
|
273
|
-
const
|
|
274
|
-
if (!doc
|
|
336
|
+
const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
337
|
+
if (!doc)
|
|
275
338
|
return;
|
|
276
339
|
const range = (_f = (_e = doc.getSelfOrHeaderFooterModel(info.segmentId).getBody()) == null ? void 0 : _e.customRanges) == null ? void 0 : _f.find((i) => i.rangeId === linkId);
|
|
277
340
|
if (this._showingLink$.next({ unitId, linkId, segmentId, segmentPage }), !!range)
|
|
@@ -285,89 +348,26 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
285
348
|
},
|
|
286
349
|
{
|
|
287
350
|
componentKey: DocLinkPopup.componentKey,
|
|
288
|
-
direction: "top",
|
|
289
|
-
|
|
351
|
+
direction: "top-center",
|
|
352
|
+
multipleDirection: "top",
|
|
290
353
|
onClickOutside: /* @__PURE__ */ __name(() => {
|
|
291
354
|
this.hideInfoPopup();
|
|
292
355
|
}, "onClickOutside")
|
|
293
|
-
}
|
|
356
|
+
},
|
|
357
|
+
info.unitId
|
|
294
358
|
), this._infoPopup;
|
|
295
359
|
}
|
|
296
360
|
hideInfoPopup() {
|
|
297
|
-
var
|
|
298
|
-
this._showingLink$.next(null), (
|
|
361
|
+
var _a7;
|
|
362
|
+
this._showingLink$.next(null), (_a7 = this._infoPopup) == null || _a7.dispose();
|
|
299
363
|
}
|
|
300
364
|
}, __name(_a, "DocHyperLinkPopupService"), _a);
|
|
301
|
-
DocHyperLinkPopupService = __decorateClass$
|
|
302
|
-
__decorateParam$
|
|
303
|
-
__decorateParam$
|
|
304
|
-
__decorateParam$
|
|
305
|
-
__decorateParam$7(3, IUniverInstanceService)
|
|
365
|
+
DocHyperLinkPopupService = __decorateClass$5([
|
|
366
|
+
__decorateParam$5(0, Inject(DocCanvasPopManagerService)),
|
|
367
|
+
__decorateParam$5(1, Inject(DocSelectionManagerService)),
|
|
368
|
+
__decorateParam$5(2, IUniverInstanceService)
|
|
306
369
|
], DocHyperLinkPopupService);
|
|
307
|
-
const
|
|
308
|
-
type: CommandType.COMMAND,
|
|
309
|
-
id: "docs.command.add-hyper-link",
|
|
310
|
-
async handler(accessor, params) {
|
|
311
|
-
if (!params)
|
|
312
|
-
return !1;
|
|
313
|
-
const { payload, unitId } = params, commandService = accessor.get(ICommandService), id = generateRandomId(), doMutation = addCustomRangeBySelectionFactory(
|
|
314
|
-
accessor,
|
|
315
|
-
{
|
|
316
|
-
rangeId: id,
|
|
317
|
-
rangeType: CustomRangeType.HYPERLINK
|
|
318
|
-
}
|
|
319
|
-
);
|
|
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;
|
|
328
|
-
}
|
|
329
|
-
}, UpdateDocHyperLinkCommand = {
|
|
330
|
-
id: "docs.command.update-hyper-link",
|
|
331
|
-
type: CommandType.COMMAND,
|
|
332
|
-
handler(accessor, params) {
|
|
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;
|
|
369
|
-
}
|
|
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 = {
|
|
370
|
+
const 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
371
|
docsLinkEdit,
|
|
372
372
|
docsLinkEditTitle,
|
|
373
373
|
docsLinkEditClose,
|
|
@@ -387,27 +387,23 @@ function transformUrl(urlStr) {
|
|
|
387
387
|
}
|
|
388
388
|
__name(transformUrl, "transformUrl");
|
|
389
389
|
const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
|
|
390
|
-
|
|
390
|
+
var _a7;
|
|
391
|
+
const hyperLinkService = useDependency(DocHyperLinkPopupService), localeService = useDependency(LocaleService), editing = useObservable$1(hyperLinkService.editingLink$), commandService = useDependency(ICommandService), univerInstanceService = useDependency(IUniverInstanceService), renderManagerService = useDependency(IRenderManagerService), docSelectionManagerService = useDependency(DocSelectionManagerService), [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), docSelectionRenderService = (_a7 = renderManagerService.getRenderById(doc.getUnitId())) == null ? void 0 : _a7.with(DocSelectionRenderService);
|
|
391
392
|
useEffect(() => {
|
|
392
|
-
var
|
|
393
|
-
const activeRange =
|
|
393
|
+
var _a8, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
394
|
+
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
394
395
|
if (!activeRange)
|
|
395
396
|
return;
|
|
396
397
|
if (editing) {
|
|
397
|
-
const
|
|
398
|
-
setLink((
|
|
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)));
|
|
398
|
+
const body = (_a8 = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(editing.segmentId)) == null ? void 0 : _a8.getBody(), matchedRange2 = (_b = body == null ? void 0 : body.customRanges) == null ? void 0 : _b.find((i) => (editing == null ? void 0 : editing.linkId) === i.rangeId);
|
|
399
|
+
doc && matchedRange2 && (setLink((_d = (_c = matchedRange2.properties) == null ? void 0 : _c.url) != null ? _d : ""), setLabel(getPlainTextFormBody(getBodySlice(body, matchedRange2.startIndex, matchedRange2.endIndex))));
|
|
401
400
|
return;
|
|
402
401
|
}
|
|
403
|
-
const matchedRange = (
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}, [doc, editing, hyperLinkModel, textSelectionManagerService, univerInstanceService]), useEffect(() => (textSelectionRenderManager.blurEditor(), () => {
|
|
409
|
-
textSelectionRenderManager.focusEditor();
|
|
410
|
-
}), [textSelectionRenderManager]);
|
|
402
|
+
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));
|
|
403
|
+
doc && matchedRange && setLink((_i = (_h = matchedRange == null ? void 0 : matchedRange.properties) == null ? void 0 : _h.url) != null ? _i : "");
|
|
404
|
+
}, [doc, editing, docSelectionManagerService, univerInstanceService]), useEffect(() => (docSelectionRenderService && docSelectionRenderService.blurEditor(), () => {
|
|
405
|
+
docSelectionRenderService && docSelectionRenderService.focusEditor();
|
|
406
|
+
}), [docSelectionRenderService]);
|
|
411
407
|
const handleCancel = /* @__PURE__ */ __name(() => {
|
|
412
408
|
hyperLinkService.hideEditPopup();
|
|
413
409
|
}, "handleCancel"), handleConfirm = /* @__PURE__ */ __name(() => {
|
|
@@ -437,7 +433,7 @@ const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
|
|
|
437
433
|
FormLayout,
|
|
438
434
|
{
|
|
439
435
|
label: localeService.t("docLink.edit.label"),
|
|
440
|
-
error: showError && !
|
|
436
|
+
error: showError && !label ? localeService.t("docLink.edit.labelError") : ""
|
|
441
437
|
},
|
|
442
438
|
/* @__PURE__ */ React.createElement(
|
|
443
439
|
Input,
|
|
@@ -490,15 +486,13 @@ const DOC_LINK_ICON = "doc-hyper-link-icon";
|
|
|
490
486
|
function AddHyperLinkMenuItemFactory(accessor) {
|
|
491
487
|
return {
|
|
492
488
|
id: ShowDocHyperLinkEditPopupOperation.id,
|
|
493
|
-
group: MenuGroup.CONTEXT_MENU_DATA,
|
|
494
489
|
type: MenuItemType.BUTTON,
|
|
495
490
|
icon: DOC_LINK_ICON,
|
|
496
491
|
title: "docLink.menu.tooltip",
|
|
497
492
|
tooltip: "docLink.menu.tooltip",
|
|
498
|
-
positions: [MenuPosition.TOOLBAR_START, MenuPosition.CONTEXT_MENU],
|
|
499
493
|
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
|
|
500
494
|
disabled$: new Observable(function(subscribe) {
|
|
501
|
-
const observer = accessor.get(
|
|
495
|
+
const observer = accessor.get(DocSelectionManagerService).textSelection$.pipe(debounceTime(16)).subscribe(() => {
|
|
502
496
|
subscribe.next(shouldDisableAddLink(accessor));
|
|
503
497
|
});
|
|
504
498
|
return () => {
|
|
@@ -513,15 +507,30 @@ const addLinkShortcut = {
|
|
|
513
507
|
binding: MetaKeys.CTRL_COMMAND | KeyCode.K,
|
|
514
508
|
description: "docLink.menu.tooltip",
|
|
515
509
|
preconditions: whenDocAndEditorFocused
|
|
510
|
+
}, menuSchema = {
|
|
511
|
+
[RibbonStartGroup.OTHERS]: {
|
|
512
|
+
[ShowDocHyperLinkEditPopupOperation.id]: {
|
|
513
|
+
order: 0,
|
|
514
|
+
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
[ContextMenuPosition.MAIN_AREA]: {
|
|
518
|
+
[ContextMenuGroup.DATA]: {
|
|
519
|
+
[ShowDocHyperLinkEditPopupOperation.id]: {
|
|
520
|
+
order: 0,
|
|
521
|
+
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
516
525
|
};
|
|
517
|
-
var __defProp$
|
|
518
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
526
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
527
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
519
528
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
520
|
-
return kind && result && __defProp$
|
|
521
|
-
}, "__decorateClass$
|
|
529
|
+
return kind && result && __defProp$4(target, key, result), result;
|
|
530
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a2;
|
|
522
531
|
let DocHyperLinkUIController = (_a2 = class extends Disposable {
|
|
523
|
-
constructor(
|
|
524
|
-
super(), this.
|
|
532
|
+
constructor(_componentManager, _commandService, _menuManagerService, _injector, _shortcutService) {
|
|
533
|
+
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
534
|
}
|
|
526
535
|
_initComponents() {
|
|
527
536
|
[
|
|
@@ -550,36 +559,34 @@ let DocHyperLinkUIController = (_a2 = class extends Disposable {
|
|
|
550
559
|
});
|
|
551
560
|
}
|
|
552
561
|
_initMenus() {
|
|
553
|
-
|
|
554
|
-
this.disposeWithMe(this._menuService.addMenuItem(menuFactory(this._injector), {}));
|
|
555
|
-
});
|
|
562
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
556
563
|
}
|
|
557
564
|
}, __name(_a2, "DocHyperLinkUIController"), _a2);
|
|
558
|
-
DocHyperLinkUIController = __decorateClass$
|
|
565
|
+
DocHyperLinkUIController = __decorateClass$4([
|
|
559
566
|
OnLifecycle(LifecycleStages.Starting, DocHyperLinkUIController),
|
|
560
|
-
__decorateParam$
|
|
561
|
-
__decorateParam$
|
|
562
|
-
__decorateParam$
|
|
563
|
-
__decorateParam$
|
|
564
|
-
__decorateParam$
|
|
567
|
+
__decorateParam$4(0, Inject(ComponentManager)),
|
|
568
|
+
__decorateParam$4(1, ICommandService),
|
|
569
|
+
__decorateParam$4(2, IMenuManagerService),
|
|
570
|
+
__decorateParam$4(3, Inject(Injector)),
|
|
571
|
+
__decorateParam$4(4, IShortcutService)
|
|
565
572
|
], DocHyperLinkUIController);
|
|
566
|
-
var __defProp$
|
|
567
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
573
|
+
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
574
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
568
575
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
569
|
-
return kind && result && __defProp$
|
|
570
|
-
}, "__decorateClass$
|
|
576
|
+
return kind && result && __defProp$3(target, key, result), result;
|
|
577
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a3;
|
|
571
578
|
let DocHyperLinkSelectionController = (_a3 = class extends Disposable {
|
|
572
|
-
constructor(_commandService, _univerInstanceService, _docHyperLinkService
|
|
573
|
-
super(), this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._docHyperLinkService = _docHyperLinkService, this.
|
|
579
|
+
constructor(_commandService, _univerInstanceService, _docHyperLinkService) {
|
|
580
|
+
super(), this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._docHyperLinkService = _docHyperLinkService, this._initSelectionChange();
|
|
574
581
|
}
|
|
575
582
|
_initSelectionChange() {
|
|
576
583
|
this.disposeWithMe(
|
|
577
584
|
this._commandService.onCommandExecuted((commandInfo) => {
|
|
578
|
-
var
|
|
585
|
+
var _a7, _b, _c;
|
|
579
586
|
if (commandInfo.id === SetTextSelectionsOperation.id) {
|
|
580
587
|
const params = commandInfo.params, { unitId, ranges, segmentId } = params, doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), primary = ranges[0];
|
|
581
588
|
if (primary && doc) {
|
|
582
|
-
const { startOffset, endOffset, collapsed, segmentPage } = primary, customRanges = (_b = (
|
|
589
|
+
const { startOffset, endOffset, collapsed, segmentPage } = primary, customRanges = (_b = (_a7 = doc.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a7.getBody()) == null ? void 0 : _b.customRanges;
|
|
583
590
|
if (collapsed) {
|
|
584
591
|
const index = (_c = customRanges == null ? void 0 : customRanges.findIndex((value) => value.startIndex < startOffset && value.endIndex > endOffset - 1)) != null ? _c : -1;
|
|
585
592
|
if (index > -1) {
|
|
@@ -596,18 +603,17 @@ let DocHyperLinkSelectionController = (_a3 = class extends Disposable {
|
|
|
596
603
|
);
|
|
597
604
|
}
|
|
598
605
|
}, __name(_a3, "DocHyperLinkSelectionController"), _a3);
|
|
599
|
-
DocHyperLinkSelectionController = __decorateClass$
|
|
606
|
+
DocHyperLinkSelectionController = __decorateClass$3([
|
|
600
607
|
OnLifecycle(LifecycleStages.Ready, DocHyperLinkSelectionController),
|
|
601
|
-
__decorateParam$
|
|
602
|
-
__decorateParam$
|
|
603
|
-
__decorateParam$
|
|
604
|
-
__decorateParam$5(3, IRenderManagerService)
|
|
608
|
+
__decorateParam$3(0, ICommandService),
|
|
609
|
+
__decorateParam$3(1, IUniverInstanceService),
|
|
610
|
+
__decorateParam$3(2, Inject(DocHyperLinkPopupService))
|
|
605
611
|
], DocHyperLinkSelectionController);
|
|
606
|
-
var __defProp$
|
|
607
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
612
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
613
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
608
614
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
609
|
-
return kind && result && __defProp$
|
|
610
|
-
}, "__decorateClass$
|
|
615
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
616
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a4;
|
|
611
617
|
let DocHyperLinkRenderController = (_a4 = class extends Disposable {
|
|
612
618
|
constructor(_context, _docInterceptorService, _hyperLinkService, _docRenderController) {
|
|
613
619
|
super(), this._context = _context, this._docInterceptorService = _docInterceptorService, this._hyperLinkService = _hyperLinkService, this._docRenderController = _docRenderController, this._init(), this._initReRender();
|
|
@@ -634,157 +640,19 @@ let DocHyperLinkRenderController = (_a4 = class extends Disposable {
|
|
|
634
640
|
}));
|
|
635
641
|
}
|
|
636
642
|
}, __name(_a4, "DocHyperLinkRenderController"), _a4);
|
|
637
|
-
DocHyperLinkRenderController = __decorateClass$
|
|
638
|
-
__decorateParam$
|
|
639
|
-
__decorateParam$
|
|
640
|
-
__decorateParam$
|
|
643
|
+
DocHyperLinkRenderController = __decorateClass$2([
|
|
644
|
+
__decorateParam$2(1, Inject(DocInterceptorService)),
|
|
645
|
+
__decorateParam$2(2, Inject(DocHyperLinkPopupService)),
|
|
646
|
+
__decorateParam$2(3, Inject(DocRenderController))
|
|
641
647
|
], 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
648
|
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
781
649
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
782
650
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
783
651
|
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"),
|
|
785
|
-
let DocHyperLinkEventRenderController = (
|
|
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();
|
|
652
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a5;
|
|
653
|
+
let DocHyperLinkEventRenderController = (_a5 = class extends Disposable {
|
|
654
|
+
constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _docSelectionManagerService) {
|
|
655
|
+
super(), this._context = _context, this._docEventManagerService = _docEventManagerService, this._commandService = _commandService, this._hyperLinkPopupService = _hyperLinkPopupService, this._docSkeletonManagerService = _docSkeletonManagerService, this._docSelectionManagerService = _docSelectionManagerService, this._initHover(), this._initClick();
|
|
788
656
|
}
|
|
789
657
|
get _skeleton() {
|
|
790
658
|
return this._docSkeletonManagerService.getSkeleton();
|
|
@@ -797,8 +665,9 @@ let DocHyperLinkEventRenderController = (_a7 = class extends Disposable {
|
|
|
797
665
|
_initHover() {
|
|
798
666
|
this.disposeWithMe(
|
|
799
667
|
this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
|
|
800
|
-
|
|
801
|
-
|
|
668
|
+
var _a7;
|
|
669
|
+
const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK), activeRanges = this._docSelectionManagerService.getCurrentTextRanges(), currentSegmentId = activeRanges == null ? void 0 : activeRanges[0].segmentId;
|
|
670
|
+
if (((_a7 = link == null ? void 0 : link.segmentId) != null ? _a7 : "") !== currentSegmentId) {
|
|
802
671
|
this._hideInfoPopup();
|
|
803
672
|
return;
|
|
804
673
|
}
|
|
@@ -823,40 +692,38 @@ let DocHyperLinkEventRenderController = (_a7 = class extends Disposable {
|
|
|
823
692
|
ClickDocHyperLinkOperation.id,
|
|
824
693
|
{
|
|
825
694
|
unitId: this._context.unitId,
|
|
826
|
-
linkId: link.rangeId
|
|
695
|
+
linkId: link.rangeId,
|
|
696
|
+
segmentId: range.segmentId
|
|
827
697
|
}
|
|
828
698
|
);
|
|
829
699
|
})
|
|
830
700
|
);
|
|
831
701
|
}
|
|
832
|
-
}, __name(
|
|
702
|
+
}, __name(_a5, "DocHyperLinkEventRenderController"), _a5);
|
|
833
703
|
DocHyperLinkEventRenderController = __decorateClass$1([
|
|
834
704
|
__decorateParam$1(1, Inject(DocEventManagerService)),
|
|
835
705
|
__decorateParam$1(2, ICommandService),
|
|
836
706
|
__decorateParam$1(3, Inject(DocHyperLinkPopupService)),
|
|
837
|
-
__decorateParam$1(4, Inject(DocSkeletonManagerService))
|
|
707
|
+
__decorateParam$1(4, Inject(DocSkeletonManagerService)),
|
|
708
|
+
__decorateParam$1(5, Inject(DocSelectionManagerService))
|
|
838
709
|
], DocHyperLinkEventRenderController);
|
|
710
|
+
const PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config", defaultPluginConfig = {};
|
|
839
711
|
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
712
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
841
713
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
842
714
|
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"),
|
|
844
|
-
let UniverDocsHyperLinkUIPlugin = (
|
|
845
|
-
constructor(_config =
|
|
846
|
-
super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv;
|
|
715
|
+
}, "__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;
|
|
716
|
+
let UniverDocsHyperLinkUIPlugin = (_a6 = class extends Plugin {
|
|
717
|
+
constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
|
|
718
|
+
super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv, this._configService = _configService;
|
|
719
|
+
const { menu, ...rest } = this._config;
|
|
720
|
+
menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
|
|
847
721
|
}
|
|
848
722
|
onStarting() {
|
|
849
723
|
[
|
|
850
724
|
[DocHyperLinkPopupService],
|
|
851
|
-
[
|
|
852
|
-
|
|
853
|
-
{
|
|
854
|
-
useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(DocHyperLinkUIController, this._config), "useFactory")
|
|
855
|
-
}
|
|
856
|
-
],
|
|
857
|
-
[DocHyperLinkSelectionController],
|
|
858
|
-
[DocHyperLinkClipboardController],
|
|
859
|
-
[DocHyperLinkCustomRangeController]
|
|
725
|
+
[DocHyperLinkUIController],
|
|
726
|
+
[DocHyperLinkSelectionController]
|
|
860
727
|
].forEach((dep) => {
|
|
861
728
|
this._injector.add(dep);
|
|
862
729
|
});
|
|
@@ -872,13 +739,14 @@ let UniverDocsHyperLinkUIPlugin = (_a8 = class extends Plugin {
|
|
|
872
739
|
this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, dep);
|
|
873
740
|
});
|
|
874
741
|
}
|
|
875
|
-
}, __name(
|
|
742
|
+
}, __name(_a6, "UniverDocsHyperLinkUIPlugin"), _a6);
|
|
876
743
|
__publicField2(UniverDocsHyperLinkUIPlugin, "pluginName", DOC_HYPER_LINK_UI_PLUGIN);
|
|
877
744
|
__publicField2(UniverDocsHyperLinkUIPlugin, "type", UniverInstanceType.UNIVER_DOC);
|
|
878
745
|
UniverDocsHyperLinkUIPlugin = __decorateClass([
|
|
879
746
|
DependentOn(UniverDocsHyperLinkPlugin),
|
|
880
747
|
__decorateParam(1, Inject(Injector)),
|
|
881
|
-
__decorateParam(2, IRenderManagerService)
|
|
748
|
+
__decorateParam(2, IRenderManagerService),
|
|
749
|
+
__decorateParam(3, IConfigService)
|
|
882
750
|
], UniverDocsHyperLinkUIPlugin);
|
|
883
751
|
export {
|
|
884
752
|
UniverDocsHyperLinkUIPlugin
|