diff --git a/apps/client/src/components/main_tree_executors.ts b/apps/client/src/components/main_tree_executors.ts index 20f0abea5..d656437ec 100644 --- a/apps/client/src/components/main_tree_executors.ts +++ b/apps/client/src/components/main_tree_executors.ts @@ -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 ); } } diff --git a/apps/client/src/components/root_command_executor.ts b/apps/client/src/components/root_command_executor.ts index 37cd4e6c2..1173ca6c8 100644 --- a/apps/client/src/components/root_command_executor.ts +++ b/apps/client/src/components/root_command_executor.ts @@ -9,7 +9,7 @@ import froca from "../services/froca.js"; import utils from "../services/utils.js"; import LlmChatPanel from "../widgets/llm_chat_panel.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() { @@ -242,7 +242,7 @@ export default class RootCommandExecutor extends Component { messages: [], title: "New AI Chat" }), - } as CreateNoteIntoUrlOpts + } as CreateNoteWithUrlOpts ); if (!result.note) { diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.ts index 38f5c995c..3afd426bb 100644 --- a/apps/client/src/menus/tree_context_menu.ts +++ b/apps/client/src/menus/tree_context_menu.ts @@ -1,7 +1,7 @@ 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"; @@ -283,7 +283,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener, options?: Options) { title: suggestion.noteTitle, activate: true, promptForType: true, - } as CreateNoteIntoUrlOpts, + } as CreateNoteWithUrlOpts, ); if (!note) return; @@ -549,7 +549,7 @@ function initNoteAutocomplete($el: JQuery, options?: Options) { title: suggestion.noteTitle, activate: false, promptForType: true, - } as CreateNoteIntoUrlOpts + } as CreateNoteWithUrlOpts ); if (!note) return; diff --git a/apps/client/src/services/note_create.ts b/apps/client/src/services/note_create.ts index 68542cf4a..a5c4eb0eb 100644 --- a/apps/client/src/services/note_create.ts +++ b/apps/client/src/services/note_create.ts @@ -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; diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts index a321ccbf6..83bc8f06d 100644 --- a/apps/client/src/widgets/collections/board/api.ts +++ b/apps/client/src/widgets/collections/board/api.ts @@ -6,7 +6,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"; @@ -33,7 +33,7 @@ export default class BoardApi { parentNoteUrl: parentNotePath, activate: false, title, - } as CreateNoteIntoUrlOpts); + } 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 CreateNoteIntoUrlOpts + } as CreateNoteWithUrlOpts ); if (!note || !branch) { diff --git a/apps/client/src/widgets/collections/table/context_menu.ts b/apps/client/src/widgets/collections/table/context_menu.ts index e0a0818eb..28c9ee1f0 100644 --- a/apps/client/src/widgets/collections/table/context_menu.ts +++ b/apps/client/src/widgets/collections/table/context_menu.ts @@ -8,7 +8,7 @@ import froca from "../../../services/froca.js"; import branches from "../../../services/branches.js"; import Component from "../../../components/component.js"; 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): Partial { const events: Partial = {}; @@ -185,7 +185,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro customOpts: { target: "before", targetBranchId: rowData.branchId, - } as CreateNoteBeforeUrlOpts + } as CreateNoteWithUrlOpts }) }, { @@ -199,7 +199,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro customOpts: { target: "after", targetBranchId: branchId, - } as CreateNoteAfterUrlOpts + } as CreateNoteWithUrlOpts }); } }, @@ -212,7 +212,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro customOpts: { target: "after", targetBranchId: rowData.branchId, - } as CreateNoteAfterUrlOpts + } as CreateNoteWithUrlOpts }) }, { kind: "separator" }, diff --git a/apps/client/src/widgets/collections/table/row_editing.ts b/apps/client/src/widgets/collections/table/row_editing.ts index 893a4acb4..d23e151d8 100644 --- a/apps/client/src/widgets/collections/table/row_editing.ts +++ b/apps/client/src/widgets/collections/table/row_editing.ts @@ -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, attributeD { parentNoteUrl: notePath, ...opts - } as CreateNoteIntoUrlOpts + } as CreateNoteWithUrlOpts ).then(({ branch }) => { if (branch) { setTimeout(() => { diff --git a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx index 42cb0b85d..86bbdc33b 100644 --- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx +++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx @@ -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(); diff --git a/apps/client/src/widgets/note_detail.ts b/apps/client/src/widgets/note_detail.ts index bf7cc9db7..290387bbc 100644 --- a/apps/client/src/widgets/note_detail.ts +++ b/apps/client/src/widgets/note_detail.ts @@ -5,7 +5,7 @@ import SpacedUpdate from "../services/spaced_update.js"; import server from "../services/server.js"; import appContext, { type CommandListenerData, type EventData } from "../components/app_context.js"; import keyboardActionsService from "../services/keyboard_actions.js"; -import noteCreateService, { CreateNoteIntoUrlOpts } from "../services/note_create.js"; +import noteCreateService, { CreateNoteWithUrlOpts } from "../services/note_create.js"; import attributeService from "../services/attributes.js"; import EmptyTypeWidget from "./type_widgets/empty.js"; @@ -436,7 +436,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { isProtected: note.isProtected, saveSelection: true, textEditor: await this.noteContext.getTextEditor() - } as CreateNoteIntoUrlOpts + } as CreateNoteWithUrlOpts ); } } diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.ts index c7c5fd9e4..f11d7e9d4 100644 --- a/apps/client/src/widgets/note_tree.ts +++ b/apps/client/src/widgets/note_tree.ts @@ -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"; @@ -237,7 +237,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); @@ -1854,7 +1854,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { target: "into", parentNoteUrl: notePath, isProtected: node.data.isProtected - } as CreateNoteIntoUrlOpts + } as CreateNoteWithUrlOpts ) } }), diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx index 5d0004a8e..3a4c5de08 100644 --- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx +++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx @@ -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; @@ -285,7 +285,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI title, activate: false, promptForType: true, - } as CreateNoteIntoUrlOpts, + } as CreateNoteWithUrlOpts, ) return resp?.note?.getBestNotePathString() ?? ""; } diff --git a/apps/client/src/widgets/type_widgets/editable_text.ts b/apps/client/src/widgets/type_widgets/editable_text.ts index 5fc07b3a3..b27d23c4f 100644 --- a/apps/client/src/widgets/type_widgets/editable_text.ts +++ b/apps/client/src/widgets/type_widgets/editable_text.ts @@ -1,7 +1,7 @@ import utils, { hasTouchBar } from "../../services/utils.js"; import keyboardActionService from "../../services/keyboard_actions.js"; import froca from "../../services/froca.js"; -import noteCreateService, { CreateNoteIntoUrlOpts, CreateNoteIntoInboxOpts } from "../../services/note_create.js"; +import noteCreateService, { CreateNoteWithUrlOpts, CreateNoteIntoInboxOpts } from "../../services/note_create.js"; import AbstractTextTypeWidget from "./abstract_text_type_widget.js"; import link from "../../services/link.js"; import appContext, { type CommandListenerData, type EventData } from "../../components/app_context.js"; @@ -523,7 +523,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { title, activate: true, promptForType: true, - } as CreateNoteIntoUrlOpts + } as CreateNoteWithUrlOpts ) return note?.getBestNotePathString() ?? ""; @@ -552,7 +552,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget { title, activate: false, promptForType: true, - } as CreateNoteIntoUrlOpts + } as CreateNoteWithUrlOpts ); return note?.getBestNotePathString() ?? "";