Back to Trilium

Class BasicWidget

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

0.102.210.2 KB
Original Source

Class BasicWidget

This is the base widget for all other widgets.

For information on using widgets, see the tutorial {@tutorial widget_basics}.

Hierarchy (View Summary)

Index

Constructors

constructor

Properties

_noteId_position$widgetattrschildrencomponentIdinitializedparent?

Accessors

positionsanitizedClassName

Methods

callMethodcanBeShownchildclasscleanupcollapsiblecontentSizedcsscssBlockdoRenderfillinggetClosestNtxIdgetPositionhandleEventhandleEventInChildrenidisEnabledisHiddenExtisHiddenIntisVisiblelogRenderingErroroptChildoptCssremoverendersetParenttoggleExttoggleInttriggerCommandtriggerEvent

Constructors

constructor

new BasicWidget(): BasicWidget

Returns BasicWidget

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>

Optionalparent

parent?: TypedComponent<any>

Accessors

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>

canBeShown

canBeShown(): boolean

Returns boolean

child

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

Parameters

Returns BasicWidget

class

class(className: string): BasicWidget

Parameters

  • className: string

Returns BasicWidget

cleanup

cleanup(): void

Returns void

collapsible

collapsible(): BasicWidget

Returns BasicWidget

contentSized

contentSized(): BasicWidget

Returns BasicWidget

css

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

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 BasicWidget

self for chaining.

cssBlock

cssBlock(block: string): BasicWidget

Accepts a string of CSS to add with the widget.

Parameters

  • block: string

Returns BasicWidget

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(): BasicWidget

Returns BasicWidget

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): BasicWidget

Parameters

  • id: string

Returns BasicWidget

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.

Returns undefined | null | boolean

whether the widget is enabled.

isHiddenExt

isHiddenExt(): boolean

Returns boolean

isHiddenInt

isHiddenInt(): boolean

Returns boolean

isVisible

isVisible(): boolean

Returns boolean

logRenderingError

logRenderingError(e: Error): void

Parameters

  • e: Error

Returns void

optChild

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

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 BasicWidget

self for chaining.

optCss

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

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 BasicWidget

self for chaining.

remove

remove(): void

Returns void

render

render(): JQuery<HTMLElement>

Returns JQuery<HTMLElement>

setParent

setParent(parent: TypedComponent<any>): BasicWidget

Parameters

Returns BasicWidget

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$widgetattrschildrencomponentIdinitializedparent Accessors positionsanitizedClassName Methods callMethodcanBeShownchildclasscleanupcollapsiblecontentSizedcsscssBlockdoRenderfillinggetClosestNtxIdgetPositionhandleEventhandleEventInChildrenidisEnabledisHiddenExtisHiddenIntisVisiblelogRenderingErroroptChildoptCssremoverendersetParenttoggleExttoggleInttriggerCommandtriggerEvent