mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
fix(type-checker): remove as casts hiding type-errors thus bugs. Solve subsequent found bugs
This commit is contained in:
parent
aada631c0f
commit
470d7eee31
@ -26,7 +26,7 @@ export default class Entrypoints extends Component {
|
||||
|
||||
async createNoteIntoInboxCommand() {
|
||||
await noteCreateService.createNote(
|
||||
{ target: "inbox" } as CreateNoteIntoInboxOpts
|
||||
{ target: "inbox" }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ export default class MainTreeExecutors extends Component {
|
||||
isProtected: activeNoteContext.note.isProtected,
|
||||
saveSelection: false,
|
||||
promptForType: false,
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ export default class MainTreeExecutors extends Component {
|
||||
targetBranchId: node.data.branchId,
|
||||
isProtected: isProtected,
|
||||
saveSelection: false
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ export default class RootCommandExecutor extends Component {
|
||||
messages: [],
|
||||
title: "New AI Chat"
|
||||
}),
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
|
||||
if (!result.note) {
|
||||
|
||||
@ -293,7 +293,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
isProtected: isProtected,
|
||||
templateNoteId: templateNoteId,
|
||||
promptForType: false,
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
} else if (command === "insertChildNote") {
|
||||
const parentNotePath = treeService.getNotePath(this.node);
|
||||
@ -306,7 +306,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
isProtected: this.node.data.isProtected,
|
||||
templateNoteId: templateNoteId,
|
||||
promptForType: false,
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
} else if (command === "openNoteInSplit") {
|
||||
const subContexts = appContext.tabManager.getActiveContext()?.getSubContexts();
|
||||
|
||||
@ -48,7 +48,14 @@ type PromptingRule = {
|
||||
type?: never;
|
||||
} | {
|
||||
promptForType?: false;
|
||||
type: string;
|
||||
/**
|
||||
* The note type (e.g. "text", "code", "image", "mermaid", etc.).
|
||||
*
|
||||
* If omitted, the server will automatically default to `"text"`.
|
||||
* TypeScript still enforces explicit typing unless `promptForType` is true,
|
||||
* to encourage clarity at the call site.
|
||||
*/
|
||||
type?: string;
|
||||
};
|
||||
|
||||
|
||||
@ -120,16 +127,15 @@ async function createNote(
|
||||
resolvedOptions = maybeResolvedOptions;
|
||||
}
|
||||
|
||||
if (resolvedOptions.target === "inbox") {
|
||||
return createNoteIntoInbox(resolvedOptions);
|
||||
}
|
||||
|
||||
// Only "into" | "before" | "after". the possibility of "inbox" was resolved
|
||||
// a line above
|
||||
return createNoteWithUrl(
|
||||
resolvedOptions.target as "into" | "before" | "after",
|
||||
resolvedOptions
|
||||
);
|
||||
switch(resolvedOptions.target) {
|
||||
case "inbox":
|
||||
return createNoteIntoInbox(resolvedOptions);
|
||||
case "into":
|
||||
case "before":
|
||||
case "after":
|
||||
return createNoteWithUrl(resolvedOptions.target, resolvedOptions);
|
||||
}
|
||||
}
|
||||
|
||||
async function promptForType(
|
||||
@ -141,12 +147,12 @@ async function promptForType(
|
||||
return null;
|
||||
}
|
||||
|
||||
let resolvedOptions = {
|
||||
let resolvedOptions: CreateNoteOpts = {
|
||||
...options,
|
||||
promptForType: false,
|
||||
type: noteType,
|
||||
templateNoteId,
|
||||
} as CreateNoteOpts;
|
||||
};
|
||||
|
||||
if (notePath) {
|
||||
resolvedOptions = resolvedOptions as CreateNoteWithUrlOpts;
|
||||
@ -154,7 +160,7 @@ async function promptForType(
|
||||
...resolvedOptions,
|
||||
target: "into",
|
||||
parentNoteUrl: notePath,
|
||||
} as CreateNoteWithUrlOpts;
|
||||
};
|
||||
}
|
||||
|
||||
return resolvedOptions;
|
||||
@ -269,7 +275,7 @@ async function createNoteIntoInbox(
|
||||
...options,
|
||||
target: "into",
|
||||
parentNoteUrl: inboxNote.noteId,
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
|
||||
return result;
|
||||
|
||||
@ -44,7 +44,7 @@ export default class BoardApi {
|
||||
parentNoteUrl: parentNotePath,
|
||||
activate: false,
|
||||
title,
|
||||
} as CreateNoteWithUrlOpts);
|
||||
});
|
||||
|
||||
if (newNote && newBranch) {
|
||||
await this.changeColumn(newNote.noteId, column);
|
||||
@ -150,7 +150,7 @@ export default class BoardApi {
|
||||
activate: false,
|
||||
targetBranchId: relativeToBranchId,
|
||||
title: t("board_view.new-item"),
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
|
||||
if (!note || !branch) {
|
||||
|
||||
@ -184,9 +184,10 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
||||
handler: () => parentComponent?.triggerCommand("addNewRow", {
|
||||
parentNotePath: parentNoteId,
|
||||
customOpts: {
|
||||
parentNoteUrl: parentNoteId,
|
||||
target: "before",
|
||||
targetBranchId: rowData.branchId,
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
@ -195,12 +196,16 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
||||
handler: async () => {
|
||||
const branchId = row.getData().branchId;
|
||||
const note = await froca.getBranch(branchId)?.getNote();
|
||||
if (!note) {
|
||||
return;
|
||||
}
|
||||
parentComponent?.triggerCommand("addNewRow", {
|
||||
parentNotePath: note?.noteId,
|
||||
parentNotePath: note.noteId,
|
||||
customOpts: {
|
||||
parentNoteUrl: note.noteId,
|
||||
target: "after",
|
||||
targetBranchId: branchId,
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
@ -211,9 +216,10 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
||||
handler: () => parentComponent?.triggerCommand("addNewRow", {
|
||||
parentNotePath: parentNoteId,
|
||||
customOpts: {
|
||||
parentNoteUrl: parentNoteId,
|
||||
target: "after",
|
||||
targetBranchId: rowData.branchId,
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
})
|
||||
},
|
||||
{ kind: "separator" },
|
||||
|
||||
@ -19,11 +19,18 @@ export default function useRowTableEditing(api: RefObject<Tabulator>, attributeD
|
||||
activate: false,
|
||||
...customOpts
|
||||
}
|
||||
|
||||
// Normalize "inbox" targets into standard path-based creation.
|
||||
// When adding a new row, we always have a concrete parent path (`notePath`),
|
||||
// so even if the originating command requested an "inbox" creation,
|
||||
// it should instead behave as "into" under the current note.
|
||||
const normalizedOpts: CreateNoteWithUrlOpts =
|
||||
opts.target === "inbox"
|
||||
? { ...opts, target: "into", parentNoteUrl: notePath }
|
||||
: { ...opts, parentNoteUrl: notePath };
|
||||
|
||||
note_create.createNote(
|
||||
{
|
||||
parentNoteUrl: notePath,
|
||||
...opts
|
||||
} as CreateNoteWithUrlOpts
|
||||
normalizedOpts
|
||||
).then(({ branch }) => {
|
||||
if (branch) {
|
||||
setTimeout(() => {
|
||||
|
||||
@ -29,12 +29,14 @@ export default function MobileDetailMenu() {
|
||||
],
|
||||
selectMenuItemHandler: async ({ command }) => {
|
||||
if (command === "insertChildNote") {
|
||||
note_create.createNote(
|
||||
{
|
||||
const parentNoteUrl = appContext.tabManager.getActiveContextNotePath();
|
||||
|
||||
if (parentNoteUrl) {
|
||||
note_create.createNote({
|
||||
target: "into",
|
||||
parentNoteUrl: appContext.tabManager.getActiveContextNotePath() ?? undefined
|
||||
} as CreateNoteWithUrlOpts
|
||||
);
|
||||
parentNoteUrl,
|
||||
});
|
||||
}
|
||||
} else if (command === "delete") {
|
||||
const notePath = appContext.tabManager.getActiveContextNotePath();
|
||||
if (!notePath) {
|
||||
|
||||
@ -229,7 +229,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
isProtected: node.data.isProtected
|
||||
} as CreateNoteWithUrlOpts,
|
||||
},
|
||||
);
|
||||
} else if (target.classList.contains("enter-workspace-button")) {
|
||||
const node = $.ui.fancytree.getNode(e as unknown as Event);
|
||||
@ -1847,7 +1847,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
||||
target: "into",
|
||||
parentNoteUrl: notePath,
|
||||
isProtected: node.data.isProtected
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
)
|
||||
}
|
||||
}),
|
||||
|
||||
@ -266,7 +266,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
||||
target: "inbox",
|
||||
title,
|
||||
activate: false
|
||||
} as CreateNoteIntoInboxOpts
|
||||
}
|
||||
);
|
||||
return note?.getBestNotePathString() ?? "";
|
||||
}
|
||||
@ -280,7 +280,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
||||
title,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
} as CreateNoteWithUrlOpts,
|
||||
},
|
||||
)
|
||||
return resp?.note?.getBestNotePathString() ?? "";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user