Command
Abstract Class defined in ui/Command.js#28

Commands are used to perform UI triggered actions on the document. For instance the ui/AnnotationCommand takes care of creating, expanding, truncating and deleting annotations such as strong and emphasis. It does so by determining a commandState by inspecting the current selection, which is used to parametrize the corresponding tool component. E.g. the strong tool gets active and clickable in create mode when a word in the text is selected. Triggered by a click on the tool, or a keyboard shortcut, the command gets executed by running the code specified in the execute method.

Example

    class MyCommand extends Command {
      getCommandState(params, context) {
        // determine commandState based on params and context
      }

      execute(params, context) {
        // perform operations on the document
      }
    }

new Command()
Constructor defined in ui/Command.js#36

Construcutor is only used internally.

this.getName()
Method defined in ui/Command.js#52

Get the command name specified at command registration. See util/Configurator#addCommand

this.getCommandState(params, context)
Method defined in ui/Command.js#82

Determines command state, based on passed params and context. The command state is usually used as props for tool components.

Parameters

params | Object | Provides documentSession, selectionState, surface, selection
context | Object | Provides app-specific context.

Example

This shows the implementation of EditAnnotationCommand#getCommandState

    getCommandState(params) {
      const sel = this._getSelection(params)
      const annos = params.selectionState.getAnnotationsForType(this.config.nodeType)
      const newState = {
        disabled: true,
      }

      if (annos.length === 1 && sel.isPropertySelection()) {
        newState.disabled = false
        newState.node = annos[0]
      }
    }

this.execute(params, context)
Method defined in ui/Command.js#94

Execute command and perform operations on the document

Parameters

params | Object | Provides commandState, documentSession, selectionState, surface, selection
context | Object | Provides app-specific context.

Returns

Object | info object with execution details