@univerjs/docs-hyper-link-ui 1.0.0-rc.0 → 1.0.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 +586 -165
- package/lib/cjs/locale/ar-SA.js +0 -1
- package/lib/cjs/locale/ca-ES.js +0 -1
- package/lib/cjs/locale/de-DE.js +0 -1
- package/lib/cjs/locale/en-US.js +0 -1
- package/lib/cjs/locale/es-ES.js +0 -1
- package/lib/cjs/locale/fa-IR.js +0 -1
- package/lib/cjs/locale/fr-FR.js +0 -1
- package/lib/cjs/locale/id-ID.js +0 -1
- package/lib/cjs/locale/it-IT.js +0 -1
- package/lib/cjs/locale/ja-JP.js +0 -1
- package/lib/cjs/locale/ko-KR.js +0 -1
- package/lib/cjs/locale/pl-PL.js +0 -1
- package/lib/cjs/locale/pt-BR.js +0 -1
- package/lib/cjs/locale/ru-RU.js +0 -1
- package/lib/cjs/locale/sk-SK.js +0 -1
- package/lib/cjs/locale/vi-VN.js +0 -1
- package/lib/cjs/locale/zh-CN.js +0 -1
- package/lib/cjs/locale/zh-HK.js +0 -1
- package/lib/cjs/locale/zh-TW.js +0 -1
- package/lib/es/index.js +585 -170
- package/lib/index.css +29 -0
- package/lib/index.js +585 -170
- package/lib/types/commands/operations/popup.operation.d.ts +1 -0
- package/lib/types/controllers/doc-hyper-link-selection.controller.d.ts +1 -0
- package/lib/types/controllers/mobile/components.controller.d.ts +24 -0
- package/lib/types/controllers/render-controllers/hyper-link-event.render-controller.d.ts +1 -0
- package/lib/types/controllers/render-controllers/mobile/hyper-link-event.render-controller.d.ts +33 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/mobile-plugin.d.ts +32 -0
- package/lib/types/services/hyper-link-popup.service.d.ts +13 -7
- package/lib/types/services/mobile/hyper-link-popup.service.d.ts +22 -0
- package/lib/types/views/MobileDocHyperLinkEdit.d.ts +19 -0
- package/lib/types/views/MobileDocLinkPopup.d.ts +19 -0
- package/lib/types/views/hyper-link-edit/index.d.ts +19 -0
- package/lib/types/views/hyper-link-edit/use-doc-hyper-link-edit.d.ts +28 -0
- package/lib/types/views/hyper-link-popup/index.d.ts +19 -0
- package/lib/umd/index.js +1 -1
- package/package.json +13 -13
package/lib/cjs/index.js
CHANGED
|
@@ -5,13 +5,32 @@ let _univerjs_core = require("@univerjs/core");
|
|
|
5
5
|
let _univerjs_docs = require("@univerjs/docs");
|
|
6
6
|
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
7
7
|
let rxjs = require("rxjs");
|
|
8
|
+
let _univerjs_docs_hyper_link = require("@univerjs/docs-hyper-link");
|
|
8
9
|
let _univerjs_design = require("@univerjs/design");
|
|
9
10
|
let react = require("react");
|
|
10
|
-
let _univerjs_docs_hyper_link = require("@univerjs/docs-hyper-link");
|
|
11
11
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
12
12
|
let _univerjs_icons = require("@univerjs/icons");
|
|
13
13
|
let _univerjs_protocol = require("@univerjs/protocol");
|
|
14
14
|
|
|
15
|
+
//#region src/commands/commands/delete-link.command.ts
|
|
16
|
+
const DeleteDocHyperLinkCommand = {
|
|
17
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
18
|
+
id: _univerjs_docs_hyper_link.DocHyperLinkCommandId.Delete,
|
|
19
|
+
async handler(accessor, params) {
|
|
20
|
+
if (!params) return false;
|
|
21
|
+
const { unitId, linkId, segmentId } = params;
|
|
22
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
23
|
+
const doMutation = (0, _univerjs_docs.deleteCustomRangeFactory)(accessor, {
|
|
24
|
+
unitId,
|
|
25
|
+
rangeId: linkId,
|
|
26
|
+
segmentId
|
|
27
|
+
});
|
|
28
|
+
if (!doMutation) return false;
|
|
29
|
+
return await commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
15
34
|
//#region src/commands/commands/add-link.command.ts
|
|
16
35
|
const AddDocHyperLinkCommand = {
|
|
17
36
|
type: _univerjs_core.CommandType.COMMAND,
|
|
@@ -20,8 +39,9 @@ const AddDocHyperLinkCommand = {
|
|
|
20
39
|
if (!params) return false;
|
|
21
40
|
const { payload, unitId, selections } = params;
|
|
22
41
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
42
|
+
const id = (0, _univerjs_core.generateRandomId)();
|
|
23
43
|
const doMutation = (0, _univerjs_docs.addCustomRangeBySelectionFactory)(accessor, {
|
|
24
|
-
rangeId:
|
|
44
|
+
rangeId: id,
|
|
25
45
|
rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
|
|
26
46
|
properties: { url: payload },
|
|
27
47
|
unitId,
|
|
@@ -38,7 +58,7 @@ const UpdateDocHyperLinkCommand = {
|
|
|
38
58
|
id: _univerjs_docs_hyper_link.DocHyperLinkCommandId.Update,
|
|
39
59
|
type: _univerjs_core.CommandType.COMMAND,
|
|
40
60
|
handler(accessor, params) {
|
|
41
|
-
var _doc$getSelfOrHeaderF, _getBodySlice$textRun;
|
|
61
|
+
var _doc$getSelfOrHeaderF, _oldBody$customRanges, _getBodySlice$textRun, _oldLink$properties, _oldLink$properties2;
|
|
42
62
|
if (!params) return false;
|
|
43
63
|
const { unitId, payload, segmentId, linkId } = params;
|
|
44
64
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
@@ -48,6 +68,7 @@ const UpdateDocHyperLinkCommand = {
|
|
|
48
68
|
if (!currentSelection || !doc) return false;
|
|
49
69
|
const oldBody = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
50
70
|
if (!oldBody) return false;
|
|
71
|
+
const oldLink = (_oldBody$customRanges = oldBody.customRanges) === null || _oldBody$customRanges === void 0 ? void 0 : _oldBody$customRanges.find((range) => range.rangeId === linkId && range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK);
|
|
51
72
|
const textRun = (_getBodySlice$textRun = (0, _univerjs_core.getBodySlice)(oldBody, currentSelection.startOffset, currentSelection.endOffset).textRuns) === null || _getBodySlice$textRun === void 0 ? void 0 : _getBodySlice$textRun[0];
|
|
52
73
|
if (textRun) textRun.ed = params.label.length + 1;
|
|
53
74
|
const replaceSelection = (0, _univerjs_docs.replaceSelectionFactory)(accessor, {
|
|
@@ -59,7 +80,11 @@ const UpdateDocHyperLinkCommand = {
|
|
|
59
80
|
rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
|
|
60
81
|
startIndex: 0,
|
|
61
82
|
endIndex: params.label.length + 1,
|
|
62
|
-
properties: {
|
|
83
|
+
properties: {
|
|
84
|
+
url: payload,
|
|
85
|
+
...(oldLink === null || oldLink === void 0 || (_oldLink$properties = oldLink.properties) === null || _oldLink$properties === void 0 ? void 0 : _oldLink$properties.textStyleMode) ? { textStyleMode: oldLink.properties.textStyleMode } : null,
|
|
86
|
+
...(oldLink === null || oldLink === void 0 || (_oldLink$properties2 = oldLink.properties) === null || _oldLink$properties2 === void 0 ? void 0 : _oldLink$properties2.textColorMode) ? { textColorMode: oldLink.properties.textColorMode } : null
|
|
87
|
+
}
|
|
63
88
|
}],
|
|
64
89
|
textRuns: textRun ? [textRun] : void 0
|
|
65
90
|
},
|
|
@@ -97,20 +122,19 @@ function isBlankInput(value) {
|
|
|
97
122
|
}
|
|
98
123
|
|
|
99
124
|
//#endregion
|
|
100
|
-
//#region src/views/
|
|
101
|
-
function hasProtocol(
|
|
102
|
-
return /^[a-zA-Z]+:\/\//.test(
|
|
125
|
+
//#region src/views/hyper-link-edit/use-doc-hyper-link-edit.ts
|
|
126
|
+
function hasProtocol(url) {
|
|
127
|
+
return /^[a-zA-Z]+:\/\//.test(url);
|
|
103
128
|
}
|
|
104
129
|
function isEmail(url) {
|
|
105
|
-
return /^[\w
|
|
130
|
+
return /^[\w.-]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
|
|
106
131
|
}
|
|
107
|
-
function transformUrl(
|
|
108
|
-
return hasProtocol(
|
|
132
|
+
function transformUrl(url) {
|
|
133
|
+
return hasProtocol(url) ? url : isEmail(url) ? `mailto://${url}` : `https://${url}`;
|
|
109
134
|
}
|
|
110
|
-
|
|
135
|
+
function useDocHyperLinkEdit() {
|
|
111
136
|
const hyperLinkService = (0, _univerjs_ui.useDependency)(DocHyperLinkPopupService);
|
|
112
|
-
const
|
|
113
|
-
const editing = (0, _univerjs_ui.useObservable)(hyperLinkService.editingLink$);
|
|
137
|
+
const editing = (0, _univerjs_ui.useObservable)(hyperLinkService.editingLink$, hyperLinkService.editing);
|
|
114
138
|
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
115
139
|
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
116
140
|
const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
|
|
@@ -126,7 +150,7 @@ const DocHyperLinkEdit = () => {
|
|
|
126
150
|
if (editing) {
|
|
127
151
|
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
128
152
|
const body = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(editing.segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
129
|
-
const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((
|
|
153
|
+
const matchedRange = body === null || body === void 0 || (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => editing.linkId === range.rangeId && range.startIndex === editing.startIndex && range.endIndex === editing.endIndex);
|
|
130
154
|
if (doc && matchedRange) {
|
|
131
155
|
var _matchedRange$propert;
|
|
132
156
|
setLink(((_matchedRange$propert = matchedRange.properties) === null || _matchedRange$propert === void 0 ? void 0 : _matchedRange$propert.url) ?? "");
|
|
@@ -139,37 +163,52 @@ const DocHyperLinkEdit = () => {
|
|
|
139
163
|
const matchedRange = selection && ((_BuildTextUtils$custo = _univerjs_core.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (body === null || body === void 0 ? void 0 : body.customRanges) ?? [])) === null || _BuildTextUtils$custo === void 0 ? void 0 : _BuildTextUtils$custo[0]);
|
|
140
164
|
if (doc && matchedRange) {
|
|
141
165
|
var _matchedRange$propert2;
|
|
142
|
-
setLink((
|
|
166
|
+
setLink(((_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) ?? "");
|
|
143
167
|
}
|
|
144
168
|
}, [
|
|
145
169
|
doc,
|
|
146
|
-
editing,
|
|
147
170
|
docSelectionManagerService,
|
|
148
|
-
|
|
171
|
+
editing
|
|
149
172
|
]);
|
|
150
|
-
const handleCancel = () =>
|
|
151
|
-
hyperLinkService.hideEditPopup();
|
|
152
|
-
};
|
|
173
|
+
const handleCancel = () => hyperLinkService.hideEditPopup();
|
|
153
174
|
const handleConfirm = () => {
|
|
154
175
|
setShowError(true);
|
|
155
176
|
if (!isLegal || !doc) return;
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
158
|
-
unitId: doc.getUnitId(),
|
|
159
|
-
payload: linkFinal
|
|
160
|
-
});
|
|
161
|
-
else {
|
|
177
|
+
const payload = transformUrl(link);
|
|
178
|
+
if (editing) {
|
|
162
179
|
if (isBlankInput(label)) return;
|
|
163
180
|
commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
|
|
164
181
|
unitId: doc.getUnitId(),
|
|
165
|
-
payload
|
|
182
|
+
payload,
|
|
166
183
|
linkId: editing.linkId,
|
|
167
184
|
label,
|
|
168
185
|
segmentId: editing.segmentId
|
|
169
|
-
});
|
|
170
|
-
}
|
|
186
|
+
}).catch(() => void 0);
|
|
187
|
+
} else commandService.executeCommand(AddDocHyperLinkCommand.id, {
|
|
188
|
+
unitId: doc.getUnitId(),
|
|
189
|
+
payload
|
|
190
|
+
}).catch(() => void 0);
|
|
171
191
|
hyperLinkService.hideEditPopup();
|
|
172
192
|
};
|
|
193
|
+
return {
|
|
194
|
+
doc,
|
|
195
|
+
editing,
|
|
196
|
+
handleCancel,
|
|
197
|
+
handleConfirm,
|
|
198
|
+
isLegal,
|
|
199
|
+
label,
|
|
200
|
+
link,
|
|
201
|
+
setLabel,
|
|
202
|
+
setLink,
|
|
203
|
+
showError
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/views/DocHyperLinkEdit.tsx
|
|
209
|
+
const DocHyperLinkEdit = () => {
|
|
210
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
211
|
+
const { doc, editing, handleCancel, handleConfirm, isLegal, label, link, setLabel, setLink, showError } = useDocHyperLinkEdit();
|
|
173
212
|
if (!doc) return;
|
|
174
213
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
175
214
|
className: (0, _univerjs_design.clsx)("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-gray-0 univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900", _univerjs_design.borderClassName),
|
|
@@ -180,8 +219,8 @@ const DocHyperLinkEdit = () => {
|
|
|
180
219
|
value: label,
|
|
181
220
|
onChange: setLabel,
|
|
182
221
|
autoFocus: true,
|
|
183
|
-
onKeyDown: (
|
|
184
|
-
if (
|
|
222
|
+
onKeyDown: (event) => {
|
|
223
|
+
if (event.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
|
|
185
224
|
}
|
|
186
225
|
})
|
|
187
226
|
}) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
@@ -191,8 +230,8 @@ const DocHyperLinkEdit = () => {
|
|
|
191
230
|
value: link,
|
|
192
231
|
onChange: setLink,
|
|
193
232
|
autoFocus: true,
|
|
194
|
-
onKeyDown: (
|
|
195
|
-
if (
|
|
233
|
+
onKeyDown: (event) => {
|
|
234
|
+
if (event.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
|
|
196
235
|
}
|
|
197
236
|
})
|
|
198
237
|
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -211,34 +250,15 @@ const DocHyperLinkEdit = () => {
|
|
|
211
250
|
};
|
|
212
251
|
DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
|
|
213
252
|
|
|
214
|
-
//#endregion
|
|
215
|
-
//#region src/commands/commands/delete-link.command.ts
|
|
216
|
-
const DeleteDocHyperLinkCommand = {
|
|
217
|
-
type: _univerjs_core.CommandType.COMMAND,
|
|
218
|
-
id: _univerjs_docs_hyper_link.DocHyperLinkCommandId.Delete,
|
|
219
|
-
async handler(accessor, params) {
|
|
220
|
-
if (!params) return false;
|
|
221
|
-
const { unitId, linkId, segmentId } = params;
|
|
222
|
-
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
223
|
-
const doMutation = (0, _univerjs_docs.deleteCustomRangeFactory)(accessor, {
|
|
224
|
-
unitId,
|
|
225
|
-
rangeId: linkId,
|
|
226
|
-
segmentId
|
|
227
|
-
});
|
|
228
|
-
if (!doMutation) return false;
|
|
229
|
-
return await commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
253
|
//#endregion
|
|
234
254
|
//#region src/views/DocLinkPopup.tsx
|
|
235
255
|
const DocLinkPopup = () => {
|
|
236
|
-
var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties;
|
|
256
|
+
var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties, _link$properties2, _link$properties3;
|
|
237
257
|
const hyperLinkService = (0, _univerjs_ui.useDependency)(DocHyperLinkPopupService);
|
|
238
258
|
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
239
259
|
const messageService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IMessageService);
|
|
240
260
|
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
241
|
-
const currentPopup = (0, _univerjs_ui.useObservable)(hyperLinkService.showingLink
|
|
261
|
+
const currentPopup = (0, _univerjs_ui.useObservable)(hyperLinkService.showingLink$, hyperLinkService.showing);
|
|
242
262
|
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
243
263
|
const permissionService = (0, _univerjs_ui.useDependency)(_univerjs_core.IPermissionService);
|
|
244
264
|
if (!currentPopup) return null;
|
|
@@ -247,7 +267,7 @@ const DocLinkPopup = () => {
|
|
|
247
267
|
const body = doc instanceof _univerjs_core.DocumentDataModel ? (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody() : void 0;
|
|
248
268
|
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);
|
|
249
269
|
if (!link) return null;
|
|
250
|
-
const
|
|
270
|
+
const target = ((_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.url) ?? `#${((_link$properties2 = link.properties) === null || _link$properties2 === void 0 ? void 0 : _link$properties2.bookmarkId) ?? ((_link$properties3 = link.properties) === null || _link$properties3 === void 0 ? void 0 : _link$properties3.headingId) ?? ""}`;
|
|
251
271
|
const canEdit = hyperLinkService.canEditLink(unitId, currentPopup);
|
|
252
272
|
const canCopy = (0, _univerjs_docs.getDocumentPermissionValue)(permissionService, unitId, unitId, _univerjs_protocol.UnitAction.Copy);
|
|
253
273
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -263,16 +283,20 @@ const DocLinkPopup = () => {
|
|
|
263
283
|
},
|
|
264
284
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
265
285
|
className: "univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500",
|
|
266
|
-
onClick: () =>
|
|
286
|
+
onClick: () => commandService.executeCommand(ClickDocHyperLinkOperation.id, {
|
|
287
|
+
unitId,
|
|
288
|
+
linkId,
|
|
289
|
+
segmentId
|
|
290
|
+
}),
|
|
267
291
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
268
292
|
className: "univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-gray-0",
|
|
269
293
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.LinkIcon, {})
|
|
270
294
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
271
295
|
showIfEllipsis: true,
|
|
272
|
-
title:
|
|
296
|
+
title: target,
|
|
273
297
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
274
298
|
className: "univer-flex-1 univer-truncate",
|
|
275
|
-
children:
|
|
299
|
+
children: target
|
|
276
300
|
})
|
|
277
301
|
})]
|
|
278
302
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -285,7 +309,7 @@ const DocLinkPopup = () => {
|
|
|
285
309
|
className: "univer-ml-2 !univer-flex univer-size-6 !univer-rounded !univer-border-0 !univer-bg-transparent !univer-p-0 !univer-text-base !univer-font-normal hover:!univer-bg-transparent active:!univer-bg-transparent disabled:!univer-pointer-events-auto disabled:!univer-opacity-40",
|
|
286
310
|
disabled: !canCopy,
|
|
287
311
|
onClick: () => {
|
|
288
|
-
navigator.clipboard.writeText(
|
|
312
|
+
navigator.clipboard.writeText(target);
|
|
289
313
|
messageService.show({
|
|
290
314
|
content: localeService.t("docs-hyper-link-ui.info.coped"),
|
|
291
315
|
type: _univerjs_design.MessageType.Info
|
|
@@ -327,7 +351,7 @@ const DocLinkPopup = () => {
|
|
|
327
351
|
DocLinkPopup.componentKey = "univer.doc.link-info-popup";
|
|
328
352
|
|
|
329
353
|
//#endregion
|
|
330
|
-
//#region \0@oxc-project+runtime@0.
|
|
354
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
331
355
|
function _typeof(o) {
|
|
332
356
|
"@babel/helpers - typeof";
|
|
333
357
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -338,7 +362,7 @@ function _typeof(o) {
|
|
|
338
362
|
}
|
|
339
363
|
|
|
340
364
|
//#endregion
|
|
341
|
-
//#region \0@oxc-project+runtime@0.
|
|
365
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
342
366
|
function toPrimitive(t, r) {
|
|
343
367
|
if ("object" != _typeof(t) || !t) return t;
|
|
344
368
|
var e = t[Symbol.toPrimitive];
|
|
@@ -351,14 +375,14 @@ function toPrimitive(t, r) {
|
|
|
351
375
|
}
|
|
352
376
|
|
|
353
377
|
//#endregion
|
|
354
|
-
//#region \0@oxc-project+runtime@0.
|
|
378
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
355
379
|
function toPropertyKey(t) {
|
|
356
380
|
var i = toPrimitive(t, "string");
|
|
357
381
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
358
382
|
}
|
|
359
383
|
|
|
360
384
|
//#endregion
|
|
361
|
-
//#region \0@oxc-project+runtime@0.
|
|
385
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
362
386
|
function _defineProperty(e, r, t) {
|
|
363
387
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
364
388
|
value: t,
|
|
@@ -369,7 +393,7 @@ function _defineProperty(e, r, t) {
|
|
|
369
393
|
}
|
|
370
394
|
|
|
371
395
|
//#endregion
|
|
372
|
-
//#region \0@oxc-project+runtime@0.
|
|
396
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
|
|
373
397
|
function __decorateParam(paramIndex, decorator) {
|
|
374
398
|
return function(target, key) {
|
|
375
399
|
decorator(target, key, paramIndex);
|
|
@@ -377,7 +401,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
377
401
|
}
|
|
378
402
|
|
|
379
403
|
//#endregion
|
|
380
|
-
//#region \0@oxc-project+runtime@0.
|
|
404
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
|
|
381
405
|
function __decorate(decorators, target, key, desc) {
|
|
382
406
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
383
407
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -387,33 +411,21 @@ function __decorate(decorators, target, key, desc) {
|
|
|
387
411
|
|
|
388
412
|
//#endregion
|
|
389
413
|
//#region src/services/hyper-link-popup.service.ts
|
|
390
|
-
/**
|
|
391
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
392
|
-
*
|
|
393
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
394
|
-
* you may not use this file except in compliance with the License.
|
|
395
|
-
* You may obtain a copy of the License at
|
|
396
|
-
*
|
|
397
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
398
|
-
*
|
|
399
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
400
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
401
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
402
|
-
* See the License for the specific language governing permissions and
|
|
403
|
-
* limitations under the License.
|
|
404
|
-
*/
|
|
405
414
|
const INFO_POPUP_HIDE_DELAY = 150;
|
|
406
415
|
function isSameLinkInfo(current, next) {
|
|
407
416
|
return (current === null || current === void 0 ? void 0 : current.linkId) === next.linkId && current.unitId === next.unitId && (current.segmentId ?? "") === (next.segmentId ?? "") && current.segmentPage === next.segmentPage && current.startIndex === next.startIndex && current.endIndex === next.endIndex;
|
|
408
417
|
}
|
|
409
418
|
let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_core.Disposable {
|
|
410
|
-
constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService, _permissionService, _renderManagerService) {
|
|
419
|
+
constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService, _permissionService, _renderManagerService, _dialogService, _localeService, _commandService) {
|
|
411
420
|
super();
|
|
412
421
|
this._docCanvasPopupManagerService = _docCanvasPopupManagerService;
|
|
413
422
|
this._textSelectionManagerService = _textSelectionManagerService;
|
|
414
423
|
this._univerInstanceService = _univerInstanceService;
|
|
415
424
|
this._permissionService = _permissionService;
|
|
416
425
|
this._renderManagerService = _renderManagerService;
|
|
426
|
+
this._dialogService = _dialogService;
|
|
427
|
+
this._localeService = _localeService;
|
|
428
|
+
this._commandService = _commandService;
|
|
417
429
|
_defineProperty(this, "_editingLink$", new rxjs.BehaviorSubject(null));
|
|
418
430
|
_defineProperty(this, "_showingLink$", new rxjs.BehaviorSubject(null));
|
|
419
431
|
_defineProperty(this, "editingLink$", this._editingLink$.asObservable());
|
|
@@ -485,21 +497,17 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
485
497
|
}]);
|
|
486
498
|
}
|
|
487
499
|
if (activeRange) {
|
|
488
|
-
this._editPopup = this.
|
|
489
|
-
componentKey: DocHyperLinkEdit.componentKey,
|
|
490
|
-
direction: "bottom",
|
|
491
|
-
offset: [0, 10]
|
|
492
|
-
}, unitId);
|
|
500
|
+
this._editPopup = this._openEditSurface(activeRange, unitId);
|
|
493
501
|
this._editPopupUnitId = unitId;
|
|
494
502
|
return this._editPopup;
|
|
495
503
|
}
|
|
496
504
|
return null;
|
|
497
505
|
}
|
|
498
506
|
hideEditPopup() {
|
|
499
|
-
var _this$_editPopup;
|
|
500
507
|
this._editingLink$.next(null);
|
|
501
|
-
|
|
508
|
+
const popup = this._editPopup;
|
|
502
509
|
this._editPopup = null;
|
|
510
|
+
popup === null || popup === void 0 || popup.dispose();
|
|
503
511
|
this._editPopupUnitId = null;
|
|
504
512
|
}
|
|
505
513
|
showInfoPopup(info, options) {
|
|
@@ -524,14 +532,39 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
524
532
|
startIndex,
|
|
525
533
|
endIndex
|
|
526
534
|
});
|
|
527
|
-
this._infoPopup = this.
|
|
535
|
+
this._infoPopup = this._openInfoSurface(info);
|
|
536
|
+
return this._infoPopup;
|
|
537
|
+
}
|
|
538
|
+
_openEditSurface(activeRange, unitId) {
|
|
539
|
+
return this._docCanvasPopupManagerService.attachPopupToRange(activeRange, {
|
|
540
|
+
componentKey: DocHyperLinkEdit.componentKey,
|
|
541
|
+
direction: "bottom",
|
|
542
|
+
offset: [0, 10]
|
|
543
|
+
}, unitId);
|
|
544
|
+
}
|
|
545
|
+
_openInfoSurface(info, componentKey = DocLinkPopup.componentKey) {
|
|
546
|
+
const { unitId, linkId, segmentId, segmentPage, startIndex, endIndex } = info;
|
|
547
|
+
return this._docCanvasPopupManagerService.attachPopupToRange({
|
|
528
548
|
collapsed: false,
|
|
529
549
|
startOffset: startIndex,
|
|
530
550
|
endOffset: endIndex + 1,
|
|
531
551
|
segmentId,
|
|
532
552
|
segmentPage
|
|
533
553
|
}, {
|
|
534
|
-
componentKey
|
|
554
|
+
componentKey,
|
|
555
|
+
extraProps: {
|
|
556
|
+
onEdit: () => {
|
|
557
|
+
this.hideInfoPopup();
|
|
558
|
+
this.showEditPopup(unitId, info);
|
|
559
|
+
},
|
|
560
|
+
onDelete: async () => {
|
|
561
|
+
if (await this._commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
|
|
562
|
+
unitId,
|
|
563
|
+
linkId,
|
|
564
|
+
segmentId
|
|
565
|
+
})) this.hideInfoPopup();
|
|
566
|
+
}
|
|
567
|
+
},
|
|
535
568
|
direction: "top-center",
|
|
536
569
|
multipleDirection: "top",
|
|
537
570
|
offset: [0, 10],
|
|
@@ -539,15 +572,19 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
539
572
|
this.hideInfoPopup();
|
|
540
573
|
}
|
|
541
574
|
}, unitId);
|
|
542
|
-
|
|
575
|
+
}
|
|
576
|
+
showInfoPopupFromHover(info) {
|
|
577
|
+
this.cancelScheduledHideInfoPopup();
|
|
578
|
+
if (this._infoPopupPinned || this._infoPopupSuppressed) return;
|
|
579
|
+
if (!this.showing) this.showInfoPopup(info);
|
|
543
580
|
}
|
|
544
581
|
hideInfoPopup() {
|
|
545
|
-
var _this$_infoPopup;
|
|
546
582
|
this.cancelScheduledHideInfoPopup();
|
|
547
583
|
this._infoPopupPinned = false;
|
|
548
584
|
this._showingLink$.next(null);
|
|
549
|
-
|
|
585
|
+
const popup = this._infoPopup;
|
|
550
586
|
this._infoPopup = null;
|
|
587
|
+
popup === null || popup === void 0 || popup.dispose();
|
|
551
588
|
}
|
|
552
589
|
scheduleHideInfoPopup() {
|
|
553
590
|
if (this._infoPopupPinned || !this.showing) return;
|
|
@@ -585,7 +622,10 @@ DocHyperLinkPopupService = __decorate([
|
|
|
585
622
|
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
|
|
586
623
|
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
587
624
|
__decorateParam(3, _univerjs_core.IPermissionService),
|
|
588
|
-
__decorateParam(4, _univerjs_engine_render.IRenderManagerService)
|
|
625
|
+
__decorateParam(4, _univerjs_engine_render.IRenderManagerService),
|
|
626
|
+
__decorateParam(5, _univerjs_ui.IDialogService),
|
|
627
|
+
__decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
628
|
+
__decorateParam(7, _univerjs_core.ICommandService)
|
|
589
629
|
], DocHyperLinkPopupService);
|
|
590
630
|
|
|
591
631
|
//#endregion
|
|
@@ -623,7 +663,8 @@ const ToggleDocHyperLinkInfoPopupOperation = {
|
|
|
623
663
|
hyperLinkService.hideInfoPopup();
|
|
624
664
|
return true;
|
|
625
665
|
}
|
|
626
|
-
hyperLinkService.
|
|
666
|
+
if (params.fromHover) hyperLinkService.showInfoPopupFromHover(params);
|
|
667
|
+
else hyperLinkService.showInfoPopup(params);
|
|
627
668
|
return true;
|
|
628
669
|
}
|
|
629
670
|
};
|
|
@@ -631,17 +672,57 @@ const ClickDocHyperLinkOperation = {
|
|
|
631
672
|
type: _univerjs_core.CommandType.OPERATION,
|
|
632
673
|
id: "doc.operation.click-hyper-link",
|
|
633
674
|
handler(accessor, params) {
|
|
634
|
-
var _doc$getSelfOrHeaderF,
|
|
675
|
+
var _doc$getSelfOrHeaderF, _sourceBody$customRan;
|
|
635
676
|
if (!params) return false;
|
|
636
677
|
const { unitId, linkId, segmentId } = params;
|
|
637
678
|
const doc = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
638
|
-
const
|
|
639
|
-
const link =
|
|
640
|
-
if (
|
|
641
|
-
|
|
679
|
+
const sourceBody = doc === null || doc === void 0 || (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
680
|
+
const link = sourceBody === null || sourceBody === void 0 || (_sourceBody$customRan = sourceBody.customRanges) === null || _sourceBody$customRan === void 0 || (_sourceBody$customRan = _sourceBody$customRan.find((range) => range.rangeId === linkId && range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK)) === null || _sourceBody$customRan === void 0 ? void 0 : _sourceBody$customRan.properties;
|
|
681
|
+
if ((link === null || link === void 0 ? void 0 : link.bookmarkId) || (link === null || link === void 0 ? void 0 : link.headingId)) {
|
|
682
|
+
var _render$getInjector;
|
|
683
|
+
const targetOffset = findInternalLinkTarget(doc === null || doc === void 0 ? void 0 : doc.getBody(), link.bookmarkId, link.headingId);
|
|
684
|
+
if (targetOffset == null) return false;
|
|
685
|
+
const range = {
|
|
686
|
+
startOffset: targetOffset,
|
|
687
|
+
endOffset: targetOffset,
|
|
688
|
+
collapsed: true
|
|
689
|
+
};
|
|
690
|
+
const selectionManager = accessor.get(_univerjs_docs.DocSelectionManagerService);
|
|
691
|
+
const selectTarget = () => selectionManager.replaceDocRanges([range], {
|
|
692
|
+
unitId,
|
|
693
|
+
subUnitId: unitId
|
|
694
|
+
}, false, { [_univerjs_docs.DOC_SELECTION_OPTION_PRESERVE_CARET]: true });
|
|
695
|
+
const render = accessor.get(_univerjs_engine_render.IRenderManagerService).getRenderUnitById(unitId);
|
|
696
|
+
const renderInjector = render === null || render === void 0 || (_render$getInjector = render.getInjector) === null || _render$getInjector === void 0 ? void 0 : _render$getInjector.call(render);
|
|
697
|
+
const backScrollController = (renderInjector === null || renderInjector === void 0 ? void 0 : renderInjector.has(_univerjs_docs_ui.DocBackScrollRenderController)) ? render === null || render === void 0 ? void 0 : render.with(_univerjs_docs_ui.DocBackScrollRenderController) : null;
|
|
698
|
+
if (backScrollController) backScrollController.scrollToRange(range, selectTarget);
|
|
699
|
+
else selectTarget();
|
|
700
|
+
return true;
|
|
701
|
+
}
|
|
702
|
+
if (!(link === null || link === void 0 ? void 0 : link.url) || !(0, _univerjs_core.isSafeUrl)(link.url)) return false;
|
|
703
|
+
window.open(link.url, "_blank", "noopener noreferrer");
|
|
642
704
|
return true;
|
|
643
705
|
}
|
|
644
706
|
};
|
|
707
|
+
function findInternalLinkTarget(body, bookmarkId, headingId) {
|
|
708
|
+
if (!body) return;
|
|
709
|
+
if (bookmarkId) {
|
|
710
|
+
var _body$customRanges;
|
|
711
|
+
const bookmark = (_body$customRanges = body.customRanges) === null || _body$customRanges === void 0 ? void 0 : _body$customRanges.find((range) => {
|
|
712
|
+
var _range$properties;
|
|
713
|
+
return range.rangeType === _univerjs_core.CustomRangeType.BOOKMARK && (range.rangeId === bookmarkId || ((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.bookmarkId) === bookmarkId);
|
|
714
|
+
});
|
|
715
|
+
if (bookmark) return bookmark.startIndex;
|
|
716
|
+
}
|
|
717
|
+
if (headingId) {
|
|
718
|
+
var _body$paragraphs;
|
|
719
|
+
const paragraphIndex = ((_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.findIndex((paragraph) => {
|
|
720
|
+
var _paragraph$paragraphS;
|
|
721
|
+
return ((_paragraph$paragraphS = paragraph.paragraphStyle) === null || _paragraph$paragraphS === void 0 ? void 0 : _paragraph$paragraphS.headingId) === headingId;
|
|
722
|
+
})) ?? -1;
|
|
723
|
+
if (paragraphIndex >= 0) return paragraphIndex === 0 ? 0 : body.paragraphs[paragraphIndex - 1].startIndex + 1;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
645
726
|
|
|
646
727
|
//#endregion
|
|
647
728
|
//#region src/menu/menu.ts
|
|
@@ -675,6 +756,10 @@ const addLinkShortcut = {
|
|
|
675
756
|
const menuSchema = {
|
|
676
757
|
[_univerjs_ui.RibbonInsertGroup.MEDIA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
677
758
|
order: 1,
|
|
759
|
+
gridLayout: {
|
|
760
|
+
row: 1,
|
|
761
|
+
column: 5
|
|
762
|
+
},
|
|
678
763
|
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
679
764
|
} },
|
|
680
765
|
[_univerjs_docs_ui.FLOAT_TOOLBAR_MENU_POSITION]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
@@ -700,7 +785,7 @@ const menuSchema = {
|
|
|
700
785
|
//#endregion
|
|
701
786
|
//#region package.json
|
|
702
787
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
703
|
-
var version = "1.0.0
|
|
788
|
+
var version = "1.0.0";
|
|
704
789
|
|
|
705
790
|
//#endregion
|
|
706
791
|
//#region src/config/config.ts
|
|
@@ -708,42 +793,6 @@ const DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config";
|
|
|
708
793
|
const configSymbol = Symbol(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
|
|
709
794
|
const defaultPluginConfig = {};
|
|
710
795
|
|
|
711
|
-
//#endregion
|
|
712
|
-
//#region src/controllers/components.controller.ts
|
|
713
|
-
/**
|
|
714
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
715
|
-
*
|
|
716
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
717
|
-
* you may not use this file except in compliance with the License.
|
|
718
|
-
* You may obtain a copy of the License at
|
|
719
|
-
*
|
|
720
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
721
|
-
*
|
|
722
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
723
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
724
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
725
|
-
* See the License for the specific language governing permissions and
|
|
726
|
-
* limitations under the License.
|
|
727
|
-
*/
|
|
728
|
-
let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
|
|
729
|
-
constructor(_componentManager, _iconManager) {
|
|
730
|
-
super();
|
|
731
|
-
this._componentManager = _componentManager;
|
|
732
|
-
this._iconManager = _iconManager;
|
|
733
|
-
this._registerComponents();
|
|
734
|
-
this._registerIcons();
|
|
735
|
-
}
|
|
736
|
-
_registerComponents() {
|
|
737
|
-
[[DocHyperLinkEdit.componentKey, DocHyperLinkEdit], [DocLinkPopup.componentKey, DocLinkPopup]].forEach(([key, comp]) => {
|
|
738
|
-
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
739
|
-
});
|
|
740
|
-
}
|
|
741
|
-
_registerIcons() {
|
|
742
|
-
this.disposeWithMe(this._iconManager.register({ LinkIcon: _univerjs_icons.LinkIcon }));
|
|
743
|
-
}
|
|
744
|
-
};
|
|
745
|
-
ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
|
|
746
|
-
|
|
747
796
|
//#endregion
|
|
748
797
|
//#region src/controllers/doc-hyper-link-selection.controller.ts
|
|
749
798
|
let DocHyperLinkSelectionController = class DocHyperLinkSelectionController extends _univerjs_core.Disposable {
|
|
@@ -752,14 +801,45 @@ let DocHyperLinkSelectionController = class DocHyperLinkSelectionController exte
|
|
|
752
801
|
this._commandService = _commandService;
|
|
753
802
|
this._univerInstanceService = _univerInstanceService;
|
|
754
803
|
this._docHyperLinkService = _docHyperLinkService;
|
|
804
|
+
_defineProperty(this, "_selection", null);
|
|
755
805
|
this._initSelectionChange();
|
|
806
|
+
this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((unit) => {
|
|
807
|
+
var _this$_selection;
|
|
808
|
+
if (((_this$_selection = this._selection) === null || _this$_selection === void 0 ? void 0 : _this$_selection.unitId) === unit.getUnitId()) this._selection = null;
|
|
809
|
+
}));
|
|
756
810
|
}
|
|
757
811
|
_initSelectionChange() {
|
|
758
812
|
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
813
|
+
if (commandInfo.id === _univerjs_docs.RichTextEditingMutation.id) {
|
|
814
|
+
var _this$_docHyperLinkSe;
|
|
815
|
+
if (commandInfo.params.unitId === ((_this$_docHyperLinkSe = this._docHyperLinkService.showing) === null || _this$_docHyperLinkSe === void 0 ? void 0 : _this$_docHyperLinkSe.unitId)) this._docHyperLinkService.hideInfoPopup();
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
759
818
|
if (commandInfo.id === _univerjs_docs.SetTextSelectionsOperation.id) {
|
|
760
|
-
|
|
819
|
+
var _this$_selection2;
|
|
820
|
+
const params = commandInfo.params;
|
|
821
|
+
const { unitId, ranges, segmentId } = params;
|
|
761
822
|
const doc = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
762
823
|
const primary = ranges[0];
|
|
824
|
+
const selectionKey = JSON.stringify([
|
|
825
|
+
unitId,
|
|
826
|
+
segmentId ?? "",
|
|
827
|
+
primary === null || primary === void 0 ? void 0 : primary.startOffset,
|
|
828
|
+
primary === null || primary === void 0 ? void 0 : primary.endOffset,
|
|
829
|
+
primary === null || primary === void 0 ? void 0 : primary.segmentPage
|
|
830
|
+
]);
|
|
831
|
+
const sameSelection = selectionKey === ((_this$_selection2 = this._selection) === null || _this$_selection2 === void 0 ? void 0 : _this$_selection2.key);
|
|
832
|
+
this._selection = {
|
|
833
|
+
unitId,
|
|
834
|
+
key: selectionKey
|
|
835
|
+
};
|
|
836
|
+
const editing = this._docHyperLinkService.editing;
|
|
837
|
+
if ((editing === null || editing === void 0 ? void 0 : editing.unitId) === unitId && (editing.segmentId ?? "") === (segmentId ?? "") && (primary === null || primary === void 0 ? void 0 : primary.startOffset) === editing.startIndex && primary.endOffset === editing.endIndex + 1) return;
|
|
838
|
+
if (params.isEditing) {
|
|
839
|
+
this._docHyperLinkService.hideInfoPopup();
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
if (sameSelection) return;
|
|
763
843
|
if ((primary === null || primary === void 0 ? void 0 : primary.collapsed) && doc) {
|
|
764
844
|
var _doc$getSelfOrHeaderF;
|
|
765
845
|
const { startOffset, endOffset, segmentPage } = primary;
|
|
@@ -791,53 +871,196 @@ DocHyperLinkSelectionController = __decorate([
|
|
|
791
871
|
], DocHyperLinkSelectionController);
|
|
792
872
|
|
|
793
873
|
//#endregion
|
|
794
|
-
//#region src/
|
|
795
|
-
|
|
874
|
+
//#region src/views/MobileDocHyperLinkEdit.tsx
|
|
875
|
+
function MobileDocHyperLinkEdit() {
|
|
876
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
877
|
+
const { doc, editing, handleCancel, handleConfirm, isLegal, label, link, setLabel, setLink, showError } = useDocHyperLinkEdit();
|
|
878
|
+
if (!doc) return;
|
|
879
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
880
|
+
className: "univer-box-border univer-w-full univer-bg-gray-0 univer-py-2 dark:!univer-bg-gray-900",
|
|
881
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [editing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
882
|
+
label: localeService.t("docs-hyper-link-ui.edit.label"),
|
|
883
|
+
error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
|
|
884
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
|
|
885
|
+
value: label,
|
|
886
|
+
onChange: setLabel,
|
|
887
|
+
autoFocus: true,
|
|
888
|
+
onKeyDown: (event) => {
|
|
889
|
+
if (event.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
|
|
890
|
+
}
|
|
891
|
+
})
|
|
892
|
+
}) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
893
|
+
label: localeService.t("docs-hyper-link-ui.edit.address"),
|
|
894
|
+
error: showError && !isLegal ? localeService.t("docs-hyper-link-ui.edit.addressError") : "",
|
|
895
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
|
|
896
|
+
value: link,
|
|
897
|
+
onChange: setLink,
|
|
898
|
+
autoFocus: !editing,
|
|
899
|
+
onKeyDown: (event) => {
|
|
900
|
+
if (event.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
|
|
901
|
+
}
|
|
902
|
+
})
|
|
903
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
904
|
+
className: "univer-mt-5 univer-flex univer-gap-3",
|
|
905
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
906
|
+
className: "univer-h-12 univer-flex-1",
|
|
907
|
+
onClick: handleCancel,
|
|
908
|
+
children: localeService.t("docs-hyper-link-ui.edit.cancel")
|
|
909
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
910
|
+
variant: "primary",
|
|
911
|
+
className: "univer-h-12 univer-flex-1",
|
|
912
|
+
disabled: isBlankInput(link),
|
|
913
|
+
onClick: handleConfirm,
|
|
914
|
+
children: localeService.t("docs-hyper-link-ui.edit.confirm")
|
|
915
|
+
})]
|
|
916
|
+
})]
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
MobileDocHyperLinkEdit.componentKey = "univer.doc.mobile-hyper-link-edit";
|
|
920
|
+
|
|
921
|
+
//#endregion
|
|
922
|
+
//#region src/views/MobileDocLinkPopup.tsx
|
|
923
|
+
function MobileDocLinkPopup() {
|
|
924
|
+
var _document$getSelfOrHe, _body$customRanges, _link$properties;
|
|
925
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
926
|
+
const hyperLinkService = (0, _univerjs_ui.useDependency)(DocHyperLinkPopupService);
|
|
927
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
928
|
+
const messageService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IMessageService);
|
|
929
|
+
const permissionService = (0, _univerjs_ui.useDependency)(_univerjs_core.IPermissionService);
|
|
930
|
+
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
931
|
+
const currentPopup = (0, _univerjs_ui.useObservable)(hyperLinkService.showingLink$, hyperLinkService.showing);
|
|
932
|
+
if (!currentPopup) return null;
|
|
933
|
+
const { unitId, linkId, segmentId, startIndex, endIndex } = currentPopup;
|
|
934
|
+
const document = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
935
|
+
const body = document instanceof _univerjs_core.DocumentDataModel ? (_document$getSelfOrHe = document.getSelfOrHeaderFooterModel(segmentId)) === null || _document$getSelfOrHe === void 0 ? void 0 : _document$getSelfOrHe.getBody() : void 0;
|
|
936
|
+
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);
|
|
937
|
+
if (!link) return null;
|
|
938
|
+
const url = (_link$properties = link.properties) === null || _link$properties === void 0 ? void 0 : _link$properties.url;
|
|
939
|
+
const canEdit = hyperLinkService.canEditLink(unitId, currentPopup);
|
|
940
|
+
const canCopy = (0, _univerjs_docs.getDocumentPermissionValue)(permissionService, unitId, unitId, _univerjs_protocol.UnitAction.Copy);
|
|
941
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
942
|
+
className: "univer-flex univer-flex-col univer-gap-2 univer-py-2",
|
|
943
|
+
children: [
|
|
944
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.MobileActionRow, {
|
|
945
|
+
title: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
946
|
+
className: "univer-truncate univer-text-primary-600",
|
|
947
|
+
children: url
|
|
948
|
+
}),
|
|
949
|
+
"aria-label": url,
|
|
950
|
+
variant: "subtle",
|
|
951
|
+
onClick: () => window.open(url, void 0, "noopener noreferrer")
|
|
952
|
+
}),
|
|
953
|
+
canCopy && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.MobileActionRow, {
|
|
954
|
+
title: localeService.t("docs-hyper-link-ui.info.copy"),
|
|
955
|
+
"aria-label": localeService.t("docs-hyper-link-ui.info.copy"),
|
|
956
|
+
variant: "subtle",
|
|
957
|
+
onClick: () => navigator.clipboard.writeText(url).then(() => {
|
|
958
|
+
messageService.show({
|
|
959
|
+
content: localeService.t("docs-hyper-link-ui.info.coped"),
|
|
960
|
+
type: _univerjs_design.MessageType.Info
|
|
961
|
+
});
|
|
962
|
+
}).catch(() => void 0)
|
|
963
|
+
}),
|
|
964
|
+
canEdit && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.MobileActionRow, {
|
|
965
|
+
title: localeService.t("docs-hyper-link-ui.info.edit"),
|
|
966
|
+
"aria-label": localeService.t("docs-hyper-link-ui.info.edit"),
|
|
967
|
+
variant: "subtle",
|
|
968
|
+
onClick: () => {
|
|
969
|
+
commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, { link: currentPopup }).catch(() => void 0);
|
|
970
|
+
}
|
|
971
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.MobileActionRow, {
|
|
972
|
+
title: localeService.t("docs-hyper-link-ui.info.cancel"),
|
|
973
|
+
"aria-label": localeService.t("docs-hyper-link-ui.info.cancel"),
|
|
974
|
+
variant: "subtle",
|
|
975
|
+
onClick: () => {
|
|
976
|
+
commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
|
|
977
|
+
unitId,
|
|
978
|
+
linkId: link.rangeId,
|
|
979
|
+
segmentId
|
|
980
|
+
}).catch(() => void 0);
|
|
981
|
+
}
|
|
982
|
+
})] })
|
|
983
|
+
]
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
MobileDocLinkPopup.componentKey = "univer.doc.mobile-link-info-popup";
|
|
987
|
+
|
|
988
|
+
//#endregion
|
|
989
|
+
//#region src/controllers/mobile/components.controller.ts
|
|
990
|
+
/**
|
|
991
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
992
|
+
*
|
|
993
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
994
|
+
* you may not use this file except in compliance with the License.
|
|
995
|
+
* You may obtain a copy of the License at
|
|
996
|
+
*
|
|
997
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
998
|
+
*
|
|
999
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1000
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1001
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1002
|
+
* See the License for the specific language governing permissions and
|
|
1003
|
+
* limitations under the License.
|
|
1004
|
+
*/
|
|
1005
|
+
let MobileComponentsController = class MobileComponentsController extends _univerjs_core.Disposable {
|
|
1006
|
+
constructor(_componentManager, _iconManager) {
|
|
1007
|
+
super();
|
|
1008
|
+
this._componentManager = _componentManager;
|
|
1009
|
+
this._iconManager = _iconManager;
|
|
1010
|
+
this._registerComponents();
|
|
1011
|
+
this._registerIcons();
|
|
1012
|
+
}
|
|
1013
|
+
_registerComponents() {
|
|
1014
|
+
[[MobileDocHyperLinkEdit.componentKey, MobileDocHyperLinkEdit], [MobileDocLinkPopup.componentKey, MobileDocLinkPopup]].forEach(([key, comp]) => {
|
|
1015
|
+
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
_registerIcons() {
|
|
1019
|
+
this.disposeWithMe(this._iconManager.register({ LinkIcon: _univerjs_icons.LinkIcon }));
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
MobileComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], MobileComponentsController);
|
|
1023
|
+
|
|
1024
|
+
//#endregion
|
|
1025
|
+
//#region src/controllers/render-controllers/mobile/hyper-link-event.render-controller.ts
|
|
1026
|
+
let MobileDocHyperLinkEventRenderController = class MobileDocHyperLinkEventRenderController extends _univerjs_core.Disposable {
|
|
796
1027
|
get _skeleton() {
|
|
797
1028
|
return this._docSkeletonManagerService.getSkeleton();
|
|
798
1029
|
}
|
|
799
|
-
constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService,
|
|
1030
|
+
constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _mobileElementMenuService) {
|
|
800
1031
|
super();
|
|
801
1032
|
this._context = _context;
|
|
802
1033
|
this._docEventManagerService = _docEventManagerService;
|
|
803
1034
|
this._commandService = _commandService;
|
|
804
1035
|
this._hyperLinkPopupService = _hyperLinkPopupService;
|
|
805
1036
|
this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
806
|
-
this.
|
|
1037
|
+
this._mobileElementMenuService = _mobileElementMenuService;
|
|
807
1038
|
if (this._context.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
|
|
808
1039
|
this._initPointerDown();
|
|
809
|
-
this._initHover();
|
|
810
1040
|
this._initClick();
|
|
811
1041
|
}
|
|
812
|
-
_hideInfoPopup() {
|
|
813
|
-
if (this._hyperLinkPopupService.infoPopupPinned) return;
|
|
814
|
-
if (this._hyperLinkPopupService.showing) this._hyperLinkPopupService.scheduleHideInfoPopup();
|
|
815
|
-
}
|
|
816
1042
|
_initPointerDown() {
|
|
817
1043
|
this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe((ranges) => {
|
|
818
|
-
if (!ranges.some((range) => range.range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK)) this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
|
|
819
|
-
}));
|
|
820
|
-
}
|
|
821
|
-
_initHover() {
|
|
822
|
-
this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
|
|
823
|
-
var _activeRanges$;
|
|
824
1044
|
const link = ranges.find((range) => range.range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK);
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
if (((link === null || link === void 0 ? void 0 : link.segmentId) ?? "") !== currentSegmentId) {
|
|
828
|
-
this._hideInfoPopup();
|
|
1045
|
+
if (!link) {
|
|
1046
|
+
this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
|
|
829
1047
|
return;
|
|
830
1048
|
}
|
|
831
|
-
|
|
1049
|
+
const info = {
|
|
832
1050
|
unitId: this._context.unitId,
|
|
833
1051
|
linkId: link.range.rangeId,
|
|
834
1052
|
segmentId: link.segmentId,
|
|
835
1053
|
segmentPage: link.segmentPageIndex,
|
|
836
|
-
rangeId: link.range.rangeId,
|
|
837
1054
|
startIndex: link.range.startIndex,
|
|
838
1055
|
endIndex: link.range.endIndex
|
|
1056
|
+
};
|
|
1057
|
+
const rect = link.rects[0];
|
|
1058
|
+
if (rect && this._hyperLinkPopupService.canEditLink(info.unitId, info)) this._mobileElementMenuService.capture({
|
|
1059
|
+
unitId: info.unitId,
|
|
1060
|
+
rect,
|
|
1061
|
+
onEdit: () => this._hyperLinkPopupService.showEditPopup(info.unitId, info),
|
|
1062
|
+
onDelete: () => this._commandService.executeCommand(DeleteDocHyperLinkCommand.id, info)
|
|
839
1063
|
});
|
|
840
|
-
else this._hideInfoPopup();
|
|
841
1064
|
}));
|
|
842
1065
|
}
|
|
843
1066
|
_initClick() {
|
|
@@ -863,13 +1086,13 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
|
|
|
863
1086
|
}));
|
|
864
1087
|
}
|
|
865
1088
|
};
|
|
866
|
-
|
|
1089
|
+
MobileDocHyperLinkEventRenderController = __decorate([
|
|
867
1090
|
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocEventManagerService)),
|
|
868
1091
|
__decorateParam(2, _univerjs_core.ICommandService),
|
|
869
1092
|
__decorateParam(3, (0, _univerjs_core.Inject)(DocHyperLinkPopupService)),
|
|
870
1093
|
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
|
|
871
|
-
__decorateParam(5, (0, _univerjs_core.Inject)(
|
|
872
|
-
],
|
|
1094
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocMobileElementMenuService))
|
|
1095
|
+
], MobileDocHyperLinkEventRenderController);
|
|
873
1096
|
|
|
874
1097
|
//#endregion
|
|
875
1098
|
//#region src/controllers/render-controllers/render.controller.ts
|
|
@@ -940,6 +1163,29 @@ DocHyperLinkUIController = __decorate([
|
|
|
940
1163
|
__decorateParam(2, _univerjs_ui.IShortcutService)
|
|
941
1164
|
], DocHyperLinkUIController);
|
|
942
1165
|
|
|
1166
|
+
//#endregion
|
|
1167
|
+
//#region src/services/mobile/hyper-link-popup.service.ts
|
|
1168
|
+
var MobileDocHyperLinkPopupService = class extends DocHyperLinkPopupService {
|
|
1169
|
+
_openEditSurface(_activeRange, _unitId) {
|
|
1170
|
+
return this._dialogService.open({
|
|
1171
|
+
id: "doc-mobile-hyper-link-editor",
|
|
1172
|
+
title: { title: this._localeService.t("docs-hyper-link-ui.menu.tooltip") },
|
|
1173
|
+
children: { label: MobileDocHyperLinkEdit.componentKey },
|
|
1174
|
+
maskClosable: false,
|
|
1175
|
+
onClose: () => this.hideEditPopup()
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
_openInfoSurface(info) {
|
|
1179
|
+
if (this.canEditLink(info.unitId, info)) return super._openInfoSurface(info, _univerjs_docs_ui.MOBILE_DOC_ELEMENT_MENU);
|
|
1180
|
+
return this._dialogService.open({
|
|
1181
|
+
id: "doc-mobile-hyper-link-viewer",
|
|
1182
|
+
title: { title: this._localeService.t("docs-hyper-link-ui.menu.tooltip") },
|
|
1183
|
+
children: { label: MobileDocLinkPopup.componentKey },
|
|
1184
|
+
onClose: () => this.hideInfoPopup()
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
|
|
943
1189
|
//#endregion
|
|
944
1190
|
//#region src/types/const/index.ts
|
|
945
1191
|
/**
|
|
@@ -959,6 +1205,175 @@ DocHyperLinkUIController = __decorate([
|
|
|
959
1205
|
*/
|
|
960
1206
|
const DOC_HYPER_LINK_UI_PLUGIN = "DOC_HYPER_LINK_UI_PLUGIN";
|
|
961
1207
|
|
|
1208
|
+
//#endregion
|
|
1209
|
+
//#region src/mobile-plugin.ts
|
|
1210
|
+
let UniverDocsHyperLinkMobileUIPlugin = class UniverDocsHyperLinkMobileUIPlugin extends _univerjs_core.Plugin {
|
|
1211
|
+
constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
|
|
1212
|
+
super();
|
|
1213
|
+
this._config = _config;
|
|
1214
|
+
this._injector = _injector;
|
|
1215
|
+
this._renderManagerSrv = _renderManagerSrv;
|
|
1216
|
+
this._configService = _configService;
|
|
1217
|
+
const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
1218
|
+
if (menu) this._configService.setConfig("menu", menu, { merge: true });
|
|
1219
|
+
this._configService.setConfig(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
|
|
1220
|
+
}
|
|
1221
|
+
onStarting() {
|
|
1222
|
+
[
|
|
1223
|
+
[MobileComponentsController],
|
|
1224
|
+
[DocHyperLinkPopupService, { useClass: MobileDocHyperLinkPopupService }],
|
|
1225
|
+
[DocHyperLinkUIController],
|
|
1226
|
+
[DocHyperLinkSelectionController]
|
|
1227
|
+
].forEach((dep) => this._injector.add(dep));
|
|
1228
|
+
this._injector.get(MobileComponentsController);
|
|
1229
|
+
this._injector.get(DocHyperLinkUIController);
|
|
1230
|
+
}
|
|
1231
|
+
onReady() {
|
|
1232
|
+
this._injector.get(DocHyperLinkSelectionController);
|
|
1233
|
+
}
|
|
1234
|
+
onRendered() {
|
|
1235
|
+
[[DocHyperLinkRenderController], [MobileDocHyperLinkEventRenderController]].forEach((dep) => {
|
|
1236
|
+
this._renderManagerSrv.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_DOC, dep);
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
_defineProperty(UniverDocsHyperLinkMobileUIPlugin, "pluginName", DOC_HYPER_LINK_UI_PLUGIN);
|
|
1241
|
+
_defineProperty(UniverDocsHyperLinkMobileUIPlugin, "packageName", name);
|
|
1242
|
+
_defineProperty(UniverDocsHyperLinkMobileUIPlugin, "version", version);
|
|
1243
|
+
_defineProperty(UniverDocsHyperLinkMobileUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
1244
|
+
UniverDocsHyperLinkMobileUIPlugin = __decorate([
|
|
1245
|
+
(0, _univerjs_core.DependentOn)(_univerjs_docs.UniverDocsPlugin, _univerjs_engine_render.UniverRenderEnginePlugin, _univerjs_docs_hyper_link.UniverDocsHyperLinkPlugin, _univerjs_docs_ui.UniverDocsMobileUIPlugin),
|
|
1246
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1247
|
+
__decorateParam(2, _univerjs_engine_render.IRenderManagerService),
|
|
1248
|
+
__decorateParam(3, _univerjs_core.IConfigService)
|
|
1249
|
+
], UniverDocsHyperLinkMobileUIPlugin);
|
|
1250
|
+
|
|
1251
|
+
//#endregion
|
|
1252
|
+
//#region src/controllers/components.controller.ts
|
|
1253
|
+
/**
|
|
1254
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1255
|
+
*
|
|
1256
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1257
|
+
* you may not use this file except in compliance with the License.
|
|
1258
|
+
* You may obtain a copy of the License at
|
|
1259
|
+
*
|
|
1260
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1261
|
+
*
|
|
1262
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1263
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1264
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1265
|
+
* See the License for the specific language governing permissions and
|
|
1266
|
+
* limitations under the License.
|
|
1267
|
+
*/
|
|
1268
|
+
let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
|
|
1269
|
+
constructor(_componentManager, _iconManager) {
|
|
1270
|
+
super();
|
|
1271
|
+
this._componentManager = _componentManager;
|
|
1272
|
+
this._iconManager = _iconManager;
|
|
1273
|
+
this._registerComponents();
|
|
1274
|
+
this._registerIcons();
|
|
1275
|
+
}
|
|
1276
|
+
_registerComponents() {
|
|
1277
|
+
[[DocHyperLinkEdit.componentKey, DocHyperLinkEdit], [DocLinkPopup.componentKey, DocLinkPopup]].forEach(([key, comp]) => {
|
|
1278
|
+
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
_registerIcons() {
|
|
1282
|
+
this.disposeWithMe(this._iconManager.register({ LinkIcon: _univerjs_icons.LinkIcon }));
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], ComponentsController);
|
|
1286
|
+
|
|
1287
|
+
//#endregion
|
|
1288
|
+
//#region src/controllers/render-controllers/hyper-link-event.render-controller.ts
|
|
1289
|
+
let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController extends _univerjs_core.Disposable {
|
|
1290
|
+
get _skeleton() {
|
|
1291
|
+
return this._docSkeletonManagerService.getSkeleton();
|
|
1292
|
+
}
|
|
1293
|
+
constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _docSelectionManagerService) {
|
|
1294
|
+
super();
|
|
1295
|
+
this._context = _context;
|
|
1296
|
+
this._docEventManagerService = _docEventManagerService;
|
|
1297
|
+
this._commandService = _commandService;
|
|
1298
|
+
this._hyperLinkPopupService = _hyperLinkPopupService;
|
|
1299
|
+
this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
1300
|
+
this._docSelectionManagerService = _docSelectionManagerService;
|
|
1301
|
+
if (this._context.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
|
|
1302
|
+
this._initPointerDown();
|
|
1303
|
+
this._initHover();
|
|
1304
|
+
this._initClick();
|
|
1305
|
+
}
|
|
1306
|
+
_hideInfoPopup() {
|
|
1307
|
+
if (this._hyperLinkPopupService.infoPopupPinned) return;
|
|
1308
|
+
if (this._hyperLinkPopupService.showing) this._hyperLinkPopupService.scheduleHideInfoPopup();
|
|
1309
|
+
}
|
|
1310
|
+
_normalizeSegmentId(segmentId) {
|
|
1311
|
+
var _this$_context$unit$g;
|
|
1312
|
+
if (!segmentId) return "";
|
|
1313
|
+
return ((_this$_context$unit$g = this._context.unit.getBody()) === null || _this$_context$unit$g === void 0 || (_this$_context$unit$g = _this$_context$unit$g.tables) === null || _this$_context$unit$g === void 0 ? void 0 : _this$_context$unit$g.some((table) => table.tableId === segmentId)) ? "" : segmentId;
|
|
1314
|
+
}
|
|
1315
|
+
_initPointerDown() {
|
|
1316
|
+
this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe((ranges) => {
|
|
1317
|
+
if (!ranges.find((range) => range.range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK)) this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
|
|
1318
|
+
}));
|
|
1319
|
+
}
|
|
1320
|
+
_initHover() {
|
|
1321
|
+
this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
|
|
1322
|
+
var _activeRanges$;
|
|
1323
|
+
const link = ranges.find((range) => range.range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK);
|
|
1324
|
+
const activeRanges = this._docSelectionManagerService.getTextRanges();
|
|
1325
|
+
const currentSegmentId = activeRanges === null || activeRanges === void 0 || (_activeRanges$ = activeRanges[0]) === null || _activeRanges$ === void 0 ? void 0 : _activeRanges$.segmentId;
|
|
1326
|
+
if (this._normalizeSegmentId(link === null || link === void 0 ? void 0 : link.segmentId) !== this._normalizeSegmentId(currentSegmentId)) {
|
|
1327
|
+
this._hideInfoPopup();
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1330
|
+
if (link) {
|
|
1331
|
+
const info = {
|
|
1332
|
+
unitId: this._context.unitId,
|
|
1333
|
+
linkId: link.range.rangeId,
|
|
1334
|
+
segmentId: link.segmentId,
|
|
1335
|
+
segmentPage: link.segmentPageIndex,
|
|
1336
|
+
startIndex: link.range.startIndex,
|
|
1337
|
+
endIndex: link.range.endIndex
|
|
1338
|
+
};
|
|
1339
|
+
this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id, {
|
|
1340
|
+
...info,
|
|
1341
|
+
fromHover: true
|
|
1342
|
+
});
|
|
1343
|
+
} else this._hideInfoPopup();
|
|
1344
|
+
}));
|
|
1345
|
+
}
|
|
1346
|
+
_initClick() {
|
|
1347
|
+
this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
|
|
1348
|
+
const link = range.range;
|
|
1349
|
+
if (link.rangeType !== _univerjs_core.CustomRangeType.HYPERLINK) return;
|
|
1350
|
+
if (!range.ctrlKey && !range.metaKey) {
|
|
1351
|
+
this._hyperLinkPopupService.showInfoPopup({
|
|
1352
|
+
unitId: this._context.unitId,
|
|
1353
|
+
linkId: link.rangeId,
|
|
1354
|
+
segmentId: range.segmentId,
|
|
1355
|
+
segmentPage: range.segmentPageIndex,
|
|
1356
|
+
startIndex: link.startIndex,
|
|
1357
|
+
endIndex: link.endIndex
|
|
1358
|
+
}, { pinned: true });
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
this._commandService.executeCommand(ClickDocHyperLinkOperation.id, {
|
|
1362
|
+
unitId: this._context.unitId,
|
|
1363
|
+
linkId: link.rangeId,
|
|
1364
|
+
segmentId: range.segmentId
|
|
1365
|
+
});
|
|
1366
|
+
}));
|
|
1367
|
+
}
|
|
1368
|
+
};
|
|
1369
|
+
DocHyperLinkEventRenderController = __decorate([
|
|
1370
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocEventManagerService)),
|
|
1371
|
+
__decorateParam(2, _univerjs_core.ICommandService),
|
|
1372
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(DocHyperLinkPopupService)),
|
|
1373
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
|
|
1374
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService))
|
|
1375
|
+
], DocHyperLinkEventRenderController);
|
|
1376
|
+
|
|
962
1377
|
//#endregion
|
|
963
1378
|
//#region src/plugin.ts
|
|
964
1379
|
let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends _univerjs_core.Plugin {
|
|
@@ -973,15 +1388,15 @@ let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends _uni
|
|
|
973
1388
|
this._configService.setConfig(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
|
|
974
1389
|
}
|
|
975
1390
|
onStarting() {
|
|
976
|
-
this._injector.add([ComponentsController]);
|
|
977
|
-
this._injector.get(ComponentsController);
|
|
978
1391
|
[
|
|
1392
|
+
[ComponentsController],
|
|
979
1393
|
[DocHyperLinkPopupService],
|
|
980
1394
|
[DocHyperLinkUIController],
|
|
981
1395
|
[DocHyperLinkSelectionController]
|
|
982
1396
|
].forEach((dep) => {
|
|
983
1397
|
this._injector.add(dep);
|
|
984
1398
|
});
|
|
1399
|
+
this._injector.get(ComponentsController);
|
|
985
1400
|
this._injector.get(DocHyperLinkUIController);
|
|
986
1401
|
}
|
|
987
1402
|
onReady() {
|
|
@@ -1009,6 +1424,12 @@ UniverDocsHyperLinkUIPlugin = __decorate([
|
|
|
1009
1424
|
|
|
1010
1425
|
//#endregion
|
|
1011
1426
|
exports.DocsHyperLinkUIMenuSchema = menuSchema;
|
|
1427
|
+
Object.defineProperty(exports, 'UniverDocsHyperLinkMobileUIPlugin', {
|
|
1428
|
+
enumerable: true,
|
|
1429
|
+
get: function () {
|
|
1430
|
+
return UniverDocsHyperLinkMobileUIPlugin;
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1012
1433
|
Object.defineProperty(exports, 'UniverDocsHyperLinkUIPlugin', {
|
|
1013
1434
|
enumerable: true,
|
|
1014
1435
|
get: function () {
|