Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Action<Data>

Actions model "things the user can do." These can be contextual menu items, menu items, buttons, keybindings, etc. The base class is always enabled but derived classes can set their own enabled state depending on whatever conditions they choose.

Type parameters

  • Data

Hierarchy

Index

Constructors

constructor

  • new Action(editor: EditorAPI, desc: string, abbreviatedDesc: string | undefined, icon?: string, needsInput?: boolean): Action
  • Parameters

    • editor: EditorAPI

      The editor to which this action belongs.

    • desc: string

      A simple string description of the action.

    • abbreviatedDesc: string | undefined

      An abbreviated description, suitable to put into a button, for instance.

    • Default value icon: string = ""

      HTML code that represents an icon for this action. This can be a simple string or something more complex.

    • Default value needsInput: boolean = false

      Indicates whether this action needs input from the user. For instance, an action which brings up a modal dialog to ask something of the user must have this parameter set to true. It is important to record whether an action needs input because, to take one example, the autoinsert logic will try to insert automatically any element it can. However, doing this for elements that need user input will just confuse the user (or could cause a crash). Therefore, it is important that the insertion operations for such elements be marked with needsInput set to true so that the autoinsert logic backs off from trying to insert these elements.

    Returns Action

Properties

Protected abbreviatedDesc

abbreviatedDesc: string | undefined

An abbreviated description, suitable to put into a button, for instance.

boundHandler

boundHandler: function

Type declaration

    • (this: Action<Data>, ev: Event): void
    • Parameters

      • this: Action<Data>
      • ev: Event

      Returns void

boundTerminalHandler

boundTerminalHandler: function

Type declaration

    • (this: Action<Data>, ev: Event): boolean
    • Parameters

      • this: Action<Data>
      • ev: Event

      Returns boolean

Protected desc

desc: string

A simple string description of the action.

editor

editor: EditorAPI

The editor to which this action belongs.

Protected icon

icon: string

HTML code that represents an icon for this action. This can be a simple string or something more complex.

needsInput

needsInput: boolean

Indicates whether this action needs input from the user. For instance, an action which brings up a modal dialog to ask something of the user must have this parameter set to true. It is important to record whether an action needs input because, to take one example, the autoinsert logic will try to insert automatically any element it can. However, doing this for elements that need user input will just confuse the user (or could cause a crash). Therefore, it is important that the insertion operations for such elements be marked with needsInput set to true so that the autoinsert logic backs off from trying to insert these elements.

Methods

eventHandler

  • An event handler. By default just calls execute. You probably want to use boundHandler rather than rebind this method. This handler always returns undefined and calls preventDefault() on the event passed to it.

    Parameters

    Returns void

Abstract execute

  • execute(data: Data): void
  • Parameters

    • data: Data

      Arbitrary data. What data must be passed is determined by the action.

    Returns void

getAbbreviatedDescription

  • getAbbreviatedDescription(): string | undefined
  • Gets the abbreviated description for this action.

    Returns string | undefined

    The abbreviated description.

getDescription

  • getDescription(): string
  • Gets a description for this action.

    Returns string

    A description for the action.

getDescriptionFor

  • getDescriptionFor(data: Data): string
  • Gets a description for this action, contextualized by the data passed.

    Parameters

    • data: Data

      The same data that would be passed to execute.

    Returns string

    The description.

getIcon

  • getIcon(): string
  • Gets the icon.

    Returns string

    The icon. This is an HTML string.

getLabelFor

  • getLabelFor(data: Data): string
  • This method returns the icon together with the description for the data passed as parameter.

    Parameters

    • data: Data

      The same data that would be passed to execute.

    Returns string

    The icon and the description, combined for presentation.

makeButton

terminalEventHandler

  • An event handler. By default just calls eventHandler. You probably want to use boundTerminalHandler rather than rebind this method. This handler always returns false and calls preventDefault() and stopPropagation on the event passed to it.

    Parameters

    Returns boolean

    False.

toString

  • toString(): string

Generated using TypeDoc