mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 02:52:27 +08:00
chore(client/ts): port menus/link_context_menu
This commit is contained in:
parent
6140bb5d99
commit
dd4885e15c
@ -8,7 +8,7 @@ import zoomComponent from "./zoom.js";
|
||||
import TabManager from "./tab_manager.js";
|
||||
import Component from "./component.js";
|
||||
import keyboardActionsService from "../services/keyboard_actions.js";
|
||||
import linkService from "../services/link.js";
|
||||
import linkService, { ViewScope } from "../services/link.js";
|
||||
import MobileScreenSwitcherExecutor from "./mobile_screen_switcher.js";
|
||||
import MainTreeExecutors from "./main_tree_executors.js";
|
||||
import toast from "../services/toast.js";
|
||||
@ -62,7 +62,14 @@ type CommandMappings = {
|
||||
openNewNoteSplit: CommandData & {
|
||||
ntxId: string;
|
||||
notePath: string;
|
||||
hoistedNoteId?: string;
|
||||
viewScope?: ViewScope;
|
||||
};
|
||||
openInWindow: CommandData & {
|
||||
notePath: string;
|
||||
hoistedNoteId: string;
|
||||
viewScope: ViewScope;
|
||||
}
|
||||
executeInActiveNoteDetailWidget: CommandData & {
|
||||
callback: (value: NoteDetailWidget | PromiseLike<NoteDetailWidget>) => void
|
||||
};
|
||||
|
@ -7,11 +7,6 @@ import { t } from '../services/i18n.js';
|
||||
import type { SelectMenuItemEventListener } from '../components/events.js';
|
||||
import NoteTreeWidget from '../widgets/note_tree.js';
|
||||
|
||||
interface ShowContext {
|
||||
pageX: number;
|
||||
pageY: number;
|
||||
}
|
||||
|
||||
export default class LauncherContextMenu implements SelectMenuItemEventListener {
|
||||
|
||||
private treeWidget: NoteTreeWidget;
|
||||
@ -22,7 +17,7 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
async show(e: ShowContext) {
|
||||
async show(e: PointerEvent) {
|
||||
contextMenu.show({
|
||||
x: e.pageX,
|
||||
y: e.pageY,
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { t } from "../services/i18n.js";
|
||||
import contextMenu from "./context_menu.js";
|
||||
import appContext from "../components/app_context.js";
|
||||
import { ViewScope } from "../services/link.js";
|
||||
|
||||
function openContextMenu(notePath, e, viewScope = {}, hoistedNoteId = null) {
|
||||
function openContextMenu(notePath: string, e: PointerEvent, viewScope: ViewScope = {}, hoistedNoteId: string | null = null) {
|
||||
contextMenu.show({
|
||||
x: e.pageX,
|
||||
y: e.pageY,
|
@ -27,7 +27,7 @@ async function getLinkIcon(noteId: string, viewMode: ViewMode | undefined) {
|
||||
|
||||
type ViewMode = "default" | "source" | "attachments" | string;
|
||||
|
||||
interface ViewScope {
|
||||
export interface ViewScope {
|
||||
viewMode?: ViewMode;
|
||||
attachmentId?: string;
|
||||
}
|
||||
@ -286,7 +286,7 @@ function goToLinkExt(evt: MouseEvent, hrefLink: string | undefined, $link: JQuer
|
||||
const electron = utils.dynamicRequire('electron');
|
||||
electron.shell.openPath(hrefLink);
|
||||
} else {
|
||||
// Enable protocols supported by CKEditor 5 to be clickable.
|
||||
// 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 = [
|
||||
@ -305,7 +305,7 @@ function goToLinkExt(evt: MouseEvent, hrefLink: string | undefined, $link: JQuer
|
||||
return true;
|
||||
}
|
||||
|
||||
function linkContextMenu(e: Event) {
|
||||
function linkContextMenu(e: PointerEvent) {
|
||||
const $link = $(e.target as any).closest("a");
|
||||
const url = $link.attr("href") || $link.attr("data-href");
|
||||
|
||||
@ -334,7 +334,7 @@ async function loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string | n
|
||||
console.warn("Missing note ID.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const note = await froca.getNote(noteId, true);
|
||||
|
||||
if (note) {
|
||||
@ -403,6 +403,8 @@ $(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
|
||||
// TODO: Check why the event is not supported.
|
||||
//@ts-ignore
|
||||
$(document).on('contextmenu', 'a', linkContextMenu);
|
||||
$(document).on('dblclick', "a", e => {
|
||||
e.preventDefault();
|
||||
|
Loading…
x
Reference in New Issue
Block a user