mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 12:50:47 +08:00
fix(type-checker): remove as casts hiding type-errors thus bugs. Solve subsequent found bugs
This commit is contained in:
parent
3d3d112d38
commit
437763eecc
13 changed files with 76 additions and 44 deletions
|
|
@ -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
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ export default class RootCommandExecutor extends Component {
|
|||
messages: [],
|
||||
title: "New AI Chat"
|
||||
}),
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
|
||||
if (!result.note) {
|
||||
|
|
|
|||
|
|
@ -283,7 +283,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);
|
||||
|
|
@ -296,7 +296,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;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export default class BoardApi {
|
|||
parentNoteUrl: parentNotePath,
|
||||
activate: false,
|
||||
title,
|
||||
} as CreateNoteWithUrlOpts);
|
||||
});
|
||||
|
||||
if (newNote && newBranch) {
|
||||
await this.changeColumn(newNote.noteId, column);
|
||||
|
|
@ -140,7 +140,7 @@ export default class BoardApi {
|
|||
activate: false,
|
||||
targetBranchId: relativeToBranchId,
|
||||
title: t("board_view.new-item"),
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
|
||||
if (!note || !branch) {
|
||||
|
|
|
|||
|
|
@ -183,9 +183,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
|
||||
}
|
||||
})
|
||||
},
|
||||
{
|
||||
|
|
@ -194,12 +195,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
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
@ -210,9 +215,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) {
|
||||
|
|
|
|||
|
|
@ -436,7 +436,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||
isProtected: note.isProtected,
|
||||
saveSelection: true,
|
||||
textEditor: await this.noteContext.getTextEditor()
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -237,7 +237,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);
|
||||
|
|
@ -1854,7 +1854,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||
target: "into",
|
||||
parentNoteUrl: notePath,
|
||||
isProtected: node.data.isProtected
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
)
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
|||
target: "inbox",
|
||||
title,
|
||||
activate: false
|
||||
} as CreateNoteIntoInboxOpts
|
||||
}
|
||||
);
|
||||
return note?.getBestNotePathString() ?? "";
|
||||
}
|
||||
|
|
@ -285,7 +285,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
|||
title,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
} as CreateNoteWithUrlOpts,
|
||||
},
|
||||
)
|
||||
return resp?.note?.getBestNotePathString() ?? "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -508,7 +508,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
title,
|
||||
activate: true,
|
||||
promptForType: true,
|
||||
} as CreateNoteIntoInboxOpts
|
||||
}
|
||||
);
|
||||
|
||||
return note?.getBestNotePathString() ?? "";
|
||||
|
|
@ -516,6 +516,13 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
|
||||
// --- Create note INTO current path ---
|
||||
case CreateNoteAction.CreateNoteIntoPath: {
|
||||
// This should be impossible but we must specify it anyways
|
||||
// because it might cause bugs, which the type-check from
|
||||
// createNote already catches
|
||||
if (!parentNotePath) {
|
||||
console.error("Cannot create note: parentNotePath is undefined.");
|
||||
return "";
|
||||
}
|
||||
const { note } = await note_create.createNote(
|
||||
{
|
||||
target: "into",
|
||||
|
|
@ -523,7 +530,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
title,
|
||||
activate: true,
|
||||
promptForType: true,
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
)
|
||||
|
||||
return note?.getBestNotePathString() ?? "";
|
||||
|
|
@ -537,7 +544,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
title,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
} as CreateNoteIntoInboxOpts
|
||||
}
|
||||
);
|
||||
|
||||
return note?.getBestNotePathString() ?? "";
|
||||
|
|
@ -545,6 +552,10 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
|
||||
// --- Create & link note INTO current path ---
|
||||
case CreateNoteAction.CreateAndLinkNoteIntoPath: {
|
||||
if (!parentNotePath) {
|
||||
console.error("Cannot create note: parentNotePath is undefined.");
|
||||
return "";
|
||||
}
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: "into",
|
||||
|
|
@ -552,7 +563,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
title,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
} as CreateNoteWithUrlOpts
|
||||
}
|
||||
);
|
||||
|
||||
return note?.getBestNotePathString() ?? "";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue