Back to Trilium

Class NoteContextAwareWidget

docs/Script API/classes/Frontend_Script_API.NoteContextAwareWidget.html

0.102.215.7 KB
Original Source

Class NoteContextAwareWidget

This widget allows for changing and updating depending on the active note.

Hierarchy (View Summary)

Index

Constructors

constructor

Properties

_noteId_position$widgetattrschildrencomponentIdinitializednoteContext?parent?

Accessors

hoistedNoteIdnotenoteIdnotePathntxIdpositionsanitizedClassName

Methods

activeContextChangedactiveContextChangedEventcallMethodcanBeShownchildclasscleanupcollapsiblecontentSizedcsscssBlockdoRenderfillingfrocaReloadedEventgetClosestNtxIdgetPositionhandleEventhandleEventInChildrenidisActiveNoteContextisEnabledisHiddenExtisHiddenIntisNoteisNoteContextisVisiblelogRenderingErrornoteSwitchednoteSwitchedAndActivatedEventnoteSwitchedEventnoteTypeMimeChangedEventoptChildoptCssrefreshrefreshWithNoteremoverendersetNoteContextEventsetParenttoggleExttoggleInttriggerCommandtriggerEvent

Constructors

constructor

new NoteContextAwareWidget(): NoteContextAwareWidget

Returns NoteContextAwareWidget

Properties

_noteId

_noteId: string

_position

_position: number

$widget

$widget: JQuery<HTMLElement>

Protectedattrs

attrs: Record<string, string>

children

children: default[]

componentId

componentId: string

initialized

initialized: null | Promise<void>

OptionalnoteContext

noteContext?: NoteContext

Optionalparent

parent?: TypedComponent<any>

Accessors

hoistedNoteId

get hoistedNoteId(): undefined | string

Returns undefined | string

note

get note(): undefined | null | FNote

Returns undefined | null | FNote

noteId

get noteId(): undefined | string

Returns undefined | string

notePath

get notePath(): undefined | null | string

Returns undefined | null | string

ntxId

get ntxId(): undefined | null | string

Returns undefined | null | string

position

get position(): number

Returns number

set position(newPosition: number): void

Parameters

  • newPosition: number

Returns void

sanitizedClassName

get sanitizedClassName(): string

Returns string

Methods

activeContextChanged

activeContextChanged(): Promise<void>

Returns Promise<void>

activeContextChangedEvent

activeContextChangedEvent(
__namedParameters: { noteContext: NoteContext },
): Promise<void>

Parameters

Returns Promise<void>

callMethod

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

Parameters

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

Returns undefined | Promise<unknown>

canBeShown

canBeShown(): boolean

Returns boolean

child

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

Parameters

Returns NoteContextAwareWidget

class

class(className: string): NoteContextAwareWidget

Parameters

  • className: string

Returns NoteContextAwareWidget

cleanup

cleanup(): void

Returns void

collapsible

collapsible(): NoteContextAwareWidget

Returns NoteContextAwareWidget

contentSized

contentSized(): NoteContextAwareWidget

Returns NoteContextAwareWidget

css

css(name: string, value: string): NoteContextAwareWidget

Sets the CSS attribute of the given name to the given value.

Parameters

  • name: string

the name of the CSS attribute to set (e.g. padding-left).

  • value: string

the value of the CSS attribute to set (e.g. 12px).

Returns NoteContextAwareWidget

self for chaining.

cssBlock

cssBlock(block: string): NoteContextAwareWidget

Accepts a string of CSS to add with the widget.

Parameters

  • block: string

Returns NoteContextAwareWidget

for chaining

doRender

doRender(): void

Method used for rendering the widget.

Your class should override this method. The method is expected to create a this.$widget containing jQuery object

Returns void

filling

filling(): NoteContextAwareWidget

Returns NoteContextAwareWidget

frocaReloadedEvent

frocaReloadedEvent(): Promise<void>

Returns Promise<void>

getClosestNtxId

getClosestNtxId(): undefined | null | string

Returns undefined | null | string

getPosition

getPosition(): number

Returns number

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>

id

id(id: string): NoteContextAwareWidget

Parameters

  • id: string

Returns NoteContextAwareWidget

isActiveNoteContext

isActiveNoteContext(): boolean

Returns boolean

isEnabled

isEnabled(): undefined | null | boolean

Indicates if the widget is enabled. Widgets are enabled by default. Generally setting this to false will cause the widget not to be displayed, however it will still be available on the DOM but hidden.

If the widget is not enabled, it will not receive refreshWithNote updates.

Returns undefined | null | boolean

true when an active note exists

isHiddenExt

isHiddenExt(): boolean

Returns boolean

isHiddenInt

isHiddenInt(): boolean

Returns boolean

isNote

isNote(noteId: string): boolean

Parameters

  • noteId: string

Returns boolean

isNoteContext

isNoteContext(
ntxId: undefined | null | string | string[],
): undefined | null | boolean | ""

Parameters

  • ntxId: undefined | null | string | string[]

Returns undefined | null | boolean | ""

isVisible

isVisible(): boolean

Returns boolean

logRenderingError

logRenderingError(e: Error): void

Parameters

  • e: Error

Returns void

noteSwitched

noteSwitched(): Promise<void>

Returns Promise<void>

noteSwitchedAndActivatedEvent

noteSwitchedAndActivatedEvent(
__namedParameters: NoteSwitchedContext,
): Promise<void>

Parameters

Returns Promise<void>

noteSwitchedEvent

noteSwitchedEvent(__namedParameters: NoteSwitchedContext): Promise<void>

Parameters

Returns Promise<void>

noteTypeMimeChangedEvent

noteTypeMimeChangedEvent(__namedParameters: { noteId: string }): Promise<void>

Parameters

  • __namedParameters: { noteId: string }

Returns Promise<void>

optChild

optChild(condition: boolean, ...components: default[]): NoteContextAwareWidget

Conditionally adds the given components as children to this component.

Parameters

  • condition: boolean

whether to add the components.

the components to be added as children to this component provided the condition is truthy.

Returns NoteContextAwareWidget

self for chaining.

optCss

optCss(condition: boolean, name: string, value: string): NoteContextAwareWidget

Sets the CSS attribute of the given name to the given value, but only if the condition provided is truthy.

Parameters

  • condition: boolean

true in order to apply the CSS, false to ignore it.

  • name: string

the name of the CSS attribute to set (e.g. padding-left).

  • value: string

the value of the CSS attribute to set (e.g. 12px).

Returns NoteContextAwareWidget

self for chaining.

refresh

refresh(): Promise<void>

Returns Promise<void>

refreshWithNote

refreshWithNote(note: undefined | null | FNote): Promise<void>

Override this method to be able to refresh your widget with each note.

Parameters

  • note: undefined | null | FNote

Returns Promise<void>

remove

remove(): void

Returns void

render

render(): JQuery<HTMLElement>

Returns JQuery<HTMLElement>

setNoteContextEvent

setNoteContextEvent(__namedParameters: { noteContext: NoteContext }): void

Parameters

Returns void

setParent

setParent(parent: TypedComponent<any>): NoteContextAwareWidget

Parameters

Returns NoteContextAwareWidget

toggleExt

toggleExt(show: undefined | null | boolean | ""): void

Parameters

  • show: undefined | null | boolean | ""

Returns void

toggleInt

toggleInt(show: undefined | null | boolean): void

Parameters

  • show: undefined | null | boolean

Returns void

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>

Settings

Member Visibility

  • Protected
  • Inherited
  • External

ThemeOSLightDark

On This Page

Constructors constructor Properties _noteId_position$widgetattrschildrencomponentIdinitializednoteContextparent Accessors hoistedNoteIdnotenoteIdnotePathntxIdpositionsanitizedClassName Methods activeContextChangedactiveContextChangedEventcallMethodcanBeShownchildclasscleanupcollapsiblecontentSizedcsscssBlockdoRenderfillingfrocaReloadedEventgetClosestNtxIdgetPositionhandleEventhandleEventInChildrenidisActiveNoteContextisEnabledisHiddenExtisHiddenIntisNoteisNoteContextisVisiblelogRenderingErrornoteSwitchednoteSwitchedAndActivatedEventnoteSwitchedEventnoteTypeMimeChangedEventoptChildoptCssrefreshrefreshWithNoteremoverendersetNoteContextEventsetParenttoggleExttoggleInttriggerCommandtriggerEvent