mirror of
https://github.com/zadam/trilium.git
synced 2025-12-05 06:54:23 +01:00
refactor(note-create): remove unnecessary deep hierarchy
This commit is contained in:
parent
b0fdb9fef2
commit
f0dead5390
@ -1,5 +1,5 @@
|
||||
import appContext, { type EventData } from "./app_context.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts, CreateNoteAfterUrlOpts } from "../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteWithUrlOpts } from "../services/note_create.js";
|
||||
import treeService from "../services/tree.js";
|
||||
import hoistedNoteService from "../services/hoisted_note.js";
|
||||
import Component from "./component.js";
|
||||
@ -55,7 +55,7 @@ export default class MainTreeExecutors extends Component {
|
||||
isProtected: activeNoteContext.note.isProtected,
|
||||
saveSelection: false,
|
||||
promptForType: false,
|
||||
} as CreateNoteIntoUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
);
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ export default class MainTreeExecutors extends Component {
|
||||
targetBranchId: node.data.branchId,
|
||||
isProtected: isProtected,
|
||||
saveSelection: false
|
||||
} as CreateNoteAfterUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import options from "../services/options.js";
|
||||
import froca from "../services/froca.js";
|
||||
import utils from "../services/utils.js";
|
||||
import toastService from "../services/toast.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts } from "../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteWithUrlOpts } from "../services/note_create.js";
|
||||
|
||||
export default class RootCommandExecutor extends Component {
|
||||
editReadOnlyNoteCommand() {
|
||||
@ -249,7 +249,7 @@ export default class RootCommandExecutor extends Component {
|
||||
messages: [],
|
||||
title: "New AI Chat"
|
||||
}),
|
||||
} as CreateNoteIntoUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
);
|
||||
|
||||
if (!result.note) {
|
||||
|
||||
@ -2,7 +2,7 @@ import NoteColorPicker from "./custom-items/NoteColorPicker.jsx";
|
||||
import treeService from "../services/tree.js";
|
||||
import froca from "../services/froca.js";
|
||||
import clipboard from "../services/clipboard.js";
|
||||
import noteCreateService, { CreateNoteAfterUrlOpts, CreateNoteIntoUrlOpts } from "../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteWithUrlOpts } from "../services/note_create.js";
|
||||
import contextMenu, { type MenuCommandItem, type MenuItem } from "./context_menu.js";
|
||||
import appContext, { type ContextMenuCommandData, type FilteredCommandNames } from "../components/app_context.js";
|
||||
import noteTypesService from "../services/note_types.js";
|
||||
@ -293,7 +293,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
isProtected: isProtected,
|
||||
templateNoteId: templateNoteId,
|
||||
promptForType: false,
|
||||
} as CreateNoteAfterUrlOpts
|
||||
} 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 CreateNoteIntoUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
);
|
||||
} else if (command === "openNoteInSplit") {
|
||||
const subContexts = appContext.tabManager.getActiveContext()?.getSubContexts();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import server from "./server.js";
|
||||
import appContext from "../components/app_context.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts, CreateNoteIntoInboxOpts } from "./note_create.js";
|
||||
import noteCreateService, { CreateNoteIntoInboxOpts, CreateNoteWithUrlOpts } from "./note_create.js";
|
||||
import froca from "./froca.js";
|
||||
import { t } from "./i18n.js";
|
||||
import commandRegistry from "./command_registry.js";
|
||||
@ -528,7 +528,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
||||
title: suggestion.noteTitle,
|
||||
activate: true,
|
||||
promptForType: true,
|
||||
} as CreateNoteIntoUrlOpts,
|
||||
} as CreateNoteWithUrlOpts,
|
||||
);
|
||||
|
||||
if (!note) return;
|
||||
@ -549,7 +549,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
||||
title: suggestion.noteTitle,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
} as CreateNoteIntoUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
);
|
||||
|
||||
if (!note) return;
|
||||
|
||||
@ -17,9 +17,8 @@ import dateNoteService from "../services/date_notes.js";
|
||||
* accepted by `note_create`.
|
||||
*
|
||||
* ## Overview
|
||||
* Each variant (e.g. `CreateNoteIntoUrlOpts`, `CreateNoteBeforeUrlOpts`, etc.)
|
||||
* extends `CreateNoteOpts` and enforces specific constraints to ensure only
|
||||
* valid note creation options are allowed at compile time.
|
||||
* Each variant extends `CreateNoteOpts` and enforces specific constraints to
|
||||
* ensure only valid note creation options are allowed at compile time.
|
||||
*
|
||||
* ## Type Safety
|
||||
* The `PromptingRule` ensures that `promptForType` and `type` stay mutually
|
||||
@ -36,10 +35,7 @@ import dateNoteService from "../services/date_notes.js";
|
||||
*
|
||||
* Hierarchy (general → specific):
|
||||
* - CreateNoteOpts
|
||||
* - CreateNoteAtUrlOpts
|
||||
* - CreateNoteIntoUrlOpts
|
||||
* - CreateNoteBeforeUrlOpts
|
||||
* - CreateNoteAfterUrlOpts
|
||||
* - CreateNoteWithUrlOpts
|
||||
* - CreateNoteIntoInboxOpts
|
||||
*/
|
||||
|
||||
@ -81,7 +77,7 @@ export type CreateNoteOpts = {
|
||||
* Serves as a base for "into", "before", and "after" variants,
|
||||
* sharing common URL-related fields.
|
||||
*/
|
||||
type CreateNoteWithUrlOpts = CreateNoteOpts & {
|
||||
export type CreateNoteWithUrlOpts = CreateNoteOpts & {
|
||||
// `Url` may refer to either parentNotePath or parentNoteId.
|
||||
// The vocabulary is inspired by existing function getNoteIdFromUrl.
|
||||
parentNoteUrl: string;
|
||||
@ -90,10 +86,6 @@ type CreateNoteWithUrlOpts = CreateNoteOpts & {
|
||||
targetBranchId: string;
|
||||
}
|
||||
|
||||
export type CreateNoteIntoUrlOpts = CreateNoteWithUrlOpts;
|
||||
export type CreateNoteBeforeUrlOpts = CreateNoteWithUrlOpts;
|
||||
export type CreateNoteAfterUrlOpts = CreateNoteWithUrlOpts;
|
||||
|
||||
type NeverDefineParentNoteUrlRule = {
|
||||
parentNoteUrl?: never;
|
||||
};
|
||||
@ -155,12 +147,12 @@ async function promptForType(
|
||||
} as CreateNoteOpts;
|
||||
|
||||
if (notePath) {
|
||||
resolvedOptions = resolvedOptions as CreateNoteIntoUrlOpts;
|
||||
resolvedOptions = resolvedOptions as CreateNoteWithUrlOpts;
|
||||
resolvedOptions = {
|
||||
...resolvedOptions,
|
||||
target: "into",
|
||||
parentNoteUrl: notePath,
|
||||
} as CreateNoteIntoUrlOpts;
|
||||
} as CreateNoteWithUrlOpts;
|
||||
}
|
||||
|
||||
return resolvedOptions;
|
||||
@ -274,7 +266,7 @@ async function createNoteIntoInbox(
|
||||
{
|
||||
...options,
|
||||
parentNoteUrl: inboxNote.noteId,
|
||||
} as CreateNoteIntoUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
);
|
||||
|
||||
return result;
|
||||
|
||||
@ -7,7 +7,7 @@ import branches from "../../../services/branches";
|
||||
import { executeBulkActions } from "../../../services/bulk_action";
|
||||
import froca from "../../../services/froca";
|
||||
import { t } from "../../../services/i18n";
|
||||
import note_create, { CreateNoteIntoUrlOpts } from "../../../services/note_create.js";
|
||||
import note_create, { CreateNoteWithUrlOpts } from "../../../services/note_create.js";
|
||||
import server from "../../../services/server";
|
||||
import { ColumnMap } from "./data";
|
||||
|
||||
@ -44,7 +44,7 @@ export default class BoardApi {
|
||||
parentNoteUrl: parentNotePath,
|
||||
activate: false,
|
||||
title,
|
||||
} as CreateNoteIntoUrlOpts);
|
||||
} 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 CreateNoteIntoUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
);
|
||||
|
||||
if (!note || !branch) {
|
||||
|
||||
@ -9,7 +9,7 @@ import branches from "../../../services/branches.js";
|
||||
import Component from "../../../components/component.js";
|
||||
import NoteColorPicker from "../../../menus/custom-items/NoteColorPicker.jsx";
|
||||
import { RefObject } from "preact";
|
||||
import { CreateNoteAfterUrlOpts, CreateNoteBeforeUrlOpts } from "../../../services/note_create.js";
|
||||
import { CreateNoteWithUrlOpts } from "../../../services/note_create.js";
|
||||
|
||||
export function useContextMenu(parentNote: FNote, parentComponent: Component | null | undefined, tabulator: RefObject<Tabulator>): Partial<EventCallBackMethods> {
|
||||
const events: Partial<EventCallBackMethods> = {};
|
||||
@ -186,7 +186,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
||||
customOpts: {
|
||||
target: "before",
|
||||
targetBranchId: rowData.branchId,
|
||||
} as CreateNoteBeforeUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
})
|
||||
},
|
||||
{
|
||||
@ -200,7 +200,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
||||
customOpts: {
|
||||
target: "after",
|
||||
targetBranchId: branchId,
|
||||
} as CreateNoteAfterUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
});
|
||||
}
|
||||
},
|
||||
@ -213,7 +213,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
||||
customOpts: {
|
||||
target: "after",
|
||||
targetBranchId: rowData.branchId,
|
||||
} as CreateNoteAfterUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
})
|
||||
},
|
||||
{ kind: "separator" },
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { EventCallBackMethods, RowComponent, Tabulator } from "tabulator-tables";
|
||||
import { CommandListenerData } from "../../../components/app_context";
|
||||
import note_create, { CreateNoteOpts, CreateNoteIntoUrlOpts as CreateNoteIntoUrlOpts } from "../../../services/note_create";
|
||||
import note_create, { CreateNoteOpts, CreateNoteWithUrlOpts } from "../../../services/note_create";
|
||||
import { useLegacyImperativeHandlers } from "../../react/hooks";
|
||||
import { RefObject } from "preact";
|
||||
import { setAttribute, setLabel } from "../../../services/attributes";
|
||||
@ -23,7 +23,7 @@ export default function useRowTableEditing(api: RefObject<Tabulator>, attributeD
|
||||
{
|
||||
parentNoteUrl: notePath,
|
||||
...opts
|
||||
} as CreateNoteIntoUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
).then(({ branch }) => {
|
||||
if (branch) {
|
||||
setTimeout(() => {
|
||||
|
||||
@ -3,7 +3,7 @@ import appContext from "../../components/app_context";
|
||||
import contextMenu from "../../menus/context_menu";
|
||||
import branches from "../../services/branches";
|
||||
import { t } from "../../services/i18n";
|
||||
import note_create, { CreateNoteIntoUrlOpts } from "../../services/note_create";
|
||||
import note_create, { CreateNoteWithUrlOpts } from "../../services/note_create";
|
||||
import tree from "../../services/tree";
|
||||
import ActionButton from "../react/ActionButton";
|
||||
import { ParentComponent } from "../react/react_utils";
|
||||
@ -33,7 +33,7 @@ export default function MobileDetailMenu() {
|
||||
{
|
||||
target: "into",
|
||||
parentNoteUrl: appContext.tabManager.getActiveContextNotePath() ?? undefined
|
||||
} as CreateNoteIntoUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
);
|
||||
} else if (command === "delete") {
|
||||
const notePath = appContext.tabManager.getActiveContextNotePath();
|
||||
|
||||
@ -7,7 +7,7 @@ import branchService from "../services/branches.js";
|
||||
import ws from "../services/ws.js";
|
||||
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
||||
import server from "../services/server.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts } from "../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteWithUrlOpts } from "../services/note_create.js";
|
||||
import toastService from "../services/toast.js";
|
||||
import appContext, { type CommandListenerData, type EventData } from "../components/app_context.js";
|
||||
import keyboardActionsService from "../services/keyboard_actions.js";
|
||||
@ -229,7 +229,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
isProtected: node.data.isProtected
|
||||
} as CreateNoteIntoUrlOpts,
|
||||
} 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 CreateNoteIntoUrlOpts
|
||||
} as CreateNoteWithUrlOpts
|
||||
)
|
||||
}
|
||||
}),
|
||||
|
||||
@ -19,7 +19,7 @@ import contextMenu from "../../../menus/context_menu";
|
||||
import type { CommandData, FilteredCommandNames } from "../../../components/app_context";
|
||||
import { AttributeType } from "@triliumnext/commons";
|
||||
import attributes from "../../../services/attributes";
|
||||
import note_create, { CreateNoteAfterUrlOpts, CreateNoteIntoUrlOpts, CreateNoteIntoInboxOpts } from "../../../services/note_create";
|
||||
import note_create, { CreateNoteWithUrlOpts, CreateNoteIntoInboxOpts } from "../../../services/note_create";
|
||||
import { CreateNoteAction } from "@triliumnext/commons";
|
||||
|
||||
type AttributeCommandNames = FilteredCommandNames<CommandData>;
|
||||
@ -280,7 +280,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
||||
title,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
} as CreateNoteIntoUrlOpts,
|
||||
} as CreateNoteWithUrlOpts,
|
||||
)
|
||||
return resp?.note?.getBestNotePathString() ?? "";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user