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