@univerjs/docs-hyper-link-ui 1.0.0-alpha.2 → 1.0.0-alpha.4
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 +257 -256
- package/lib/es/index.js +257 -257
- package/lib/index.js +257 -257
- package/lib/types/index.d.ts +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
package/lib/es/index.js
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
|
|
3
|
-
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
4
|
-
import { CopyIcon, LinkIcon, UnlinkIcon, WriteIcon } from "@univerjs/icons";
|
|
1
|
+
import { DocCanvasPopManagerService, DocEventManagerService, DocRenderController, EMPTY_PARAGRAPH_MENU_ID, FLOAT_TOOLBAR_MENU_POSITION, INSERT_BELLOW_MENU_ID, whenDocAndEditorFocused } from "@univerjs/docs-ui";
|
|
5
2
|
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IMessageService, IShortcutService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
|
|
6
|
-
import {
|
|
3
|
+
import { BuildTextUtils, CommandType, CustomRangeType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Disposable, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, generateRandomId, getBodySlice, isSafeUrl, merge } from "@univerjs/core";
|
|
7
4
|
import { DOC_INTERCEPTOR_POINT, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, SetTextSelectionsOperation, addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory } from "@univerjs/docs";
|
|
8
|
-
import { useEffect, useState } from "react";
|
|
9
|
-
import { DocCanvasPopManagerService, DocEventManagerService, DocRenderController, EMPTY_PARAGRAPH_MENU_ID, FLOAT_TOOLBAR_MENU_POSITION, INSERT_BELLOW_MENU_ID, whenDocAndEditorFocused } from "@univerjs/docs-ui";
|
|
10
5
|
import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, pairwise } from "rxjs";
|
|
6
|
+
import { Button, FormLayout, Input, MessageType, Tooltip, borderClassName, clsx } from "@univerjs/design";
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
11
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { CopyIcon, LinkIcon, UnlinkIcon, WriteIcon } from "@univerjs/icons";
|
|
10
|
+
import { UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
|
|
11
|
+
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
12
12
|
|
|
13
|
-
//#region package.json
|
|
14
|
-
var name = "@univerjs/docs-hyper-link-ui";
|
|
15
|
-
var version = "1.0.0-alpha.2";
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/config/config.ts
|
|
19
|
-
const DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config";
|
|
20
|
-
const configSymbol = Symbol(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
|
|
21
|
-
const defaultPluginConfig = {};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
13
|
//#region src/commands/commands/add-link.command.ts
|
|
25
14
|
const AddDocHyperLinkCommand = {
|
|
26
15
|
type: CommandType.COMMAND,
|
|
@@ -84,6 +73,142 @@ const UpdateDocHyperLinkCommand = {
|
|
|
84
73
|
}
|
|
85
74
|
};
|
|
86
75
|
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/views/hyper-link-edit/utils.ts
|
|
78
|
+
/**
|
|
79
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
80
|
+
*
|
|
81
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
82
|
+
* you may not use this file except in compliance with the License.
|
|
83
|
+
* You may obtain a copy of the License at
|
|
84
|
+
*
|
|
85
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
86
|
+
*
|
|
87
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
88
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
89
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
90
|
+
* See the License for the specific language governing permissions and
|
|
91
|
+
* limitations under the License.
|
|
92
|
+
*/
|
|
93
|
+
function isBlankInput(value) {
|
|
94
|
+
return value.trim().length === 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/views/DocHyperLinkEdit.tsx
|
|
99
|
+
function hasProtocol(urlString) {
|
|
100
|
+
return /^[a-zA-Z]+:\/\//.test(urlString);
|
|
101
|
+
}
|
|
102
|
+
function isEmail(url) {
|
|
103
|
+
return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
|
|
104
|
+
}
|
|
105
|
+
function transformUrl(urlStr) {
|
|
106
|
+
return hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `https://${urlStr}`;
|
|
107
|
+
}
|
|
108
|
+
const DocHyperLinkEdit = () => {
|
|
109
|
+
const hyperLinkService = useDependency(DocHyperLinkPopupService);
|
|
110
|
+
const localeService = useDependency(LocaleService);
|
|
111
|
+
const editing = useObservable(hyperLinkService.editingLink$);
|
|
112
|
+
const commandService = useDependency(ICommandService);
|
|
113
|
+
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
114
|
+
const docSelectionManagerService = useDependency(DocSelectionManagerService);
|
|
115
|
+
const [link, setLink] = useState("");
|
|
116
|
+
const [label, setLabel] = useState("");
|
|
117
|
+
const [showError, setShowError] = useState(false);
|
|
118
|
+
const isLegal = Tools.isLegalUrl(link);
|
|
119
|
+
const doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
var _doc$getSelfOrHeaderF2, _BuildTextUtils$custo, _body$customRanges2;
|
|
122
|
+
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
123
|
+
if (!activeRange) return;
|
|
124
|
+
if (editing) {
|
|
125
|
+
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
126
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
127
|
+
const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((i) => (editing === null || editing === void 0 ? void 0 : editing.linkId) === i.rangeId && i.startIndex === editing.startIndex && i.endIndex === editing.endIndex);
|
|
128
|
+
if (doc && matchedRange) {
|
|
129
|
+
var _matchedRange$propert, _matchedRange$propert2;
|
|
130
|
+
setLink((_matchedRange$propert = (_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) !== null && _matchedRange$propert !== void 0 ? _matchedRange$propert : "");
|
|
131
|
+
setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(body, matchedRange.startIndex, matchedRange.endIndex + 1).dataStream));
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF2 = doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) === null || _doc$getSelfOrHeaderF2 === void 0 ? void 0 : _doc$getSelfOrHeaderF2.getBody();
|
|
136
|
+
const selection = body ? activeRange : null;
|
|
137
|
+
const matchedRange = selection && ((_BuildTextUtils$custo = BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_body$customRanges2 = body === null || body === void 0 ? void 0 : body.customRanges) !== null && _body$customRanges2 !== void 0 ? _body$customRanges2 : [])) === null || _BuildTextUtils$custo === void 0 ? void 0 : _BuildTextUtils$custo[0]);
|
|
138
|
+
if (doc && matchedRange) {
|
|
139
|
+
var _matchedRange$propert3, _matchedRange$propert4;
|
|
140
|
+
setLink((_matchedRange$propert3 = matchedRange === null || matchedRange === void 0 || (_matchedRange$propert4 = matchedRange.properties) === null || _matchedRange$propert4 === void 0 ? void 0 : _matchedRange$propert4.url) !== null && _matchedRange$propert3 !== void 0 ? _matchedRange$propert3 : "");
|
|
141
|
+
}
|
|
142
|
+
}, [
|
|
143
|
+
doc,
|
|
144
|
+
editing,
|
|
145
|
+
docSelectionManagerService,
|
|
146
|
+
univerInstanceService
|
|
147
|
+
]);
|
|
148
|
+
const handleCancel = () => {
|
|
149
|
+
hyperLinkService.hideEditPopup();
|
|
150
|
+
};
|
|
151
|
+
const handleConfirm = () => {
|
|
152
|
+
setShowError(true);
|
|
153
|
+
if (!isLegal || !doc) return;
|
|
154
|
+
const linkFinal = transformUrl(link);
|
|
155
|
+
if (!editing) commandService.executeCommand(AddDocHyperLinkCommand.id, {
|
|
156
|
+
unitId: doc.getUnitId(),
|
|
157
|
+
payload: linkFinal
|
|
158
|
+
});
|
|
159
|
+
else {
|
|
160
|
+
if (isBlankInput(label)) return;
|
|
161
|
+
commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
|
|
162
|
+
unitId: doc.getUnitId(),
|
|
163
|
+
payload: linkFinal,
|
|
164
|
+
linkId: editing.linkId,
|
|
165
|
+
label,
|
|
166
|
+
segmentId: editing.segmentId
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
hyperLinkService.hideEditPopup();
|
|
170
|
+
};
|
|
171
|
+
if (!doc) return;
|
|
172
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
173
|
+
className: clsx("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900", borderClassName),
|
|
174
|
+
children: [/* @__PURE__ */ jsxs("div", { children: [editing ? /* @__PURE__ */ jsx(FormLayout, {
|
|
175
|
+
label: localeService.t("docs-hyper-link-ui.edit.label"),
|
|
176
|
+
error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
|
|
177
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
178
|
+
value: label,
|
|
179
|
+
onChange: setLabel,
|
|
180
|
+
autoFocus: true,
|
|
181
|
+
onKeyDown: (evt) => {
|
|
182
|
+
if (evt.keyCode === KeyCode.ENTER) handleConfirm();
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
}) : null, /* @__PURE__ */ jsx(FormLayout, {
|
|
186
|
+
label: localeService.t("docs-hyper-link-ui.edit.address"),
|
|
187
|
+
error: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : "",
|
|
188
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
189
|
+
value: link,
|
|
190
|
+
onChange: setLink,
|
|
191
|
+
autoFocus: true,
|
|
192
|
+
onKeyDown: (evt) => {
|
|
193
|
+
if (evt.keyCode === KeyCode.ENTER) handleConfirm();
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
})] }), /* @__PURE__ */ jsxs("div", {
|
|
197
|
+
className: "univer-flex univer-justify-end univer-gap-3",
|
|
198
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
199
|
+
onClick: handleCancel,
|
|
200
|
+
children: localeService.t("docs-hyper-link-ui.edit.cancel")
|
|
201
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
202
|
+
variant: "primary",
|
|
203
|
+
disabled: isBlankInput(link),
|
|
204
|
+
onClick: handleConfirm,
|
|
205
|
+
children: localeService.t("docs-hyper-link-ui.edit.confirm")
|
|
206
|
+
})]
|
|
207
|
+
})]
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
|
|
211
|
+
|
|
87
212
|
//#endregion
|
|
88
213
|
//#region src/commands/commands/delete-link.command.ts
|
|
89
214
|
const DeleteDocHyperLinkCommand = {
|
|
@@ -103,61 +228,6 @@ const DeleteDocHyperLinkCommand = {
|
|
|
103
228
|
}
|
|
104
229
|
};
|
|
105
230
|
|
|
106
|
-
//#endregion
|
|
107
|
-
//#region src/commands/operations/popup.operation.ts
|
|
108
|
-
const shouldDisableAddLink = (accessor) => {
|
|
109
|
-
const textSelectionService = accessor.get(DocSelectionManagerService);
|
|
110
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
111
|
-
const textRanges = textSelectionService.getTextRanges();
|
|
112
|
-
if (!(textRanges === null || textRanges === void 0 ? void 0 : textRanges.length)) return true;
|
|
113
|
-
const activeRange = textRanges[0];
|
|
114
|
-
if (!univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC) || !activeRange || activeRange.collapsed) return true;
|
|
115
|
-
return false;
|
|
116
|
-
};
|
|
117
|
-
const ShowDocHyperLinkEditPopupOperation = {
|
|
118
|
-
type: CommandType.OPERATION,
|
|
119
|
-
id: "doc.operation.show-hyper-link-edit-popup",
|
|
120
|
-
handler(accessor, params) {
|
|
121
|
-
var _univerInstanceServic;
|
|
122
|
-
const linkInfo = params === null || params === void 0 ? void 0 : params.link;
|
|
123
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
124
|
-
if (shouldDisableAddLink(accessor) && !linkInfo) return false;
|
|
125
|
-
const hyperLinkService = accessor.get(DocHyperLinkPopupService);
|
|
126
|
-
const unitId = (linkInfo === null || linkInfo === void 0 ? void 0 : linkInfo.unitId) || ((_univerInstanceServic = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId());
|
|
127
|
-
if (!unitId) return false;
|
|
128
|
-
hyperLinkService.showEditPopup(unitId, linkInfo);
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
const ToggleDocHyperLinkInfoPopupOperation = {
|
|
133
|
-
type: CommandType.OPERATION,
|
|
134
|
-
id: "doc.operation.toggle-hyper-link-info-popup",
|
|
135
|
-
handler(accessor, params) {
|
|
136
|
-
const hyperLinkService = accessor.get(DocHyperLinkPopupService);
|
|
137
|
-
if (!params) {
|
|
138
|
-
hyperLinkService.hideInfoPopup();
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
hyperLinkService.showInfoPopup(params);
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
const ClickDocHyperLinkOperation = {
|
|
146
|
-
type: CommandType.OPERATION,
|
|
147
|
-
id: "doc.operation.click-hyper-link",
|
|
148
|
-
handler(accessor, params) {
|
|
149
|
-
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
150
|
-
if (!params) return false;
|
|
151
|
-
const { unitId, linkId, segmentId } = params;
|
|
152
|
-
const doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
153
|
-
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
154
|
-
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.properties) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.url;
|
|
155
|
-
if (!isSafeUrl(link)) return false;
|
|
156
|
-
window.open(link, "_blank", "noopener noreferrer");
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
231
|
//#endregion
|
|
162
232
|
//#region src/views/DocLinkPopup.tsx
|
|
163
233
|
const DocLinkPopup = () => {
|
|
@@ -407,140 +477,124 @@ DocHyperLinkPopupService = __decorate([
|
|
|
407
477
|
], DocHyperLinkPopupService);
|
|
408
478
|
|
|
409
479
|
//#endregion
|
|
410
|
-
//#region src/
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
480
|
+
//#region src/commands/operations/popup.operation.ts
|
|
481
|
+
const shouldDisableAddLink = (accessor) => {
|
|
482
|
+
const textSelectionService = accessor.get(DocSelectionManagerService);
|
|
483
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
484
|
+
const textRanges = textSelectionService.getTextRanges();
|
|
485
|
+
if (!(textRanges === null || textRanges === void 0 ? void 0 : textRanges.length)) return true;
|
|
486
|
+
const activeRange = textRanges[0];
|
|
487
|
+
if (!univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC) || !activeRange || activeRange.collapsed) return true;
|
|
488
|
+
return false;
|
|
489
|
+
};
|
|
490
|
+
const ShowDocHyperLinkEditPopupOperation = {
|
|
491
|
+
type: CommandType.OPERATION,
|
|
492
|
+
id: "doc.operation.show-hyper-link-edit-popup",
|
|
493
|
+
handler(accessor, params) {
|
|
494
|
+
var _univerInstanceServic;
|
|
495
|
+
const linkInfo = params === null || params === void 0 ? void 0 : params.link;
|
|
496
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
497
|
+
if (shouldDisableAddLink(accessor) && !linkInfo) return false;
|
|
498
|
+
const hyperLinkService = accessor.get(DocHyperLinkPopupService);
|
|
499
|
+
const unitId = (linkInfo === null || linkInfo === void 0 ? void 0 : linkInfo.unitId) || ((_univerInstanceServic = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId());
|
|
500
|
+
if (!unitId) return false;
|
|
501
|
+
hyperLinkService.showEditPopup(unitId, linkInfo);
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
const ToggleDocHyperLinkInfoPopupOperation = {
|
|
506
|
+
type: CommandType.OPERATION,
|
|
507
|
+
id: "doc.operation.toggle-hyper-link-info-popup",
|
|
508
|
+
handler(accessor, params) {
|
|
509
|
+
const hyperLinkService = accessor.get(DocHyperLinkPopupService);
|
|
510
|
+
if (!params) {
|
|
511
|
+
hyperLinkService.hideInfoPopup();
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
hyperLinkService.showInfoPopup(params);
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
const ClickDocHyperLinkOperation = {
|
|
519
|
+
type: CommandType.OPERATION,
|
|
520
|
+
id: "doc.operation.click-hyper-link",
|
|
521
|
+
handler(accessor, params) {
|
|
522
|
+
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
523
|
+
if (!params) return false;
|
|
524
|
+
const { unitId, linkId, segmentId } = params;
|
|
525
|
+
const doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
526
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
527
|
+
const link = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)) === null || _body$customRanges === void 0 || (_body$customRanges = _body$customRanges.properties) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.url;
|
|
528
|
+
if (!isSafeUrl(link)) return false;
|
|
529
|
+
window.open(link, "_blank", "noopener noreferrer");
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
532
|
+
};
|
|
429
533
|
|
|
430
534
|
//#endregion
|
|
431
|
-
//#region src/
|
|
432
|
-
function
|
|
433
|
-
return
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
const localeService = useDependency(LocaleService);
|
|
444
|
-
const editing = useObservable(hyperLinkService.editingLink$);
|
|
445
|
-
const commandService = useDependency(ICommandService);
|
|
446
|
-
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
447
|
-
const docSelectionManagerService = useDependency(DocSelectionManagerService);
|
|
448
|
-
const [link, setLink] = useState("");
|
|
449
|
-
const [label, setLabel] = useState("");
|
|
450
|
-
const [showError, setShowError] = useState(false);
|
|
451
|
-
const isLegal = Tools.isLegalUrl(link);
|
|
452
|
-
const doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
453
|
-
useEffect(() => {
|
|
454
|
-
var _doc$getSelfOrHeaderF2, _BuildTextUtils$custo, _body$customRanges2;
|
|
455
|
-
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
456
|
-
if (!activeRange) return;
|
|
457
|
-
if (editing) {
|
|
458
|
-
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
459
|
-
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
460
|
-
const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((i) => (editing === null || editing === void 0 ? void 0 : editing.linkId) === i.rangeId && i.startIndex === editing.startIndex && i.endIndex === editing.endIndex);
|
|
461
|
-
if (doc && matchedRange) {
|
|
462
|
-
var _matchedRange$propert, _matchedRange$propert2;
|
|
463
|
-
setLink((_matchedRange$propert = (_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) !== null && _matchedRange$propert !== void 0 ? _matchedRange$propert : "");
|
|
464
|
-
setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(body, matchedRange.startIndex, matchedRange.endIndex + 1).dataStream));
|
|
465
|
-
}
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF2 = doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) === null || _doc$getSelfOrHeaderF2 === void 0 ? void 0 : _doc$getSelfOrHeaderF2.getBody();
|
|
469
|
-
const selection = body ? activeRange : null;
|
|
470
|
-
const matchedRange = selection && ((_BuildTextUtils$custo = BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_body$customRanges2 = body === null || body === void 0 ? void 0 : body.customRanges) !== null && _body$customRanges2 !== void 0 ? _body$customRanges2 : [])) === null || _BuildTextUtils$custo === void 0 ? void 0 : _BuildTextUtils$custo[0]);
|
|
471
|
-
if (doc && matchedRange) {
|
|
472
|
-
var _matchedRange$propert3, _matchedRange$propert4;
|
|
473
|
-
setLink((_matchedRange$propert3 = matchedRange === null || matchedRange === void 0 || (_matchedRange$propert4 = matchedRange.properties) === null || _matchedRange$propert4 === void 0 ? void 0 : _matchedRange$propert4.url) !== null && _matchedRange$propert3 !== void 0 ? _matchedRange$propert3 : "");
|
|
474
|
-
}
|
|
475
|
-
}, [
|
|
476
|
-
doc,
|
|
477
|
-
editing,
|
|
478
|
-
docSelectionManagerService,
|
|
479
|
-
univerInstanceService
|
|
480
|
-
]);
|
|
481
|
-
const handleCancel = () => {
|
|
482
|
-
hyperLinkService.hideEditPopup();
|
|
483
|
-
};
|
|
484
|
-
const handleConfirm = () => {
|
|
485
|
-
setShowError(true);
|
|
486
|
-
if (!isLegal || !doc) return;
|
|
487
|
-
const linkFinal = transformUrl(link);
|
|
488
|
-
if (!editing) commandService.executeCommand(AddDocHyperLinkCommand.id, {
|
|
489
|
-
unitId: doc.getUnitId(),
|
|
490
|
-
payload: linkFinal
|
|
491
|
-
});
|
|
492
|
-
else {
|
|
493
|
-
if (isBlankInput(label)) return;
|
|
494
|
-
commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
|
|
495
|
-
unitId: doc.getUnitId(),
|
|
496
|
-
payload: linkFinal,
|
|
497
|
-
linkId: editing.linkId,
|
|
498
|
-
label,
|
|
499
|
-
segmentId: editing.segmentId
|
|
535
|
+
//#region src/menu/menu.ts
|
|
536
|
+
function AddHyperLinkMenuItemFactory(accessor) {
|
|
537
|
+
return {
|
|
538
|
+
id: ShowDocHyperLinkEditPopupOperation.id,
|
|
539
|
+
type: MenuItemType.BUTTON,
|
|
540
|
+
icon: "LinkIcon",
|
|
541
|
+
title: "docs-hyper-link-ui.menu.tooltip",
|
|
542
|
+
tooltip: "docs-hyper-link-ui.menu.tooltip",
|
|
543
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
|
|
544
|
+
disabled$: new Observable(function(subscribe) {
|
|
545
|
+
const observer = accessor.get(DocSelectionManagerService).textSelection$.pipe(debounceTime(16)).subscribe(() => {
|
|
546
|
+
subscribe.next(shouldDisableAddLink(accessor));
|
|
500
547
|
});
|
|
501
|
-
|
|
502
|
-
|
|
548
|
+
return () => {
|
|
549
|
+
observer.unsubscribe();
|
|
550
|
+
};
|
|
551
|
+
})
|
|
503
552
|
};
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
onClick: handleConfirm,
|
|
538
|
-
children: localeService.t("docs-hyper-link-ui.edit.confirm")
|
|
539
|
-
})]
|
|
540
|
-
})]
|
|
541
|
-
});
|
|
553
|
+
}
|
|
554
|
+
const addLinkShortcut = {
|
|
555
|
+
id: ShowDocHyperLinkEditPopupOperation.id,
|
|
556
|
+
binding: MetaKeys.CTRL_COMMAND | KeyCode.K,
|
|
557
|
+
description: "docs-hyper-link-ui.menu.tooltip",
|
|
558
|
+
preconditions: whenDocAndEditorFocused
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
//#endregion
|
|
562
|
+
//#region src/menu/schema.ts
|
|
563
|
+
const menuSchema = {
|
|
564
|
+
[RibbonInsertGroup.MEDIA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
565
|
+
order: 1,
|
|
566
|
+
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
567
|
+
} },
|
|
568
|
+
[FLOAT_TOOLBAR_MENU_POSITION]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
569
|
+
order: 20,
|
|
570
|
+
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
571
|
+
} },
|
|
572
|
+
[ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.DATA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
573
|
+
order: 0,
|
|
574
|
+
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
575
|
+
} } },
|
|
576
|
+
[ContextMenuPosition.PARAGRAPH]: {
|
|
577
|
+
[ContextMenuGroup.LAYOUT]: { [INSERT_BELLOW_MENU_ID]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
578
|
+
order: 6,
|
|
579
|
+
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
580
|
+
} } },
|
|
581
|
+
[EMPTY_PARAGRAPH_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
582
|
+
order: 6,
|
|
583
|
+
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
584
|
+
} } }
|
|
585
|
+
}
|
|
542
586
|
};
|
|
543
|
-
|
|
587
|
+
|
|
588
|
+
//#endregion
|
|
589
|
+
//#region package.json
|
|
590
|
+
var name = "@univerjs/docs-hyper-link-ui";
|
|
591
|
+
var version = "1.0.0-alpha.4";
|
|
592
|
+
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region src/config/config.ts
|
|
595
|
+
const DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config";
|
|
596
|
+
const configSymbol = Symbol(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
|
|
597
|
+
const defaultPluginConfig = {};
|
|
544
598
|
|
|
545
599
|
//#endregion
|
|
546
600
|
//#region src/controllers/components.controller.ts
|
|
@@ -732,60 +786,6 @@ DocHyperLinkRenderController = __decorate([
|
|
|
732
786
|
__decorateParam(3, Inject(DocRenderController))
|
|
733
787
|
], DocHyperLinkRenderController);
|
|
734
788
|
|
|
735
|
-
//#endregion
|
|
736
|
-
//#region src/menu/menu.ts
|
|
737
|
-
function AddHyperLinkMenuItemFactory(accessor) {
|
|
738
|
-
return {
|
|
739
|
-
id: ShowDocHyperLinkEditPopupOperation.id,
|
|
740
|
-
type: MenuItemType.BUTTON,
|
|
741
|
-
icon: "LinkIcon",
|
|
742
|
-
title: "docs-hyper-link-ui.menu.tooltip",
|
|
743
|
-
tooltip: "docs-hyper-link-ui.menu.tooltip",
|
|
744
|
-
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
|
|
745
|
-
disabled$: new Observable(function(subscribe) {
|
|
746
|
-
const observer = accessor.get(DocSelectionManagerService).textSelection$.pipe(debounceTime(16)).subscribe(() => {
|
|
747
|
-
subscribe.next(shouldDisableAddLink(accessor));
|
|
748
|
-
});
|
|
749
|
-
return () => {
|
|
750
|
-
observer.unsubscribe();
|
|
751
|
-
};
|
|
752
|
-
})
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
const addLinkShortcut = {
|
|
756
|
-
id: ShowDocHyperLinkEditPopupOperation.id,
|
|
757
|
-
binding: MetaKeys.CTRL_COMMAND | KeyCode.K,
|
|
758
|
-
description: "docs-hyper-link-ui.menu.tooltip",
|
|
759
|
-
preconditions: whenDocAndEditorFocused
|
|
760
|
-
};
|
|
761
|
-
|
|
762
|
-
//#endregion
|
|
763
|
-
//#region src/menu/schema.ts
|
|
764
|
-
const menuSchema = {
|
|
765
|
-
[RibbonInsertGroup.MEDIA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
766
|
-
order: 1,
|
|
767
|
-
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
768
|
-
} },
|
|
769
|
-
[FLOAT_TOOLBAR_MENU_POSITION]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
770
|
-
order: 20,
|
|
771
|
-
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
772
|
-
} },
|
|
773
|
-
[ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.DATA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
774
|
-
order: 0,
|
|
775
|
-
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
776
|
-
} } },
|
|
777
|
-
[ContextMenuPosition.PARAGRAPH]: {
|
|
778
|
-
[ContextMenuGroup.LAYOUT]: { [INSERT_BELLOW_MENU_ID]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
779
|
-
order: 6,
|
|
780
|
-
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
781
|
-
} } },
|
|
782
|
-
[EMPTY_PARAGRAPH_MENU_ID]: { [ContextMenuGroup.LAYOUT]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
783
|
-
order: 6,
|
|
784
|
-
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
785
|
-
} } }
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
|
-
|
|
789
789
|
//#endregion
|
|
790
790
|
//#region src/controllers/ui.controller.ts
|
|
791
791
|
let DocHyperLinkUIController = class DocHyperLinkUIController extends Disposable {
|
|
@@ -894,4 +894,4 @@ UniverDocsHyperLinkUIPlugin = __decorate([
|
|
|
894
894
|
], UniverDocsHyperLinkUIPlugin);
|
|
895
895
|
|
|
896
896
|
//#endregion
|
|
897
|
-
export { UniverDocsHyperLinkUIPlugin };
|
|
897
|
+
export { menuSchema as DocsHyperLinkUIMenuSchema, UniverDocsHyperLinkUIPlugin };
|