@univerjs/docs-hyper-link-ui 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +178 -193
- package/lib/es/index.js +179 -194
- package/lib/index.css +0 -192
- package/lib/index.js +179 -194
- package/lib/types/commands/operations/popup.operation.d.ts +2 -1
- package/lib/types/utils/hyper-link-target.d.ts +19 -0
- package/lib/types/views/DocHyperLinkEdit.d.ts +3 -1
- package/lib/types/views/MobileDocHyperLinkEdit.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +14 -14
package/lib/es/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { DocBackScrollRenderController, DocCanvasPopManagerService, DocEventManagerService, DocMobileElementMenuService, EMPTY_PARAGRAPH_MENU_ID, FLOAT_TOOLBAR_MENU_POSITION, INSERT_BELLOW_MENU_ID, MOBILE_DOC_ELEMENT_MENU, UniverDocsMobileUIPlugin, UniverDocsUIPlugin, getEditorRuntimeConfig, whenDocAndEditorFocused } from "@univerjs/docs-ui";
|
|
2
|
-
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IDialogService, IMenuManagerService, IMessageService, IShortcutService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
|
|
2
|
+
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, HyperlinkEditor, HyperlinkPreview, IClipboardInterfaceService, IDialogService, ILayoutService, IMenuManagerService, IMessageService, IShortcutService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
|
|
3
3
|
import { BuildTextUtils, CommandType, CustomRangeType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Disposable, DocumentDataModel, ICommandService, IConfigService, IPermissionService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, generateRandomId, getBodySlice, isSafeUrl, merge } from "@univerjs/core";
|
|
4
4
|
import { DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation, SetTextSelectionsOperation, UniverDocsPlugin, addCustomRangeBySelectionFactory, canEditDocumentTargets, deleteCustomRangeFactory, getDocumentEntityParentPermissionObjectIds, getDocumentEntityPermissionObjectId, getDocumentPermissionValue, replaceSelectionFactory } from "@univerjs/docs";
|
|
5
5
|
import { IRenderManagerService, UniverRenderEnginePlugin } from "@univerjs/engine-render";
|
|
6
6
|
import { BehaviorSubject, Observable, debounceTime } from "rxjs";
|
|
7
7
|
import { DocHyperLinkCommandId, UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
|
|
8
|
-
import { Button, FormLayout, Input, MessageType, MobileActionRow, Tooltip, borderClassName, clsx } from "@univerjs/design";
|
|
9
8
|
import { useEffect, useState } from "react";
|
|
10
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
-
import {
|
|
10
|
+
import { MessageType, MobileActionRow } from "@univerjs/design";
|
|
12
11
|
import { UnitAction } from "@univerjs/protocol";
|
|
12
|
+
import { LinkIcon } from "@univerjs/icons";
|
|
13
13
|
|
|
14
14
|
// src/commands/commands/delete-link.command.ts
|
|
15
15
|
const DeleteDocHyperLinkCommand = {
|
|
@@ -29,6 +29,42 @@ const DeleteDocHyperLinkCommand = {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
// src/utils/hyper-link-target.ts
|
|
33
|
+
function getDocHyperLinkTarget(properties) {
|
|
34
|
+
return (properties === null || properties === void 0 ? void 0 : properties.url) ?? ((properties === null || properties === void 0 ? void 0 : properties.bookmarkId) ? `#${properties.bookmarkId}` : (properties === null || properties === void 0 ? void 0 : properties.headingId) ? `#${properties.headingId}` : "");
|
|
35
|
+
}
|
|
36
|
+
function getDocHyperLinkTargetLabel(properties, body) {
|
|
37
|
+
var _body$customRanges, _body$paragraphs, _bookmark$properties, _body$paragraphs2;
|
|
38
|
+
const target = getDocHyperLinkTarget(properties);
|
|
39
|
+
if (!target.startsWith("#") || !body) return target;
|
|
40
|
+
const id = target.slice(1);
|
|
41
|
+
const bookmark = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => {
|
|
42
|
+
var _range$properties;
|
|
43
|
+
return range.rangeType === CustomRangeType.BOOKMARK && (range.rangeId === id || ((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.bookmarkId) === id);
|
|
44
|
+
});
|
|
45
|
+
const paragraphIndex = ((_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.findIndex((paragraph) => {
|
|
46
|
+
var _paragraph$paragraphS;
|
|
47
|
+
return paragraph.paragraphId === id || ((_paragraph$paragraphS = paragraph.paragraphStyle) === null || _paragraph$paragraphS === void 0 ? void 0 : _paragraph$paragraphS.headingId) === id;
|
|
48
|
+
})) ?? -1;
|
|
49
|
+
const start = (bookmark === null || bookmark === void 0 ? void 0 : bookmark.startIndex) ?? (paragraphIndex < 0 ? void 0 : paragraphIndex === 0 ? 0 : body.paragraphs[paragraphIndex - 1].startIndex + 1);
|
|
50
|
+
if (start == null) return target;
|
|
51
|
+
const end = bookmark && !((_bookmark$properties = bookmark.properties) === null || _bookmark$properties === void 0 ? void 0 : _bookmark$properties.collapsed) ? bookmark.endIndex + 1 : ((_body$paragraphs2 = body.paragraphs) === null || _body$paragraphs2 === void 0 || (_body$paragraphs2 = _body$paragraphs2.find((paragraph) => paragraph.startIndex >= start)) === null || _body$paragraphs2 === void 0 ? void 0 : _body$paragraphs2.startIndex) ?? start;
|
|
52
|
+
return body.dataStream.slice(start, Math.min(end, start + 512)).replace(/[\u0000-\u001F\uFFFC]/g, " ").replace(/\s+/g, " ").trim().slice(0, 160) || target;
|
|
53
|
+
}
|
|
54
|
+
function getDocHyperLinkTargetProperties(target, body, previous) {
|
|
55
|
+
var _body$customRanges2, _body$paragraphs3;
|
|
56
|
+
if (!target.startsWith("#")) return { url: target };
|
|
57
|
+
const id = target.slice(1);
|
|
58
|
+
if ((previous === null || previous === void 0 ? void 0 : previous.headingId) === id || !(body === null || body === void 0 || (_body$customRanges2 = body.customRanges) === null || _body$customRanges2 === void 0 ? void 0 : _body$customRanges2.some((range) => {
|
|
59
|
+
var _range$properties2;
|
|
60
|
+
return range.rangeType === CustomRangeType.BOOKMARK && (range.rangeId === id || ((_range$properties2 = range.properties) === null || _range$properties2 === void 0 ? void 0 : _range$properties2.bookmarkId) === id);
|
|
61
|
+
})) && (body === null || body === void 0 || (_body$paragraphs3 = body.paragraphs) === null || _body$paragraphs3 === void 0 ? void 0 : _body$paragraphs3.some((paragraph) => {
|
|
62
|
+
var _paragraph$paragraphS2;
|
|
63
|
+
return paragraph.paragraphId === id || ((_paragraph$paragraphS2 = paragraph.paragraphStyle) === null || _paragraph$paragraphS2 === void 0 ? void 0 : _paragraph$paragraphS2.headingId) === id;
|
|
64
|
+
}))) return { headingId: id };
|
|
65
|
+
return { bookmarkId: id };
|
|
66
|
+
}
|
|
67
|
+
|
|
32
68
|
// src/commands/commands/add-link.command.ts
|
|
33
69
|
const AddDocHyperLinkCommand = {
|
|
34
70
|
type: CommandType.COMMAND,
|
|
@@ -37,11 +73,12 @@ const AddDocHyperLinkCommand = {
|
|
|
37
73
|
if (!params) return false;
|
|
38
74
|
const { payload, unitId, selections } = params;
|
|
39
75
|
const commandService = accessor.get(ICommandService);
|
|
76
|
+
const doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
40
77
|
const id = generateRandomId();
|
|
41
78
|
const doMutation = addCustomRangeBySelectionFactory(accessor, {
|
|
42
79
|
rangeId: id,
|
|
43
80
|
rangeType: CustomRangeType.HYPERLINK,
|
|
44
|
-
properties: {
|
|
81
|
+
properties: { ...getDocHyperLinkTargetProperties(payload, doc === null || doc === void 0 ? void 0 : doc.getBody()) },
|
|
45
82
|
unitId,
|
|
46
83
|
selections
|
|
47
84
|
});
|
|
@@ -55,7 +92,7 @@ const UpdateDocHyperLinkCommand = {
|
|
|
55
92
|
id: DocHyperLinkCommandId.Update,
|
|
56
93
|
type: CommandType.COMMAND,
|
|
57
94
|
handler(accessor, params) {
|
|
58
|
-
var _doc$getSelfOrHeaderF, _oldBody$customRanges,
|
|
95
|
+
var _doc$getSelfOrHeaderF, _oldBody$customRanges, _original$textRuns, _original$customRange, _oldLink$properties, _oldLink$properties2;
|
|
59
96
|
if (!params) return false;
|
|
60
97
|
const { unitId, payload, segmentId, linkId } = params;
|
|
61
98
|
const commandService = accessor.get(ICommandService);
|
|
@@ -66,24 +103,28 @@ const UpdateDocHyperLinkCommand = {
|
|
|
66
103
|
const oldBody = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
67
104
|
if (!oldBody) return false;
|
|
68
105
|
const oldLink = (_oldBody$customRanges = oldBody.customRanges) === null || _oldBody$customRanges === void 0 ? void 0 : _oldBody$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK);
|
|
69
|
-
const
|
|
70
|
-
|
|
106
|
+
const original = getBodySlice(oldBody, currentSelection.startOffset, currentSelection.endOffset);
|
|
107
|
+
const unchangedLabel = params.label === BuildTextUtils.transform.getPlainText(original.dataStream).replace(/[\u001F\u001E]/g, "");
|
|
108
|
+
const textRun = (_original$textRuns = original.textRuns) === null || _original$textRuns === void 0 ? void 0 : _original$textRuns[0];
|
|
109
|
+
if (textRun && !unchangedLabel) textRun.ed = params.label.length + 1;
|
|
71
110
|
const replaceSelection = replaceSelectionFactory(accessor, {
|
|
72
111
|
unitId,
|
|
73
112
|
body: {
|
|
74
|
-
|
|
75
|
-
|
|
113
|
+
...unchangedLabel ? original : {
|
|
114
|
+
dataStream: params.label,
|
|
115
|
+
textRuns: textRun ? [textRun] : void 0
|
|
116
|
+
},
|
|
117
|
+
customRanges: [...unchangedLabel ? ((_original$customRange = original.customRanges) === null || _original$customRange === void 0 ? void 0 : _original$customRange.filter((range) => range.rangeId !== linkId)) ?? [] : [], {
|
|
76
118
|
rangeId: linkId,
|
|
77
119
|
rangeType: CustomRangeType.HYPERLINK,
|
|
78
120
|
startIndex: 0,
|
|
79
|
-
endIndex: params.label.length
|
|
121
|
+
endIndex: (unchangedLabel ? original.dataStream.length : params.label.length) - 1,
|
|
80
122
|
properties: {
|
|
81
|
-
|
|
123
|
+
...getDocHyperLinkTargetProperties(payload, doc.getBody(), oldLink === null || oldLink === void 0 ? void 0 : oldLink.properties),
|
|
82
124
|
...(oldLink === null || oldLink === void 0 || (_oldLink$properties = oldLink.properties) === null || _oldLink$properties === void 0 ? void 0 : _oldLink$properties.textStyleMode) ? { textStyleMode: oldLink.properties.textStyleMode } : null,
|
|
83
125
|
...(oldLink === null || oldLink === void 0 || (_oldLink$properties2 = oldLink.properties) === null || _oldLink$properties2 === void 0 ? void 0 : _oldLink$properties2.textColorMode) ? { textColorMode: oldLink.properties.textColorMode } : null
|
|
84
126
|
}
|
|
85
|
-
}]
|
|
86
|
-
textRuns: textRun ? [textRun] : void 0
|
|
127
|
+
}]
|
|
87
128
|
},
|
|
88
129
|
selection: {
|
|
89
130
|
startOffset: currentSelection.startOffset,
|
|
@@ -125,6 +166,7 @@ function isEmail(url) {
|
|
|
125
166
|
return /^[\w.-]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
|
|
126
167
|
}
|
|
127
168
|
function transformUrl(url) {
|
|
169
|
+
if (url.startsWith("#")) return url;
|
|
128
170
|
return hasProtocol(url) ? url : isEmail(url) ? `mailto://${url}` : `https://${url}`;
|
|
129
171
|
}
|
|
130
172
|
function useDocHyperLinkEdit() {
|
|
@@ -136,8 +178,8 @@ function useDocHyperLinkEdit() {
|
|
|
136
178
|
const [link, setLink] = useState("");
|
|
137
179
|
const [label, setLabel] = useState("");
|
|
138
180
|
const [showError, setShowError] = useState(false);
|
|
139
|
-
const isLegal = Tools.isLegalUrl(link);
|
|
140
181
|
const doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
182
|
+
const isLegal = link.startsWith("#") ? findInternalLinkTarget(doc === null || doc === void 0 ? void 0 : doc.getBody(), link.slice(1), link.slice(1)) != null : Tools.isLegalUrl(link);
|
|
141
183
|
useEffect(() => {
|
|
142
184
|
var _doc$getSelfOrHeaderF2, _BuildTextUtils$custo;
|
|
143
185
|
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
@@ -147,19 +189,15 @@ function useDocHyperLinkEdit() {
|
|
|
147
189
|
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
148
190
|
const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => editing.linkId === range.rangeId && range.startIndex === editing.startIndex && range.endIndex === editing.endIndex);
|
|
149
191
|
if (doc && matchedRange) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(body, matchedRange.startIndex, matchedRange.endIndex + 1).dataStream));
|
|
192
|
+
setLink(getDocHyperLinkTarget(matchedRange.properties));
|
|
193
|
+
setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(body, matchedRange.startIndex, matchedRange.endIndex + 1).dataStream).replace(/[\u001F\u001E]/g, ""));
|
|
153
194
|
}
|
|
154
195
|
return;
|
|
155
196
|
}
|
|
156
197
|
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF2 = doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) === null || _doc$getSelfOrHeaderF2 === void 0 ? void 0 : _doc$getSelfOrHeaderF2.getBody();
|
|
157
198
|
const selection = body ? activeRange : null;
|
|
158
199
|
const matchedRange = selection && ((_BuildTextUtils$custo = BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (body === null || body === void 0 ? void 0 : body.customRanges) ?? [])) === null || _BuildTextUtils$custo === void 0 ? void 0 : _BuildTextUtils$custo[0]);
|
|
159
|
-
if (doc && matchedRange)
|
|
160
|
-
var _matchedRange$propert2;
|
|
161
|
-
setLink(((_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) ?? "");
|
|
162
|
-
}
|
|
200
|
+
if (doc && matchedRange) setLink(getDocHyperLinkTarget(matchedRange.properties));
|
|
163
201
|
}, [
|
|
164
202
|
doc,
|
|
165
203
|
docSelectionManagerService,
|
|
@@ -200,46 +238,41 @@ function useDocHyperLinkEdit() {
|
|
|
200
238
|
}
|
|
201
239
|
|
|
202
240
|
// src/views/DocHyperLinkEdit.tsx
|
|
203
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
243
|
+
*
|
|
244
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
245
|
+
* you may not use this file except in compliance with the License.
|
|
246
|
+
* You may obtain a copy of the License at
|
|
247
|
+
*
|
|
248
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
249
|
+
*
|
|
250
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
251
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
252
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
253
|
+
* See the License for the specific language governing permissions and
|
|
254
|
+
* limitations under the License.
|
|
255
|
+
*/
|
|
256
|
+
const DocHyperLinkEdit = ({ mobile = false } = {}) => {
|
|
204
257
|
const localeService = useDependency(LocaleService);
|
|
205
258
|
const { doc, editing, handleCancel, handleConfirm, isLegal, label, link, setLabel, setLink, showError } = useDocHyperLinkEdit();
|
|
206
259
|
if (!doc) return;
|
|
207
|
-
return /* @__PURE__ */
|
|
208
|
-
|
|
209
|
-
|
|
260
|
+
return /* @__PURE__ */ jsx(HyperlinkEditor, {
|
|
261
|
+
mobile,
|
|
262
|
+
url: link,
|
|
263
|
+
label: editing ? label : void 0,
|
|
264
|
+
onUrlChange: setLink,
|
|
265
|
+
onLabelChange: setLabel,
|
|
266
|
+
onCancel: handleCancel,
|
|
267
|
+
onConfirm: handleConfirm,
|
|
268
|
+
labelError: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : void 0,
|
|
269
|
+
urlError: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : void 0,
|
|
270
|
+
labels: {
|
|
210
271
|
label: localeService.t("docs-hyper-link-ui.edit.label"),
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
autoFocus: true,
|
|
216
|
-
onKeyDown: (event) => {
|
|
217
|
-
if (event.keyCode === KeyCode.ENTER) handleConfirm();
|
|
218
|
-
}
|
|
219
|
-
})
|
|
220
|
-
}) : null, /* @__PURE__ */ jsx(FormLayout, {
|
|
221
|
-
label: localeService.t("docs-hyper-link-ui.edit.address"),
|
|
222
|
-
error: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : "",
|
|
223
|
-
children: /* @__PURE__ */ jsx(Input, {
|
|
224
|
-
value: link,
|
|
225
|
-
onChange: setLink,
|
|
226
|
-
autoFocus: true,
|
|
227
|
-
onKeyDown: (event) => {
|
|
228
|
-
if (event.keyCode === KeyCode.ENTER) handleConfirm();
|
|
229
|
-
}
|
|
230
|
-
})
|
|
231
|
-
})] }), /* @__PURE__ */ jsxs("div", {
|
|
232
|
-
className: "univer-flex univer-justify-end univer-gap-3",
|
|
233
|
-
children: [/* @__PURE__ */ jsx(Button, {
|
|
234
|
-
onClick: handleCancel,
|
|
235
|
-
children: localeService.t("docs-hyper-link-ui.edit.cancel")
|
|
236
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
237
|
-
variant: "primary",
|
|
238
|
-
disabled: isBlankInput(link),
|
|
239
|
-
onClick: handleConfirm,
|
|
240
|
-
children: localeService.t("docs-hyper-link-ui.edit.confirm")
|
|
241
|
-
})]
|
|
242
|
-
})]
|
|
272
|
+
address: localeService.t("docs-hyper-link-ui.edit.address"),
|
|
273
|
+
cancel: localeService.t("docs-hyper-link-ui.edit.cancel"),
|
|
274
|
+
confirm: localeService.t("docs-hyper-link-ui.edit.confirm")
|
|
275
|
+
}
|
|
243
276
|
});
|
|
244
277
|
};
|
|
245
278
|
DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
|
|
@@ -261,10 +294,11 @@ DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
|
|
|
261
294
|
* limitations under the License.
|
|
262
295
|
*/
|
|
263
296
|
const DocLinkPopup = () => {
|
|
264
|
-
var _doc$getSelfOrHeaderF, _body$customRanges
|
|
297
|
+
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
265
298
|
const hyperLinkService = useDependency(DocHyperLinkPopupService);
|
|
266
299
|
const commandService = useDependency(ICommandService);
|
|
267
300
|
const messageService = useDependency(IMessageService);
|
|
301
|
+
const clipboardService = useDependency(IClipboardInterfaceService);
|
|
268
302
|
const localeService = useDependency(LocaleService);
|
|
269
303
|
const currentPopup = useObservable(hyperLinkService.showingLink$, hyperLinkService.showing);
|
|
270
304
|
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
@@ -275,91 +309,47 @@ const DocLinkPopup = () => {
|
|
|
275
309
|
const body = doc instanceof DocumentDataModel ? (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody() : void 0;
|
|
276
310
|
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK && range.startIndex === startIndex && range.endIndex === endIndex);
|
|
277
311
|
if (!link) return null;
|
|
278
|
-
const target = (
|
|
312
|
+
const target = getDocHyperLinkTarget(link.properties);
|
|
313
|
+
const targetLabel = getDocHyperLinkTargetLabel(link.properties, body);
|
|
279
314
|
const canEdit = hyperLinkService.canEditLink(unitId, currentPopup);
|
|
280
315
|
const canCopy = getDocumentPermissionValue(permissionService, unitId, unitId, UnitAction.Copy);
|
|
281
|
-
return /* @__PURE__ */
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
316
|
+
return /* @__PURE__ */ jsx(HyperlinkPreview, {
|
|
317
|
+
title: targetLabel,
|
|
318
|
+
copyDisabled: !canCopy,
|
|
319
|
+
labels: {
|
|
320
|
+
copy: localeService.t("docs-hyper-link-ui.info.copy"),
|
|
321
|
+
edit: localeService.t("docs-hyper-link-ui.info.edit"),
|
|
322
|
+
remove: localeService.t("docs-hyper-link-ui.info.cancel")
|
|
285
323
|
},
|
|
324
|
+
onPointerEnter: () => hyperLinkService.setInfoPopupHovered(true),
|
|
286
325
|
onPointerLeave: () => {
|
|
287
326
|
hyperLinkService.setInfoPopupHovered(false);
|
|
288
327
|
hyperLinkService.scheduleHideInfoPopup();
|
|
289
328
|
},
|
|
290
|
-
|
|
291
|
-
|
|
329
|
+
onDismiss: () => hyperLinkService.hideInfoPopup(),
|
|
330
|
+
onOpen: () => commandService.executeCommand(ClickDocHyperLinkOperation.id, {
|
|
331
|
+
unitId,
|
|
332
|
+
linkId,
|
|
333
|
+
segmentId
|
|
334
|
+
}),
|
|
335
|
+
onCopy: async () => {
|
|
336
|
+
await clipboardService.writeText(target);
|
|
337
|
+
messageService.show({
|
|
338
|
+
content: localeService.t("docs-hyper-link-ui.info.coped"),
|
|
339
|
+
type: MessageType.Info
|
|
340
|
+
});
|
|
292
341
|
},
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}),
|
|
300
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
301
|
-
className: "univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-gray-0",
|
|
302
|
-
children: /* @__PURE__ */ jsx(LinkIcon, {})
|
|
303
|
-
}), /* @__PURE__ */ jsx(Tooltip, {
|
|
304
|
-
showIfEllipsis: true,
|
|
305
|
-
title: target,
|
|
306
|
-
children: /* @__PURE__ */ jsx("span", {
|
|
307
|
-
className: "univer-flex-1 univer-truncate",
|
|
308
|
-
children: target
|
|
309
|
-
})
|
|
310
|
-
})]
|
|
311
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
312
|
-
className: "univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center",
|
|
313
|
-
children: [/* @__PURE__ */ jsx(Button, {
|
|
314
|
-
type: "button",
|
|
315
|
-
variant: "text",
|
|
316
|
-
size: "small",
|
|
317
|
-
"aria-label": localeService.t("docs-hyper-link-ui.info.copy"),
|
|
318
|
-
className: "univer-ml-2 !univer-flex univer-size-6 !univer-rounded !univer-border-0 !univer-bg-transparent !univer-p-0 !univer-text-base !univer-font-normal hover:!univer-bg-transparent active:!univer-bg-transparent disabled:!univer-pointer-events-auto disabled:!univer-opacity-40",
|
|
319
|
-
disabled: !canCopy,
|
|
320
|
-
onClick: () => {
|
|
321
|
-
navigator.clipboard.writeText(target);
|
|
322
|
-
messageService.show({
|
|
323
|
-
content: localeService.t("docs-hyper-link-ui.info.coped"),
|
|
324
|
-
type: MessageType.Info
|
|
325
|
-
});
|
|
326
|
-
},
|
|
327
|
-
children: /* @__PURE__ */ jsx(Tooltip, {
|
|
328
|
-
placement: "bottom",
|
|
329
|
-
title: localeService.t("docs-hyper-link-ui.info.copy"),
|
|
330
|
-
children: /* @__PURE__ */ jsx(CopyIcon, {})
|
|
331
|
-
})
|
|
332
|
-
}), canEdit && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
333
|
-
className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
|
|
334
|
-
onClick: () => {
|
|
335
|
-
commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, { link: currentPopup });
|
|
336
|
-
},
|
|
337
|
-
children: /* @__PURE__ */ jsx(Tooltip, {
|
|
338
|
-
placement: "bottom",
|
|
339
|
-
title: localeService.t("docs-hyper-link-ui.info.edit"),
|
|
340
|
-
children: /* @__PURE__ */ jsx(WriteIcon, {})
|
|
341
|
-
})
|
|
342
|
-
}), /* @__PURE__ */ jsx("div", {
|
|
343
|
-
className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
|
|
344
|
-
onClick: () => {
|
|
345
|
-
commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
|
|
346
|
-
unitId,
|
|
347
|
-
linkId: link.rangeId,
|
|
348
|
-
segmentId
|
|
349
|
-
});
|
|
350
|
-
},
|
|
351
|
-
children: /* @__PURE__ */ jsx(Tooltip, {
|
|
352
|
-
placement: "bottom",
|
|
353
|
-
title: localeService.t("docs-hyper-link-ui.info.cancel"),
|
|
354
|
-
children: /* @__PURE__ */ jsx(UnlinkIcon, {})
|
|
355
|
-
})
|
|
356
|
-
})] })]
|
|
357
|
-
})]
|
|
342
|
+
onEdit: canEdit ? () => commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, { link: currentPopup }) : void 0,
|
|
343
|
+
onRemove: canEdit ? () => commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
|
|
344
|
+
unitId,
|
|
345
|
+
linkId: link.rangeId,
|
|
346
|
+
segmentId
|
|
347
|
+
}) : void 0
|
|
358
348
|
});
|
|
359
349
|
};
|
|
360
350
|
DocLinkPopup.componentKey = "univer.doc.link-info-popup";
|
|
361
351
|
|
|
362
|
-
// \0@oxc-project+runtime@0.
|
|
352
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/typeof.js
|
|
363
353
|
function _typeof(o) {
|
|
364
354
|
"@babel/helpers - typeof";
|
|
365
355
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -369,7 +359,7 @@ function _typeof(o) {
|
|
|
369
359
|
}, _typeof(o);
|
|
370
360
|
}
|
|
371
361
|
|
|
372
|
-
// \0@oxc-project+runtime@0.
|
|
362
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPrimitive.js
|
|
373
363
|
function toPrimitive(t, e) {
|
|
374
364
|
if ("object" != _typeof(t) || !t) return t;
|
|
375
365
|
var r;
|
|
@@ -381,13 +371,13 @@ function toPrimitive(t, e) {
|
|
|
381
371
|
return ("string" === e ? String : Number)(t);
|
|
382
372
|
}
|
|
383
373
|
|
|
384
|
-
// \0@oxc-project+runtime@0.
|
|
374
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/toPropertyKey.js
|
|
385
375
|
function toPropertyKey(t) {
|
|
386
376
|
var i = toPrimitive(t, "string");
|
|
387
377
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
388
378
|
}
|
|
389
379
|
|
|
390
|
-
// \0@oxc-project+runtime@0.
|
|
380
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/defineProperty.js
|
|
391
381
|
function _defineProperty(e, r, t) {
|
|
392
382
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
393
383
|
value: t,
|
|
@@ -397,14 +387,14 @@ function _defineProperty(e, r, t) {
|
|
|
397
387
|
}) : e[r] = t, e;
|
|
398
388
|
}
|
|
399
389
|
|
|
400
|
-
// \0@oxc-project+runtime@0.
|
|
390
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorateParam.js
|
|
401
391
|
function __decorateParam(paramIndex, decorator) {
|
|
402
392
|
return function(target, key) {
|
|
403
393
|
decorator(target, key, paramIndex);
|
|
404
394
|
};
|
|
405
395
|
}
|
|
406
396
|
|
|
407
|
-
// \0@oxc-project+runtime@0.
|
|
397
|
+
// \0@oxc-project+runtime@0.158.0/helpers/esm/decorate.js
|
|
408
398
|
function __decorate(decorators, target, key, desc) {
|
|
409
399
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
410
400
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -654,10 +644,26 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
654
644
|
}, 0);
|
|
655
645
|
}
|
|
656
646
|
canEditLink(unitId, linkInfo) {
|
|
647
|
+
var _document$getSelfOrHe, _body$customRanges, _link$properties, _body$customRanges2;
|
|
657
648
|
const document = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
658
649
|
if (!(document instanceof DocumentDataModel)) return false;
|
|
659
650
|
if (!linkInfo) return canEditDocumentTargets(this._permissionService, unitId, []);
|
|
660
651
|
const segmentId = linkInfo.segmentId ?? "";
|
|
652
|
+
const body = (_document$getSelfOrHe = document.getSelfOrHeaderFooterModel(segmentId)) === null || _document$getSelfOrHe === void 0 ? void 0 : _document$getSelfOrHe.getBody();
|
|
653
|
+
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => range.rangeId === linkInfo.linkId);
|
|
654
|
+
if ((link === null || link === void 0 || (_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.referenceFieldLink) === true || link && (body === null || body === void 0 || (_body$customRanges2 = body.customRanges) === null || _body$customRanges2 === void 0 ? void 0 : _body$customRanges2.some((range) => {
|
|
655
|
+
var _range$properties;
|
|
656
|
+
return range.rangeType === CustomRangeType.FIELD && range.startIndex <= link.startIndex && range.endIndex >= link.endIndex && [
|
|
657
|
+
"TOC",
|
|
658
|
+
"INDEX",
|
|
659
|
+
"TOA",
|
|
660
|
+
"REF",
|
|
661
|
+
"PAGEREF",
|
|
662
|
+
"NOTEREF",
|
|
663
|
+
"CITATION",
|
|
664
|
+
"BIBLIOGRAPHY"
|
|
665
|
+
].includes(String((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.fieldType));
|
|
666
|
+
}))) return false;
|
|
661
667
|
return canEditDocumentTargets(this._permissionService, unitId, [...getDocumentEntityParentPermissionObjectIds(document, segmentId, "custom-range", linkInfo.linkId), getDocumentEntityPermissionObjectId(segmentId, "custom-range", linkInfo.linkId)]);
|
|
662
668
|
}
|
|
663
669
|
};
|
|
@@ -731,10 +737,13 @@ const ClickDocHyperLinkOperation = {
|
|
|
731
737
|
collapsed: true
|
|
732
738
|
};
|
|
733
739
|
const selectionManager = accessor.get(DocSelectionManagerService);
|
|
734
|
-
const selectTarget = () =>
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
740
|
+
const selectTarget = () => {
|
|
741
|
+
selectionManager.replaceDocRanges([range], {
|
|
742
|
+
unitId,
|
|
743
|
+
subUnitId: unitId
|
|
744
|
+
}, false, { [DOC_SELECTION_OPTION_PRESERVE_CARET]: true });
|
|
745
|
+
accessor.get(ILayoutService).focus(unitId);
|
|
746
|
+
};
|
|
738
747
|
const render = accessor.get(IRenderManagerService).getRenderUnitById(unitId);
|
|
739
748
|
const renderInjector = render === null || render === void 0 || (_render$getInjector = render.getInjector) === null || _render$getInjector === void 0 ? void 0 : _render$getInjector.call(render);
|
|
740
749
|
const backScrollController = (renderInjector === null || renderInjector === void 0 ? void 0 : renderInjector.has(DocBackScrollRenderController)) ? render === null || render === void 0 ? void 0 : render.with(DocBackScrollRenderController) : null;
|
|
@@ -761,7 +770,7 @@ function findInternalLinkTarget(body, bookmarkId, headingId) {
|
|
|
761
770
|
var _body$paragraphs;
|
|
762
771
|
const paragraphIndex = ((_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.findIndex((paragraph) => {
|
|
763
772
|
var _paragraph$paragraphS;
|
|
764
|
-
return ((_paragraph$paragraphS = paragraph.paragraphStyle) === null || _paragraph$paragraphS === void 0 ? void 0 : _paragraph$paragraphS.headingId) === headingId;
|
|
773
|
+
return ((_paragraph$paragraphS = paragraph.paragraphStyle) === null || _paragraph$paragraphS === void 0 ? void 0 : _paragraph$paragraphS.headingId) === headingId || paragraph.paragraphId === headingId;
|
|
765
774
|
})) ?? -1;
|
|
766
775
|
if (paragraphIndex >= 0) return paragraphIndex === 0 ? 0 : body.paragraphs[paragraphIndex - 1].startIndex + 1;
|
|
767
776
|
}
|
|
@@ -825,7 +834,7 @@ const menuSchema = {
|
|
|
825
834
|
|
|
826
835
|
// package.json
|
|
827
836
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
828
|
-
var version = "1.
|
|
837
|
+
var version = "1.6.0";
|
|
829
838
|
|
|
830
839
|
// src/config/config.ts
|
|
831
840
|
const DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config";
|
|
@@ -925,62 +934,33 @@ DocHyperLinkSelectionController = __decorate([
|
|
|
925
934
|
* limitations under the License.
|
|
926
935
|
*/
|
|
927
936
|
function MobileDocHyperLinkEdit() {
|
|
928
|
-
|
|
929
|
-
const { doc, editing, handleCancel, handleConfirm, isLegal, label, link, setLabel, setLink, showError } = useDocHyperLinkEdit();
|
|
930
|
-
if (!doc) return;
|
|
931
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
932
|
-
className: "univer-box-border univer-w-full univer-bg-gray-0 univer-py-2 dark:!univer-bg-gray-900",
|
|
933
|
-
children: [/* @__PURE__ */ jsxs("div", { children: [editing ? /* @__PURE__ */ jsx(FormLayout, {
|
|
934
|
-
label: localeService.t("docs-hyper-link-ui.edit.label"),
|
|
935
|
-
error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
|
|
936
|
-
children: /* @__PURE__ */ jsx(Input, {
|
|
937
|
-
value: label,
|
|
938
|
-
onChange: setLabel,
|
|
939
|
-
autoFocus: true,
|
|
940
|
-
onKeyDown: (event) => {
|
|
941
|
-
if (event.keyCode === KeyCode.ENTER) handleConfirm();
|
|
942
|
-
},
|
|
943
|
-
size: "small"
|
|
944
|
-
})
|
|
945
|
-
}) : null, /* @__PURE__ */ jsx(FormLayout, {
|
|
946
|
-
label: localeService.t("docs-hyper-link-ui.edit.address"),
|
|
947
|
-
error: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : "",
|
|
948
|
-
children: /* @__PURE__ */ jsx(Input, {
|
|
949
|
-
value: link,
|
|
950
|
-
onChange: setLink,
|
|
951
|
-
autoFocus: !editing,
|
|
952
|
-
onKeyDown: (event) => {
|
|
953
|
-
if (event.keyCode === KeyCode.ENTER) handleConfirm();
|
|
954
|
-
},
|
|
955
|
-
size: "small"
|
|
956
|
-
})
|
|
957
|
-
})] }), /* @__PURE__ */ jsxs("div", {
|
|
958
|
-
className: "univer-mt-5 univer-flex univer-gap-3",
|
|
959
|
-
children: [/* @__PURE__ */ jsx(Button, {
|
|
960
|
-
className: "univer-flex-1",
|
|
961
|
-
onClick: handleCancel,
|
|
962
|
-
size: "middle",
|
|
963
|
-
children: localeService.t("docs-hyper-link-ui.edit.cancel")
|
|
964
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
965
|
-
variant: "primary",
|
|
966
|
-
className: "univer-flex-1",
|
|
967
|
-
disabled: isBlankInput(link),
|
|
968
|
-
onClick: handleConfirm,
|
|
969
|
-
size: "middle",
|
|
970
|
-
children: localeService.t("docs-hyper-link-ui.edit.confirm")
|
|
971
|
-
})]
|
|
972
|
-
})]
|
|
973
|
-
});
|
|
937
|
+
return /* @__PURE__ */ jsx(DocHyperLinkEdit, { mobile: true });
|
|
974
938
|
}
|
|
975
939
|
MobileDocHyperLinkEdit.componentKey = "univer.doc.mobile-hyper-link-edit";
|
|
976
940
|
|
|
977
941
|
// src/views/MobileDocLinkPopup.tsx
|
|
942
|
+
/**
|
|
943
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
944
|
+
*
|
|
945
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
946
|
+
* you may not use this file except in compliance with the License.
|
|
947
|
+
* You may obtain a copy of the License at
|
|
948
|
+
*
|
|
949
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
950
|
+
*
|
|
951
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
952
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
953
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
954
|
+
* See the License for the specific language governing permissions and
|
|
955
|
+
* limitations under the License.
|
|
956
|
+
*/
|
|
978
957
|
function MobileDocLinkPopup() {
|
|
979
|
-
var _document$getSelfOrHe, _body$customRanges
|
|
958
|
+
var _document$getSelfOrHe, _body$customRanges;
|
|
980
959
|
const commandService = useDependency(ICommandService);
|
|
981
960
|
const hyperLinkService = useDependency(DocHyperLinkPopupService);
|
|
982
961
|
const localeService = useDependency(LocaleService);
|
|
983
962
|
const messageService = useDependency(IMessageService);
|
|
963
|
+
const clipboardService = useDependency(IClipboardInterfaceService);
|
|
984
964
|
const permissionService = useDependency(IPermissionService);
|
|
985
965
|
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
986
966
|
const currentPopup = useObservable(hyperLinkService.showingLink$, hyperLinkService.showing);
|
|
@@ -990,7 +970,8 @@ function MobileDocLinkPopup() {
|
|
|
990
970
|
const body = document instanceof DocumentDataModel ? (_document$getSelfOrHe = document.getSelfOrHeaderFooterModel(segmentId)) === null || _document$getSelfOrHe === void 0 ? void 0 : _document$getSelfOrHe.getBody() : void 0;
|
|
991
971
|
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK && range.startIndex === startIndex && range.endIndex === endIndex);
|
|
992
972
|
if (!link) return null;
|
|
993
|
-
const url = (
|
|
973
|
+
const url = getDocHyperLinkTarget(link.properties);
|
|
974
|
+
const label = getDocHyperLinkTargetLabel(link.properties, body);
|
|
994
975
|
const canEdit = hyperLinkService.canEditLink(unitId, currentPopup);
|
|
995
976
|
const canCopy = getDocumentPermissionValue(permissionService, unitId, unitId, UnitAction.Copy);
|
|
996
977
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -999,17 +980,21 @@ function MobileDocLinkPopup() {
|
|
|
999
980
|
/* @__PURE__ */ jsx(MobileActionRow, {
|
|
1000
981
|
title: /* @__PURE__ */ jsx("span", {
|
|
1001
982
|
className: "univer-truncate univer-text-primary-600",
|
|
1002
|
-
children:
|
|
983
|
+
children: label
|
|
1003
984
|
}),
|
|
1004
|
-
"aria-label":
|
|
985
|
+
"aria-label": label,
|
|
1005
986
|
variant: "subtle",
|
|
1006
|
-
onClick: () =>
|
|
987
|
+
onClick: () => commandService.executeCommand(ClickDocHyperLinkOperation.id, {
|
|
988
|
+
unitId,
|
|
989
|
+
linkId,
|
|
990
|
+
segmentId
|
|
991
|
+
})
|
|
1007
992
|
}),
|
|
1008
993
|
canCopy && /* @__PURE__ */ jsx(MobileActionRow, {
|
|
1009
994
|
title: localeService.t("docs-hyper-link-ui.info.copy"),
|
|
1010
995
|
"aria-label": localeService.t("docs-hyper-link-ui.info.copy"),
|
|
1011
996
|
variant: "subtle",
|
|
1012
|
-
onClick: () =>
|
|
997
|
+
onClick: () => clipboardService.writeText(url).then(() => {
|
|
1013
998
|
messageService.show({
|
|
1014
999
|
content: localeService.t("docs-hyper-link-ui.info.coped"),
|
|
1015
1000
|
type: MessageType.Info
|