mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 12:50:47 +08:00
refactor(note-create): replace enum with optional fields
This commit is contained in:
parent
b34c521977
commit
d725be9e36
15 changed files with 46 additions and 54 deletions
|
|
@ -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, { CreateNoteIntoInboxOpts, CreateNoteTarget } from "../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteIntoInboxOpts } from "../services/note_create.js";
|
||||
|
||||
export default class Entrypoints extends Component {
|
||||
constructor() {
|
||||
|
|
@ -26,7 +26,7 @@ export default class Entrypoints extends Component {
|
|||
|
||||
async createNoteIntoInboxCommand() {
|
||||
await noteCreateService.createNote(
|
||||
{ target: CreateNoteTarget.IntoInbox } as CreateNoteIntoInboxOpts
|
||||
{ target: "into" } as CreateNoteIntoInboxOpts
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import appContext, { type EventData } from "./app_context.js";
|
||||
import noteCreateService, { CreateNoteTarget, CreateNoteIntoUrlOpts, CreateNoteAfterUrlOpts } from "../services/note_create.js";
|
||||
import noteCreateService, { 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";
|
||||
|
|
@ -50,7 +50,7 @@ export default class MainTreeExecutors extends Component {
|
|||
|
||||
await noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: activeNoteContext.notePath,
|
||||
isProtected: activeNoteContext.note.isProtected,
|
||||
saveSelection: false,
|
||||
|
|
@ -79,7 +79,7 @@ export default class MainTreeExecutors extends Component {
|
|||
|
||||
await noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.AfterNoteURL,
|
||||
target: "after",
|
||||
parentNoteUrl: parentNotePath,
|
||||
targetBranchId: node.data.branchId,
|
||||
isProtected: isProtected,
|
||||
|
|
|
|||
|
|
@ -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, CreateNoteTarget } from "../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts } from "../services/note_create.js";
|
||||
|
||||
export default class RootCommandExecutor extends Component {
|
||||
editReadOnlyNoteCommand() {
|
||||
|
|
@ -235,7 +235,7 @@ export default class RootCommandExecutor extends Component {
|
|||
|
||||
const result = await noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
title: "New AI Chat",
|
||||
type: "aiChat",
|
||||
content: JSON.stringify({
|
||||
|
|
|
|||
|
|
@ -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, CreateNoteTarget } from "../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteAfterUrlOpts, CreateNoteIntoUrlOpts } 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";
|
||||
|
|
@ -276,7 +276,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
|||
|
||||
noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.AfterNoteURL,
|
||||
target: "after",
|
||||
parentNoteUrl: parentNotePath,
|
||||
targetBranchId: this.node.data.branchId,
|
||||
type: type,
|
||||
|
|
@ -290,7 +290,7 @@ export default class TreeContextMenu implements SelectMenuItemEventListener<Tree
|
|||
|
||||
noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
type: type,
|
||||
isProtected: this.node.data.isProtected,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import server from "./server.js";
|
||||
import appContext from "../components/app_context.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts, CreateNoteTarget, CreateNoteIntoInboxOpts } from "./note_create.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts, CreateNoteIntoInboxOpts } from "./note_create.js";
|
||||
import froca from "./froca.js";
|
||||
import { t } from "./i18n.js";
|
||||
import commandRegistry from "./command_registry.js";
|
||||
|
|
@ -483,7 +483,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
|||
case SuggestionAction.CreateNoteIntoInbox: {
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoInbox,
|
||||
target: "inbox",
|
||||
title: suggestion.noteTitle,
|
||||
activate: true,
|
||||
promptForType: true,
|
||||
|
|
@ -503,7 +503,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
|||
case SuggestionAction.CreateAndLinkNoteIntoInbox: {
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoInbox,
|
||||
target: "inbox",
|
||||
title: suggestion.noteTitle,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
|
|
@ -523,7 +523,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
|||
case SuggestionAction.CreateNoteIntoPath: {
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: suggestion.parentNoteId,
|
||||
title: suggestion.noteTitle,
|
||||
activate: true,
|
||||
|
|
@ -544,7 +544,7 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
|||
case SuggestionAction.CreateAndLinkNoteIntoPath: {
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: suggestion.parentNoteId,
|
||||
title: suggestion.noteTitle,
|
||||
activate: false,
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ type PromptingRule = {
|
|||
* Combine with `&` to ensure valid logical combinations.
|
||||
*/
|
||||
export type CreateNoteOpts = {
|
||||
target: CreateNoteTarget;
|
||||
target: "into" | "after" | "before" | "inbox";
|
||||
isProtected?: boolean;
|
||||
saveSelection?: boolean;
|
||||
title?: string | null;
|
||||
|
|
@ -99,13 +99,6 @@ type NeverDefineParentNoteUrlRule = {
|
|||
};
|
||||
export type CreateNoteIntoInboxOpts = CreateNoteOpts & NeverDefineParentNoteUrlRule;
|
||||
|
||||
export enum CreateNoteTarget {
|
||||
IntoNoteURL,
|
||||
AfterNoteURL,
|
||||
BeforeNoteURL,
|
||||
IntoInbox,
|
||||
}
|
||||
|
||||
interface Response {
|
||||
// TODO: Deduplicate with server once we have client/server architecture.
|
||||
note: FNote;
|
||||
|
|
@ -136,16 +129,16 @@ async function createNote(
|
|||
}
|
||||
|
||||
switch (resolvedOptions.target) {
|
||||
case CreateNoteTarget.IntoNoteURL:
|
||||
case "into":
|
||||
return await createNoteAtNote("into", {...options} as CreateNoteAtUrlOpts);
|
||||
|
||||
case CreateNoteTarget.BeforeNoteURL:
|
||||
case "before":
|
||||
return await createNoteAtNote("before", resolvedOptions as CreateNoteBeforeUrlOpts);
|
||||
|
||||
case CreateNoteTarget.AfterNoteURL:
|
||||
case "after":
|
||||
return await createNoteAtNote("after", resolvedOptions as CreateNoteAfterUrlOpts);
|
||||
|
||||
case CreateNoteTarget.IntoInbox:
|
||||
case "inbox":
|
||||
return await createNoteIntoInbox(resolvedOptions as CreateNoteIntoInboxOpts);
|
||||
|
||||
default: {
|
||||
|
|
@ -176,7 +169,7 @@ async function promptForType(
|
|||
resolvedOptions = resolvedOptions as CreateNoteIntoUrlOpts;
|
||||
resolvedOptions = {
|
||||
...resolvedOptions,
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: notePath,
|
||||
} as CreateNoteIntoUrlOpts;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, CreateNoteTarget } from "../../../services/note_create.js";
|
||||
import note_create, { CreateNoteIntoUrlOpts } from "../../../services/note_create.js";
|
||||
import server from "../../../services/server";
|
||||
import { ColumnMap } from "./data";
|
||||
|
||||
|
|
@ -29,7 +29,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: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
activate: false,
|
||||
title,
|
||||
|
|
@ -131,7 +131,7 @@ export default class BoardApi {
|
|||
async insertRowAtPosition(
|
||||
column: string,
|
||||
relativeToBranchId: string,
|
||||
direction: CreateNoteTarget.BeforeNoteURL | CreateNoteTarget.AfterNoteURL
|
||||
direction: "before" | "after"
|
||||
) {
|
||||
const { note, branch } = await note_create.createNote(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import attributes from "../../../services/attributes";
|
|||
import branches from "../../../services/branches";
|
||||
import dialog from "../../../services/dialog";
|
||||
import { t } from "../../../services/i18n";
|
||||
import { CreateNoteTarget } from "../../../services/note_create";
|
||||
import Api from "./api";
|
||||
|
||||
export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column: string) {
|
||||
|
|
@ -60,7 +59,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
|
|||
handler: () => api.insertRowAtPosition(
|
||||
column,
|
||||
branchId,
|
||||
CreateNoteTarget.BeforeNoteURL)
|
||||
"before")
|
||||
},
|
||||
{
|
||||
title: t("board_view.insert-below"),
|
||||
|
|
@ -68,7 +67,7 @@ export function openNoteContextMenu(api: Api, event: ContextMenuEvent, note: FNo
|
|||
handler: () => api.insertRowAtPosition(
|
||||
column,
|
||||
branchId,
|
||||
CreateNoteTarget.AfterNoteURL)
|
||||
"after")
|
||||
},
|
||||
{ kind: "separator" },
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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, CreateNoteTarget } from "../../../services/note_create.js";
|
||||
import { CreateNoteAfterUrlOpts, CreateNoteBeforeUrlOpts } from "../../../services/note_create.js";
|
||||
|
||||
export function useContextMenu(parentNote: FNote, parentComponent: Component | null | undefined, tabulator: RefObject<Tabulator>): Partial<EventCallBackMethods> {
|
||||
const events: Partial<EventCallBackMethods> = {};
|
||||
|
|
@ -183,7 +183,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
|||
handler: () => parentComponent?.triggerCommand("addNewRow", {
|
||||
parentNotePath: parentNoteId,
|
||||
customOpts: {
|
||||
target: CreateNoteTarget.BeforeNoteURL,
|
||||
target: "before",
|
||||
targetBranchId: rowData.branchId,
|
||||
} as CreateNoteBeforeUrlOpts
|
||||
})
|
||||
|
|
@ -197,7 +197,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
|||
parentComponent?.triggerCommand("addNewRow", {
|
||||
parentNotePath: note?.noteId,
|
||||
customOpts: {
|
||||
target: CreateNoteTarget.AfterNoteURL,
|
||||
target: "after",
|
||||
targetBranchId: branchId,
|
||||
} as CreateNoteAfterUrlOpts
|
||||
});
|
||||
|
|
@ -210,7 +210,7 @@ export function showRowContextMenu(parentComponent: Component, e: MouseEvent, ro
|
|||
handler: () => parentComponent?.triggerCommand("addNewRow", {
|
||||
parentNotePath: parentNoteId,
|
||||
customOpts: {
|
||||
target: CreateNoteTarget.AfterNoteURL,
|
||||
target: "after",
|
||||
targetBranchId: rowData.branchId,
|
||||
} as CreateNoteAfterUrlOpts
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { EventCallBackMethods, RowComponent, Tabulator } from "tabulator-tables";
|
||||
import { CommandListenerData } from "../../../components/app_context";
|
||||
import note_create, { CreateNoteOpts, CreateNoteIntoUrlOpts as CreateNoteIntoUrlOpts, CreateNoteTarget } from "../../../services/note_create";
|
||||
import note_create, { CreateNoteOpts, CreateNoteIntoUrlOpts as CreateNoteIntoUrlOpts } from "../../../services/note_create";
|
||||
import { useLegacyImperativeHandlers } from "../../react/hooks";
|
||||
import { RefObject } from "preact";
|
||||
import { setAttribute, setLabel } from "../../../services/attributes";
|
||||
|
|
|
|||
|
|
@ -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, CreateNoteTarget } from "../../services/note_create";
|
||||
import note_create, { CreateNoteIntoUrlOpts } from "../../services/note_create";
|
||||
import tree from "../../services/tree";
|
||||
import ActionButton from "../react/ActionButton";
|
||||
import { ParentComponent } from "../react/react_utils";
|
||||
|
|
@ -31,7 +31,7 @@ export default function MobileDetailMenu() {
|
|||
if (command === "insertChildNote") {
|
||||
note_create.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: appContext.tabManager.getActiveContextNotePath() ?? undefined
|
||||
} as CreateNoteIntoUrlOpts
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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, CreateNoteTarget } from "../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts } from "../services/note_create.js";
|
||||
import attributeService from "../services/attributes.js";
|
||||
|
||||
import EmptyTypeWidget from "./type_widgets/empty.js";
|
||||
|
|
@ -431,7 +431,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||
if (this.noteContext && parentNotePath) {
|
||||
noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
isProtected: note.isProtected,
|
||||
saveSelection: true,
|
||||
|
|
|
|||
|
|
@ -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, CreateNoteTarget } from "../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts } 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";
|
||||
|
|
@ -234,7 +234,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||
const parentNotePath = treeService.getNotePath(node);
|
||||
noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
isProtected: node.data.isProtected
|
||||
} as CreateNoteIntoUrlOpts,
|
||||
|
|
@ -1851,7 +1851,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {
|
|||
const notePath = treeService.getNotePath(node);
|
||||
noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: notePath,
|
||||
isProtected: node.data.isProtected
|
||||
} as CreateNoteIntoUrlOpts
|
||||
|
|
|
|||
|
|
@ -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, CreateNoteTarget, CreateNoteIntoInboxOpts } from "../../../services/note_create";
|
||||
import note_create, { CreateNoteAfterUrlOpts, CreateNoteIntoUrlOpts, CreateNoteIntoInboxOpts } from "../../../services/note_create";
|
||||
import { CreateNoteAction } from "@triliumnext/commons";
|
||||
|
||||
type AttributeCommandNames = FilteredCommandNames<CommandData>;
|
||||
|
|
@ -268,7 +268,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
|||
case CreateNoteAction.CreateAndLinkNoteIntoInbox: {
|
||||
const { note } = await note_create.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoInbox,
|
||||
target: "inbox",
|
||||
title,
|
||||
activate: false
|
||||
} as CreateNoteIntoInboxOpts
|
||||
|
|
@ -280,7 +280,7 @@ export default function AttributeEditor({ api, note, componentId, notePath, ntxI
|
|||
case CreateNoteAction.CreateAndLinkNoteIntoPath: {
|
||||
const resp = await note_create.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
title,
|
||||
activate: false,
|
||||
|
|
|
|||
|
|
@ -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, CreateNoteTarget, CreateNoteIntoInboxOpts } from "../../services/note_create.js";
|
||||
import noteCreateService, { CreateNoteIntoUrlOpts, 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";
|
||||
|
|
@ -504,7 +504,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
case CreateNoteAction.CreateNoteIntoInbox: {
|
||||
const { note } = await note_create.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoInbox,
|
||||
target: "inbox",
|
||||
title,
|
||||
activate: true,
|
||||
promptForType: true,
|
||||
|
|
@ -518,7 +518,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
case CreateNoteAction.CreateNoteIntoPath: {
|
||||
const { note } = await note_create.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
title,
|
||||
activate: true,
|
||||
|
|
@ -533,7 +533,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
case CreateNoteAction.CreateAndLinkNoteIntoInbox: {
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoInbox,
|
||||
target: "inbox",
|
||||
title,
|
||||
activate: false,
|
||||
promptForType: true,
|
||||
|
|
@ -547,7 +547,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||
case CreateNoteAction.CreateAndLinkNoteIntoPath: {
|
||||
const { note } = await noteCreateService.createNote(
|
||||
{
|
||||
target: CreateNoteTarget.IntoNoteURL,
|
||||
target: "into",
|
||||
parentNoteUrl: parentNotePath,
|
||||
title,
|
||||
activate: false,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue