# 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)

- default
  - NoteContext

#### Implements

- EventListener <"entitiesReloaded">

- Defined in src/public/app/components/note_context.ts:21

##### Index

### Constructors

constructor

### Properties

_position
$widget
children
componentId
hoistedNoteId
initialized
mainNtxId
noteId?
notePath?
ntxId
parent?
parentNoteId?
viewScope?

### Accessors

note
notePathArray
position
sanitizedClassName

### Methods

callMethod
child
entitiesReloadedEvent
getCodeEditor
getContentElement
getMainContext
getNavigationTitle
getPojoState
getResolvedNotePath
getSubContexts
getTextEditor
getTypeWidget
handleEvent
handleEventInChildren
hasNoteList
isActive
isEmpty
isMainContext
isReadOnly
resetViewScope
saveToRecentNotes
setEmpty
setHoistedNoteId
setHoistedNoteIfNeeded
setNote
setParent
timeout
triggerCommand
triggerEvent
unhoist
generateNtxId

## 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

  Overrides default.constructor

  - Defined in src/public/app/components/note_context.ts:31

## Properties

### _position

_position: number

Inherited from default._position

- Defined in src/public/app/components/component.ts:21

### $widget

$widget: JQuery<HTMLElement>

Inherited from default.$widget

- Defined in src/public/app/components/component.ts:16

### children

children: default []

Inherited from default.children

- Defined in src/public/app/components/component.ts:18

### componentId

componentId: string

Inherited from default.componentId

- Defined in src/public/app/components/component.ts:17

### hoistedNoteId

hoistedNoteId: string

- Defined in src/public/app/components/note_context.ts:23

### initialized

initialized: null | Promise<void>

Inherited from default.initialized

- Defined in src/public/app/components/component.ts:19

### mainNtxId

mainNtxId: null | string

- Defined in src/public/app/components/note_context.ts:24

### `Optional` noteId

noteId?: null | string

- Defined in src/public/app/components/note_context.ts:27

### `Optional` notePath

notePath?: null | string

- Defined in src/public/app/components/note_context.ts:26

### ntxId

ntxId: null | string

- Defined in src/public/app/components/note_context.ts:22

### `Optional` parent

parent?: TypedComponent <any>

Inherited from default.parent

- Defined in src/public/app/components/component.ts:20

### `Optional` parentNoteId

parentNoteId?: null | string

- Defined in src/public/app/components/note_context.ts:28

### `Optional` viewScope

viewScope?: ViewScope

- Defined in src/public/app/components/note_context.ts:29

## Accessors

### note

- get note(): null | FNote

  #### Returns null | FNote

  - Defined in src/public/app/components/note_context.ts:187

### notePathArray

- get notePathArray(): string[]

  #### Returns string[]

  - Defined in src/public/app/components/note_context.ts:196

### position

- get position(): number

  #### Returns number

  Inherited from Component.position

  - Defined in src/public/app/components/component.ts:34
- set position(newPosition: number): void

  #### Parameters

  - newPosition: number

  #### Returns void

  Inherited from Component.position

  - Defined in src/public/app/components/component.ts:38

### sanitizedClassName

- get sanitizedClassName(): string

  #### Returns string

  Inherited from Component.sanitizedClassName

  - Defined in src/public/app/components/component.ts:29

## 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>

  Inherited from default.callMethod

  - Defined in src/public/app/components/component.ts:105

### child

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

  #### Parameters

  - ...components: default []

  #### Returns NoteContext

  Inherited from default.child

  - Defined in src/public/app/components/component.ts:47

### entitiesReloadedEvent

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

  #### Parameters

  - __namedParameters: { loadResults: default }

  #### Returns Promise<void>

  Implementation of EventListener.entitiesReloadedEvent

  - Defined in src/public/app/components/note_context.ts:273

### getCodeEditor

- getCodeEditor(): Promise< CodeMirrorInstance >

  #### Returns Promise< CodeMirrorInstance >

  - Defined in src/public/app/components/note_context.ts:312

### 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>>

  - Defined in src/public/app/components/note_context.ts:332

### getMainContext

- getMainContext(): NoteContext

  See docs for isMainContext() for better explanation.

  #### Returns NoteContext

  - Defined in src/public/app/components/note_context.ts:146

### getNavigationTitle

- getNavigationTitle(): Promise<null | string>

  #### Returns Promise<null | string>

  - Defined in src/public/app/components/note_context.ts:365

### 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 ;
  }

  - Defined in src/public/app/components/note_context.ts:204

### getResolvedNotePath

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

  #### Parameters

  - inputNotePath: string

  #### Returns Promise<undefined | string>

  - Defined in src/public/app/components/note_context.ts:172

### getSubContexts

- getSubContexts(): NoteContext []

  #### Returns NoteContext []

  - Defined in src/public/app/components/note_context.ts:124

### getTextEditor

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

  #### Parameters

  - `Optional` callback: GetTextEditorCallback

  #### Returns Promise< TextEditor >

  - Defined in src/public/app/components/note_context.ts:300

### getTypeWidget

- getTypeWidget(): Promise< default >

  #### Returns Promise< default >

  - Defined in src/public/app/components/note_context.ts:343

### handleEvent

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

  #### Type Parameters

  - T extends EventNames

  #### Parameters

  - name: T
  - data: EventData < T >

  #### Returns undefined | null | Promise<unknown>

  Inherited from default.handleEvent

  - Defined in src/public/app/components/component.ts:57

### handleEventInChildren

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

  #### Type Parameters

  - T extends EventNames

  #### Parameters

  - name: T
  - data: EventData < T >

  #### Returns null | Promise<unknown>

  Inherited from default.handleEventInChildren

  - Defined in src/public/app/components/component.ts:76

### hasNoteList

- hasNoteList(): null | boolean

  #### Returns null | boolean

  - Defined in src/public/app/components/note_context.ts:289

### isActive

- isActive(): boolean

  #### Returns boolean

  - Defined in src/public/app/components/note_context.ts:200

### isEmpty

- isEmpty(): boolean

  #### Returns boolean

  - Defined in src/public/app/components/note_context.ts:59

### 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)

  - Defined in src/public/app/components/note_context.ts:136

### isReadOnly

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

  #### Returns Promise<null | boolean | 0>

  - Defined in src/public/app/components/note_context.ts:245

### resetViewScope

- resetViewScope(): void

  #### Returns void

  - Defined in src/public/app/components/note_context.ts:358

### saveToRecentNotes

- saveToRecentNotes(resolvedNotePath: string): void

  #### Parameters

  - resolvedNotePath: string

  #### Returns void

  - Defined in src/public/app/components/note_context.ts:159

### setEmpty

- setEmpty(): void

  #### Returns void

  - Defined in src/public/app/components/note_context.ts:45

### setHoistedNoteId

- setHoistedNoteId(noteIdToHoist: string): Promise<void>

  #### Parameters

  - noteIdToHoist: string

  #### Returns Promise<void>

  - Defined in src/public/app/components/note_context.ts:227

### setHoistedNoteIfNeeded

- setHoistedNoteIfNeeded(): Promise<void>

  #### Returns Promise<void>

  - Defined in src/public/app/components/note_context.ts:108

### setNote

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

  #### Parameters

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

  #### Returns Promise<void>

  - Defined in src/public/app/components/note_context.ts:63

### setParent

- setParent(parent: TypedComponent <any>): NoteContext

  #### Parameters

  - parent: TypedComponent <any>

  #### Returns NoteContext

  Inherited from default.setParent

  - Defined in src/public/app/components/component.ts:42

### timeout

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

  #### Type Parameters

  - T

  #### Parameters

  - promise: Promise<null | T >

  #### Returns Promise< T >

  - Defined in src/public/app/components/note_context.ts:354

### triggerCommand

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

  #### Type Parameters

  - K extends keyof CommandMappings

  #### Parameters

  - name: K
  - `Optional` data: CommandMappings [ K ]

  #### Returns undefined | null | Promise<unknown>

  Inherited from default.triggerCommand

  - Defined in src/public/app/components/component.ts:91

### triggerEvent

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

  #### Type Parameters

  - T extends EventNames

  #### Parameters

  - name: T
  - data: EventData < T >

  #### Returns undefined | null | Promise<unknown>

  Inherited from default.triggerEvent

  - Defined in src/public/app/components/component.ts:72

### unhoist

- unhoist(): Promise<void>

  #### Returns Promise<void>

  - Defined in src/public/app/components/note_context.ts:223

### `Static` generateNtxId

- generateNtxId(): string

  #### Returns string

  - Defined in src/public/app/components/note_context.ts:41