@univerjs/docs-hyper-link-ui 0.25.0 → 1.0.0-alpha.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 +197 -167
- package/lib/es/index.js +199 -169
- package/lib/index.js +199 -169
- package/lib/types/controllers/components.controller.d.ts +24 -0
- package/lib/types/controllers/ui.controller.d.ts +2 -4
- package/lib/types/locale/types.d.ts +18 -0
- package/lib/types/menu/menu.d.ts +2 -2
- package/lib/types/views/{hyper-link-edit/index.d.ts → DocHyperLinkEdit.d.ts} +1 -1
- package/lib/types/views/{hyper-link-popup/index.d.ts → DocLinkPopup.d.ts} +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +11 -11
package/lib/es/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { BuildTextUtils, CommandType, CustomRangeType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
|
|
1
|
+
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";
|
|
2
2
|
import { UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
|
|
3
3
|
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, pairwise } from "rxjs";
|
|
4
|
+
import { CopyIcon, LinkIcon, UnlinkIcon, WriteIcon } from "@univerjs/icons";
|
|
5
|
+
import { ComponentManager, ContextMenuGroup, ContextMenuPosition, IMenuManagerService, IMessageService, IShortcutService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonInsertGroup, getMenuHiddenObservable, useDependency, useObservable } from "@univerjs/ui";
|
|
7
6
|
import { Button, FormLayout, Input, MessageType, Tooltip, borderClassName, clsx } from "@univerjs/design";
|
|
8
|
-
import {
|
|
7
|
+
import { DOC_INTERCEPTOR_POINT, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, SetTextSelectionsOperation, addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory } from "@univerjs/docs";
|
|
9
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
|
+
import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, pairwise } from "rxjs";
|
|
10
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { CopyIcon, LinkIcon, UnlinkIcon, WriteIcon } from "@univerjs/icons";
|
|
12
12
|
|
|
13
13
|
//#region package.json
|
|
14
14
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
15
|
-
var version = "0.
|
|
15
|
+
var version = "1.0.0-alpha.0";
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/config/config.ts
|
|
@@ -82,142 +82,6 @@ const UpdateDocHyperLinkCommand = {
|
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
//#endregion
|
|
86
|
-
//#region src/views/hyper-link-edit/utils.ts
|
|
87
|
-
/**
|
|
88
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
89
|
-
*
|
|
90
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
91
|
-
* you may not use this file except in compliance with the License.
|
|
92
|
-
* You may obtain a copy of the License at
|
|
93
|
-
*
|
|
94
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
95
|
-
*
|
|
96
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
97
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
98
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
99
|
-
* See the License for the specific language governing permissions and
|
|
100
|
-
* limitations under the License.
|
|
101
|
-
*/
|
|
102
|
-
function isBlankInput(value) {
|
|
103
|
-
return value.trim().length === 0;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
//#endregion
|
|
107
|
-
//#region src/views/hyper-link-edit/index.tsx
|
|
108
|
-
function hasProtocol(urlString) {
|
|
109
|
-
return /^[a-zA-Z]+:\/\//.test(urlString);
|
|
110
|
-
}
|
|
111
|
-
function isEmail(url) {
|
|
112
|
-
return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
|
|
113
|
-
}
|
|
114
|
-
function transformUrl(urlStr) {
|
|
115
|
-
return hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `https://${urlStr}`;
|
|
116
|
-
}
|
|
117
|
-
const DocHyperLinkEdit = () => {
|
|
118
|
-
const hyperLinkService = useDependency(DocHyperLinkPopupService);
|
|
119
|
-
const localeService = useDependency(LocaleService);
|
|
120
|
-
const editing = useObservable(hyperLinkService.editingLink$);
|
|
121
|
-
const commandService = useDependency(ICommandService);
|
|
122
|
-
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
123
|
-
const docSelectionManagerService = useDependency(DocSelectionManagerService);
|
|
124
|
-
const [link, setLink] = useState("");
|
|
125
|
-
const [label, setLabel] = useState("");
|
|
126
|
-
const [showError, setShowError] = useState(false);
|
|
127
|
-
const isLegal = Tools.isLegalUrl(link);
|
|
128
|
-
const doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
129
|
-
useEffect(() => {
|
|
130
|
-
var _doc$getSelfOrHeaderF2, _BuildTextUtils$custo, _body$customRanges2;
|
|
131
|
-
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
132
|
-
if (!activeRange) return;
|
|
133
|
-
if (editing) {
|
|
134
|
-
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
135
|
-
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
136
|
-
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);
|
|
137
|
-
if (doc && matchedRange) {
|
|
138
|
-
var _matchedRange$propert, _matchedRange$propert2;
|
|
139
|
-
setLink((_matchedRange$propert = (_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) !== null && _matchedRange$propert !== void 0 ? _matchedRange$propert : "");
|
|
140
|
-
setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(body, matchedRange.startIndex, matchedRange.endIndex + 1).dataStream));
|
|
141
|
-
}
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF2 = doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) === null || _doc$getSelfOrHeaderF2 === void 0 ? void 0 : _doc$getSelfOrHeaderF2.getBody();
|
|
145
|
-
const selection = body ? activeRange : null;
|
|
146
|
-
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]);
|
|
147
|
-
if (doc && matchedRange) {
|
|
148
|
-
var _matchedRange$propert3, _matchedRange$propert4;
|
|
149
|
-
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 : "");
|
|
150
|
-
}
|
|
151
|
-
}, [
|
|
152
|
-
doc,
|
|
153
|
-
editing,
|
|
154
|
-
docSelectionManagerService,
|
|
155
|
-
univerInstanceService
|
|
156
|
-
]);
|
|
157
|
-
const handleCancel = () => {
|
|
158
|
-
hyperLinkService.hideEditPopup();
|
|
159
|
-
};
|
|
160
|
-
const handleConfirm = () => {
|
|
161
|
-
setShowError(true);
|
|
162
|
-
if (!isLegal || !doc) return;
|
|
163
|
-
const linkFinal = transformUrl(link);
|
|
164
|
-
if (!editing) commandService.executeCommand(AddDocHyperLinkCommand.id, {
|
|
165
|
-
unitId: doc.getUnitId(),
|
|
166
|
-
payload: linkFinal
|
|
167
|
-
});
|
|
168
|
-
else {
|
|
169
|
-
if (isBlankInput(label)) return;
|
|
170
|
-
commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
|
|
171
|
-
unitId: doc.getUnitId(),
|
|
172
|
-
payload: linkFinal,
|
|
173
|
-
linkId: editing.linkId,
|
|
174
|
-
label,
|
|
175
|
-
segmentId: editing.segmentId
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
hyperLinkService.hideEditPopup();
|
|
179
|
-
};
|
|
180
|
-
if (!doc) return;
|
|
181
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
182
|
-
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),
|
|
183
|
-
children: [/* @__PURE__ */ jsxs("div", { children: [editing ? /* @__PURE__ */ jsx(FormLayout, {
|
|
184
|
-
label: localeService.t("docs-hyper-link-ui.edit.label"),
|
|
185
|
-
error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
|
|
186
|
-
children: /* @__PURE__ */ jsx(Input, {
|
|
187
|
-
value: label,
|
|
188
|
-
onChange: setLabel,
|
|
189
|
-
autoFocus: true,
|
|
190
|
-
onKeyDown: (evt) => {
|
|
191
|
-
if (evt.keyCode === KeyCode.ENTER) handleConfirm();
|
|
192
|
-
}
|
|
193
|
-
})
|
|
194
|
-
}) : null, /* @__PURE__ */ jsx(FormLayout, {
|
|
195
|
-
label: localeService.t("docs-hyper-link-ui.edit.address"),
|
|
196
|
-
error: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : "",
|
|
197
|
-
children: /* @__PURE__ */ jsx(Input, {
|
|
198
|
-
value: link,
|
|
199
|
-
onChange: setLink,
|
|
200
|
-
autoFocus: true,
|
|
201
|
-
onKeyDown: (evt) => {
|
|
202
|
-
if (evt.keyCode === KeyCode.ENTER) handleConfirm();
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
})] }), /* @__PURE__ */ jsxs("div", {
|
|
206
|
-
className: "univer-flex univer-justify-end univer-gap-3",
|
|
207
|
-
children: [/* @__PURE__ */ jsx(Button, {
|
|
208
|
-
onClick: handleCancel,
|
|
209
|
-
children: localeService.t("docs-hyper-link-ui.edit.cancel")
|
|
210
|
-
}), /* @__PURE__ */ jsx(Button, {
|
|
211
|
-
variant: "primary",
|
|
212
|
-
disabled: isBlankInput(link),
|
|
213
|
-
onClick: handleConfirm,
|
|
214
|
-
children: localeService.t("docs-hyper-link-ui.edit.confirm")
|
|
215
|
-
})]
|
|
216
|
-
})]
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
|
|
220
|
-
|
|
221
85
|
//#endregion
|
|
222
86
|
//#region src/commands/commands/delete-link.command.ts
|
|
223
87
|
const DeleteDocHyperLinkCommand = {
|
|
@@ -293,7 +157,7 @@ const ClickDocHyperLinkOperation = {
|
|
|
293
157
|
};
|
|
294
158
|
|
|
295
159
|
//#endregion
|
|
296
|
-
//#region src/views/
|
|
160
|
+
//#region src/views/DocLinkPopup.tsx
|
|
297
161
|
const DocLinkPopup = () => {
|
|
298
162
|
var _body$customRanges, _link$properties;
|
|
299
163
|
const hyperLinkService = useDependency(DocHyperLinkPopupService);
|
|
@@ -379,7 +243,7 @@ const DocLinkPopup = () => {
|
|
|
379
243
|
DocLinkPopup.componentKey = "univer.doc.link-info-popup";
|
|
380
244
|
|
|
381
245
|
//#endregion
|
|
382
|
-
//#region \0@oxc-project+runtime@0.
|
|
246
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
383
247
|
function _typeof(o) {
|
|
384
248
|
"@babel/helpers - typeof";
|
|
385
249
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -390,7 +254,7 @@ function _typeof(o) {
|
|
|
390
254
|
}
|
|
391
255
|
|
|
392
256
|
//#endregion
|
|
393
|
-
//#region \0@oxc-project+runtime@0.
|
|
257
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
394
258
|
function toPrimitive(t, r) {
|
|
395
259
|
if ("object" != _typeof(t) || !t) return t;
|
|
396
260
|
var e = t[Symbol.toPrimitive];
|
|
@@ -403,14 +267,14 @@ function toPrimitive(t, r) {
|
|
|
403
267
|
}
|
|
404
268
|
|
|
405
269
|
//#endregion
|
|
406
|
-
//#region \0@oxc-project+runtime@0.
|
|
270
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
407
271
|
function toPropertyKey(t) {
|
|
408
272
|
var i = toPrimitive(t, "string");
|
|
409
273
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
410
274
|
}
|
|
411
275
|
|
|
412
276
|
//#endregion
|
|
413
|
-
//#region \0@oxc-project+runtime@0.
|
|
277
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
414
278
|
function _defineProperty(e, r, t) {
|
|
415
279
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
416
280
|
value: t,
|
|
@@ -421,7 +285,7 @@ function _defineProperty(e, r, t) {
|
|
|
421
285
|
}
|
|
422
286
|
|
|
423
287
|
//#endregion
|
|
424
|
-
//#region \0@oxc-project+runtime@0.
|
|
288
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
425
289
|
function __decorateParam(paramIndex, decorator) {
|
|
426
290
|
return function(target, key) {
|
|
427
291
|
decorator(target, key, paramIndex);
|
|
@@ -429,7 +293,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
429
293
|
}
|
|
430
294
|
|
|
431
295
|
//#endregion
|
|
432
|
-
//#region \0@oxc-project+runtime@0.
|
|
296
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
|
|
433
297
|
function __decorate(decorators, target, key, desc) {
|
|
434
298
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
435
299
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -540,6 +404,178 @@ DocHyperLinkPopupService = __decorate([
|
|
|
540
404
|
__decorateParam(2, IUniverInstanceService)
|
|
541
405
|
], DocHyperLinkPopupService);
|
|
542
406
|
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/views/hyper-link-edit/utils.ts
|
|
409
|
+
/**
|
|
410
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
411
|
+
*
|
|
412
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
413
|
+
* you may not use this file except in compliance with the License.
|
|
414
|
+
* You may obtain a copy of the License at
|
|
415
|
+
*
|
|
416
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
417
|
+
*
|
|
418
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
419
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
420
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
421
|
+
* See the License for the specific language governing permissions and
|
|
422
|
+
* limitations under the License.
|
|
423
|
+
*/
|
|
424
|
+
function isBlankInput(value) {
|
|
425
|
+
return value.trim().length === 0;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/views/DocHyperLinkEdit.tsx
|
|
430
|
+
function hasProtocol(urlString) {
|
|
431
|
+
return /^[a-zA-Z]+:\/\//.test(urlString);
|
|
432
|
+
}
|
|
433
|
+
function isEmail(url) {
|
|
434
|
+
return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
|
|
435
|
+
}
|
|
436
|
+
function transformUrl(urlStr) {
|
|
437
|
+
return hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `https://${urlStr}`;
|
|
438
|
+
}
|
|
439
|
+
const DocHyperLinkEdit = () => {
|
|
440
|
+
const hyperLinkService = useDependency(DocHyperLinkPopupService);
|
|
441
|
+
const localeService = useDependency(LocaleService);
|
|
442
|
+
const editing = useObservable(hyperLinkService.editingLink$);
|
|
443
|
+
const commandService = useDependency(ICommandService);
|
|
444
|
+
const univerInstanceService = useDependency(IUniverInstanceService);
|
|
445
|
+
const docSelectionManagerService = useDependency(DocSelectionManagerService);
|
|
446
|
+
const [link, setLink] = useState("");
|
|
447
|
+
const [label, setLabel] = useState("");
|
|
448
|
+
const [showError, setShowError] = useState(false);
|
|
449
|
+
const isLegal = Tools.isLegalUrl(link);
|
|
450
|
+
const doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);
|
|
451
|
+
useEffect(() => {
|
|
452
|
+
var _doc$getSelfOrHeaderF2, _BuildTextUtils$custo, _body$customRanges2;
|
|
453
|
+
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
454
|
+
if (!activeRange) return;
|
|
455
|
+
if (editing) {
|
|
456
|
+
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
457
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
458
|
+
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);
|
|
459
|
+
if (doc && matchedRange) {
|
|
460
|
+
var _matchedRange$propert, _matchedRange$propert2;
|
|
461
|
+
setLink((_matchedRange$propert = (_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) !== null && _matchedRange$propert !== void 0 ? _matchedRange$propert : "");
|
|
462
|
+
setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(body, matchedRange.startIndex, matchedRange.endIndex + 1).dataStream));
|
|
463
|
+
}
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF2 = doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) === null || _doc$getSelfOrHeaderF2 === void 0 ? void 0 : _doc$getSelfOrHeaderF2.getBody();
|
|
467
|
+
const selection = body ? activeRange : null;
|
|
468
|
+
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]);
|
|
469
|
+
if (doc && matchedRange) {
|
|
470
|
+
var _matchedRange$propert3, _matchedRange$propert4;
|
|
471
|
+
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 : "");
|
|
472
|
+
}
|
|
473
|
+
}, [
|
|
474
|
+
doc,
|
|
475
|
+
editing,
|
|
476
|
+
docSelectionManagerService,
|
|
477
|
+
univerInstanceService
|
|
478
|
+
]);
|
|
479
|
+
const handleCancel = () => {
|
|
480
|
+
hyperLinkService.hideEditPopup();
|
|
481
|
+
};
|
|
482
|
+
const handleConfirm = () => {
|
|
483
|
+
setShowError(true);
|
|
484
|
+
if (!isLegal || !doc) return;
|
|
485
|
+
const linkFinal = transformUrl(link);
|
|
486
|
+
if (!editing) commandService.executeCommand(AddDocHyperLinkCommand.id, {
|
|
487
|
+
unitId: doc.getUnitId(),
|
|
488
|
+
payload: linkFinal
|
|
489
|
+
});
|
|
490
|
+
else {
|
|
491
|
+
if (isBlankInput(label)) return;
|
|
492
|
+
commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
|
|
493
|
+
unitId: doc.getUnitId(),
|
|
494
|
+
payload: linkFinal,
|
|
495
|
+
linkId: editing.linkId,
|
|
496
|
+
label,
|
|
497
|
+
segmentId: editing.segmentId
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
hyperLinkService.hideEditPopup();
|
|
501
|
+
};
|
|
502
|
+
if (!doc) return;
|
|
503
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
504
|
+
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),
|
|
505
|
+
children: [/* @__PURE__ */ jsxs("div", { children: [editing ? /* @__PURE__ */ jsx(FormLayout, {
|
|
506
|
+
label: localeService.t("docs-hyper-link-ui.edit.label"),
|
|
507
|
+
error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
|
|
508
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
509
|
+
value: label,
|
|
510
|
+
onChange: setLabel,
|
|
511
|
+
autoFocus: true,
|
|
512
|
+
onKeyDown: (evt) => {
|
|
513
|
+
if (evt.keyCode === KeyCode.ENTER) handleConfirm();
|
|
514
|
+
}
|
|
515
|
+
})
|
|
516
|
+
}) : null, /* @__PURE__ */ jsx(FormLayout, {
|
|
517
|
+
label: localeService.t("docs-hyper-link-ui.edit.address"),
|
|
518
|
+
error: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : "",
|
|
519
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
520
|
+
value: link,
|
|
521
|
+
onChange: setLink,
|
|
522
|
+
autoFocus: true,
|
|
523
|
+
onKeyDown: (evt) => {
|
|
524
|
+
if (evt.keyCode === KeyCode.ENTER) handleConfirm();
|
|
525
|
+
}
|
|
526
|
+
})
|
|
527
|
+
})] }), /* @__PURE__ */ jsxs("div", {
|
|
528
|
+
className: "univer-flex univer-justify-end univer-gap-3",
|
|
529
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
530
|
+
onClick: handleCancel,
|
|
531
|
+
children: localeService.t("docs-hyper-link-ui.edit.cancel")
|
|
532
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
533
|
+
variant: "primary",
|
|
534
|
+
disabled: isBlankInput(link),
|
|
535
|
+
onClick: handleConfirm,
|
|
536
|
+
children: localeService.t("docs-hyper-link-ui.edit.confirm")
|
|
537
|
+
})]
|
|
538
|
+
})]
|
|
539
|
+
});
|
|
540
|
+
};
|
|
541
|
+
DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
|
|
542
|
+
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region src/controllers/components.controller.ts
|
|
545
|
+
/**
|
|
546
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
547
|
+
*
|
|
548
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
549
|
+
* you may not use this file except in compliance with the License.
|
|
550
|
+
* You may obtain a copy of the License at
|
|
551
|
+
*
|
|
552
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
553
|
+
*
|
|
554
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
555
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
556
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
557
|
+
* See the License for the specific language governing permissions and
|
|
558
|
+
* limitations under the License.
|
|
559
|
+
*/
|
|
560
|
+
let ComponentsController = class ComponentsController extends Disposable {
|
|
561
|
+
constructor(_componentManager, _iconManager) {
|
|
562
|
+
super();
|
|
563
|
+
this._componentManager = _componentManager;
|
|
564
|
+
this._iconManager = _iconManager;
|
|
565
|
+
this._registerComponents();
|
|
566
|
+
this._registerIcons();
|
|
567
|
+
}
|
|
568
|
+
_registerComponents() {
|
|
569
|
+
[[DocHyperLinkEdit.componentKey, DocHyperLinkEdit], [DocLinkPopup.componentKey, DocLinkPopup]].forEach(([key, comp]) => {
|
|
570
|
+
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
_registerIcons() {
|
|
574
|
+
this.disposeWithMe(this._iconManager.register({ LinkIcon }));
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
|
|
578
|
+
|
|
543
579
|
//#endregion
|
|
544
580
|
//#region src/controllers/doc-hyper-link-selection.controller.ts
|
|
545
581
|
let DocHyperLinkSelectionController = class DocHyperLinkSelectionController extends Disposable {
|
|
@@ -603,7 +639,7 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
|
|
|
603
639
|
this._hyperLinkPopupService = _hyperLinkPopupService;
|
|
604
640
|
this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
605
641
|
this._docSelectionManagerService = _docSelectionManagerService;
|
|
606
|
-
if (this._context.unitId ===
|
|
642
|
+
if (this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
|
|
607
643
|
this._initHover();
|
|
608
644
|
this._initClick();
|
|
609
645
|
}
|
|
@@ -696,12 +732,11 @@ DocHyperLinkRenderController = __decorate([
|
|
|
696
732
|
|
|
697
733
|
//#endregion
|
|
698
734
|
//#region src/menu/menu.ts
|
|
699
|
-
const DOC_LINK_ICON = "doc-hyper-link-icon";
|
|
700
735
|
function AddHyperLinkMenuItemFactory(accessor) {
|
|
701
736
|
return {
|
|
702
737
|
id: ShowDocHyperLinkEditPopupOperation.id,
|
|
703
738
|
type: MenuItemType.BUTTON,
|
|
704
|
-
icon:
|
|
739
|
+
icon: "LinkIcon",
|
|
705
740
|
title: "docs-hyper-link-ui.menu.tooltip",
|
|
706
741
|
tooltip: "docs-hyper-link-ui.menu.tooltip",
|
|
707
742
|
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
|
|
@@ -729,6 +764,10 @@ const menuSchema = {
|
|
|
729
764
|
order: 1,
|
|
730
765
|
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
731
766
|
} },
|
|
767
|
+
[FLOAT_TOOLBAR_MENU_POSITION]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
768
|
+
order: 20,
|
|
769
|
+
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
770
|
+
} },
|
|
732
771
|
[ContextMenuPosition.MAIN_AREA]: { [ContextMenuGroup.DATA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
733
772
|
order: 0,
|
|
734
773
|
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
@@ -748,26 +787,15 @@ const menuSchema = {
|
|
|
748
787
|
//#endregion
|
|
749
788
|
//#region src/controllers/ui.controller.ts
|
|
750
789
|
let DocHyperLinkUIController = class DocHyperLinkUIController extends Disposable {
|
|
751
|
-
constructor(
|
|
790
|
+
constructor(_commandService, _menuManagerService, _shortcutService) {
|
|
752
791
|
super();
|
|
753
|
-
this._componentManager = _componentManager;
|
|
754
792
|
this._commandService = _commandService;
|
|
755
793
|
this._menuManagerService = _menuManagerService;
|
|
756
794
|
this._shortcutService = _shortcutService;
|
|
757
|
-
this._initComponents();
|
|
758
795
|
this._initCommands();
|
|
759
796
|
this._initMenus();
|
|
760
797
|
this._initShortcut();
|
|
761
798
|
}
|
|
762
|
-
_initComponents() {
|
|
763
|
-
[
|
|
764
|
-
[DocHyperLinkEdit.componentKey, DocHyperLinkEdit],
|
|
765
|
-
[DocLinkPopup.componentKey, DocLinkPopup],
|
|
766
|
-
[DOC_LINK_ICON, LinkIcon]
|
|
767
|
-
].forEach(([key, comp]) => {
|
|
768
|
-
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
799
|
_initCommands() {
|
|
772
800
|
[
|
|
773
801
|
AddDocHyperLinkCommand,
|
|
@@ -786,14 +814,14 @@ let DocHyperLinkUIController = class DocHyperLinkUIController extends Disposable
|
|
|
786
814
|
});
|
|
787
815
|
}
|
|
788
816
|
_initMenus() {
|
|
817
|
+
this._menuManagerService.appendRootMenu({ [FLOAT_TOOLBAR_MENU_POSITION]: {} });
|
|
789
818
|
this._menuManagerService.mergeMenu(menuSchema);
|
|
790
819
|
}
|
|
791
820
|
};
|
|
792
821
|
DocHyperLinkUIController = __decorate([
|
|
793
|
-
__decorateParam(0,
|
|
794
|
-
__decorateParam(1,
|
|
795
|
-
__decorateParam(2,
|
|
796
|
-
__decorateParam(3, IShortcutService)
|
|
822
|
+
__decorateParam(0, ICommandService),
|
|
823
|
+
__decorateParam(1, IMenuManagerService),
|
|
824
|
+
__decorateParam(2, IShortcutService)
|
|
797
825
|
], DocHyperLinkUIController);
|
|
798
826
|
|
|
799
827
|
//#endregion
|
|
@@ -829,6 +857,8 @@ let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends Plug
|
|
|
829
857
|
this._configService.setConfig(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
|
|
830
858
|
}
|
|
831
859
|
onStarting() {
|
|
860
|
+
this._injector.add([ComponentsController]);
|
|
861
|
+
this._injector.get(ComponentsController);
|
|
832
862
|
[
|
|
833
863
|
[DocHyperLinkPopupService],
|
|
834
864
|
[DocHyperLinkUIController],
|