fix(client): type errors due to command change

This commit is contained in:
Elian Doran
2025-02-24 12:39:40 +02:00
parent 147c340529
commit 2ab22e7b0e
7 changed files with 29 additions and 18 deletions

View File

@@ -56,7 +56,7 @@ export interface ContextMenuCommandData extends CommandData {
}
export interface NoteCommandData extends CommandData {
notePath: string;
notePath?: string;
hoistedNoteId?: string;
viewScope?: ViewScope;
}
@@ -79,6 +79,7 @@ export type CommandMappings = {
ancestorNoteId?: string | null;
};
closeTocCommand: CommandData;
closeHlt: CommandData;
showLaunchBarSubtree: CommandData;
showRevisions: CommandData;
showOptions: CommandData & {
@@ -113,6 +114,8 @@ export type CommandMappings = {
openNoteInNewTab: CommandData;
openNoteInNewSplit: CommandData;
openNoteInNewWindow: CommandData;
openAboutDialog: CommandData;
hideFloatingButtons: {};
hideLeftPane: CommandData;
showLeftPane: CommandData;
hoistNote: CommandData & { noteId: string };
@@ -129,7 +132,7 @@ export type CommandMappings = {
protectSubtree: ContextMenuCommandData;
unprotectSubtree: ContextMenuCommandData;
openBulkActionsDialog: ContextMenuCommandData | {
selectedOrActiveNoteIds: string[]
selectedOrActiveNoteIds?: string[]
};
editBranchPrefix: ContextMenuCommandData;
convertNoteToAttachment: ContextMenuCommandData;
@@ -186,6 +189,7 @@ export type CommandMappings = {
importMarkdownInline: CommandData;
showPasswordNotSet: CommandData;
showProtectedSessionPasswordDialog: CommandData;
showUploadAttachmentsDialog: CommandData & { noteId: string };
closeProtectedSessionPasswordDialog: CommandData;
copyImageReferenceToClipboard: CommandData;
copyImageToClipboard: CommandData;
@@ -209,6 +213,7 @@ export type CommandMappings = {
screen: Screen;
};
closeTab: CommandData;
closeToc: CommandData;
closeOtherTabs: CommandData;
closeRightTabs: CommandData;
closeAllTabs: CommandData;
@@ -227,15 +232,20 @@ export type CommandMappings = {
scrollContainerToCommand: CommandData & {
position: number;
};
moveThisNoteSplit: CommandData & {
isMovingLeft: boolean;
};
scrollToEnd: CommandData;
closeThisNoteSplit: CommandData;
moveThisNoteSplit: CommandData & { isMovingLeft: boolean; };
// Geomap
deleteFromMap: { noteId: string },
openGeoLocation: { noteId: string, event: JQuery.MouseDownEvent }
toggleZenMode: CommandData;
updateAttributeList: CommandData & { attributes: Attribute[] };
saveAttributes: CommandData;
reloadAttributes: CommandData;
refreshNoteList: CommandData & { noteId: string; };
};
type EventMappings = {
@@ -336,7 +346,6 @@ type EventMappings = {
showToc: {
noteId: string;
};
scrollToEnd: { ntxId: string };
noteTypeMimeChanged: { noteId: string };
zenModeChanged: { isEnabled: boolean };
};

View File

@@ -80,8 +80,7 @@ export class TypedComponent<ChildT extends TypedComponent<ChildT>> {
return promises.length > 0 ? Promise.all(promises) : null;
}
triggerCommand<K extends CommandNames>(name: K, _data?: CommandMappings[K]): Promise<unknown> | undefined | null {
const data = _data || {};
triggerCommand<K extends CommandNames>(name: K, data?: CommandMappings[K]): Promise<unknown> | undefined | null {
const fun = (this as any)[`${name}Command`];
if (fun) {

View File

@@ -21,8 +21,8 @@ export default class LauncherContextMenu implements SelectMenuItemEventListener<
async show(e: PointerEvent | JQuery.TouchStartEvent | JQuery.ContextMenuEvent) {
contextMenu.show({
x: e.pageX,
y: e.pageY,
x: e.pageX ?? 0,
y: e.pageY ?? 0,
items: await this.getMenuItems(),
selectMenuItemHandler: (item, e) => this.selectMenuItemHandler(item)
});

View File

@@ -31,8 +31,8 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
async show(e: PointerEvent | JQuery.TouchStartEvent | JQuery.ContextMenuEvent) {
contextMenu.show({
x: e.pageX,
y: e.pageY,
x: e.pageX ?? 0,
y: e.pageY ?? 0,
items: await this.getMenuItems(),
selectMenuItemHandler: (item, e) => this.selectMenuItemHandler(item)
});

View File

@@ -1,5 +1,5 @@
import appContext from "../components/app_context.js";
import treeService, { type Node } from "./tree.js";
import treeService from "./tree.js";
import dialogService from "./dialog.js";
import froca from "./froca.js";
import type NoteContext from "../components/note_context.js";
@@ -19,11 +19,11 @@ async function unhoist() {
}
}
function isTopLevelNode(node: Node) {
function isTopLevelNode(node: Fancytree.FancytreeNode) {
return isHoistedNode(node.getParent());
}
function isHoistedNode(node: Node) {
function isHoistedNode(node: Fancytree.FancytreeNode) {
// even though check for 'root' should not be necessary, we keep it just in case
return node.data.noteId === "root" || node.data.noteId === getHoistedNoteId();
}

View File

@@ -3,7 +3,7 @@
import dateNoteService from "../../services/date_notes.js";
import sql from "../../services/sql.js";
import cls from "../../services/cls.js";
import specialNotesService from "../../services/special_notes.js";
import specialNotesService, { type LauncherType } from "../../services/special_notes.js";
import becca from "../../becca/becca.js";
import type { Request } from "express";
@@ -85,7 +85,8 @@ function getHoistedNote() {
function createLauncher(req: Request) {
return specialNotesService.createLauncher({
parentNoteId: req.params.parentNoteId,
launcherType: req.params.launcherType
// TODO: Validate the parameter
launcherType: req.params.launcherType as LauncherType
});
}

View File

@@ -156,9 +156,11 @@ function createScriptLauncher(parentNoteId: string, forceNoteId?: string) {
return note;
}
export type LauncherType = "launcher" | "note" | "script" | "customWidget" | "spacer";
interface LauncherConfig {
parentNoteId: string;
launcherType: "launcher" | "note" | "script" | "customWidget" | "spacer";
launcherType: LauncherType;
noteId?: string;
}