diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts index bda3536da..fd01a2211 100644 --- a/apps/client/src/components/app_context.ts +++ b/apps/client/src/components/app_context.ts @@ -25,7 +25,7 @@ import TouchBarComponent from "./touch_bar.js"; import type { CKTextEditor } from "@triliumnext/ckeditor5"; import type CodeMirror from "@triliumnext/codemirror"; import { StartupChecks } from "./startup_checks.js"; -import type { CreateNoteOpts } from "../services/note_create.js"; +import type { BaseCreateNoteOpts } from "../services/note_create.js"; import { ColumnComponent } from "tabulator-tables"; import { ChooseNoteTypeCallback } from "../widgets/dialogs/note_type_chooser.jsx"; import type RootContainer from "../widgets/containers/root_container.js"; @@ -359,7 +359,7 @@ export type CommandMappings = { // Table view addNewRow: CommandData & { - customOpts: CreateNoteOpts; + customOpts: BaseCreateNoteOpts; parentNotePath?: string; }; addNewTableColumn: CommandData & { diff --git a/apps/client/src/components/entrypoints.ts b/apps/client/src/components/entrypoints.ts index ec90d5d5c..96721e26c 100644 --- a/apps/client/src/components/entrypoints.ts +++ b/apps/client/src/components/entrypoints.ts @@ -11,7 +11,7 @@ import froca from "../services/froca.js"; import linkService from "../services/link.js"; import { t } from "../services/i18n.js"; import { CreateChildrenResponse, SqlExecuteResponse } from "@triliumnext/commons"; -import noteCreateService from "../services/note_create.js"; +import noteCreateService, { CreateNoteTarget } from "../services/note_create.js"; export default class Entrypoints extends Component { constructor() { @@ -25,7 +25,9 @@ export default class Entrypoints extends Component { } async createNoteIntoInboxCommand() { - await noteCreateService.createNoteIntoInbox(); + await noteCreateService.createNote( + CreateNoteTarget.IntoInbox + ); } async toggleNoteHoistingCommand({ noteId = appContext.tabManager.getActiveContextNoteId() }) { diff --git a/apps/client/src/components/main_tree_executors.ts b/apps/client/src/components/main_tree_executors.ts index e29251b5c..d8ced149c 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 from "../services/note_create.js"; +import noteCreateService, { CreateNoteTarget, CreateNoteIntoURLOpts, CreateNoteAfterURLOpts } from "../services/note_create.js"; import treeService from "../services/tree.js"; import hoistedNoteService from "../services/hoisted_note.js"; import Component from "./component.js"; @@ -48,10 +48,15 @@ export default class MainTreeExecutors extends Component { return; } - await noteCreateService.createNoteIntoPath(activeNoteContext.notePath, { - isProtected: activeNoteContext.note.isProtected, - saveSelection: false - }); + await noteCreateService.createNote( + CreateNoteTarget.IntoNoteURL, + { + parentNoteUrl: activeNoteContext.notePath, + isProtected: activeNoteContext.note.isProtected, + saveSelection: false, + promptForType: false, + } as CreateNoteIntoURLOpts + ); } async createNoteAfterCommand() { @@ -72,11 +77,14 @@ export default class MainTreeExecutors extends Component { return; } - await noteCreateService.createNoteIntoPath(parentNotePath, { - target: "after", - targetBranchId: node.data.branchId, - isProtected: isProtected, - saveSelection: false - }); + await noteCreateService.createNote( + CreateNoteTarget.AfterNoteURL, + { + parentNoteUrl: parentNotePath, + targetBranchId: node.data.branchId, + isProtected: isProtected, + saveSelection: false + } as CreateNoteAfterURLOpts + ); } } diff --git a/apps/client/src/components/root_command_executor.ts b/apps/client/src/components/root_command_executor.ts index b953613ab..b86ea10cc 100644 --- a/apps/client/src/components/root_command_executor.ts +++ b/apps/client/src/components/root_command_executor.ts @@ -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 from "../services/note_create.js"; +import noteCreateService, { CreateNoteIntoURLOpts, CreateNoteTarget } from "../services/note_create.js"; export default class RootCommandExecutor extends Component { editReadOnlyNoteCommand() { @@ -240,14 +240,17 @@ export default class RootCommandExecutor extends Component { // Create a new AI Chat note at the root level const rootNoteId = "root"; - const result = await noteCreateService.createNoteIntoPath(rootNoteId, { - title: "New AI Chat", - type: "aiChat", - content: JSON.stringify({ - messages: [], - title: "New AI Chat" - }) - }); + const result = await noteCreateService.createNote( + CreateNoteTarget.IntoNoteURL, + { + title: "New AI Chat", + type: "aiChat", + content: JSON.stringify({ + messages: [], + title: "New AI Chat" + }), + } as CreateNoteIntoURLOpts + ); if (!result.note) { toastService.showError("Failed to create AI Chat note"); diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.ts index 9215ee5f6..03ba5f898 100644 --- a/apps/client/src/menus/tree_context_menu.ts +++ b/apps/client/src/menus/tree_context_menu.ts @@ -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 from "../services/note_create.js"; +import noteCreateService, { CreateNoteAfterURLOpts, CreateNoteIntoURLOpts, CreateNoteTarget } 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,21 +283,32 @@ export default class TreeContextMenu implements SelectMenuItemEventListener, options?: Options) { // --- CREATE NOTE INTO INBOX --- case SuggestionAction.CreateNoteIntoInbox: { - const { success, noteType, templateNoteId } = await noteCreateService.chooseNoteType(); - if (!success) return; + const { note } = await noteCreateService.createNote( + CreateNoteTarget.IntoInbox, + { + title: suggestion.noteTitle, + activate: true, + promptForType: true, + } as InboxNoteOpts + ); - const { note } = await noteCreateService.createNoteIntoInbox({ - title: suggestion.noteTitle, - activate: true, - type: noteType, - templateNoteId, - }); + if (!note) return; const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId; suggestion.notePath = note?.getBestNotePathString(hoistedNoteId); @@ -501,15 +502,16 @@ function initNoteAutocomplete($el: JQuery, options?: Options) { // --- CREATE AND LINK NOTE INTO INBOX --- case SuggestionAction.CreateAndLinkNoteIntoInbox: { - const { success, noteType, templateNoteId } = await noteCreateService.chooseNoteType(); - if (!success) return; + const { note } = await noteCreateService.createNote( + CreateNoteTarget.IntoInbox, + { + title: suggestion.noteTitle, + activate: false, + promptForType: true, + } as InboxNoteOpts, + ); - const { note } = await noteCreateService.createNoteIntoInbox({ - title: suggestion.noteTitle, - activate: false, - type: noteType, - templateNoteId, - }); + if (!note) return; const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId; suggestion.notePath = note?.getBestNotePathString(hoistedNoteId); @@ -521,15 +523,17 @@ function initNoteAutocomplete($el: JQuery, options?: Options) { // --- CREATE NOTE INTO PATH --- case SuggestionAction.CreateNoteIntoPath: { - const { success, noteType, templateNoteId, notePath } = await noteCreateService.chooseNoteType(); - if (!success) return; + const { note } = await noteCreateService.createNote( + CreateNoteTarget.IntoNoteURL, + { + parentNoteUrl: suggestion.parentNoteId, + title: suggestion.noteTitle, + activate: true, + promptForType: true, + } as CreateNoteIntoURLOpts + ) - const { note } = await noteCreateService.createNoteIntoPath(notePath || suggestion.parentNoteId, { - title: suggestion.noteTitle, - activate: true, - type: noteType, - templateNoteId, - }); + if (!note) return; const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId; suggestion.notePath = note?.getBestNotePathString(hoistedNoteId); @@ -541,15 +545,16 @@ function initNoteAutocomplete($el: JQuery, options?: Options) { // --- CREATE AND LINK NOTE INTO PATH --- case SuggestionAction.CreateAndLinkNoteIntoPath: { - const { success, noteType, templateNoteId, notePath } = await noteCreateService.chooseNoteType(); - if (!success) return; + const { note } = await noteCreateService.createNote( + CreateNoteTarget.IntoNoteURL, + { + title: suggestion.noteTitle, + activate: false, + promptForType: true, + } as CreateNoteIntoURLOpts + ); - const { note } = await noteCreateService.createNoteIntoPath(notePath || suggestion.parentNoteId, { - title: suggestion.noteTitle, - activate: false, - type: noteType, - templateNoteId, - }); + if (!note) return const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId; suggestion.notePath = note?.getBestNotePathString(hoistedNoteId); diff --git a/apps/client/src/services/note_create.ts b/apps/client/src/services/note_create.ts index 785db66d9..ff22e6bf9 100644 --- a/apps/client/src/services/note_create.ts +++ b/apps/client/src/services/note_create.ts @@ -13,7 +13,30 @@ import type { CKTextEditor } from "@triliumnext/ckeditor5"; import dateNoteService from "../services/date_notes.js"; import { CreateChildrenResponse } from "@triliumnext/commons"; -export interface CreateNoteOpts { +// // Creating a note at a path creates ambiguity, do we want it created Into or +// // Next to as sibling? +// // TODO: where the heck is this defined +// export enum NotePlacement { +// Into = "into", +// After = "after" +// } +export enum CreateNoteTarget { + IntoNoteURL, + AfterNoteURL, + IntoInbox, +} + +export type BaseCreateNoteOpts = + | ({ + promptForType: true; + type?: never; + } & BaseCreateNoteSharedOpts) + | ({ + promptForType?: false; + type?: string; + } & BaseCreateNoteSharedOpts); + +export interface BaseCreateNoteSharedOpts { isProtected?: boolean; saveSelection?: boolean; title?: string | null; @@ -23,11 +46,30 @@ export interface CreateNoteOpts { templateNoteId?: string; activate?: boolean; focus?: "title" | "content"; - target?: string; targetBranchId?: string; textEditor?: CKTextEditor; } +// For creating *in a specific path* +type CreateNoteAtURLOpts = BaseCreateNoteSharedOpts & { + // Url is either path or Id + parentNoteUrl: string; +} + +export type CreateNoteIntoURLOpts = CreateNoteAtURLOpts; +export type CreateNoteAfterURLOpts = Omit & { + // targetBranchId disambiguates the position for cloned notes, thus it must + // only be specified for a sibling + // This is also specified in the backend + targetBranchId: string; +}; + +// For creating *in the inbox* +export type InboxNoteOpts = BaseCreateNoteSharedOpts & { + // disallowed + parentNoteUrl?: never; +} + interface Response { // TODO: Deduplicate with server once we have client/server architecture. note: FNote; @@ -42,14 +84,15 @@ interface DuplicateResponse { /** * Core function that creates a new note under the specified parent note path. * - * @param {string | undefined} parentNotePath - The parent note path where the new note will be created. - * @param {CreateNoteOpts} [options] - Options controlling note creation (title, content, type, template, focus, etc.). + * @param target - Duplicates apps/server/src/routes/api/notes.ts createNote + * @param {BaseCreateNoteSharedOpts} [options] - Options controlling note creation (title, content, type, template, focus, etc.). + * with parentNotePath - The parent note path where the new note will be created. * @returns {Promise<{ note: FNote | null; branch: FBranch | undefined }>} * Resolves with the created note and branch entities. */ -async function createNoteIntoPath( - parentNotePath: string | undefined, - options: CreateNoteOpts = {} +async function createNoteAtNote( + target: "into" | "after" | "before", + options: CreateNoteAtURLOpts ): Promise<{ note: FNote | null; branch: FBranch | undefined }> { options = Object.assign( { @@ -74,7 +117,8 @@ async function createNoteIntoPath( [options.title, options.content] = parseSelectedHtml(options.textEditor.getSelectedHtml()); } - const parentNoteId = treeService.getNoteIdFromUrl(parentNotePath); + const parentNoteUrl = options.parentNoteUrl; + const parentNoteId = treeService.getNoteIdFromUrl(parentNoteUrl); if (options.type === "mermaid" && !options.content && !options.templateNoteId) { options.content = `graph TD; @@ -84,7 +128,7 @@ async function createNoteIntoPath( C-->D;`; } - const { note, branch } = await server.post(`notes/${parentNoteId}/children?target=${options.target}&targetBranchId=${options.targetBranchId || ""}`, { + const { note, branch } = await server.post(`notes/${parentNoteId}/children?target=${target}&targetBranchId=${options.targetBranchId || ""}`, { title: options.title, content: options.content || "", isProtected: options.isProtected, @@ -102,7 +146,7 @@ async function createNoteIntoPath( const activeNoteContext = appContext.tabManager.getActiveContext(); if (activeNoteContext && options.activate) { - await activeNoteContext.setNote(`${parentNotePath}/${note.noteId}`); + await activeNoteContext.setNote(`${parentNoteId}/${note.noteId}`); if (options.focus === "title") { appContext.triggerEvent("focusAndSelectTitle", { isNewNote: true }); @@ -120,15 +164,27 @@ async function createNoteIntoPath( }; } +async function createNoteIntoNote( + options: CreateNoteIntoURLOpts +): Promise<{ note: FNote | null; branch: FBranch | undefined }> { + return createNoteAtNote("into", {...options} as CreateNoteAtURLOpts); +} + +async function createNoteAfterNote( + options: CreateNoteAfterURLOpts +): Promise<{ note: FNote | null; branch: FBranch | undefined }> { + return createNoteAtNote("after", {...options} as CreateNoteAtURLOpts); +} + /** * Creates a new note inside the user's Inbox. * - * @param {CreateNoteOpts} [options] - Optional settings such as title, type, template, or content. + * @param {BaseCreateNoteSharedOpts} [options] - Optional settings such as title, type, template, or content. * @returns {Promise<{ note: FNote | null; branch: FBranch | undefined }>} * Resolves with the created note and its branch, or `{ note: null, branch: undefined }` if the inbox is missing. */ async function createNoteIntoInbox( - options: CreateNoteOpts = {} + options: InboxNoteOpts ): Promise<{ note: FNote | null; branch: FBranch | undefined }> { const inboxNote = await dateNoteService.getInboxNote(); if (!inboxNote) { @@ -142,10 +198,12 @@ async function createNoteIntoInbox( inboxNote.isProtected && protectedSessionHolder.isProtectedSessionAvailable(); } - const result = await createNoteIntoPath(inboxNote.noteId, { - ...options, - target: "into", - }); + const result = await createNoteIntoNote( + { + ...options, + parentNoteUrl: inboxNote.noteId, + } as CreateNoteIntoURLOpts + ); return result; } @@ -156,17 +214,70 @@ async function chooseNoteType() { }); } -async function createNoteIntoPathWithTypePrompt(parentNotePath: string, options: CreateNoteOpts = {}) { - const { success, noteType, templateNoteId, notePath } = await chooseNoteType(); +async function createNote( + target: CreateNoteTarget.IntoNoteURL, + options: CreateNoteIntoURLOpts +): Promise<{ note: FNote | null; branch: FBranch | undefined }>; - if (!success) { - return; +async function createNote( + target: CreateNoteTarget.AfterNoteURL, + options: CreateNoteAfterURLOpts +): Promise<{ note: FNote | null; branch: FBranch | undefined }>; + +async function createNote( + target: CreateNoteTarget.IntoInbox, + options?: InboxNoteOpts +): Promise<{ note: FNote | null; branch: FBranch | undefined }>; + +async function createNote( + target: CreateNoteTarget, + options: BaseCreateNoteOpts = {promptForType: true} +): Promise<{ note: FNote | null; branch: FBranch | undefined }> { + + let resolvedOptions = { ...options }; + let resolvedTarget = target; + + // handle prompts centrally to write once fix for all + if (options.promptForType) { + const { success, noteType, templateNoteId, notePath } = await chooseNoteType(); + + if (!success) return { + note: null, branch: undefined + }; + + resolvedOptions = { + ...resolvedOptions, + promptForType: false, + type: noteType, + templateNoteId, + } as BaseCreateNoteOpts; + + if (notePath) { + resolvedOptions = resolvedOptions as CreateNoteIntoURLOpts; + resolvedOptions = { + ...resolvedOptions, + parentNoteUrl: notePath, + } as CreateNoteIntoURLOpts; + resolvedTarget = CreateNoteTarget.IntoNoteURL; + } } - options.type = noteType; - options.templateNoteId = templateNoteId; + switch (resolvedTarget) { + case CreateNoteTarget.IntoNoteURL: + return await createNoteIntoNote(resolvedOptions as CreateNoteIntoURLOpts); - return await createNoteIntoPath(notePath || parentNotePath, options); + case CreateNoteTarget.AfterNoteURL: + return await createNoteAfterNote(resolvedOptions as CreateNoteAfterURLOpts); + + case CreateNoteTarget.IntoInbox: + return await createNoteIntoInbox(resolvedOptions as InboxNoteOpts); + + default: { + console.warn("[createNote] Unknown target:", target, resolvedOptions); + toastService.showMessage("Unknown note creation target."); // optional + return { note: null, branch: undefined }; + } + } } /* If the first element is heading, parse it out and use it as a new heading. */ @@ -201,9 +312,6 @@ async function duplicateSubtree(noteId: string, parentNotePath: string) { } export default { - createNoteIntoInbox, - createNoteIntoPath, - createNoteIntoPathWithTypePrompt, + createNote, duplicateSubtree, - chooseNoteType }; diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts index dd32dfaa1..e169e8609 100644 --- a/apps/client/src/widgets/collections/board/api.ts +++ b/apps/client/src/widgets/collections/board/api.ts @@ -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 from "../../../services/note_create.js"; +import note_create, { CreateNoteIntoURLOpts, CreateNoteTarget } from "../../../services/note_create.js"; import server from "../../../services/server"; import { ColumnMap } from "./data"; @@ -39,10 +39,11 @@ export default class BoardApi { const parentNotePath = this.parentNote.noteId; // Create a new note as a child of the parent note - const { note: newNote, branch: newBranch } = await note_create.createNoteIntoPath(parentNotePath, { + const { note: newNote, branch: newBranch } = await note_create.createNote(CreateNoteTarget.IntoNoteURL, { + parentNoteUrl: parentNotePath, activate: false, - title - }); + title, + } as CreateNoteIntoURLOpts); if (newNote && newBranch) { await this.changeColumn(newNote.noteId, column); @@ -140,12 +141,16 @@ export default class BoardApi { column: string, relativeToBranchId: string, direction: "before" | "after") { - const { note, branch } = await note_create.createNoteIntoPath(this.parentNote.noteId, { - activate: false, - targetBranchId: relativeToBranchId, - target: direction, - title: t("board_view.new-item") - }); + const { note, branch } = await note_create.createNote( + CreateNoteTarget.IntoNoteURL, + { + parentNoteUrl: this.parentNote.noteId, + activate: false, + targetBranchId: relativeToBranchId, + target: direction, + title: t("board_view.new-item"), + } as CreateNoteIntoURLOpts + ); if (!note || !branch) { throw new Error("Failed to create note"); diff --git a/apps/client/src/widgets/collections/table/row_editing.ts b/apps/client/src/widgets/collections/table/row_editing.ts index 026fc03b6..e36f25dfb 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 } from "../../../services/note_create"; +import note_create, { BaseCreateNoteOpts, CreateNoteIntoURLOpts as CreateNoteIntoURLOpts, CreateNoteTarget } from "../../../services/note_create"; import { useLegacyImperativeHandlers } from "../../react/hooks"; import { RefObject } from "preact"; import { setAttribute, setLabel } from "../../../services/attributes"; @@ -15,11 +15,17 @@ export default function useRowTableEditing(api: RefObject, attributeD addNewRowCommand({ customOpts, parentNotePath: customNotePath }: CommandListenerData<"addNewRow">) { const notePath = customNotePath ?? parentNotePath; if (notePath) { - const opts: CreateNoteOpts = { + const opts: BaseCreateNoteOpts = { activate: false, ...customOpts } - note_create.createNoteIntoPath(notePath, opts).then(({ branch }) => { + note_create.createNote( + CreateNoteTarget.IntoNoteURL, + { + parentNoteUrl: notePath, + ...opts + } as CreateNoteIntoURLOpts + ).then(({ branch }) => { if (branch) { setTimeout(() => { if (!api.current) return; 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 8c0c93c11..b73a7b0ba 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 from "../../services/note_create"; +import note_create, { CreateNoteIntoURLOpts, CreateNoteTarget } from "../../services/note_create"; import tree from "../../services/tree"; import ActionButton from "../react/ActionButton"; import { ParentComponent } from "../react/react_utils"; @@ -29,7 +29,12 @@ export default function MobileDetailMenu() { ], selectMenuItemHandler: async ({ command }) => { if (command === "insertChildNote") { - note_create.createNoteIntoPath(appContext.tabManager.getActiveContextNotePath() ?? undefined); + note_create.createNote( + CreateNoteTarget.IntoNoteURL, + { + parentNoteUrl: appContext.tabManager.getActiveContextNotePath() ?? undefined + } as CreateNoteIntoURLOpts + ); } else if (command === "delete") { const notePath = appContext.tabManager.getActiveContextNotePath(); if (!notePath) { diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.ts index 12bcaac43..e1eab8532 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 from "../services/note_create.js"; +import noteCreateService, { CreateNoteIntoURLOpts, CreateNoteTarget } 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"; @@ -224,7 +224,13 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { } else if (target.classList.contains("add-note-button")) { const node = $.ui.fancytree.getNode(e as unknown as Event); const parentNotePath = treeService.getNotePath(node); - noteCreateService.createNoteIntoPath(parentNotePath, { isProtected: node.data.isProtected }); + noteCreateService.createNote( + CreateNoteTarget.IntoNoteURL, + { + parentNoteUrl: parentNotePath, + isProtected: node.data.isProtected + } as CreateNoteIntoURLOpts, + ); } else if (target.classList.contains("enter-workspace-button")) { const node = $.ui.fancytree.getNode(e as unknown as Event); this.triggerCommand("hoistNote", { noteId: node.data.noteId }); @@ -1836,9 +1842,13 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { const node = this.getActiveNode(); if (!node) return; const notePath = treeService.getNotePath(node); - noteCreateService.createNoteIntoPath(notePath, { - isProtected: node.data.isProtected - }); + noteCreateService.createNote( + CreateNoteTarget.IntoNoteURL, + { + parentNoteUrl: notePath, + isProtected: node.data.isProtected + } as CreateNoteIntoURLOpts + ) } }), new TouchBar.TouchBarButton({ diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx index a0faf10a9..a5166f688 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 from "../../../services/note_create"; +import note_create, { CreateNoteAfterURLOpts, CreateNoteIntoURLOpts, CreateNoteTarget, InboxNoteOpts } from "../../../services/note_create"; import { CreateNoteAction } from "@triliumnext/commons"; type AttributeCommandNames = FilteredCommandNames; @@ -261,19 +261,27 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI switch (action) { case CreateNoteAction.CreateNoteIntoInbox: case CreateNoteAction.CreateAndLinkNoteIntoInbox: { - const { note } = await note_create.createNoteIntoInbox({ - title, - activate: false - }); + const { note } = await note_create.createNote( + CreateNoteTarget.IntoInbox, + { + title, + activate: false + } as InboxNoteOpts + ); return note?.getBestNotePathString() ?? ""; } case CreateNoteAction.CreateNoteIntoPath: case CreateNoteAction.CreateAndLinkNoteIntoPath: { - const resp = await note_create.createNoteIntoPathWithTypePrompt(parentNotePath, { - title, - activate: false - }); + const resp = await note_create.createNote( + CreateNoteTarget.IntoNoteURL, + { + parentNoteUrl: parentNotePath, + title, + activate: false, + promptForType: true, + } as CreateNoteIntoURLOpts, + ) return resp?.note?.getBestNotePathString() ?? ""; }