All files / src/markdown extension.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 45                              40x               14x       14x           14x   14x                  
import { CommandToolbarButton } from '@jupyterlab/apputils';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { FileEditorPanel } from '@jupyterlab/fileeditor';
import { CommandRegistry } from '@lumino/commands';
import { IDisposable, DisposableDelegate } from '@lumino/disposable';
 
import { CommandIds, MARKDOWN_MIMETYPES } from '../tokens';
 
export class EditorDeckExtension
  implements
    DocumentRegistry.IWidgetExtension<FileEditorPanel, DocumentRegistry.ICodeModel>
{
  private _commands: CommandRegistry;
 
  constructor(options: EditorDeckExtension.IOptions) {
    this._commands = options.commands;
  }
 
  createNew(
    panel: FileEditorPanel,
    context: DocumentRegistry.IContext<DocumentRegistry.ICodeModel>,
  ): IDisposable {
    /* istanbul ignore if */
    if (!MARKDOWN_MIMETYPES.includes(context.model.mimeType)) {
      return new DisposableDelegate(() => {});
    }
 
    const button = new CommandToolbarButton({
      commands: this._commands,
      label: '',
      id: CommandIds.toggle,
    });
 
    panel.toolbar.insertItem(5, 'deck', button);
 
    return new DisposableDelegate(() => button.dispose());
  }
}
 
export namespace EditorDeckExtension {
  export interface IOptions {
    commands: CommandRegistry;
  }
}