Back to Trilium

Class NoteContext

docs/Script API/classes/Frontend_Script_API._internal_.NoteContext.html

0.102.214.0 KB
Original Source

Class NoteContext

Abstract class for all components in the Trilium's frontend.

Contains also event implementation with following properties:

  • event / command distribution is synchronous which among others mean that events are well-ordered - event which was sent out first will also be processed first by the component
  • execution of the event / command is asynchronous - each component executes the event on its own without regard for other components.
  • although the execution is async, we are collecting all the promises, and therefore it is possible to wait until the event / command is executed in all components - by simply awaiting the triggerEvent().

Hierarchy (View Summary)

Implements

Index

Constructors

constructor

Properties

_position$widgetchildrencomponentIdhoistedNoteIdinitializedmainNtxIdnoteId?notePath?ntxIdparent?parentNoteId?viewScope?

Accessors

notenotePathArraypositionsanitizedClassName

Methods

callMethodchildentitiesReloadedEventgetCodeEditorgetContentElementgetMainContextgetNavigationTitlegetPojoStategetResolvedNotePathgetSubContextsgetTextEditorgetTypeWidgethandleEventhandleEventInChildrenhasNoteListisActiveisEmptyisMainContextisReadOnlyresetViewScopesaveToRecentNotessetEmptysetHoistedNoteIdsetHoistedNoteIfNeededsetNotesetParenttimeouttriggerCommandtriggerEventunhoistgenerateNtxId

Constructors

constructor

new NoteContext(
ntxId?: null | string,
hoistedNoteId?: string,
mainNtxId?: null | string,
): NoteContext

Parameters

  • ntxId: null | string = null
  • hoistedNoteId: string = "root"
  • mainNtxId: null | string = null

Returns NoteContext

Properties

_position

_position: number

$widget

$widget: JQuery<HTMLElement>

children

children: default[]

componentId

componentId: string

hoistedNoteId

hoistedNoteId: string

initialized

initialized: null | Promise<void>

mainNtxId

mainNtxId: null | string

OptionalnoteId

noteId?: null | string

OptionalnotePath

notePath?: null | string

ntxId

ntxId: null | string

Optionalparent

parent?: TypedComponent<any>

OptionalparentNoteId

parentNoteId?: null | string

OptionalviewScope

viewScope?: ViewScope

Accessors

note

get note(): null | FNote

Returns null | FNote

notePathArray

get notePathArray(): string[]

Returns string[]

position

get position(): number

Returns number

set position(newPosition: number): void

Parameters

  • newPosition: number

Returns void

sanitizedClassName

get sanitizedClassName(): string

Returns string

Methods

callMethod

callMethod(
fun: (arg: unknown) => Promise<unknown>,
data: unknown,
): undefined | Promise<unknown>

Parameters

  • fun: (arg: unknown) => Promise<unknown>
  • data: unknown

Returns undefined | Promise<unknown>

child

child(...components: default[]): NoteContext

Parameters

Returns NoteContext

entitiesReloadedEvent

entitiesReloadedEvent(
__namedParameters: { loadResults: default },
): Promise<void>

Parameters

  • __namedParameters: { loadResults: default }

Returns Promise<void>

getCodeEditor

getCodeEditor(): Promise<CodeMirrorInstance>

Returns Promise<CodeMirrorInstance>

getContentElement

getContentElement(): Promise<JQuery<HTMLElement>>

Returns a promise which will retrieve the JQuery element of the content of this note context.

Do note that retrieving the content element needs to be handled by the type widget, which is the one which provides the content element by listening to the executeWithContentElement event. Not all note types support this.

If no content could be determined null is returned instead.

Returns Promise<JQuery<HTMLElement>>

getMainContext

getMainContext(): NoteContext

See docs for isMainContext() for better explanation.

Returns NoteContext

getNavigationTitle

getNavigationTitle(): Promise<null | string>

Returns Promise<null | string>

getPojoState

getPojoState(): | null
| {
active: boolean;
hoistedNoteId: string;
mainNtxId: null
| string;
notePath: undefined | null | string;
ntxId: null | string;
viewScope: undefined | ViewScope;
}

Returns | null | { active: boolean; hoistedNoteId: string; mainNtxId: null | string; notePath: undefined | null | string; ntxId: null | string; viewScope: undefined | ViewScope; }

getResolvedNotePath

getResolvedNotePath(inputNotePath: string): Promise<undefined | string>

Parameters

  • inputNotePath: string

Returns Promise<undefined | string>

getSubContexts

getSubContexts(): NoteContext[]

Returns NoteContext[]

getTextEditor

getTextEditor(callback?: GetTextEditorCallback): Promise<TextEditor>

Parameters

Returns Promise<TextEditor>

getTypeWidget

getTypeWidget(): Promise<default>

Returns Promise<default>

handleEvent

handleEvent<T extends EventNames>(
name: T,
data: EventData<T>,
): undefined | null | Promise<unknown>

Type Parameters

Parameters

Returns undefined | null | Promise<unknown>

handleEventInChildren

handleEventInChildren<T extends EventNames>(
name: T,
data: EventData<T>,
): null | Promise<unknown>

Type Parameters

Parameters

Returns null | Promise<unknown>

hasNoteList

hasNoteList(): null | boolean

Returns null | boolean

isActive

isActive(): boolean

Returns boolean

isEmpty

isEmpty(): boolean

Returns boolean

isMainContext

isMainContext(): boolean

A main context represents a tab and also the first split. Further splits are the children contexts of the main context. Imagine you have a tab with 3 splits, each showing notes A, B, C (in this order). In such a scenario, A context is the main context (also representing the tab as a whole), and B, C are the children of context A.

Returns boolean

true if the context is main (= tab)

isReadOnly

isReadOnly(): Promise<null | boolean | 0>

Returns Promise<null | boolean | 0>

resetViewScope

resetViewScope(): void

Returns void

saveToRecentNotes

saveToRecentNotes(resolvedNotePath: string): void

Parameters

  • resolvedNotePath: string

Returns void

setEmpty

setEmpty(): void

Returns void

setHoistedNoteId

setHoistedNoteId(noteIdToHoist: string): Promise<void>

Parameters

  • noteIdToHoist: string

Returns Promise<void>

setHoistedNoteIfNeeded

setHoistedNoteIfNeeded(): Promise<void>

Returns Promise<void>

setNote

setNote(inputNotePath: undefined | string, opts?: SetNoteOpts): Promise<void>

Parameters

  • inputNotePath: undefined | string
  • opts: SetNoteOpts = {}

Returns Promise<void>

setParent

setParent(parent: TypedComponent<any>): NoteContext

Parameters

Returns NoteContext

timeout

timeout<T>(promise: Promise<null | T>): Promise<T>

Type Parameters

  • T

Parameters

  • promise: Promise<null | T>

Returns Promise<T>

triggerCommand

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

Type Parameters

Parameters

Returns undefined | null | Promise<unknown>

triggerEvent

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

Type Parameters

Parameters

Returns undefined | null | Promise<unknown>

unhoist

unhoist(): Promise<void>

Returns Promise<void>

StaticgenerateNtxId

generateNtxId(): string

Returns string

Settings

Member Visibility

  • Protected
  • Inherited
  • External

ThemeOSLightDark

On This Page

Constructors constructor Properties _position$widgetchildrencomponentIdhoistedNoteIdinitializedmainNtxIdnoteIdnotePathntxIdparentparentNoteIdviewScope Accessors notenotePathArraypositionsanitizedClassName Methods callMethodchildentitiesReloadedEventgetCodeEditorgetContentElementgetMainContextgetNavigationTitlegetPojoStategetResolvedNotePathgetSubContextsgetTextEditorgetTypeWidgethandleEventhandleEventInChildrenhasNoteListisActiveisEmptyisMainContextisReadOnlyresetViewScopesaveToRecentNotessetEmptysetHoistedNoteIdsetHoistedNoteIfNeededsetNotesetParenttimeouttriggerCommandtriggerEventunhoistgenerateNtxId