mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 17:55:52 +01:00
chore(prettier): fix all files
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import treeService from './tree.js';
|
||||
import treeService from "./tree.js";
|
||||
import linkContextMenuService from "../menus/link_context_menu.js";
|
||||
import appContext, { NoteCommandData } from "../components/app_context.js";
|
||||
import froca from "./froca.js";
|
||||
@@ -13,14 +13,14 @@ function getNotePathFromUrl(url: string) {
|
||||
async function getLinkIcon(noteId: string, viewMode: ViewMode | undefined) {
|
||||
let icon;
|
||||
|
||||
if (!viewMode || viewMode === 'default') {
|
||||
if (!viewMode || viewMode === "default") {
|
||||
const note = await froca.getNote(noteId);
|
||||
|
||||
icon = note?.getIcon();
|
||||
} else if (viewMode === 'source') {
|
||||
icon = 'bx bx-code-curly';
|
||||
} else if (viewMode === 'attachments') {
|
||||
icon = 'bx bx-file';
|
||||
} else if (viewMode === "source") {
|
||||
icon = "bx bx-code-curly";
|
||||
} else if (viewMode === "attachments") {
|
||||
icon = "bx bx-file";
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
@@ -72,14 +72,14 @@ async function createLink(notePath: string, options: CreateLinkOptions = {}) {
|
||||
}
|
||||
|
||||
const viewScope = options.viewScope || {};
|
||||
const viewMode = viewScope.viewMode || 'default';
|
||||
const viewMode = viewScope.viewMode || "default";
|
||||
let linkTitle = options.title;
|
||||
|
||||
if (!linkTitle) {
|
||||
if (viewMode === 'attachments' && viewScope.attachmentId) {
|
||||
if (viewMode === "attachments" && viewScope.attachmentId) {
|
||||
const attachment = await froca.getAttachment(viewScope.attachmentId);
|
||||
|
||||
linkTitle = attachment ? attachment.title : '[missing attachment]';
|
||||
linkTitle = attachment ? attachment.title : "[missing attachment]";
|
||||
} else if (noteId) {
|
||||
linkTitle = await treeService.getNoteTitle(noteId, parentNoteId);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ async function createLink(notePath: string, options: CreateLinkOptions = {}) {
|
||||
|
||||
const note = await froca.getNote(noteId);
|
||||
|
||||
if (autoConvertToImage && (note?.type && ['image', 'canvas', 'mermaid'].includes(note.type)) && viewMode === 'default') {
|
||||
if (autoConvertToImage && note?.type && ["image", "canvas", "mermaid"].includes(note.type) && viewMode === "default") {
|
||||
const encodedTitle = encodeURIComponent(linkTitle || "");
|
||||
|
||||
return $("<img>")
|
||||
@@ -101,9 +101,7 @@ async function createLink(notePath: string, options: CreateLinkOptions = {}) {
|
||||
let icon = await getLinkIcon(noteId, viewMode);
|
||||
|
||||
if (icon) {
|
||||
$container
|
||||
.append($("<span>").addClass(`bx ${icon}`))
|
||||
.append(" ");
|
||||
$container.append($("<span>").addClass(`bx ${icon}`)).append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +126,7 @@ async function createLink(notePath: string, options: CreateLinkOptions = {}) {
|
||||
$container.append($noteLink);
|
||||
|
||||
if (showNotePath) {
|
||||
const resolvedPathSegments = await treeService.resolveNotePathToSegments(notePath) || [];
|
||||
const resolvedPathSegments = (await treeService.resolveNotePathToSegments(notePath)) || [];
|
||||
resolvedPathSegments.pop(); // Remove last element
|
||||
|
||||
const resolvedPath = resolvedPathSegments.join("/");
|
||||
@@ -144,21 +142,23 @@ async function createLink(notePath: string, options: CreateLinkOptions = {}) {
|
||||
return $container;
|
||||
}
|
||||
|
||||
function calculateHash({notePath, ntxId, hoistedNoteId, viewScope = {}}: NoteCommandData) {
|
||||
function calculateHash({ notePath, ntxId, hoistedNoteId, viewScope = {} }: NoteCommandData) {
|
||||
notePath = notePath || "";
|
||||
const params = [
|
||||
ntxId ? { ntxId: ntxId } : null,
|
||||
(hoistedNoteId && hoistedNoteId !== 'root') ? { hoistedNoteId: hoistedNoteId } : null,
|
||||
viewScope.viewMode && viewScope.viewMode !== 'default' ? { viewMode: viewScope.viewMode } : null,
|
||||
hoistedNoteId && hoistedNoteId !== "root" ? { hoistedNoteId: hoistedNoteId } : null,
|
||||
viewScope.viewMode && viewScope.viewMode !== "default" ? { viewMode: viewScope.viewMode } : null,
|
||||
viewScope.attachmentId ? { attachmentId: viewScope.attachmentId } : null
|
||||
].filter(p => !!p);
|
||||
].filter((p) => !!p);
|
||||
|
||||
const paramStr = params.map(pair => {
|
||||
const name = Object.keys(pair)[0];
|
||||
const value = (pair as Record<string, string | undefined>)[name];
|
||||
const paramStr = params
|
||||
.map((pair) => {
|
||||
const name = Object.keys(pair)[0];
|
||||
const value = (pair as Record<string, string | undefined>)[name];
|
||||
|
||||
return `${encodeURIComponent(name)}=${encodeURIComponent(value || "")}`;
|
||||
}).join("&");
|
||||
return `${encodeURIComponent(name)}=${encodeURIComponent(value || "")}`;
|
||||
})
|
||||
.join("&");
|
||||
|
||||
if (!notePath && !paramStr) {
|
||||
return "";
|
||||
@@ -178,7 +178,7 @@ function parseNavigationStateFromUrl(url: string | undefined) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const hashIdx = url.indexOf('#');
|
||||
const hashIdx = url.indexOf("#");
|
||||
if (hashIdx === -1) {
|
||||
return {};
|
||||
}
|
||||
@@ -191,7 +191,7 @@ function parseNavigationStateFromUrl(url: string | undefined) {
|
||||
}
|
||||
|
||||
const viewScope: ViewScope = {
|
||||
viewMode: 'default'
|
||||
viewMode: "default"
|
||||
};
|
||||
let ntxId = null;
|
||||
let hoistedNoteId = null;
|
||||
@@ -203,13 +203,13 @@ function parseNavigationStateFromUrl(url: string | undefined) {
|
||||
name = decodeURIComponent(name);
|
||||
value = decodeURIComponent(value);
|
||||
|
||||
if (name === 'ntxId') {
|
||||
if (name === "ntxId") {
|
||||
ntxId = value;
|
||||
} else if (name === 'hoistedNoteId') {
|
||||
} else if (name === "hoistedNoteId") {
|
||||
hoistedNoteId = value;
|
||||
} else if (name === 'searchString') {
|
||||
} else if (name === "searchString") {
|
||||
searchString = value; // supports triggering search from URL, e.g. #?searchString=blabla
|
||||
} else if (['viewMode', 'attachmentId'].includes(name)) {
|
||||
} else if (["viewMode", "attachmentId"].includes(name)) {
|
||||
(viewScope as any)[name] = value;
|
||||
} else {
|
||||
console.warn(`Unrecognized hash parameter '${name}'.`);
|
||||
@@ -229,7 +229,7 @@ function parseNavigationStateFromUrl(url: string | undefined) {
|
||||
|
||||
function goToLink(evt: MouseEvent | JQuery.ClickEvent) {
|
||||
const $link = $(evt.target as any).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);
|
||||
}
|
||||
@@ -246,7 +246,7 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent, hrefLink: string | und
|
||||
return handleFootnote(hrefLink, $link);
|
||||
}
|
||||
|
||||
const {notePath, viewScope} = parseNavigationStateFromUrl(hrefLink);
|
||||
const { notePath, viewScope } = parseNavigationStateFromUrl(hrefLink);
|
||||
|
||||
const ctrlKey = utils.isCtrlKey(evt);
|
||||
const isLeftClick = evt.which === 1;
|
||||
@@ -258,15 +258,15 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent, hrefLink: string | und
|
||||
|
||||
if (notePath) {
|
||||
if (openInNewTab) {
|
||||
appContext.tabManager.openTabWithNoteWithHoisting(notePath, {viewScope});
|
||||
appContext.tabManager.openTabWithNoteWithHoisting(notePath, { viewScope });
|
||||
} else if (isLeftClick) {
|
||||
const ntxId = $(evt.target as any).closest("[data-ntx-id]").attr("data-ntx-id");
|
||||
const ntxId = $(evt.target as any)
|
||||
.closest("[data-ntx-id]")
|
||||
.attr("data-ntx-id");
|
||||
|
||||
const noteContext = ntxId
|
||||
? appContext.tabManager.getNoteContextById(ntxId)
|
||||
: appContext.tabManager.getActiveContext();
|
||||
const noteContext = ntxId ? appContext.tabManager.getNoteContextById(ntxId) : appContext.tabManager.getActiveContext();
|
||||
|
||||
noteContext.setNote(notePath, {viewScope}).then(() => {
|
||||
noteContext.setNote(notePath, { viewScope }).then(() => {
|
||||
if (noteContext !== appContext.tabManager.getActiveContext()) {
|
||||
appContext.tabManager.activateNoteContext(noteContext.ntxId);
|
||||
}
|
||||
@@ -276,27 +276,67 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent, hrefLink: string | und
|
||||
const withinEditLink = $link?.hasClass("ck-link-actions__preview");
|
||||
const outsideOfCKEditor = !$link || $link.closest("[contenteditable]").length === 0;
|
||||
|
||||
if (openInNewTab
|
||||
|| (withinEditLink && (leftClick || middleClick))
|
||||
|| (outsideOfCKEditor && (leftClick || middleClick))
|
||||
) {
|
||||
if (hrefLink.toLowerCase().startsWith('http') || hrefLink.startsWith("api/")) {
|
||||
window.open(hrefLink, '_blank');
|
||||
} else if ((hrefLink.toLowerCase().startsWith('file:') || hrefLink.toLowerCase().startsWith('geo:')) && utils.isElectron()) {
|
||||
const electron = utils.dynamicRequire('electron');
|
||||
if (openInNewTab || (withinEditLink && (leftClick || middleClick)) || (outsideOfCKEditor && (leftClick || middleClick))) {
|
||||
if (hrefLink.toLowerCase().startsWith("http") || hrefLink.startsWith("api/")) {
|
||||
window.open(hrefLink, "_blank");
|
||||
} else if ((hrefLink.toLowerCase().startsWith("file:") || hrefLink.toLowerCase().startsWith("geo:")) && utils.isElectron()) {
|
||||
const electron = utils.dynamicRequire("electron");
|
||||
electron.shell.openPath(hrefLink);
|
||||
} else {
|
||||
// Enable protocols supported by CKEditor 5 to be clickable.
|
||||
// Refer to `allowedProtocols` in https://github.com/TriliumNext/trilium-ckeditor5/blob/main/packages/ckeditor5-build-balloon-block/src/ckeditor.ts.
|
||||
// And be consistent with `allowedSchemes` in `src\services\html_sanitizer.ts`
|
||||
const allowedSchemes = [
|
||||
'http', 'https', 'ftp', 'ftps', 'mailto', 'data', 'evernote', 'file', 'facetime', 'gemini', 'git',
|
||||
'gopher', 'imap', 'irc', 'irc6', 'jabber', 'jar', 'lastfm', 'ldap', 'ldaps', 'magnet', 'message',
|
||||
'mumble', 'nfs', 'onenote', 'pop', 'rmi', 's3', 'sftp', 'skype', 'sms', 'spotify', 'steam', 'svn', 'udp',
|
||||
'view-source', 'vlc', 'vnc', 'ws', 'wss', 'xmpp', 'jdbc', 'slack', 'tel', 'smb', 'zotero', 'geo'
|
||||
"http",
|
||||
"https",
|
||||
"ftp",
|
||||
"ftps",
|
||||
"mailto",
|
||||
"data",
|
||||
"evernote",
|
||||
"file",
|
||||
"facetime",
|
||||
"gemini",
|
||||
"git",
|
||||
"gopher",
|
||||
"imap",
|
||||
"irc",
|
||||
"irc6",
|
||||
"jabber",
|
||||
"jar",
|
||||
"lastfm",
|
||||
"ldap",
|
||||
"ldaps",
|
||||
"magnet",
|
||||
"message",
|
||||
"mumble",
|
||||
"nfs",
|
||||
"onenote",
|
||||
"pop",
|
||||
"rmi",
|
||||
"s3",
|
||||
"sftp",
|
||||
"skype",
|
||||
"sms",
|
||||
"spotify",
|
||||
"steam",
|
||||
"svn",
|
||||
"udp",
|
||||
"view-source",
|
||||
"vlc",
|
||||
"vnc",
|
||||
"ws",
|
||||
"wss",
|
||||
"xmpp",
|
||||
"jdbc",
|
||||
"slack",
|
||||
"tel",
|
||||
"smb",
|
||||
"zotero",
|
||||
"geo"
|
||||
];
|
||||
if (allowedSchemes.some(protocol => hrefLink.toLowerCase().startsWith(protocol+':'))){
|
||||
window.open(hrefLink, '_blank');
|
||||
if (allowedSchemes.some((protocol) => hrefLink.toLowerCase().startsWith(protocol + ":"))) {
|
||||
window.open(hrefLink, "_blank");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -313,10 +353,9 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent, hrefLink: string | und
|
||||
* @returns whether the event should be consumed or not.
|
||||
*/
|
||||
function handleFootnote(hrefLink: string, $link: JQuery<HTMLElement>) {
|
||||
const el = $link.closest(".ck-content")
|
||||
.find(hrefLink)[0];
|
||||
const el = $link.closest(".ck-content").find(hrefLink)[0];
|
||||
if (el) {
|
||||
el.scrollIntoView({ behavior: "smooth", block: "center" })
|
||||
el.scrollIntoView({ behavior: "smooth", block: "center" });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -337,7 +376,7 @@ function linkContextMenu(e: PointerEvent) {
|
||||
}
|
||||
|
||||
async function loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string | null | undefined = null) {
|
||||
const $link = $el[0].tagName === 'A' ? $el : $el.find("a");
|
||||
const $link = $el[0].tagName === "A" ? $el : $el.find("a");
|
||||
|
||||
href = href || $link.attr("href");
|
||||
if (!href) {
|
||||
@@ -345,7 +384,7 @@ async function loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string | n
|
||||
return;
|
||||
}
|
||||
|
||||
const {noteId, viewScope} = parseNavigationStateFromUrl(href);
|
||||
const { noteId, viewScope } = parseNavigationStateFromUrl(href);
|
||||
if (!noteId) {
|
||||
console.warn("Missing note ID.");
|
||||
return;
|
||||
@@ -370,7 +409,7 @@ async function loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string | n
|
||||
}
|
||||
|
||||
async function getReferenceLinkTitle(href: string) {
|
||||
const {noteId, viewScope} = parseNavigationStateFromUrl(href);
|
||||
const { noteId, viewScope } = parseNavigationStateFromUrl(href);
|
||||
if (!noteId) {
|
||||
return "[missing note]";
|
||||
}
|
||||
@@ -380,7 +419,7 @@ async function getReferenceLinkTitle(href: string) {
|
||||
return "[missing note]";
|
||||
}
|
||||
|
||||
if (viewScope?.viewMode === 'attachments' && viewScope?.attachmentId) {
|
||||
if (viewScope?.viewMode === "attachments" && viewScope?.attachmentId) {
|
||||
const attachment = await note.getAttachmentById(viewScope.attachmentId);
|
||||
|
||||
return attachment ? attachment.title : "[missing attachment]";
|
||||
@@ -390,7 +429,7 @@ async function getReferenceLinkTitle(href: string) {
|
||||
}
|
||||
|
||||
function getReferenceLinkTitleSync(href: string) {
|
||||
const {noteId, viewScope} = parseNavigationStateFromUrl(href);
|
||||
const { noteId, viewScope } = parseNavigationStateFromUrl(href);
|
||||
if (!noteId) {
|
||||
return "[missing note]";
|
||||
}
|
||||
@@ -400,12 +439,12 @@ function getReferenceLinkTitleSync(href: string) {
|
||||
return "[missing note]";
|
||||
}
|
||||
|
||||
if (viewScope?.viewMode === 'attachments' && viewScope?.attachmentId) {
|
||||
if (viewScope?.viewMode === "attachments" && viewScope?.attachmentId) {
|
||||
if (!note.attachments) {
|
||||
return "[loading title...]";
|
||||
}
|
||||
|
||||
const attachment = note.attachments.find(att => att.attachmentId === viewScope.attachmentId);
|
||||
const attachment = note.attachments.find((att) => att.attachmentId === viewScope.attachmentId);
|
||||
|
||||
return attachment ? attachment.title : "[missing attachment]";
|
||||
} else {
|
||||
@@ -415,27 +454,27 @@ function getReferenceLinkTitleSync(href: string) {
|
||||
|
||||
// TODO: Check why the event is not supported.
|
||||
//@ts-ignore
|
||||
$(document).on('click', "a", goToLink);
|
||||
$(document).on("click", "a", goToLink);
|
||||
// TODO: Check why the event is not supported.
|
||||
//@ts-ignore
|
||||
$(document).on('auxclick', "a", goToLink); // to handle the middle button
|
||||
$(document).on("auxclick", "a", goToLink); // to handle the middle button
|
||||
// TODO: Check why the event is not supported.
|
||||
//@ts-ignore
|
||||
$(document).on('contextmenu', 'a', linkContextMenu);
|
||||
$(document).on('dblclick', "a", e => {
|
||||
$(document).on("contextmenu", "a", linkContextMenu);
|
||||
$(document).on("dblclick", "a", (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
const $link = $(e.target).closest("a");
|
||||
|
||||
const address = $link.attr('href');
|
||||
const address = $link.attr("href");
|
||||
|
||||
if (address && address.startsWith('http')) {
|
||||
window.open(address, '_blank');
|
||||
if (address && address.startsWith("http")) {
|
||||
window.open(address, "_blank");
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('mousedown', 'a', e => {
|
||||
$(document).on("mousedown", "a", (e) => {
|
||||
if (e.which === 2) {
|
||||
// prevent paste on middle click
|
||||
// https://github.com/zadam/trilium/issues/2995
|
||||
|
||||
Reference in New Issue
Block a user