@univerjs/docs-hyper-link-ui 1.0.0-insiders.20260813-7c9aa50 → 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/LICENSE +176 -0
- package/README.md +0 -1
- package/lib/cjs/index.js +767 -232
- package/lib/cjs/locale/ar-SA.js +0 -3
- package/lib/cjs/locale/ca-ES.js +0 -3
- package/lib/cjs/locale/de-DE.js +0 -3
- package/lib/cjs/locale/en-US.js +0 -3
- package/lib/cjs/locale/es-ES.js +0 -3
- package/lib/cjs/locale/fa-IR.js +0 -3
- package/lib/cjs/locale/fr-FR.js +0 -3
- package/lib/cjs/locale/id-ID.js +0 -3
- package/lib/cjs/locale/it-IT.js +0 -3
- package/lib/cjs/locale/ja-JP.js +0 -3
- package/lib/cjs/locale/ko-KR.js +0 -3
- package/lib/cjs/locale/pl-PL.js +0 -3
- package/lib/cjs/locale/pt-BR.js +0 -3
- package/lib/cjs/locale/ru-RU.js +0 -3
- package/lib/cjs/locale/sk-SK.js +0 -3
- package/lib/cjs/locale/vi-VN.js +0 -3
- package/lib/cjs/locale/zh-CN.js +0 -3
- package/lib/cjs/locale/zh-HK.js +0 -3
- package/lib/cjs/locale/zh-TW.js +0 -3
- package/lib/es/index.js +769 -240
- package/lib/es/locale/ar-SA.js +0 -2
- package/lib/es/locale/ca-ES.js +0 -2
- package/lib/es/locale/de-DE.js +0 -2
- package/lib/es/locale/en-US.js +0 -2
- package/lib/es/locale/es-ES.js +0 -2
- package/lib/es/locale/fa-IR.js +0 -2
- package/lib/es/locale/fr-FR.js +0 -2
- package/lib/es/locale/id-ID.js +0 -2
- package/lib/es/locale/it-IT.js +0 -2
- package/lib/es/locale/ja-JP.js +0 -2
- package/lib/es/locale/ko-KR.js +0 -2
- package/lib/es/locale/pl-PL.js +0 -2
- package/lib/es/locale/pt-BR.js +0 -2
- package/lib/es/locale/ru-RU.js +0 -2
- package/lib/es/locale/sk-SK.js +0 -2
- package/lib/es/locale/vi-VN.js +0 -2
- package/lib/es/locale/zh-CN.js +0 -2
- package/lib/es/locale/zh-HK.js +0 -2
- package/lib/es/locale/zh-TW.js +0 -2
- package/lib/index.css +80 -4
- package/lib/index.js +769 -240
- package/lib/locale/ar-SA.js +0 -2
- package/lib/locale/ca-ES.js +0 -2
- package/lib/locale/de-DE.js +0 -2
- package/lib/locale/en-US.js +0 -2
- package/lib/locale/es-ES.js +0 -2
- package/lib/locale/fa-IR.js +0 -2
- package/lib/locale/fr-FR.js +0 -2
- package/lib/locale/id-ID.js +0 -2
- package/lib/locale/it-IT.js +0 -2
- package/lib/locale/ja-JP.js +0 -2
- package/lib/locale/ko-KR.js +0 -2
- package/lib/locale/pl-PL.js +0 -2
- package/lib/locale/pt-BR.js +0 -2
- package/lib/locale/ru-RU.js +0 -2
- package/lib/locale/sk-SK.js +0 -2
- package/lib/locale/vi-VN.js +0 -2
- package/lib/locale/zh-CN.js +0 -2
- package/lib/locale/zh-HK.js +0 -2
- package/lib/locale/zh-TW.js +0 -2
- 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 +2 -0
- package/lib/types/controllers/render-controllers/mobile/hyper-link-event.render-controller.d.ts +33 -0
- package/lib/types/controllers/render-controllers/render.controller.d.ts +1 -5
- package/lib/types/index.d.ts +1 -0
- package/lib/types/locale/en-US.d.ts +0 -2
- package/lib/types/mobile-plugin.d.ts +32 -0
- package/lib/types/services/hyper-link-popup.service.d.ts +33 -10
- 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/lib/umd/locale/ar-SA.js +1 -1
- package/lib/umd/locale/ca-ES.js +1 -1
- package/lib/umd/locale/de-DE.js +1 -1
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/es-ES.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/id-ID.js +1 -1
- package/lib/umd/locale/it-IT.js +1 -1
- package/lib/umd/locale/ja-JP.js +1 -1
- package/lib/umd/locale/ko-KR.js +1 -1
- package/lib/umd/locale/pl-PL.js +1 -1
- package/lib/umd/locale/pt-BR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/sk-SK.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-HK.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +13 -12
package/lib/cjs/index.js
CHANGED
|
@@ -3,24 +3,45 @@ let _univerjs_docs_ui = require("@univerjs/docs-ui");
|
|
|
3
3
|
let _univerjs_ui = require("@univerjs/ui");
|
|
4
4
|
let _univerjs_core = require("@univerjs/core");
|
|
5
5
|
let _univerjs_docs = require("@univerjs/docs");
|
|
6
|
+
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
6
7
|
let rxjs = require("rxjs");
|
|
8
|
+
let _univerjs_docs_hyper_link = require("@univerjs/docs-hyper-link");
|
|
7
9
|
let _univerjs_design = require("@univerjs/design");
|
|
8
10
|
let react = require("react");
|
|
9
11
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
12
|
let _univerjs_icons = require("@univerjs/icons");
|
|
11
|
-
let
|
|
12
|
-
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
13
|
+
let _univerjs_protocol = require("@univerjs/protocol");
|
|
13
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
|
|
14
34
|
//#region src/commands/commands/add-link.command.ts
|
|
15
35
|
const AddDocHyperLinkCommand = {
|
|
16
36
|
type: _univerjs_core.CommandType.COMMAND,
|
|
17
|
-
id:
|
|
37
|
+
id: _univerjs_docs_hyper_link.DocHyperLinkCommandId.Add,
|
|
18
38
|
async handler(accessor, params) {
|
|
19
39
|
if (!params) return false;
|
|
20
40
|
const { payload, unitId, selections } = params;
|
|
21
41
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
42
|
+
const id = (0, _univerjs_core.generateRandomId)();
|
|
22
43
|
const doMutation = (0, _univerjs_docs.addCustomRangeBySelectionFactory)(accessor, {
|
|
23
|
-
rangeId:
|
|
44
|
+
rangeId: id,
|
|
24
45
|
rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
|
|
25
46
|
properties: { url: payload },
|
|
26
47
|
unitId,
|
|
@@ -34,10 +55,10 @@ const AddDocHyperLinkCommand = {
|
|
|
34
55
|
//#endregion
|
|
35
56
|
//#region src/commands/commands/update-link.command.ts
|
|
36
57
|
const UpdateDocHyperLinkCommand = {
|
|
37
|
-
id:
|
|
58
|
+
id: _univerjs_docs_hyper_link.DocHyperLinkCommandId.Update,
|
|
38
59
|
type: _univerjs_core.CommandType.COMMAND,
|
|
39
60
|
handler(accessor, params) {
|
|
40
|
-
var _doc$getSelfOrHeaderF, _getBodySlice$textRun;
|
|
61
|
+
var _doc$getSelfOrHeaderF, _oldBody$customRanges, _getBodySlice$textRun, _oldLink$properties, _oldLink$properties2;
|
|
41
62
|
if (!params) return false;
|
|
42
63
|
const { unitId, payload, segmentId, linkId } = params;
|
|
43
64
|
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
@@ -47,6 +68,7 @@ const UpdateDocHyperLinkCommand = {
|
|
|
47
68
|
if (!currentSelection || !doc) return false;
|
|
48
69
|
const oldBody = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.getBody();
|
|
49
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);
|
|
50
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];
|
|
51
73
|
if (textRun) textRun.ed = params.label.length + 1;
|
|
52
74
|
const replaceSelection = (0, _univerjs_docs.replaceSelectionFactory)(accessor, {
|
|
@@ -58,7 +80,11 @@ const UpdateDocHyperLinkCommand = {
|
|
|
58
80
|
rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
|
|
59
81
|
startIndex: 0,
|
|
60
82
|
endIndex: params.label.length + 1,
|
|
61
|
-
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
|
+
}
|
|
62
88
|
}],
|
|
63
89
|
textRuns: textRun ? [textRun] : void 0
|
|
64
90
|
},
|
|
@@ -96,20 +122,19 @@ function isBlankInput(value) {
|
|
|
96
122
|
}
|
|
97
123
|
|
|
98
124
|
//#endregion
|
|
99
|
-
//#region src/views/
|
|
100
|
-
function hasProtocol(
|
|
101
|
-
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);
|
|
102
128
|
}
|
|
103
129
|
function isEmail(url) {
|
|
104
|
-
return /^[\w
|
|
130
|
+
return /^[\w.-]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
|
|
105
131
|
}
|
|
106
|
-
function transformUrl(
|
|
107
|
-
return hasProtocol(
|
|
132
|
+
function transformUrl(url) {
|
|
133
|
+
return hasProtocol(url) ? url : isEmail(url) ? `mailto://${url}` : `https://${url}`;
|
|
108
134
|
}
|
|
109
|
-
|
|
135
|
+
function useDocHyperLinkEdit() {
|
|
110
136
|
const hyperLinkService = (0, _univerjs_ui.useDependency)(DocHyperLinkPopupService);
|
|
111
|
-
const
|
|
112
|
-
const editing = (0, _univerjs_ui.useObservable)(hyperLinkService.editingLink$);
|
|
137
|
+
const editing = (0, _univerjs_ui.useObservable)(hyperLinkService.editingLink$, hyperLinkService.editing);
|
|
113
138
|
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
114
139
|
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
115
140
|
const docSelectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_docs.DocSelectionManagerService);
|
|
@@ -125,7 +150,7 @@ const DocHyperLinkEdit = () => {
|
|
|
125
150
|
if (editing) {
|
|
126
151
|
var _doc$getSelfOrHeaderF, _body$customRanges;
|
|
127
152
|
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((
|
|
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);
|
|
129
154
|
if (doc && matchedRange) {
|
|
130
155
|
var _matchedRange$propert;
|
|
131
156
|
setLink(((_matchedRange$propert = matchedRange.properties) === null || _matchedRange$propert === void 0 ? void 0 : _matchedRange$propert.url) ?? "");
|
|
@@ -138,40 +163,55 @@ const DocHyperLinkEdit = () => {
|
|
|
138
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]);
|
|
139
164
|
if (doc && matchedRange) {
|
|
140
165
|
var _matchedRange$propert2;
|
|
141
|
-
setLink((
|
|
166
|
+
setLink(((_matchedRange$propert2 = matchedRange.properties) === null || _matchedRange$propert2 === void 0 ? void 0 : _matchedRange$propert2.url) ?? "");
|
|
142
167
|
}
|
|
143
168
|
}, [
|
|
144
169
|
doc,
|
|
145
|
-
editing,
|
|
146
170
|
docSelectionManagerService,
|
|
147
|
-
|
|
171
|
+
editing
|
|
148
172
|
]);
|
|
149
|
-
const handleCancel = () =>
|
|
150
|
-
hyperLinkService.hideEditPopup();
|
|
151
|
-
};
|
|
173
|
+
const handleCancel = () => hyperLinkService.hideEditPopup();
|
|
152
174
|
const handleConfirm = () => {
|
|
153
175
|
setShowError(true);
|
|
154
176
|
if (!isLegal || !doc) return;
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
unitId: doc.getUnitId(),
|
|
158
|
-
payload: linkFinal
|
|
159
|
-
});
|
|
160
|
-
else {
|
|
177
|
+
const payload = transformUrl(link);
|
|
178
|
+
if (editing) {
|
|
161
179
|
if (isBlankInput(label)) return;
|
|
162
180
|
commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
|
|
163
181
|
unitId: doc.getUnitId(),
|
|
164
|
-
payload
|
|
182
|
+
payload,
|
|
165
183
|
linkId: editing.linkId,
|
|
166
184
|
label,
|
|
167
185
|
segmentId: editing.segmentId
|
|
168
|
-
});
|
|
169
|
-
}
|
|
186
|
+
}).catch(() => void 0);
|
|
187
|
+
} else commandService.executeCommand(AddDocHyperLinkCommand.id, {
|
|
188
|
+
unitId: doc.getUnitId(),
|
|
189
|
+
payload
|
|
190
|
+
}).catch(() => void 0);
|
|
170
191
|
hyperLinkService.hideEditPopup();
|
|
171
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();
|
|
172
212
|
if (!doc) return;
|
|
173
213
|
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-
|
|
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),
|
|
175
215
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [editing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
176
216
|
label: localeService.t("docs-hyper-link-ui.edit.label"),
|
|
177
217
|
error: showError && isBlankInput(label) ? localeService.t("docs-hyper-link-ui.edit.labelError") : "",
|
|
@@ -179,8 +219,8 @@ const DocHyperLinkEdit = () => {
|
|
|
179
219
|
value: label,
|
|
180
220
|
onChange: setLabel,
|
|
181
221
|
autoFocus: true,
|
|
182
|
-
onKeyDown: (
|
|
183
|
-
if (
|
|
222
|
+
onKeyDown: (event) => {
|
|
223
|
+
if (event.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
|
|
184
224
|
}
|
|
185
225
|
})
|
|
186
226
|
}) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
|
|
@@ -190,8 +230,8 @@ const DocHyperLinkEdit = () => {
|
|
|
190
230
|
value: link,
|
|
191
231
|
onChange: setLink,
|
|
192
232
|
autoFocus: true,
|
|
193
|
-
onKeyDown: (
|
|
194
|
-
if (
|
|
233
|
+
onKeyDown: (event) => {
|
|
234
|
+
if (event.keyCode === _univerjs_ui.KeyCode.ENTER) handleConfirm();
|
|
195
235
|
}
|
|
196
236
|
})
|
|
197
237
|
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -210,113 +250,108 @@ const DocHyperLinkEdit = () => {
|
|
|
210
250
|
};
|
|
211
251
|
DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
|
|
212
252
|
|
|
213
|
-
//#endregion
|
|
214
|
-
//#region src/commands/commands/delete-link.command.ts
|
|
215
|
-
const DeleteDocHyperLinkCommand = {
|
|
216
|
-
type: _univerjs_core.CommandType.COMMAND,
|
|
217
|
-
id: "docs.command.delete-hyper-link",
|
|
218
|
-
async handler(accessor, params) {
|
|
219
|
-
if (!params) return false;
|
|
220
|
-
const { unitId, linkId, segmentId } = params;
|
|
221
|
-
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
222
|
-
const doMutation = (0, _univerjs_docs.deleteCustomRangeFactory)(accessor, {
|
|
223
|
-
unitId,
|
|
224
|
-
rangeId: linkId,
|
|
225
|
-
segmentId
|
|
226
|
-
});
|
|
227
|
-
if (!doMutation) return false;
|
|
228
|
-
return await commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
253
|
//#endregion
|
|
233
254
|
//#region src/views/DocLinkPopup.tsx
|
|
234
255
|
const DocLinkPopup = () => {
|
|
235
|
-
var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties;
|
|
256
|
+
var _doc$getSelfOrHeaderF, _body$customRanges, _link$properties, _link$properties2, _link$properties3;
|
|
236
257
|
const hyperLinkService = (0, _univerjs_ui.useDependency)(DocHyperLinkPopupService);
|
|
237
258
|
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
238
259
|
const messageService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IMessageService);
|
|
239
260
|
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
240
|
-
const currentPopup = (0, _univerjs_ui.useObservable)(hyperLinkService.showingLink
|
|
261
|
+
const currentPopup = (0, _univerjs_ui.useObservable)(hyperLinkService.showingLink$, hyperLinkService.showing);
|
|
241
262
|
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
263
|
+
const permissionService = (0, _univerjs_ui.useDependency)(_univerjs_core.IPermissionService);
|
|
242
264
|
if (!currentPopup) return null;
|
|
243
265
|
const { unitId, linkId, segmentId, startIndex, endIndex } = currentPopup;
|
|
244
266
|
const doc = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
245
|
-
const body = doc
|
|
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;
|
|
246
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);
|
|
247
269
|
if (!link) return null;
|
|
248
|
-
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) ?? ""}`;
|
|
271
|
+
const canEdit = hyperLinkService.canEditLink(unitId, currentPopup);
|
|
272
|
+
const canCopy = (0, _univerjs_docs.getDocumentPermissionValue)(permissionService, unitId, unitId, _univerjs_protocol.UnitAction.Copy);
|
|
249
273
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
250
|
-
className: (0, _univerjs_design.clsx)("univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-
|
|
274
|
+
className: (0, _univerjs_design.clsx)("univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-gray-0 univer-p-3 univer-shadow dark:!univer-bg-gray-900", _univerjs_design.borderClassName),
|
|
275
|
+
onPointerEnter: () => {
|
|
276
|
+
hyperLinkService.cancelScheduledHideInfoPopup();
|
|
277
|
+
},
|
|
278
|
+
onPointerLeave: () => {
|
|
279
|
+
hyperLinkService.scheduleHideInfoPopup();
|
|
280
|
+
},
|
|
251
281
|
onClick: () => {
|
|
252
282
|
hyperLinkService.hideInfoPopup();
|
|
253
283
|
},
|
|
254
284
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
255
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",
|
|
256
|
-
onClick: () =>
|
|
286
|
+
onClick: () => commandService.executeCommand(ClickDocHyperLinkOperation.id, {
|
|
287
|
+
unitId,
|
|
288
|
+
linkId,
|
|
289
|
+
segmentId
|
|
290
|
+
}),
|
|
257
291
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
258
|
-
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-
|
|
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",
|
|
259
293
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.LinkIcon, {})
|
|
260
294
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
261
295
|
showIfEllipsis: true,
|
|
262
|
-
title:
|
|
296
|
+
title: target,
|
|
263
297
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
264
298
|
className: "univer-flex-1 univer-truncate",
|
|
265
|
-
children:
|
|
299
|
+
children: target
|
|
266
300
|
})
|
|
267
301
|
})]
|
|
268
302
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
269
303
|
className: "univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center",
|
|
270
|
-
children: [
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
onClick: () => {
|
|
289
|
-
commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, { link: currentPopup });
|
|
290
|
-
},
|
|
291
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
292
|
-
placement: "bottom",
|
|
293
|
-
title: localeService.t("docs-hyper-link-ui.info.edit"),
|
|
294
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.WriteIcon, {})
|
|
295
|
-
})
|
|
296
|
-
}),
|
|
297
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
298
|
-
className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
|
|
299
|
-
onClick: () => {
|
|
300
|
-
commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
|
|
301
|
-
unitId,
|
|
302
|
-
linkId: link.rangeId,
|
|
303
|
-
segmentId
|
|
304
|
-
});
|
|
305
|
-
},
|
|
306
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
307
|
-
placement: "bottom",
|
|
308
|
-
title: localeService.t("docs-hyper-link-ui.info.cancel"),
|
|
309
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.UnlinkIcon, {})
|
|
310
|
-
})
|
|
304
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
305
|
+
type: "button",
|
|
306
|
+
variant: "text",
|
|
307
|
+
size: "small",
|
|
308
|
+
"aria-label": localeService.t("docs-hyper-link-ui.info.copy"),
|
|
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",
|
|
310
|
+
disabled: !canCopy,
|
|
311
|
+
onClick: () => {
|
|
312
|
+
navigator.clipboard.writeText(target);
|
|
313
|
+
messageService.show({
|
|
314
|
+
content: localeService.t("docs-hyper-link-ui.info.coped"),
|
|
315
|
+
type: _univerjs_design.MessageType.Info
|
|
316
|
+
});
|
|
317
|
+
},
|
|
318
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
319
|
+
placement: "bottom",
|
|
320
|
+
title: localeService.t("docs-hyper-link-ui.info.copy"),
|
|
321
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CopyIcon, {})
|
|
311
322
|
})
|
|
312
|
-
|
|
323
|
+
}), canEdit && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
324
|
+
className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
|
|
325
|
+
onClick: () => {
|
|
326
|
+
commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, { link: currentPopup });
|
|
327
|
+
},
|
|
328
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
329
|
+
placement: "bottom",
|
|
330
|
+
title: localeService.t("docs-hyper-link-ui.info.edit"),
|
|
331
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.WriteIcon, {})
|
|
332
|
+
})
|
|
333
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
334
|
+
className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
|
|
335
|
+
onClick: () => {
|
|
336
|
+
commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
|
|
337
|
+
unitId,
|
|
338
|
+
linkId: link.rangeId,
|
|
339
|
+
segmentId
|
|
340
|
+
});
|
|
341
|
+
},
|
|
342
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Tooltip, {
|
|
343
|
+
placement: "bottom",
|
|
344
|
+
title: localeService.t("docs-hyper-link-ui.info.cancel"),
|
|
345
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.UnlinkIcon, {})
|
|
346
|
+
})
|
|
347
|
+
})] })]
|
|
313
348
|
})]
|
|
314
349
|
});
|
|
315
350
|
};
|
|
316
351
|
DocLinkPopup.componentKey = "univer.doc.link-info-popup";
|
|
317
352
|
|
|
318
353
|
//#endregion
|
|
319
|
-
//#region \0@oxc-project+runtime@0.
|
|
354
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
320
355
|
function _typeof(o) {
|
|
321
356
|
"@babel/helpers - typeof";
|
|
322
357
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -327,7 +362,7 @@ function _typeof(o) {
|
|
|
327
362
|
}
|
|
328
363
|
|
|
329
364
|
//#endregion
|
|
330
|
-
//#region \0@oxc-project+runtime@0.
|
|
365
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
331
366
|
function toPrimitive(t, r) {
|
|
332
367
|
if ("object" != _typeof(t) || !t) return t;
|
|
333
368
|
var e = t[Symbol.toPrimitive];
|
|
@@ -340,14 +375,14 @@ function toPrimitive(t, r) {
|
|
|
340
375
|
}
|
|
341
376
|
|
|
342
377
|
//#endregion
|
|
343
|
-
//#region \0@oxc-project+runtime@0.
|
|
378
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
344
379
|
function toPropertyKey(t) {
|
|
345
380
|
var i = toPrimitive(t, "string");
|
|
346
381
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
347
382
|
}
|
|
348
383
|
|
|
349
384
|
//#endregion
|
|
350
|
-
//#region \0@oxc-project+runtime@0.
|
|
385
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
351
386
|
function _defineProperty(e, r, t) {
|
|
352
387
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
353
388
|
value: t,
|
|
@@ -358,7 +393,7 @@ function _defineProperty(e, r, t) {
|
|
|
358
393
|
}
|
|
359
394
|
|
|
360
395
|
//#endregion
|
|
361
|
-
//#region \0@oxc-project+runtime@0.
|
|
396
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
|
|
362
397
|
function __decorateParam(paramIndex, decorator) {
|
|
363
398
|
return function(target, key) {
|
|
364
399
|
decorator(target, key, paramIndex);
|
|
@@ -366,7 +401,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
366
401
|
}
|
|
367
402
|
|
|
368
403
|
//#endregion
|
|
369
|
-
//#region \0@oxc-project+runtime@0.
|
|
404
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
|
|
370
405
|
function __decorate(decorators, target, key, desc) {
|
|
371
406
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
372
407
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -376,22 +411,54 @@ function __decorate(decorators, target, key, desc) {
|
|
|
376
411
|
|
|
377
412
|
//#endregion
|
|
378
413
|
//#region src/services/hyper-link-popup.service.ts
|
|
414
|
+
const INFO_POPUP_HIDE_DELAY = 150;
|
|
415
|
+
function isSameLinkInfo(current, next) {
|
|
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;
|
|
417
|
+
}
|
|
379
418
|
let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_core.Disposable {
|
|
380
|
-
constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService) {
|
|
419
|
+
constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService, _permissionService, _renderManagerService, _dialogService, _localeService, _commandService) {
|
|
381
420
|
super();
|
|
382
421
|
this._docCanvasPopupManagerService = _docCanvasPopupManagerService;
|
|
383
422
|
this._textSelectionManagerService = _textSelectionManagerService;
|
|
384
423
|
this._univerInstanceService = _univerInstanceService;
|
|
424
|
+
this._permissionService = _permissionService;
|
|
425
|
+
this._renderManagerService = _renderManagerService;
|
|
426
|
+
this._dialogService = _dialogService;
|
|
427
|
+
this._localeService = _localeService;
|
|
428
|
+
this._commandService = _commandService;
|
|
385
429
|
_defineProperty(this, "_editingLink$", new rxjs.BehaviorSubject(null));
|
|
386
430
|
_defineProperty(this, "_showingLink$", new rxjs.BehaviorSubject(null));
|
|
387
431
|
_defineProperty(this, "editingLink$", this._editingLink$.asObservable());
|
|
388
432
|
_defineProperty(this, "showingLink$", this._showingLink$.asObservable());
|
|
389
433
|
_defineProperty(this, "_editPopup", null);
|
|
434
|
+
_defineProperty(this, "_editPopupUnitId", null);
|
|
390
435
|
_defineProperty(this, "_infoPopup", null);
|
|
436
|
+
_defineProperty(this, "_infoPopupPinned", false);
|
|
437
|
+
_defineProperty(this, "_infoPopupHideTimer", null);
|
|
438
|
+
_defineProperty(this, "_infoPopupSuppressed", false);
|
|
439
|
+
_defineProperty(this, "_infoPopupSuppressionTimer", null);
|
|
391
440
|
this.disposeWithMe(() => {
|
|
441
|
+
this.cancelScheduledHideInfoPopup();
|
|
442
|
+
if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
|
|
392
443
|
this._editingLink$.complete();
|
|
393
444
|
this._showingLink$.complete();
|
|
394
445
|
});
|
|
446
|
+
this.disposeWithMe(this._permissionService.permissionPointUpdate$.subscribe(() => {
|
|
447
|
+
const editing = this.editing;
|
|
448
|
+
if (editing && !this.canEditLink(editing.unitId, editing)) this.hideEditPopup();
|
|
449
|
+
const showing = this.showing;
|
|
450
|
+
if (showing) this._showingLink$.next({ ...showing });
|
|
451
|
+
}));
|
|
452
|
+
this.disposeWithMe(this._renderManagerService.disposed$.subscribe((unitId) => {
|
|
453
|
+
var _this$showing;
|
|
454
|
+
if (this._editPopupUnitId === unitId) this.hideEditPopup();
|
|
455
|
+
if (((_this$showing = this.showing) === null || _this$showing === void 0 ? void 0 : _this$showing.unitId) === unitId) this.hideInfoPopup();
|
|
456
|
+
}));
|
|
457
|
+
}
|
|
458
|
+
dispose() {
|
|
459
|
+
this.hideEditPopup();
|
|
460
|
+
this.hideInfoPopup();
|
|
461
|
+
super.dispose();
|
|
395
462
|
}
|
|
396
463
|
get editing() {
|
|
397
464
|
return this._editingLink$.value;
|
|
@@ -399,8 +466,16 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
399
466
|
get showing() {
|
|
400
467
|
return this._showingLink$.value;
|
|
401
468
|
}
|
|
469
|
+
get infoPopupPinned() {
|
|
470
|
+
return this._infoPopupPinned;
|
|
471
|
+
}
|
|
402
472
|
showEditPopup(unitId, linkInfo) {
|
|
403
|
-
if (this.
|
|
473
|
+
if (!this.canEditLink(unitId, linkInfo)) return null;
|
|
474
|
+
if (this._editPopup) {
|
|
475
|
+
this._editPopup.dispose();
|
|
476
|
+
this._editPopup = null;
|
|
477
|
+
this._editPopupUnitId = null;
|
|
478
|
+
}
|
|
404
479
|
this._editingLink$.next(linkInfo);
|
|
405
480
|
const textRanges = this._textSelectionManagerService.getTextRanges({
|
|
406
481
|
unitId,
|
|
@@ -422,25 +497,33 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
422
497
|
}]);
|
|
423
498
|
}
|
|
424
499
|
if (activeRange) {
|
|
425
|
-
this._editPopup = this.
|
|
426
|
-
|
|
427
|
-
direction: "bottom"
|
|
428
|
-
}, unitId);
|
|
500
|
+
this._editPopup = this._openEditSurface(activeRange, unitId);
|
|
501
|
+
this._editPopupUnitId = unitId;
|
|
429
502
|
return this._editPopup;
|
|
430
503
|
}
|
|
431
504
|
return null;
|
|
432
505
|
}
|
|
433
506
|
hideEditPopup() {
|
|
434
|
-
var _this$_editPopup;
|
|
435
507
|
this._editingLink$.next(null);
|
|
436
|
-
|
|
508
|
+
const popup = this._editPopup;
|
|
509
|
+
this._editPopup = null;
|
|
510
|
+
popup === null || popup === void 0 || popup.dispose();
|
|
511
|
+
this._editPopupUnitId = null;
|
|
437
512
|
}
|
|
438
|
-
showInfoPopup(info) {
|
|
439
|
-
|
|
513
|
+
showInfoPopup(info, options) {
|
|
514
|
+
this.cancelScheduledHideInfoPopup();
|
|
515
|
+
if (this._infoPopupSuppressed) return;
|
|
440
516
|
const { linkId, unitId, segmentId, segmentPage, startIndex, endIndex } = info;
|
|
441
|
-
if ((
|
|
442
|
-
|
|
443
|
-
|
|
517
|
+
if (isSameLinkInfo(this.showing, info)) {
|
|
518
|
+
if (options === null || options === void 0 ? void 0 : options.pinned) this._infoPopupPinned = true;
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (this._infoPopup) {
|
|
522
|
+
this._infoPopup.dispose();
|
|
523
|
+
this._infoPopup = null;
|
|
524
|
+
}
|
|
525
|
+
if (!(this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC) instanceof _univerjs_core.DocumentDataModel)) return;
|
|
526
|
+
this._infoPopupPinned = (options === null || options === void 0 ? void 0 : options.pinned) ?? false;
|
|
444
527
|
this._showingLink$.next({
|
|
445
528
|
unitId,
|
|
446
529
|
linkId,
|
|
@@ -449,32 +532,100 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
449
532
|
startIndex,
|
|
450
533
|
endIndex
|
|
451
534
|
});
|
|
452
|
-
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({
|
|
453
548
|
collapsed: false,
|
|
454
549
|
startOffset: startIndex,
|
|
455
550
|
endOffset: endIndex + 1,
|
|
456
551
|
segmentId,
|
|
457
552
|
segmentPage
|
|
458
553
|
}, {
|
|
459
|
-
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
|
+
},
|
|
460
568
|
direction: "top-center",
|
|
461
569
|
multipleDirection: "top",
|
|
570
|
+
offset: [0, 10],
|
|
462
571
|
onClickOutside: () => {
|
|
463
572
|
this.hideInfoPopup();
|
|
464
573
|
}
|
|
465
574
|
}, unitId);
|
|
466
|
-
|
|
575
|
+
}
|
|
576
|
+
showInfoPopupFromHover(info) {
|
|
577
|
+
this.cancelScheduledHideInfoPopup();
|
|
578
|
+
if (this._infoPopupPinned || this._infoPopupSuppressed) return;
|
|
579
|
+
if (!this.showing) this.showInfoPopup(info);
|
|
467
580
|
}
|
|
468
581
|
hideInfoPopup() {
|
|
469
|
-
|
|
582
|
+
this.cancelScheduledHideInfoPopup();
|
|
583
|
+
this._infoPopupPinned = false;
|
|
470
584
|
this._showingLink$.next(null);
|
|
471
|
-
|
|
585
|
+
const popup = this._infoPopup;
|
|
586
|
+
this._infoPopup = null;
|
|
587
|
+
popup === null || popup === void 0 || popup.dispose();
|
|
588
|
+
}
|
|
589
|
+
scheduleHideInfoPopup() {
|
|
590
|
+
if (this._infoPopupPinned || !this.showing) return;
|
|
591
|
+
this.cancelScheduledHideInfoPopup();
|
|
592
|
+
this._infoPopupHideTimer = setTimeout(() => {
|
|
593
|
+
this._infoPopupHideTimer = null;
|
|
594
|
+
if (!this._infoPopupPinned) this.hideInfoPopup();
|
|
595
|
+
}, INFO_POPUP_HIDE_DELAY);
|
|
596
|
+
}
|
|
597
|
+
cancelScheduledHideInfoPopup() {
|
|
598
|
+
if (this._infoPopupHideTimer !== null) {
|
|
599
|
+
clearTimeout(this._infoPopupHideTimer);
|
|
600
|
+
this._infoPopupHideTimer = null;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
hideInfoPopupOnPointerDown() {
|
|
604
|
+
this._infoPopupSuppressed = true;
|
|
605
|
+
if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
|
|
606
|
+
this.hideInfoPopup();
|
|
607
|
+
this._infoPopupSuppressionTimer = setTimeout(() => {
|
|
608
|
+
this._infoPopupSuppressed = false;
|
|
609
|
+
this._infoPopupSuppressionTimer = null;
|
|
610
|
+
}, 0);
|
|
611
|
+
}
|
|
612
|
+
canEditLink(unitId, linkInfo) {
|
|
613
|
+
const document = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
614
|
+
if (!(document instanceof _univerjs_core.DocumentDataModel)) return false;
|
|
615
|
+
if (!linkInfo) return (0, _univerjs_docs.canEditDocumentTargets)(this._permissionService, unitId, []);
|
|
616
|
+
const segmentId = linkInfo.segmentId ?? "";
|
|
617
|
+
return (0, _univerjs_docs.canEditDocumentTargets)(this._permissionService, unitId, [...(0, _univerjs_docs.getDocumentEntityParentPermissionObjectIds)(document, segmentId, "custom-range", linkInfo.linkId), (0, _univerjs_docs.getDocumentEntityPermissionObjectId)(segmentId, "custom-range", linkInfo.linkId)]);
|
|
472
618
|
}
|
|
473
619
|
};
|
|
474
620
|
DocHyperLinkPopupService = __decorate([
|
|
475
621
|
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocCanvasPopManagerService)),
|
|
476
622
|
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocSelectionManagerService)),
|
|
477
|
-
__decorateParam(2, _univerjs_core.IUniverInstanceService)
|
|
623
|
+
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
624
|
+
__decorateParam(3, _univerjs_core.IPermissionService),
|
|
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)
|
|
478
629
|
], DocHyperLinkPopupService);
|
|
479
630
|
|
|
480
631
|
//#endregion
|
|
@@ -499,7 +650,7 @@ const ShowDocHyperLinkEditPopupOperation = {
|
|
|
499
650
|
const hyperLinkService = accessor.get(DocHyperLinkPopupService);
|
|
500
651
|
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
652
|
if (!unitId) return false;
|
|
502
|
-
hyperLinkService.showEditPopup(unitId, linkInfo);
|
|
653
|
+
hyperLinkService.showEditPopup(unitId, linkInfo ?? null);
|
|
503
654
|
return true;
|
|
504
655
|
}
|
|
505
656
|
};
|
|
@@ -512,7 +663,8 @@ const ToggleDocHyperLinkInfoPopupOperation = {
|
|
|
512
663
|
hyperLinkService.hideInfoPopup();
|
|
513
664
|
return true;
|
|
514
665
|
}
|
|
515
|
-
hyperLinkService.
|
|
666
|
+
if (params.fromHover) hyperLinkService.showInfoPopupFromHover(params);
|
|
667
|
+
else hyperLinkService.showInfoPopup(params);
|
|
516
668
|
return true;
|
|
517
669
|
}
|
|
518
670
|
};
|
|
@@ -520,17 +672,57 @@ const ClickDocHyperLinkOperation = {
|
|
|
520
672
|
type: _univerjs_core.CommandType.OPERATION,
|
|
521
673
|
id: "doc.operation.click-hyper-link",
|
|
522
674
|
handler(accessor, params) {
|
|
523
|
-
var _doc$getSelfOrHeaderF,
|
|
675
|
+
var _doc$getSelfOrHeaderF, _sourceBody$customRan;
|
|
524
676
|
if (!params) return false;
|
|
525
677
|
const { unitId, linkId, segmentId } = params;
|
|
526
678
|
const doc = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
527
|
-
const
|
|
528
|
-
const link =
|
|
529
|
-
if (
|
|
530
|
-
|
|
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");
|
|
531
704
|
return true;
|
|
532
705
|
}
|
|
533
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
|
+
}
|
|
534
726
|
|
|
535
727
|
//#endregion
|
|
536
728
|
//#region src/menu/menu.ts
|
|
@@ -564,6 +756,10 @@ const addLinkShortcut = {
|
|
|
564
756
|
const menuSchema = {
|
|
565
757
|
[_univerjs_ui.RibbonInsertGroup.MEDIA]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
566
758
|
order: 1,
|
|
759
|
+
gridLayout: {
|
|
760
|
+
row: 1,
|
|
761
|
+
column: 5
|
|
762
|
+
},
|
|
567
763
|
menuItemFactory: AddHyperLinkMenuItemFactory
|
|
568
764
|
} },
|
|
569
765
|
[_univerjs_docs_ui.FLOAT_TOOLBAR_MENU_POSITION]: { [ShowDocHyperLinkEditPopupOperation.id]: {
|
|
@@ -589,7 +785,7 @@ const menuSchema = {
|
|
|
589
785
|
//#endregion
|
|
590
786
|
//#region package.json
|
|
591
787
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
592
|
-
var version = "1.0.0
|
|
788
|
+
var version = "1.0.0";
|
|
593
789
|
|
|
594
790
|
//#endregion
|
|
595
791
|
//#region src/config/config.ts
|
|
@@ -598,7 +794,199 @@ const configSymbol = Symbol(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY);
|
|
|
598
794
|
const defaultPluginConfig = {};
|
|
599
795
|
|
|
600
796
|
//#endregion
|
|
601
|
-
//#region src/controllers/
|
|
797
|
+
//#region src/controllers/doc-hyper-link-selection.controller.ts
|
|
798
|
+
let DocHyperLinkSelectionController = class DocHyperLinkSelectionController extends _univerjs_core.Disposable {
|
|
799
|
+
constructor(_commandService, _univerInstanceService, _docHyperLinkService) {
|
|
800
|
+
super();
|
|
801
|
+
this._commandService = _commandService;
|
|
802
|
+
this._univerInstanceService = _univerInstanceService;
|
|
803
|
+
this._docHyperLinkService = _docHyperLinkService;
|
|
804
|
+
_defineProperty(this, "_selection", null);
|
|
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
|
+
}));
|
|
810
|
+
}
|
|
811
|
+
_initSelectionChange() {
|
|
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
|
+
}
|
|
818
|
+
if (commandInfo.id === _univerjs_docs.SetTextSelectionsOperation.id) {
|
|
819
|
+
var _this$_selection2;
|
|
820
|
+
const params = commandInfo.params;
|
|
821
|
+
const { unitId, ranges, segmentId } = params;
|
|
822
|
+
const doc = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
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;
|
|
843
|
+
if ((primary === null || primary === void 0 ? void 0 : primary.collapsed) && doc) {
|
|
844
|
+
var _doc$getSelfOrHeaderF;
|
|
845
|
+
const { startOffset, endOffset, segmentPage } = primary;
|
|
846
|
+
const customRanges = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.customRanges;
|
|
847
|
+
const showing = this._docHyperLinkService.showing;
|
|
848
|
+
const customRange = ((showing === null || showing === void 0 ? void 0 : showing.unitId) === unitId && (showing.segmentId ?? "") === segmentId && showing.segmentPage === segmentPage && showing.endIndex === endOffset - 1 ? customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.rangeId === showing.linkId && value.rangeType === _univerjs_core.CustomRangeType.HYPERLINK && value.startIndex <= startOffset && value.endIndex === endOffset - 1) : void 0) ?? (customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.rangeType === _univerjs_core.CustomRangeType.HYPERLINK && value.startIndex <= startOffset && value.endIndex > endOffset - 1));
|
|
849
|
+
if (customRange) {
|
|
850
|
+
this._docHyperLinkService.showInfoPopup({
|
|
851
|
+
unitId,
|
|
852
|
+
linkId: customRange.rangeId,
|
|
853
|
+
segmentId,
|
|
854
|
+
segmentPage,
|
|
855
|
+
startIndex: customRange.startIndex,
|
|
856
|
+
endIndex: customRange.endIndex
|
|
857
|
+
});
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
this._docHyperLinkService.hideInfoPopup();
|
|
862
|
+
this._docHyperLinkService.hideEditPopup();
|
|
863
|
+
}
|
|
864
|
+
}));
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
DocHyperLinkSelectionController = __decorate([
|
|
868
|
+
__decorateParam(0, _univerjs_core.ICommandService),
|
|
869
|
+
__decorateParam(1, _univerjs_core.IUniverInstanceService),
|
|
870
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(DocHyperLinkPopupService))
|
|
871
|
+
], DocHyperLinkSelectionController);
|
|
872
|
+
|
|
873
|
+
//#endregion
|
|
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
|
|
602
990
|
/**
|
|
603
991
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
604
992
|
*
|
|
@@ -614,7 +1002,7 @@ const defaultPluginConfig = {};
|
|
|
614
1002
|
* See the License for the specific language governing permissions and
|
|
615
1003
|
* limitations under the License.
|
|
616
1004
|
*/
|
|
617
|
-
let
|
|
1005
|
+
let MobileComponentsController = class MobileComponentsController extends _univerjs_core.Disposable {
|
|
618
1006
|
constructor(_componentManager, _iconManager) {
|
|
619
1007
|
super();
|
|
620
1008
|
this._componentManager = _componentManager;
|
|
@@ -623,7 +1011,7 @@ let ComponentsController = class ComponentsController extends _univerjs_core.Dis
|
|
|
623
1011
|
this._registerIcons();
|
|
624
1012
|
}
|
|
625
1013
|
_registerComponents() {
|
|
626
|
-
[[
|
|
1014
|
+
[[MobileDocHyperLinkEdit.componentKey, MobileDocHyperLinkEdit], [MobileDocLinkPopup.componentKey, MobileDocLinkPopup]].forEach(([key, comp]) => {
|
|
627
1015
|
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
628
1016
|
});
|
|
629
1017
|
}
|
|
@@ -631,103 +1019,66 @@ let ComponentsController = class ComponentsController extends _univerjs_core.Dis
|
|
|
631
1019
|
this.disposeWithMe(this._iconManager.register({ LinkIcon: _univerjs_icons.LinkIcon }));
|
|
632
1020
|
}
|
|
633
1021
|
};
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
//#endregion
|
|
637
|
-
//#region src/controllers/doc-hyper-link-selection.controller.ts
|
|
638
|
-
let DocHyperLinkSelectionController = class DocHyperLinkSelectionController extends _univerjs_core.Disposable {
|
|
639
|
-
constructor(_commandService, _univerInstanceService, _docHyperLinkService) {
|
|
640
|
-
super();
|
|
641
|
-
this._commandService = _commandService;
|
|
642
|
-
this._univerInstanceService = _univerInstanceService;
|
|
643
|
-
this._docHyperLinkService = _docHyperLinkService;
|
|
644
|
-
this._initSelectionChange();
|
|
645
|
-
}
|
|
646
|
-
_initSelectionChange() {
|
|
647
|
-
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
648
|
-
if (commandInfo.id === _univerjs_docs.SetTextSelectionsOperation.id) {
|
|
649
|
-
const { unitId, ranges, segmentId } = commandInfo.params;
|
|
650
|
-
const doc = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
651
|
-
const primary = ranges[0];
|
|
652
|
-
if (primary && doc) {
|
|
653
|
-
var _doc$getSelfOrHeaderF;
|
|
654
|
-
const { startOffset, endOffset, collapsed, segmentPage } = primary;
|
|
655
|
-
const customRanges = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.customRanges;
|
|
656
|
-
if (collapsed) {
|
|
657
|
-
const index = (customRanges === null || customRanges === void 0 ? void 0 : customRanges.findIndex((value) => value.startIndex < startOffset && value.endIndex > endOffset - 1)) ?? -1;
|
|
658
|
-
if (index > -1) {
|
|
659
|
-
const customRange = customRanges[index];
|
|
660
|
-
this._docHyperLinkService.showInfoPopup({
|
|
661
|
-
unitId,
|
|
662
|
-
linkId: customRange.rangeId,
|
|
663
|
-
segmentId,
|
|
664
|
-
segmentPage,
|
|
665
|
-
startIndex: customRange.startIndex,
|
|
666
|
-
endIndex: customRange.endIndex
|
|
667
|
-
});
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
} else if (customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1)) return;
|
|
671
|
-
}
|
|
672
|
-
this._docHyperLinkService.hideInfoPopup();
|
|
673
|
-
this._docHyperLinkService.hideEditPopup();
|
|
674
|
-
}
|
|
675
|
-
}));
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
DocHyperLinkSelectionController = __decorate([
|
|
679
|
-
__decorateParam(0, _univerjs_core.ICommandService),
|
|
680
|
-
__decorateParam(1, _univerjs_core.IUniverInstanceService),
|
|
681
|
-
__decorateParam(2, (0, _univerjs_core.Inject)(DocHyperLinkPopupService))
|
|
682
|
-
], DocHyperLinkSelectionController);
|
|
1022
|
+
MobileComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IconManager))], MobileComponentsController);
|
|
683
1023
|
|
|
684
1024
|
//#endregion
|
|
685
|
-
//#region src/controllers/render-controllers/hyper-link-event.render-controller.ts
|
|
686
|
-
let
|
|
1025
|
+
//#region src/controllers/render-controllers/mobile/hyper-link-event.render-controller.ts
|
|
1026
|
+
let MobileDocHyperLinkEventRenderController = class MobileDocHyperLinkEventRenderController extends _univerjs_core.Disposable {
|
|
687
1027
|
get _skeleton() {
|
|
688
1028
|
return this._docSkeletonManagerService.getSkeleton();
|
|
689
1029
|
}
|
|
690
|
-
constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService,
|
|
1030
|
+
constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _mobileElementMenuService) {
|
|
691
1031
|
super();
|
|
692
1032
|
this._context = _context;
|
|
693
1033
|
this._docEventManagerService = _docEventManagerService;
|
|
694
1034
|
this._commandService = _commandService;
|
|
695
1035
|
this._hyperLinkPopupService = _hyperLinkPopupService;
|
|
696
1036
|
this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
697
|
-
this.
|
|
1037
|
+
this._mobileElementMenuService = _mobileElementMenuService;
|
|
698
1038
|
if (this._context.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
|
|
699
|
-
this.
|
|
1039
|
+
this._initPointerDown();
|
|
700
1040
|
this._initClick();
|
|
701
1041
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
}
|
|
705
|
-
_initHover() {
|
|
706
|
-
this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
|
|
707
|
-
var _activeRanges$;
|
|
1042
|
+
_initPointerDown() {
|
|
1043
|
+
this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe((ranges) => {
|
|
708
1044
|
const link = ranges.find((range) => range.range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK);
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
if (((link === null || link === void 0 ? void 0 : link.segmentId) ?? "") !== currentSegmentId) {
|
|
712
|
-
this._hideInfoPopup();
|
|
1045
|
+
if (!link) {
|
|
1046
|
+
this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
|
|
713
1047
|
return;
|
|
714
1048
|
}
|
|
715
|
-
|
|
1049
|
+
const info = {
|
|
716
1050
|
unitId: this._context.unitId,
|
|
717
1051
|
linkId: link.range.rangeId,
|
|
718
1052
|
segmentId: link.segmentId,
|
|
719
1053
|
segmentPage: link.segmentPageIndex,
|
|
720
|
-
rangeId: link.range.rangeId,
|
|
721
1054
|
startIndex: link.range.startIndex,
|
|
722
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)
|
|
723
1063
|
});
|
|
724
|
-
else this._hideInfoPopup();
|
|
725
1064
|
}));
|
|
726
1065
|
}
|
|
727
1066
|
_initClick() {
|
|
728
1067
|
this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
|
|
729
1068
|
const link = range.range;
|
|
730
|
-
if (link
|
|
1069
|
+
if (link.rangeType !== _univerjs_core.CustomRangeType.HYPERLINK) return;
|
|
1070
|
+
if (!range.ctrlKey && !range.metaKey) {
|
|
1071
|
+
this._hyperLinkPopupService.showInfoPopup({
|
|
1072
|
+
unitId: this._context.unitId,
|
|
1073
|
+
linkId: link.rangeId,
|
|
1074
|
+
segmentId: range.segmentId,
|
|
1075
|
+
segmentPage: range.segmentPageIndex,
|
|
1076
|
+
startIndex: link.startIndex,
|
|
1077
|
+
endIndex: link.endIndex
|
|
1078
|
+
}, { pinned: true });
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
this._commandService.executeCommand(ClickDocHyperLinkOperation.id, {
|
|
731
1082
|
unitId: this._context.unitId,
|
|
732
1083
|
linkId: link.rangeId,
|
|
733
1084
|
segmentId: range.segmentId
|
|
@@ -735,25 +1086,22 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
|
|
|
735
1086
|
}));
|
|
736
1087
|
}
|
|
737
1088
|
};
|
|
738
|
-
|
|
1089
|
+
MobileDocHyperLinkEventRenderController = __decorate([
|
|
739
1090
|
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocEventManagerService)),
|
|
740
1091
|
__decorateParam(2, _univerjs_core.ICommandService),
|
|
741
1092
|
__decorateParam(3, (0, _univerjs_core.Inject)(DocHyperLinkPopupService)),
|
|
742
1093
|
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_docs.DocSkeletonManagerService)),
|
|
743
|
-
__decorateParam(5, (0, _univerjs_core.Inject)(
|
|
744
|
-
],
|
|
1094
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocMobileElementMenuService))
|
|
1095
|
+
], MobileDocHyperLinkEventRenderController);
|
|
745
1096
|
|
|
746
1097
|
//#endregion
|
|
747
1098
|
//#region src/controllers/render-controllers/render.controller.ts
|
|
748
1099
|
let DocHyperLinkRenderController = class DocHyperLinkRenderController extends _univerjs_core.Disposable {
|
|
749
|
-
constructor(_context, _docInterceptorService, _hyperLinkService
|
|
1100
|
+
constructor(_context, _docInterceptorService, _hyperLinkService) {
|
|
750
1101
|
super();
|
|
751
|
-
this._context = _context;
|
|
752
1102
|
this._docInterceptorService = _docInterceptorService;
|
|
753
1103
|
this._hyperLinkService = _hyperLinkService;
|
|
754
|
-
this._docRenderController = _docRenderController;
|
|
755
1104
|
this._init();
|
|
756
|
-
this._initReRender();
|
|
757
1105
|
}
|
|
758
1106
|
_init() {
|
|
759
1107
|
this._docInterceptorService.intercept(_univerjs_docs.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, { handler: (data, pos, next) => {
|
|
@@ -772,19 +1120,8 @@ let DocHyperLinkRenderController = class DocHyperLinkRenderController extends _u
|
|
|
772
1120
|
});
|
|
773
1121
|
} });
|
|
774
1122
|
}
|
|
775
|
-
_initReRender() {
|
|
776
|
-
this.disposeWithMe(this._hyperLinkService.showingLink$.pipe((0, rxjs.distinctUntilChanged)((prev, aft) => (prev === null || prev === void 0 ? void 0 : prev.linkId) === (aft === null || aft === void 0 ? void 0 : aft.linkId) && (prev === null || prev === void 0 ? void 0 : prev.unitId) === (aft === null || aft === void 0 ? void 0 : aft.unitId) && (prev === null || prev === void 0 ? void 0 : prev.startIndex) === (aft === null || aft === void 0 ? void 0 : aft.startIndex)), (0, rxjs.pairwise)()).subscribe(([preLink, link]) => {
|
|
777
|
-
if (link) {
|
|
778
|
-
if (link.unitId === this._context.unitId) this._docRenderController.reRender(link.unitId);
|
|
779
|
-
} else if (preLink && preLink.unitId === this._context.unitId) this._docRenderController.reRender(preLink.unitId);
|
|
780
|
-
}));
|
|
781
|
-
}
|
|
782
1123
|
};
|
|
783
|
-
DocHyperLinkRenderController = __decorate([
|
|
784
|
-
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocInterceptorService)),
|
|
785
|
-
__decorateParam(2, (0, _univerjs_core.Inject)(DocHyperLinkPopupService)),
|
|
786
|
-
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocRenderController))
|
|
787
|
-
], DocHyperLinkRenderController);
|
|
1124
|
+
DocHyperLinkRenderController = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_docs.DocInterceptorService)), __decorateParam(2, (0, _univerjs_core.Inject)(DocHyperLinkPopupService))], DocHyperLinkRenderController);
|
|
788
1125
|
|
|
789
1126
|
//#endregion
|
|
790
1127
|
//#region src/controllers/ui.controller.ts
|
|
@@ -826,6 +1163,29 @@ DocHyperLinkUIController = __decorate([
|
|
|
826
1163
|
__decorateParam(2, _univerjs_ui.IShortcutService)
|
|
827
1164
|
], DocHyperLinkUIController);
|
|
828
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
|
+
|
|
829
1189
|
//#endregion
|
|
830
1190
|
//#region src/types/const/index.ts
|
|
831
1191
|
/**
|
|
@@ -845,6 +1205,175 @@ DocHyperLinkUIController = __decorate([
|
|
|
845
1205
|
*/
|
|
846
1206
|
const DOC_HYPER_LINK_UI_PLUGIN = "DOC_HYPER_LINK_UI_PLUGIN";
|
|
847
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
|
+
|
|
848
1377
|
//#endregion
|
|
849
1378
|
//#region src/plugin.ts
|
|
850
1379
|
let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends _univerjs_core.Plugin {
|
|
@@ -859,15 +1388,15 @@ let UniverDocsHyperLinkUIPlugin = class UniverDocsHyperLinkUIPlugin extends _uni
|
|
|
859
1388
|
this._configService.setConfig(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
|
|
860
1389
|
}
|
|
861
1390
|
onStarting() {
|
|
862
|
-
this._injector.add([ComponentsController]);
|
|
863
|
-
this._injector.get(ComponentsController);
|
|
864
1391
|
[
|
|
1392
|
+
[ComponentsController],
|
|
865
1393
|
[DocHyperLinkPopupService],
|
|
866
1394
|
[DocHyperLinkUIController],
|
|
867
1395
|
[DocHyperLinkSelectionController]
|
|
868
1396
|
].forEach((dep) => {
|
|
869
1397
|
this._injector.add(dep);
|
|
870
1398
|
});
|
|
1399
|
+
this._injector.get(ComponentsController);
|
|
871
1400
|
this._injector.get(DocHyperLinkUIController);
|
|
872
1401
|
}
|
|
873
1402
|
onReady() {
|
|
@@ -895,6 +1424,12 @@ UniverDocsHyperLinkUIPlugin = __decorate([
|
|
|
895
1424
|
|
|
896
1425
|
//#endregion
|
|
897
1426
|
exports.DocsHyperLinkUIMenuSchema = menuSchema;
|
|
1427
|
+
Object.defineProperty(exports, 'UniverDocsHyperLinkMobileUIPlugin', {
|
|
1428
|
+
enumerable: true,
|
|
1429
|
+
get: function () {
|
|
1430
|
+
return UniverDocsHyperLinkMobileUIPlugin;
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
898
1433
|
Object.defineProperty(exports, 'UniverDocsHyperLinkUIPlugin', {
|
|
899
1434
|
enumerable: true,
|
|
900
1435
|
get: function () {
|