From 656e7c069dc444cab868064974e1588c4b2128bb Mon Sep 17 00:00:00 2001 From: Jakob Schlanstedt Date: Wed, 22 Oct 2025 16:21:55 +0200 Subject: [PATCH] refactor(create_note): rename types to fit ontological concepts better --- apps/client/src/components/app_context.ts | 4 ++-- apps/client/src/services/note_create.ts | 24 +++++++++---------- .../widgets/collections/table/row_editing.ts | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts index fd01a2211..bda3536da 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 { BaseCreateNoteOpts } from "../services/note_create.js"; +import type { CreateNoteOpts } 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: BaseCreateNoteOpts; + customOpts: CreateNoteOpts; parentNotePath?: string; }; addNewTableColumn: CommandData & { diff --git a/apps/client/src/services/note_create.ts b/apps/client/src/services/note_create.ts index a98857266..119d39bd5 100644 --- a/apps/client/src/services/note_create.ts +++ b/apps/client/src/services/note_create.ts @@ -29,9 +29,9 @@ import dateNoteService from "../services/date_notes.js"; * * * Hierarchy of general to specific categories(hypernyms -> hyponyms): * - * * BaseCreateNoteSharedOpts + * * CreateNoteEntity * | - * \-- BaseCreateNoteOpts + * \-- CreateNoteOpts * | * +-- CreateNoteAtUrlOpts * | +-- CreateNoteIntoURLOpts @@ -46,7 +46,7 @@ import dateNoteService from "../services/date_notes.js"; * this is the shared basis for all types. Every other type is child (hyponym) * of it (domain hypernym). */ -type BaseCreateNoteSharedOpts = { +type CreateNoteEntity = { target: CreateNoteTarget; isProtected?: boolean; saveSelection?: boolean; @@ -60,12 +60,12 @@ type BaseCreateNoteSharedOpts = { textEditor?: CKTextEditor; } -export type BaseCreateNoteOpts = - | (BaseCreateNoteSharedOpts & { +export type CreateNoteOpts = + | (CreateNoteEntity & { promptForType: true; type?: never; }) - | (BaseCreateNoteSharedOpts & { + | (CreateNoteEntity & { promptForType?: false; type?: string; }); @@ -75,7 +75,7 @@ export type BaseCreateNoteOpts = * of "into" and "as siblings". It is not exported because it only exists, to * have its legal values propagated to its children (types inheriting from it). */ -type CreateNoteAtUrlOpts = BaseCreateNoteOpts & { +type CreateNoteAtUrlOpts = CreateNoteOpts & { // `Url` means either parentNotePath or parentNoteId. // The vocabulary is inspired by its loose semantics of getNoteIdFromUrl. parentNoteUrl: string; @@ -92,7 +92,7 @@ type CreateNoteSiblingURLOpts = CreateNoteAtUrlOpts; export type CreateNoteBeforeURLOpts = CreateNoteSiblingURLOpts; export type CreateNoteAfterURLOpts = CreateNoteSiblingURLOpts; -export type CreateNoteIntoInboxURLOpts = BaseCreateNoteOpts & { +export type CreateNoteIntoInboxURLOpts = CreateNoteOpts & { parentNoteUrl?: never; } @@ -132,7 +132,7 @@ async function createNote( ): Promise<{ note: FNote | null; branch: FBranch | undefined }>; async function createNote( - options: BaseCreateNoteOpts + options: CreateNoteOpts ): Promise<{ note: FNote | null; branch: FBranch | undefined }> { let resolvedOptions = { ...options }; @@ -150,7 +150,7 @@ async function createNote( promptForType: false, type: noteType, templateNoteId, - } as BaseCreateNoteOpts; + } as CreateNoteOpts; if (notePath) { resolvedOptions = resolvedOptions as CreateNoteIntoURLOpts; @@ -187,7 +187,7 @@ async function createNote( * Core function that creates a new note under the specified parent note path. * * @param target - Duplicates apps/server/src/routes/api/notes.ts createNote - * @param {BaseCreateNoteSharedOpts} [options] - Options controlling note creation (title, content, type, template, focus, etc.). + * @param {CreateNoteEntity} [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. @@ -290,7 +290,7 @@ async function createNoteAfterNote( /** * Creates a new note inside the user's Inbox. * - * @param {BaseCreateNoteSharedOpts} [options] - Optional settings such as title, type, template, or content. + * @param {CreateNoteEntity} [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. */ diff --git a/apps/client/src/widgets/collections/table/row_editing.ts b/apps/client/src/widgets/collections/table/row_editing.ts index 914b8c4d0..94eb3028a 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, { BaseCreateNoteOpts, CreateNoteIntoURLOpts as CreateNoteIntoURLOpts, CreateNoteTarget } from "../../../services/note_create"; +import note_create, { CreateNoteOpts, CreateNoteIntoURLOpts as CreateNoteIntoURLOpts, CreateNoteTarget } from "../../../services/note_create"; import { useLegacyImperativeHandlers } from "../../react/hooks"; import { RefObject } from "preact"; import { setAttribute, setLabel } from "../../../services/attributes"; @@ -15,7 +15,7 @@ export default function useRowTableEditing(api: RefObject, attributeD addNewRowCommand({ customOpts, parentNotePath: customNotePath }: CommandListenerData<"addNewRow">) { const notePath = customNotePath ?? parentNotePath; if (notePath) { - const opts: BaseCreateNoteOpts = { + const opts: CreateNoteOpts = { activate: false, ...customOpts }