All files / src plugin.ts

100% Statements 26/26
100% Branches 12/12
100% Functions 5/5
100% Lines 26/26

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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133                                                              40x                               40x     40x   40x                 796x     40x   40x   40x 40x 40x 40x 40x     40x       40x                   40x 6x   34x 34x         34x   34x             40x                     40x 40x       16x   40x   40x          
import { IFontManager } from '@deathbeds/jupyterlab-fonts';
import {
  JupyterFrontEnd,
  JupyterFrontEndPlugin,
  ILabShell,
  ILayoutRestorer,
} from '@jupyterlab/application';
import { ICommandPalette } from '@jupyterlab/apputils';
import { IDocumentManager } from '@jupyterlab/docmanager';
import { INotebookTools } from '@jupyterlab/notebook';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { IStatusBar, StatusBar } from '@jupyterlab/statusbar';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
import { Widget } from '@lumino/widgets';
 
import { DeckManager } from './manager';
import { EditorDeckExtension } from './markdown/extension';
import { SimpleMarkdownPresenter } from './markdown/presenter';
import { NotebookDeckExtension } from './notebook/extension';
import { NotebookPresenter } from './notebook/presenter';
import {
  NS,
  IDeckManager,
  CommandIds,
  CATEGORY,
  PLUGIN_ID,
  NOTEBOOK_FACTORY,
} from './tokens';
 
import '../style/index.css';
 
const plugin: JupyterFrontEndPlugin<IDeckManager> = {
  id: `${NS}:plugin`,
  requires: [ITranslator, ISettingRegistry, IFontManager],
  optional: [ILabShell, ILayoutRestorer, ICommandPalette, IStatusBar],
  provides: IDeckManager,
  autoStart: true,
  activate: (
    app: JupyterFrontEnd,
    translator: ITranslator,
    settings: ISettingRegistry,
    fonts: IFontManager,
    labShell?: ILabShell,
    restorer?: ILayoutRestorer,
    palette?: ICommandPalette,
    statusbar?: IStatusBar,
  ) => {
    const { commands, shell } = app;
 
    const theStatusBar =
      statusbar instanceof StatusBar ? statusbar : /* istanbul ignore next */ null;
 
    const manager = new DeckManager({
      commands,
      shell,
      labShell: labShell || null,
      translator: (translator || /* istanbul ignore next */ nullTranslator).load(NS),
      statusbar: theStatusBar,
      fonts,
      settings: settings.load(PLUGIN_ID),
      appStarted: async () =>
        await Promise.all([app.started, ...(restorer ? [restorer.restored] : [])]),
    });
 
    const { __ } = manager;
 
    let category = __(CATEGORY);
 
    if (palette) {
      palette.addItem({ command: CommandIds.start, category });
      palette.addItem({ command: CommandIds.stop, category });
      palette.addItem({ command: CommandIds.showLayover, category });
      palette.addItem({ command: CommandIds.hideLayover, category });
    }
 
    return manager;
  },
};
 
const notebookPlugin: JupyterFrontEndPlugin<void> = {
  id: `${NS}:notebooks`,
  requires: [IDeckManager],
  optional: [INotebookTools],
  autoStart: true,
  activate: (
    app: JupyterFrontEnd,
    decks: IDeckManager,
    notebookTools?: INotebookTools,
  ) => {
    if (!notebookTools) {
      return;
    }
    const { commands } = app;
    const presenter = new NotebookPresenter({
      manager: decks,
      notebookTools,
      commands,
    });
    decks.addPresenter(presenter);
 
    app.docRegistry.addWidgetExtension(
      NOTEBOOK_FACTORY,
      new NotebookDeckExtension({ commands, presenter }),
    );
  },
};
 
const simpleMarkdownPlugin: JupyterFrontEndPlugin<void> = {
  id: `${NS}:simple-markdown`,
  requires: [IDeckManager, IDocumentManager],
  optional: [ILabShell],
  autoStart: true,
  activate: (
    app: JupyterFrontEnd,
    decks: IDeckManager,
    docManager: IDocumentManager,
    labShell?: ILabShell,
  ) => {
    const { commands } = app;
    const presenter = new SimpleMarkdownPresenter({
      manager: decks,
      commands,
      docManager,
      activateWidget: (widget: Widget) => labShell?.activateById(widget.node.id),
    });
    decks.addPresenter(presenter);
 
    app.docRegistry.addWidgetExtension('Editor', new EditorDeckExtension({ commands }));
  },
};
 
export default [plugin, notebookPlugin, simpleMarkdownPlugin];