From eca5a4a07217c2864e9d9716468ae083e04e1f2a Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Fri, 21 Nov 2025 09:55:03 +0100 Subject: [PATCH] refactor(url -> link): let link refer to url and path. before there was polysemy in word url that is now resolved by making link hypernym to url and path. --- apps/client/src/components/app_context.ts | 4 +- .../src/components/main_tree_executors.ts | 4 +- .../src/components/root_command_executor.ts | 4 +- apps/client/src/components/tab_manager.ts | 4 +- apps/client/src/menus/tree_context_menu.ts | 4 +- apps/client/src/services/hoisted_note.ts | 2 +- apps/client/src/services/link.ts | 2 +- apps/client/src/services/note_create.ts | 39 ++++++++++--------- apps/client/src/services/tree.ts | 6 +-- .../src/widgets/collections/board/api.ts | 4 +- .../widgets/collections/table/context_menu.ts | 6 +-- .../widgets/collections/table/row_editing.ts | 4 +- apps/client/src/widgets/dialogs/add_link.tsx | 2 +- .../src/widgets/dialogs/include_note.tsx | 4 +- .../mobile_widgets/mobile_detail_menu.tsx | 2 +- apps/client/src/widgets/note_tree.ts | 8 ++-- 16 files changed, 50 insertions(+), 49 deletions(-) diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts index 4efaaba92..1219bc6f4 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, CreateNoteWithUrlOpts } from "../services/note_create.js"; +import type { CreateNoteOpts, CreateNoteWithLinkOpts } 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?: CreateNoteWithUrlOpts; + customOpts?: CreateNoteWithLinkOpts; }; addNewTableColumn: CommandData & { columnToEdit?: ColumnComponent; diff --git a/apps/client/src/components/main_tree_executors.ts b/apps/client/src/components/main_tree_executors.ts index df573acb1..067c6491b 100644 --- a/apps/client/src/components/main_tree_executors.ts +++ b/apps/client/src/components/main_tree_executors.ts @@ -51,7 +51,7 @@ export default class MainTreeExecutors extends Component { await noteCreateService.createNote( { target: "into", - parentNoteUrl: activeNoteContext.notePath, + parentNoteLink: activeNoteContext.notePath, isProtected: activeNoteContext.note.isProtected, saveSelection: false, promptForType: false, @@ -80,7 +80,7 @@ export default class MainTreeExecutors extends Component { await noteCreateService.createNote( { target: "after", - parentNoteUrl: parentNotePath, + parentNoteLink: parentNotePath, targetBranchId: node.data.branchId, isProtected: isProtected, saveSelection: false diff --git a/apps/client/src/components/root_command_executor.ts b/apps/client/src/components/root_command_executor.ts index c6f7b264a..50eb15c01 100644 --- a/apps/client/src/components/root_command_executor.ts +++ b/apps/client/src/components/root_command_executor.ts @@ -45,7 +45,7 @@ export default class RootCommandExecutor extends Component { } async searchInSubtreeCommand({ notePath }: CommandListenerData<"searchInSubtree">) { - const noteId = treeService.getNoteIdFromUrl(notePath); + const noteId = treeService.getNoteIdFromLink(notePath); this.searchNotesCommand({ ancestorNoteId: noteId }); } @@ -242,7 +242,7 @@ export default class RootCommandExecutor extends Component { const result = await noteCreateService.createNote( { - parentNoteUrl: rootNoteId, + parentNoteLink: rootNoteId, target: "into", title: "New AI Chat", type: "aiChat", diff --git a/apps/client/src/components/tab_manager.ts b/apps/client/src/components/tab_manager.ts index 127ec30b7..9bfcef22b 100644 --- a/apps/client/src/components/tab_manager.ts +++ b/apps/client/src/components/tab_manager.ts @@ -74,10 +74,10 @@ export default class TabManager extends Component { // preload all notes at once await froca.getNotes([...noteContextsToOpen.flatMap((tab: NoteContextState) => - [treeService.getNoteIdFromUrl(tab.notePath), tab.hoistedNoteId])], true); + [treeService.getNoteIdFromLink(tab.notePath), tab.hoistedNoteId])], true); const filteredNoteContexts = noteContextsToOpen.filter((openTab: NoteContextState) => { - const noteId = treeService.getNoteIdFromUrl(openTab.notePath); + const noteId = treeService.getNoteIdFromLink(openTab.notePath); if (!noteId || !(noteId in froca.notes)) { // note doesn't exist so don't try to open tab for it return false; diff --git a/apps/client/src/menus/tree_context_menu.ts b/apps/client/src/menus/tree_context_menu.ts index 128c6ae1e..b886cddef 100644 --- a/apps/client/src/menus/tree_context_menu.ts +++ b/apps/client/src/menus/tree_context_menu.ts @@ -287,7 +287,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener { switch (action) { case CreateNoteAction.CreateNote: { @@ -174,7 +175,7 @@ async function createNoteFromAction( return resp; } case CreateNoteAction.CreateChildNote: { - if (!parentNoteUrl) { + if (!parentNoteLink) { console.warn("Missing parentNotePath in createNoteFromCkEditor()"); return { note: null, branch: undefined }; } @@ -182,7 +183,7 @@ async function createNoteFromAction( const resp = await createNote( { target: "into", - parentNoteUrl, + parentNoteLink, title, activate: true, promptForType: true, @@ -191,14 +192,14 @@ async function createNoteFromAction( return resp } case CreateNoteAction.CreateAndLinkChildNote: { - if (!parentNoteUrl) { + if (!parentNoteLink) { console.warn("Missing parentNotePath in createNoteFromCkEditor()"); return { note: null, branch: undefined }; } const resp = await createNote( { target: "into", - parentNoteUrl: parentNoteUrl, + parentNoteLink: parentNoteLink, title, activate: false, promptForType: promptForType, @@ -233,7 +234,7 @@ async function promptForType( resolvedOptions = { ...resolvedOptions, target: "into", - parentNoteUrl: notePath, + parentNoteLink: notePath, }; } @@ -247,8 +248,8 @@ async function promptForType( * @param options - Note creation options * @returns A promise resolving with the created note and its branch. */ -async function createNoteWithUrl( - options: CreateNoteWithUrlOpts +async function createNoteWithLink( + options: CreateNoteWithLinkOpts ): Promise<{ note: FNote | null; branch: FBranch | undefined }> { options = Object.assign( { @@ -273,8 +274,8 @@ async function createNoteWithUrl( [options.title, options.content] = parseSelectedHtml(options.textEditor.getSelectedHtml()); } - const parentNoteUrl = options.parentNoteUrl; - const parentNoteId = treeService.getNoteIdFromUrl(parentNoteUrl); + const parentNoteLink = options.parentNoteLink; + const parentNoteId = treeService.getNoteIdFromLink(parentNoteLink); if (options.type === "mermaid" && !options.content && !options.templateNoteId) { options.content = `graph TD; @@ -348,11 +349,11 @@ async function createNoteIntoDefaultLocation( inboxNote.isProtected && protectedSessionHolder.isProtectedSessionAvailable(); } - const result = await createNoteWithUrl( + const result = await createNoteWithLink( { ...options, target: "into", - parentNoteUrl: inboxNote.noteId, + parentNoteLink: inboxNote.noteId, } ); @@ -385,7 +386,7 @@ function parseSelectedHtml(selectedHtml: string) { } async function duplicateSubtree(noteId: string, parentNotePath: string) { - const parentNoteId = treeService.getNoteIdFromUrl(parentNotePath); + const parentNoteId = treeService.getNoteIdFromLink(parentNotePath); const { note } = await server.post(`notes/${noteId}/duplicate/${parentNoteId}`); await ws.waitForMaxKnownEntityChangeId(); diff --git a/apps/client/src/services/tree.ts b/apps/client/src/services/tree.ts index cfa210600..6c0700b81 100644 --- a/apps/client/src/services/tree.ts +++ b/apps/client/src/services/tree.ts @@ -92,7 +92,7 @@ async function resolveNotePathToSegments(notePath: string, hoistedNoteId = "root if (effectivePathSegments.includes(hoistedNoteId) && effectivePathSegments.includes('root')) { return effectivePathSegments; } else { - const noteId = getNoteIdFromUrl(notePath); + const noteId = getNoteIdFromLink(notePath); if (!noteId) { throw new Error(`Unable to find note with ID: ${noteId}.`); } @@ -129,7 +129,7 @@ function getParentProtectedStatus(node: Fancytree.FancytreeNode) { return hoistedNoteService.isHoistedNode(node) ? false : node.getParent().data.isProtected; } -function getNoteIdFromUrl(urlOrNotePath: string | null | undefined) { +function getNoteIdFromLink(urlOrNotePath: string | null | undefined) { if (!urlOrNotePath) { return null; } @@ -306,7 +306,7 @@ export default { getParentProtectedStatus, getNotePath, getNotePathTitleComponents, - getNoteIdFromUrl, + getNoteIdFromLink, getNoteIdAndParentIdFromUrl, getBranchIdFromUrl, getNoteTitle, diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts index b3217e466..28d74a0e4 100644 --- a/apps/client/src/widgets/collections/board/api.ts +++ b/apps/client/src/widgets/collections/board/api.ts @@ -41,7 +41,7 @@ export default class BoardApi { // Create a new note as a child of the parent note const { note: newNote, branch: newBranch } = await note_create.createNote({ target: "into", - parentNoteUrl: parentNotePath, + parentNoteLink: parentNotePath, activate: false, title, }); @@ -146,7 +146,7 @@ export default class BoardApi { const { note, branch } = await note_create.createNote( { target: direction, - parentNoteUrl: this.parentNote.noteId, + parentNoteLink: this.parentNote.noteId, activate: false, targetBranchId: relativeToBranchId, title: t("board_view.new-item"), diff --git a/apps/client/src/widgets/collections/table/context_menu.ts b/apps/client/src/widgets/collections/table/context_menu.ts index 22342b3dd..9319c58d7 100644 --- a/apps/client/src/widgets/collections/table/context_menu.ts +++ b/apps/client/src/widgets/collections/table/context_menu.ts @@ -182,7 +182,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro enabled: !sorters.length, handler: () => parentComponent?.triggerCommand("addNewRow", { customOpts: { - parentNoteUrl: parentNoteId, + parentNoteLink: parentNoteId, target: "before", targetBranchId: rowData.branchId, } @@ -199,7 +199,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro } parentComponent?.triggerCommand("addNewRow", { customOpts: { - parentNoteUrl: note.noteId, + parentNoteLink: note.noteId, target: "after", targetBranchId: branchId, } @@ -212,7 +212,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro enabled: !sorters.length, handler: () => parentComponent?.triggerCommand("addNewRow", { customOpts: { - parentNoteUrl: parentNoteId, + parentNoteLink: parentNoteId, target: "after", targetBranchId: rowData.branchId, } diff --git a/apps/client/src/widgets/collections/table/row_editing.ts b/apps/client/src/widgets/collections/table/row_editing.ts index 9ad7da588..9d6456167 100644 --- a/apps/client/src/widgets/collections/table/row_editing.ts +++ b/apps/client/src/widgets/collections/table/row_editing.ts @@ -21,9 +21,9 @@ export default function useRowTableEditing(api: RefObject, attributeD }; } - const noteUrl = customOpts.parentNoteUrl ?? parentNotePath; + const noteUrl = customOpts.parentNoteLink ?? parentNotePath; if (noteUrl) { - customOpts.parentNoteUrl = noteUrl; + customOpts.parentNoteLink = noteUrl; customOpts.activate = false; note_create.createNote(customOpts).then(({ branch }) => { if (branch) { diff --git a/apps/client/src/widgets/dialogs/add_link.tsx b/apps/client/src/widgets/dialogs/add_link.tsx index b33cc64dc..0cc3361df 100644 --- a/apps/client/src/widgets/dialogs/add_link.tsx +++ b/apps/client/src/widgets/dialogs/add_link.tsx @@ -58,7 +58,7 @@ export default function AddLinkDialog() { } if (suggestion.notePath) { - const noteId = tree.getNoteIdFromUrl(suggestion.notePath); + const noteId = tree.getNoteIdFromLink(suggestion.notePath); if (noteId) { setDefaultLinkTitle(noteId); } diff --git a/apps/client/src/widgets/dialogs/include_note.tsx b/apps/client/src/widgets/dialogs/include_note.tsx index 2ee3858a1..882c82125 100644 --- a/apps/client/src/widgets/dialogs/include_note.tsx +++ b/apps/client/src/widgets/dialogs/include_note.tsx @@ -70,8 +70,8 @@ export default function IncludeNoteDialog() { ) } -async function includeNote(notePath: string, editorApi: CKEditorApi, boxSize: BoxSize) { - const noteId = tree.getNoteIdFromUrl(notePath); +async function includeNote(notePath: string, textTypeWidget: EditableTextTypeWidget, boxSize: BoxSize) { + const noteId = tree.getNoteIdFromLink(notePath); if (!noteId) { 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 016483490..a5703f290 100644 --- a/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx +++ b/apps/client/src/widgets/mobile_widgets/mobile_detail_menu.tsx @@ -34,7 +34,7 @@ export default function MobileDetailMenu() { if (parentNoteUrl) { note_create.createNote({ target: "into", - parentNoteUrl, + parentNoteLink: parentNoteUrl, }); } } else if (command === "delete") { diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.ts index efddc5414..ff7635eb5 100644 --- a/apps/client/src/widgets/note_tree.ts +++ b/apps/client/src/widgets/note_tree.ts @@ -227,7 +227,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { noteCreateService.createNote( { target: "into", - parentNoteUrl: parentNotePath, + parentNoteLink: parentNotePath, isProtected: node.data.isProtected }, ); @@ -1409,10 +1409,10 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { let node: Fancytree.FancytreeNode | null | undefined = await this.expandToNote(activeNotePath, false); - if (node && node.data.noteId !== treeService.getNoteIdFromUrl(activeNotePath)) { + if (node && node.data.noteId !== treeService.getNoteIdFromLink(activeNotePath)) { // if the active note has been moved elsewhere then it won't be found by the path, // so we switch to the alternative of trying to find it by noteId - const noteId = treeService.getNoteIdFromUrl(activeNotePath); + const noteId = treeService.getNoteIdFromLink(activeNotePath); if (noteId) { const notesById = this.getNodesByNoteId(noteId); @@ -1845,7 +1845,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { noteCreateService.createNote( { target: "into", - parentNoteUrl: notePath, + parentNoteLink: notePath, isProtected: node.data.isProtected } )