mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
add ability to excalidraw to follow links
This commit is contained in:
parent
f37dc66074
commit
5f6d562bf8
@ -69,7 +69,8 @@ export default class TreeContextMenu {
|
|||||||
{ title: 'Collapse subtree <kbd data-command="collapseSubtree"></kbd>', command: "collapseSubtree", uiIcon: "bx bx-collapse", enabled: noSelectedNotes },
|
{ title: 'Collapse subtree <kbd data-command="collapseSubtree"></kbd>', command: "collapseSubtree", uiIcon: "bx bx-collapse", enabled: noSelectedNotes },
|
||||||
{ title: 'Sort by ... <kbd data-command="sortChildNotes"></kbd>', command: "sortChildNotes", uiIcon: "bx bx-empty", enabled: noSelectedNotes && notSearch },
|
{ title: 'Sort by ... <kbd data-command="sortChildNotes"></kbd>', command: "sortChildNotes", uiIcon: "bx bx-empty", enabled: noSelectedNotes && notSearch },
|
||||||
{ title: 'Recent changes in subtree', command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes },
|
{ title: 'Recent changes in subtree', command: "recentChangesInSubtree", uiIcon: "bx bx-history", enabled: noSelectedNotes },
|
||||||
{ title: 'Convert to attachment', command: "convertNoteToAttachment", uiIcon: "bx bx-empty", enabled: isNotRoot && !isHoisted }
|
{ title: 'Convert to attachment', command: "convertNoteToAttachment", uiIcon: "bx bx-empty", enabled: isNotRoot && !isHoisted },
|
||||||
|
{ title: 'Copy note path to clipboard', command: "copyNotePathToClipboard", uiIcon: "bx bx-empty", enabled: true }
|
||||||
] },
|
] },
|
||||||
{ title: "----" },
|
{ title: "----" },
|
||||||
{ title: "Protect subtree", command: "protectSubtree", uiIcon: "bx bx-check-shield", enabled: noSelectedNotes },
|
{ title: "Protect subtree", command: "protectSubtree", uiIcon: "bx bx-check-shield", enabled: noSelectedNotes },
|
||||||
@ -153,6 +154,9 @@ export default class TreeContextMenu {
|
|||||||
|
|
||||||
toastService.showMessage(`${converted} notes have been converted to attachments.`);
|
toastService.showMessage(`${converted} notes have been converted to attachments.`);
|
||||||
}
|
}
|
||||||
|
else if (command === 'copyNotePathToClipboard') {
|
||||||
|
navigator.clipboard.writeText('#' + notePath);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.treeWidget.triggerCommand(command, {
|
this.treeWidget.triggerCommand(command, {
|
||||||
node: this.node,
|
node: this.node,
|
||||||
|
@ -194,6 +194,10 @@ function goToLink(evt) {
|
|||||||
const $link = $(evt.target).closest("a,.block-link");
|
const $link = $(evt.target).closest("a,.block-link");
|
||||||
const hrefLink = $link.attr('href') || $link.attr('data-href');
|
const hrefLink = $link.attr('href') || $link.attr('data-href');
|
||||||
|
|
||||||
|
return goToLinkExt(evt, hrefLink, $link);
|
||||||
|
}
|
||||||
|
|
||||||
|
function goToLinkExt(evt, hrefLink, $link) {
|
||||||
if (hrefLink?.startsWith("data:")) {
|
if (hrefLink?.startsWith("data:")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -201,7 +205,7 @@ function goToLink(evt) {
|
|||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
|
|
||||||
const { notePath, viewScope } = parseNavigationStateFromUrl(hrefLink);
|
const {notePath, viewScope} = parseNavigationStateFromUrl(hrefLink);
|
||||||
|
|
||||||
const ctrlKey = utils.isCtrlKey(evt);
|
const ctrlKey = utils.isCtrlKey(evt);
|
||||||
const isLeftClick = evt.which === 1;
|
const isLeftClick = evt.which === 1;
|
||||||
@ -213,25 +217,23 @@ function goToLink(evt) {
|
|||||||
|
|
||||||
if (notePath) {
|
if (notePath) {
|
||||||
if (openInNewTab) {
|
if (openInNewTab) {
|
||||||
appContext.tabManager.openTabWithNoteWithHoisting(notePath, { viewScope });
|
appContext.tabManager.openTabWithNoteWithHoisting(notePath, {viewScope});
|
||||||
}
|
} else if (isLeftClick) {
|
||||||
else if (isLeftClick) {
|
|
||||||
const ntxId = $(evt.target).closest("[data-ntx-id]").attr("data-ntx-id");
|
const ntxId = $(evt.target).closest("[data-ntx-id]").attr("data-ntx-id");
|
||||||
|
|
||||||
const noteContext = ntxId
|
const noteContext = ntxId
|
||||||
? appContext.tabManager.getNoteContextById(ntxId)
|
? appContext.tabManager.getNoteContextById(ntxId)
|
||||||
: appContext.tabManager.getActiveContext();
|
: appContext.tabManager.getActiveContext();
|
||||||
|
|
||||||
noteContext.setNote(notePath, { viewScope }).then(() => {
|
noteContext.setNote(notePath, {viewScope}).then(() => {
|
||||||
if (noteContext !== appContext.tabManager.getActiveContext()) {
|
if (noteContext !== appContext.tabManager.getActiveContext()) {
|
||||||
appContext.tabManager.activateNoteContext(noteContext.ntxId);
|
appContext.tabManager.activateNoteContext(noteContext.ntxId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
} else if (hrefLink) {
|
||||||
else if (hrefLink) {
|
const withinEditLink = $link?.hasClass("ck-link-actions__preview");
|
||||||
const withinEditLink = $link.hasClass("ck-link-actions__preview");
|
const outsideOfCKEditor = !$link || $link.closest("[contenteditable]").length === 0;
|
||||||
const outsideOfCKEditor = $link.closest("[contenteditable]").length === 0;
|
|
||||||
|
|
||||||
if (openInNewTab
|
if (openInNewTab
|
||||||
|| (withinEditLink && (leftClick || middleClick))
|
|| (withinEditLink && (leftClick || middleClick))
|
||||||
@ -239,8 +241,7 @@ function goToLink(evt) {
|
|||||||
) {
|
) {
|
||||||
if (hrefLink.toLowerCase().startsWith('http') || hrefLink.startsWith("api/")) {
|
if (hrefLink.toLowerCase().startsWith('http') || hrefLink.startsWith("api/")) {
|
||||||
window.open(hrefLink, '_blank');
|
window.open(hrefLink, '_blank');
|
||||||
}
|
} else if (hrefLink.toLowerCase().startsWith('file:') && utils.isElectron()) {
|
||||||
else if (hrefLink.toLowerCase().startsWith('file:') && utils.isElectron()) {
|
|
||||||
const electron = utils.dynamicRequire('electron');
|
const electron = utils.dynamicRequire('electron');
|
||||||
|
|
||||||
electron.shell.openPath(hrefLink);
|
electron.shell.openPath(hrefLink);
|
||||||
@ -364,6 +365,7 @@ export default {
|
|||||||
getNotePathFromUrl,
|
getNotePathFromUrl,
|
||||||
createLink,
|
createLink,
|
||||||
goToLink,
|
goToLink,
|
||||||
|
goToLinkExt,
|
||||||
loadReferenceLinkTitle,
|
loadReferenceLinkTitle,
|
||||||
getReferenceLinkTitle,
|
getReferenceLinkTitle,
|
||||||
getReferenceLinkTitleSync,
|
getReferenceLinkTitleSync,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import libraryLoader from "../../services/library_loader.js";
|
import libraryLoader from "../../services/library_loader.js";
|
||||||
import TypeWidget from "./type_widget.js";
|
import TypeWidget from "./type_widget.js";
|
||||||
import utils from '../../services/utils.js';
|
import utils from '../../services/utils.js';
|
||||||
|
import linkService from '../../services/link.js';
|
||||||
import debounce from "../../services/debounce.js";
|
import debounce from "../../services/debounce.js";
|
||||||
|
|
||||||
const {sleep} = utils;
|
const {sleep} = utils;
|
||||||
@ -404,20 +405,17 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
|
|||||||
}, [excalidrawWrapperRef]);
|
}, [excalidrawWrapperRef]);
|
||||||
|
|
||||||
const onLinkOpen = React.useCallback((element, event) => {
|
const onLinkOpen = React.useCallback((element, event) => {
|
||||||
const link = element.link;
|
let link = element.link;
|
||||||
const { nativeEvent } = event.detail;
|
|
||||||
const isNewTab = nativeEvent.ctrlKey || nativeEvent.metaKey;
|
|
||||||
const isNewWindow = nativeEvent.shiftKey;
|
|
||||||
const isInternalLink = link.startsWith("/") || link.includes(window.location.origin);
|
|
||||||
|
|
||||||
if (isInternalLink && !isNewTab && !isNewWindow) {
|
if (link.startsWith("root/")) {
|
||||||
// signal that we're handling the redirect ourselves
|
link = "#" + link;
|
||||||
event.preventDefault();
|
|
||||||
// do a custom redirect, such as passing to react-router
|
|
||||||
// ...
|
|
||||||
} else {
|
|
||||||
// open in the same tab
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { nativeEvent } = event.detail;
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
return linkService.goToLinkExt(nativeEvent, link, null);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return React.createElement(
|
return React.createElement(
|
||||||
@ -450,7 +448,7 @@ export default class ExcalidrawTypeWidget extends TypeWidget {
|
|||||||
isCollaborating: false,
|
isCollaborating: false,
|
||||||
detectScroll: false,
|
detectScroll: false,
|
||||||
handleKeyboardGlobally: false,
|
handleKeyboardGlobally: false,
|
||||||
autoFocus: true,
|
autoFocus: false,
|
||||||
onLinkOpen,
|
onLinkOpen,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user