trilium
    Preparing search index...
    interface Api {
        $container: null | JQuery<HTMLElement>;
        BasicWidget: typeof BasicWidget;
        bindGlobalShortcut: (
            keyboardShortcut: string,
            handler: null | Handler,
            namespace?: null | string,
        ) => void;
        createLink: (
            notePath: undefined | string,
            options?: CreateLinkOptions,
        ) => Promise<JQuery<HTMLElement>>;
        createNoteLink: (
            notePath: undefined | string,
            options?: CreateLinkOptions,
        ) => Promise<JQuery<HTMLElement>>;
        currentNote: FNote;
        dayjs: __module;
        formatDateISO: (date: Date) => string;
        formatNoteSize: (size: number) => string;
        formatSize: (size: number) => string;
        getDayNote: (date: string) => Promise<null | FNote>;
        getMonthNote: (month: string) => Promise<null | FNote>;
        getQuarterNote: (quarter: string) => Promise<null | FNote>;
        getTodayNote: () => Promise<null | FNote>;
        getWeekFirstDayNote: (date: string) => Promise<null | FNote>;
        getWeekNote: (week: string) => Promise<null | FNote>;
        getYearNote: (year: string) => Promise<null | FNote>;
        logMessages: Record<string, string[]>;
        logSpacedUpdates: Record<string, default>;
        NoteContextAwareWidget: typeof NoteContextAwareWidget;
        originEntity: unknown;
        parseDate: (str: string) => Date;
        protectNote: (
            noteId: string,
            protect: boolean,
            includingSubtree: boolean,
        ) => Promise<void>;
        protectSubTree: (
            noteId: string,
            protect: boolean,
            includingSubtree: boolean,
        ) => Promise<void>;
        randomString: (len: number) => string;
        RightPanelWidget: typeof RightPanelWidget;
        setupElementTooltip: ($el: JQuery<HTMLElement>) => void;
        showConfirmDialog: (message: string) => Promise<unknown>;
        showError: (message: string, delay?: number) => void;
        showInfoDialog: (message: string) => Promise<unknown>;
        showMessage: (message: string, delay?: number) => void;
        showPromptDialog: (props: PromptDialogOptions) => Promise<null | string>;
        startNote: FNote;
        triggerCommand: <K extends keyof CommandMappings>(
            name: K,
            _data?: CommandMappings[K],
        ) => undefined | null | Promise<unknown>;
        triggerEvent: <K extends EventNames>(
            name: K,
            data: EventData<K>,
        ) => undefined | null | Promise<unknown>;
        waitUntilSynced: () => Promise<void>;
        activateNewNote(notePath: string): Promise<void>;
        activateNote(notePath: string): Promise<void>;
        addButtonToToolbar(opts: AddToToolbarOpts): void;
        addTextToActiveContextEditor(text: string): void;
        getActiveContext(): NoteContext;
        getActiveContextCodeEditor(): Promise<unknown>;
        getActiveContextNote(): FNote;
        getActiveContextNotePath(): null | string;
        getActiveContextTextEditor(): Promise<unknown>;
        getActiveMainContext(): NoteContext;
        getActiveNoteDetailWidget(): Promise<default>;
        getComponentByEl(el: HTMLElement): default;
        getInstanceName(): string;
        getMainNoteContexts(): NoteContext[];
        getNote(noteId: string): Promise<null | FNote>;
        getNoteContexts(): NoteContext[];
        getNotes(
            noteIds: string[],
            silentNotFoundError?: boolean,
        ): Promise<FNote[]>;
        log(message: string): void;
        openSplitWithNote(notePath: string, activate: boolean): Promise<void>;
        openTabWithNote(notePath: string, activate: boolean): Promise<void>;
        refreshIncludedNote(includedNoteId: string): void;
        reloadNotes(noteIds: string[]): Promise<void>;
        runAsyncOnBackendWithManualTransactionHandling(
            func: Func,
            params: unknown[],
        ): unknown;
        runOnBackend(func: Func, params: unknown[]): unknown;
        searchForNote(searchString: string): Promise<null | FNote>;
        searchForNotes(searchString: string): Promise<FNote[]>;
        setHoistedNoteId(noteId: string): void;
    }
    Index

    Properties

    $container: null | JQuery<HTMLElement>

    Container of all the rendered script content

    BasicWidget: typeof BasicWidget
    bindGlobalShortcut: (
        keyboardShortcut: string,
        handler: null | Handler,
        namespace?: null | string,
    ) => void

    Type declaration

      • (
            keyboardShortcut: string,
            handler: null | Handler,
            namespace?: null | string,
        ): void
      • Parameters

        • keyboardShortcut: string

          e.g. "ctrl+shift+a"

        • handler: null | Handler
        • namespace: null | string = null

          specify namespace of the handler for the cases where call for bind may be repeated. If a handler with this ID exists, it's replaced by the new handler.

        Returns void

    createLink: (
        notePath: undefined | string,
        options?: CreateLinkOptions,
    ) => Promise<JQuery<HTMLElement>>

    Create a note link (jQuery object) for given note.

    Type declaration

      • (
            notePath: undefined | string,
            options?: CreateLinkOptions,
        ): Promise<JQuery<HTMLElement>>
      • Parameters

        Returns Promise<JQuery<HTMLElement>>

        • jQuery element with the link (wrapped in )
    createNoteLink: (
        notePath: undefined | string,
        options?: CreateLinkOptions,
    ) => Promise<JQuery<HTMLElement>>
    • use api.createLink() instead
    currentNote: FNote

    Note where the script is currently executing, i.e. the note where the currently executing source code is written.

    dayjs: __module

    day.js library for date manipulation. See https://day.js.org for documentation

    formatDateISO: (date: Date) => string

    Type declaration

      • (date: Date): string
      • this is producing local time! *

        Parameters

        • date: Date

        Returns string

    date in YYYY-MM-DD format

    formatNoteSize: (size: number) => string

    Type declaration

      • (size: number): string
      • Parameters

        • size: number

          in bytes

        Returns string

        formatted string

    • use api.formatSize()
    formatSize: (size: number) => string

    Type declaration

      • (size: number): string
      • Parameters

        • size: number

          in bytes

        Returns string

        formatted string

    getDayNote: (date: string) => Promise<null | FNote>

    Returns day note for a given date. If it doesn't exist, it is automatically created.

    Type declaration

      • (date: string): Promise<null | FNote>
      • Parameters

        • date: string

          e.g. "2019-04-29"

        Returns Promise<null | FNote>

    getMonthNote: (month: string) => Promise<null | FNote>

    Returns month-note. If it doesn't exist, it is automatically created.

    Type declaration

      • (month: string): Promise<null | FNote>
      • Parameters

        • month: string

          e.g. "2019-04"

        Returns Promise<null | FNote>

    getQuarterNote: (quarter: string) => Promise<null | FNote>

    Returns quarter note for given date. If such a note doesn't exist, it is automatically created.

    getTodayNote: () => Promise<null | FNote>

    Returns date-note for today. If it doesn't exist, it is automatically created.

    getWeekFirstDayNote: (date: string) => Promise<null | FNote>

    Returns day note for the first date of the week of the given date. If it doesn't exist, it is automatically created.

    Type declaration

      • (date: string): Promise<null | FNote>
      • Parameters

        • date: string

          e.g. "2019-04-29"

        Returns Promise<null | FNote>

    getWeekNote: (week: string) => Promise<null | FNote>

    Returns week note for given date. If such a note doesn't exist, it is automatically created.

    getYearNote: (year: string) => Promise<null | FNote>

    Returns year-note. If it doesn't exist, it is automatically created.

    Type declaration

      • (year: string): Promise<null | FNote>
      • Parameters

        • year: string

          e.g. "2019"

        Returns Promise<null | FNote>

    logMessages: Record<string, string[]>
    logSpacedUpdates: Record<string, default>
    NoteContextAwareWidget: typeof NoteContextAwareWidget
    originEntity: unknown

    Entity whose event triggered this execution.

    parseDate: (str: string) => Date
    protectNote: (
        noteId: string,
        protect: boolean,
        includingSubtree: boolean,
    ) => Promise<void>

    Type declaration

      • (noteId: string, protect: boolean, includingSubtree: boolean): Promise<void>
      • Parameters

        • noteId: string
        • protect: boolean

          true to protect note, false to unprotect

        • includingSubtree: boolean

        Returns Promise<void>

    protectSubTree: (
        noteId: string,
        protect: boolean,
        includingSubtree: boolean,
    ) => Promise<void>

    Type declaration

      • (noteId: string, protect: boolean, includingSubtree: boolean): Promise<void>
      • Parameters

        • noteId: string
        • protect: boolean

          true to protect subtree, false to unprotect

        • includingSubtree: boolean

        Returns Promise<void>

    randomString: (len: number) => string

    Return randomly generated string of given length. This random string generation is NOT cryptographically secure.

    Type declaration

      • (len: number): string
      • Parameters

        • len: number

        Returns string

        random string

    RightPanelWidget: typeof RightPanelWidget
    setupElementTooltip: ($el: JQuery<HTMLElement>) => void

    Type declaration

      • ($el: JQuery<HTMLElement>): void
      • Parameters

        • $el: JQuery<HTMLElement>

          jquery object on which to set up the tooltip

        Returns void

    showConfirmDialog: (message: string) => Promise<unknown>

    Show confirm dialog to the user.

    Type declaration

      • (message: string): Promise<unknown>
      • Parameters

        • message: string

        Returns Promise<unknown>

        promise resolving to true if the user confirmed

    showError: (message: string, delay?: number) => void

    Show an error toast message to the user.

    showInfoDialog: (message: string) => Promise<unknown>

    Show an info dialog to the user.

    showMessage: (message: string, delay?: number) => void

    Show an info toast message to the user.

    showPromptDialog: (props: PromptDialogOptions) => Promise<null | string>

    Show prompt dialog to the user.

    Type declaration

    startNote: FNote

    Note where the script started executing, i.e., the (event) entrypoint of the current script execution.

    triggerCommand: <K extends keyof CommandMappings>(
        name: K,
        _data?: CommandMappings[K],
    ) => undefined | null | Promise<unknown>

    Trigger command. This is a very low-level API which should be avoided if possible.

    triggerEvent: <K extends EventNames>(
        name: K,
        data: EventData<K>,
    ) => undefined | null | Promise<unknown>

    Trigger event. This is a very low-level API which should be avoided if possible.

    waitUntilSynced: () => Promise<void>

    Trilium runs in a backend and frontend process, when something is changed on the backend from a script, frontend will get asynchronously synchronized.

    This method returns a promise which resolves once all the backend -> frontend synchronization is finished. Typical use case is when a new note has been created, we should wait until it is synced into frontend and only then activate it.

    Methods

    • Activates newly created note. Compared to this.activateNote() also makes sure that frontend has been fully synced.

      Parameters

      • notePath: string

        (or noteId)

      Returns Promise<void>

    • Adds a new launcher to the launchbar. If the launcher (id) already exists, it will be updated.

      Parameters

      Returns void

      you can now create/modify launchers in the top-left Menu -> Configure Launchbar for special needs there's also backend API's createOrUpdateLauncher()

    • Returns list of notes. If note is missing from the cache, it's loaded.

      This is often used to bulk-fill the cache with notes which would have to be picked one by one otherwise (by e.g. createLink())

      Parameters

      • noteIds: string[]
      • OptionalsilentNotFoundError: boolean

        don't report error if the note is not found

      Returns Promise<FNote[]>

    • Open a note in a new split.

      Parameters

      • notePath: string

        (or noteId)

      • activate: boolean

        set to true to activate the new split, false to stay on the current split

      Returns Promise<void>

    • Open a note in a new tab.

      Parameters

      • notePath: string

        (or noteId)

      • activate: boolean

        set to true to activate the new tab, false to stay on the current tab

      Returns Promise<void>

    • This will refresh all currently opened notes which have included note specified in the parameter

      Parameters

      • includedNoteId: string

        noteId of the included note

      Returns void

    • Executes given anonymous function on the backend. Internally this serializes the anonymous function into string and sends it to backend via AJAX. This function is meant for advanced needs where an async function is necessary. In this case, the automatic request-scoped transaction management is not applied, and you need to manually define transaction via api.transactional().

      If you have a synchronous function, please use api.runOnBackend().

      Parameters

      • func: Func

        (synchronous) function to be executed on the backend

      • params: unknown[]

        list of parameters to the anonymous function to be sent to backend

      Returns unknown

      return value of the executed function on the backend

    • Executes given anonymous function on the backend. Internally this serializes the anonymous function into string and sends it to backend via AJAX. Please make sure that the supplied function is synchronous. Only sync functions will work correctly with transaction management. If you really know what you're doing, you can call api.runAsyncOnBackendWithManualTransactionHandling()

      Parameters

      • func: Func

        (synchronous) function to be executed on the backend

      • params: unknown[]

        list of parameters to the anonymous function to be sent to backend

      Returns unknown

      return value of the executed function on the backend