mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
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.
This commit is contained in:
parent
71b3ad5027
commit
eca5a4a072
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -287,7 +287,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
noteCreateService.createNote(
|
||||
{
|
||||
target: "after",
|
||||
parentNoteUrl: parentNotePath,
|
||||
parentNoteLink: parentNotePath,
|
||||
targetBranchId: this.node.data.branchId,
|
||||
type: type,
|
||||
isProtected: isProtected,
|
||||
@ -301,7 +301,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
||||
noteCreateService.createNote(
|
||||
{
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
parentNoteLink: parentNotePath,
|
||||
type: type,
|
||||
isProtected: this.node.data.isProtected,
|
||||
templateNoteId: templateNoteId,
|
||||
|
||||
@ -50,7 +50,7 @@ async function checkNoteAccess(notePath: string, noteContext: NoteContext) {
|
||||
const hoistedNoteId = noteContext.hoistedNoteId;
|
||||
|
||||
if (!resolvedNotePath.includes(hoistedNoteId) && (!resolvedNotePath.includes("_hidden") || resolvedNotePath.includes("_lbBookmarks"))) {
|
||||
const noteId = treeService.getNoteIdFromUrl(resolvedNotePath);
|
||||
const noteId = treeService.getNoteIdFromLink(resolvedNotePath);
|
||||
if (!noteId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ export function parseNavigationStateFromUrl(url: string | undefined) {
|
||||
|
||||
return {
|
||||
notePath,
|
||||
noteId: treeService.getNoteIdFromUrl(notePath),
|
||||
noteId: treeService.getNoteIdFromLink(notePath),
|
||||
ntxId,
|
||||
hoistedNoteId,
|
||||
viewScope,
|
||||
|
||||
@ -84,25 +84,26 @@ type CreateNoteBase = {
|
||||
* Serves as a base for "into", "before", and "after" variants,
|
||||
* sharing common URL-related fields.
|
||||
*/
|
||||
export type CreateNoteWithUrlOpts =
|
||||
export type CreateNoteWithLinkOpts =
|
||||
| (CreateNoteBase & {
|
||||
target: "into";
|
||||
parentNoteUrl?: string;
|
||||
parentNoteLink?: string;
|
||||
// No branch ID needed for "into"
|
||||
})
|
||||
| (CreateNoteBase & {
|
||||
target: "before" | "after";
|
||||
parentNoteUrl?: string;
|
||||
// Either an Url or a Path
|
||||
parentNoteLink?: string;
|
||||
// Required for "before"/"after"
|
||||
targetBranchId: string;
|
||||
});
|
||||
|
||||
export type CreateNoteIntoDefaultOpts = CreateNoteBase & {
|
||||
target: "default";
|
||||
parentNoteUrl?: never;
|
||||
parentNoteLink?: never;
|
||||
};
|
||||
|
||||
export type CreateNoteOpts = CreateNoteWithUrlOpts | CreateNoteIntoDefaultOpts;
|
||||
export type CreateNoteOpts = CreateNoteWithLinkOpts | CreateNoteIntoDefaultOpts;
|
||||
|
||||
interface Response {
|
||||
// TODO: Deduplicate with server once we have client/server architecture.
|
||||
@ -139,7 +140,7 @@ async function createNote(
|
||||
case "into":
|
||||
case "before":
|
||||
case "after":
|
||||
return createNoteWithUrl(resolvedOptions);
|
||||
return createNoteWithLink(resolvedOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +149,7 @@ async function createNoteFromAction(
|
||||
action: CreateNoteAction,
|
||||
promptForType: boolean,
|
||||
title: string | undefined,
|
||||
parentNoteUrl: string | undefined,
|
||||
parentNoteLink: string | undefined,
|
||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
|
||||
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<DuplicateResponse>(`notes/${noteId}/duplicate/${parentNoteId}`);
|
||||
|
||||
await ws.waitForMaxKnownEntityChangeId();
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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"),
|
||||
|
||||
@ -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,
|
||||
}
|
||||
|
||||
@ -21,9 +21,9 @@ export default function useRowTableEditing(api: RefObject<Tabulator>, 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) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ export default function MobileDetailMenu() {
|
||||
if (parentNoteUrl) {
|
||||
note_create.createNote({
|
||||
target: "into",
|
||||
parentNoteUrl,
|
||||
parentNoteLink: parentNoteUrl,
|
||||
});
|
||||
}
|
||||
} else if (command === "delete") {
|
||||
|
||||
@ -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
|
||||
}
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user