all files / ui/ EditAnnotationCommand.js

72.73% Statements 8/11
42.86% Branches 3/7
75% Functions 3/4
72.73% Lines 8/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                    205×   205×                     761× 761× 761×     761×       761×           761×          
import Command from './Command'
 
/**
  Used for edit tools or property annotations (e.g. EditLinkTool)
 
  @class
*/
class EditAnnotationCommand extends Command {
 
  constructor(...args) {
    super(...args)
 
    Iif (!this.config.nodeType) {
      throw new Error("'nodeType' is required")
    }
  }
 
  /**
    Get command state
 
    @return {Object} object with `disabled` and `node` properties
  */
  getCommandState(params) {
    let sel = this._getSelection(params)
    let annos = this._getAnnotationsForSelection(params)
    let newState = {
      disabled: true,
    }
    Iif (annos.length === 1 && sel.isPropertySelection() && sel.isCollapsed()) {
      newState.disabled = false
      newState.node = annos[0]
    }
    return newState
  }
 
  execute(params) { } // eslint-disable-line
 
  _getAnnotationsForSelection(params) {
    return params.selectionState.getAnnotationsForType(this.config.nodeType)
  }
}
 
export default EditAnnotationCommand