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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
import appContext from "../components/app_context.js"; 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 dialogService from "./dialog.js";
import froca from "./froca.js"; import froca from "./froca.js";
import type NoteContext from "../components/note_context.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()); 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 // even though check for 'root' should not be necessary, we keep it just in case
return node.data.noteId === "root" || node.data.noteId === getHoistedNoteId(); return node.data.noteId === "root" || node.data.noteId === getHoistedNoteId();
} }

View File

@@ -3,7 +3,7 @@
import dateNoteService from "../../services/date_notes.js"; import dateNoteService from "../../services/date_notes.js";
import sql from "../../services/sql.js"; import sql from "../../services/sql.js";
import cls from "../../services/cls.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 becca from "../../becca/becca.js";
import type { Request } from "express"; import type { Request } from "express";
@@ -85,7 +85,8 @@ function getHoistedNote() {
function createLauncher(req: Request) { function createLauncher(req: Request) {
return specialNotesService.createLauncher({ return specialNotesService.createLauncher({
parentNoteId: req.params.parentNoteId, 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; return note;
} }
export type LauncherType = "launcher" | "note" | "script" | "customWidget" | "spacer";
interface LauncherConfig { interface LauncherConfig {
parentNoteId: string; parentNoteId: string;
launcherType: "launcher" | "note" | "script" | "customWidget" | "spacer"; launcherType: LauncherType;
noteId?: string; noteId?: string;
} }