Просмотр исходного кода

Merge pull request #9067 from bollwyvl/add-codemirror-singleton

Add codemirror singleton plugin
Jason Grout 4 лет назад
Родитель
Сommit
0aab1cd037

+ 1 - 0
dev_mode/package.json

@@ -251,6 +251,7 @@
       "@jupyterlab/application",
       "@jupyterlab/apputils",
       "@jupyterlab/codeeditor",
+      "@jupyterlab/codemirror",
       "@jupyterlab/completer",
       "@jupyterlab/console",
       "@jupyterlab/coreutils",

+ 27 - 2
packages/codemirror-extension/src/index.ts

@@ -19,7 +19,8 @@ import {
   editorServices,
   EditorSyntaxStatus,
   CodeMirrorEditor,
-  Mode
+  Mode,
+  ICodeMirror
 } from '@jupyterlab/codemirror';
 
 import { IDocumentWidget } from '@jupyterlab/docregistry';
@@ -47,6 +48,13 @@ namespace CommandIDs {
   export const goToLine = 'codemirror:go-to-line';
 }
 
+/** The CodeMirror singleton. */
+const codemirrorSingleton: JupyterFrontEndPlugin<ICodeMirror> = {
+  id: '@jupyterlab/codemirror-extension:codemirror',
+  provides: ICodeMirror,
+  activate: activateCodeMirror
+};
+
 /**
  * The editor services.
  */
@@ -116,7 +124,8 @@ export const editorSyntaxStatus: JupyterFrontEndPlugin<void> = {
 const plugins: JupyterFrontEndPlugin<any>[] = [
   commands,
   services,
-  editorSyntaxStatus
+  editorSyntaxStatus,
+  codemirrorSingleton
 ];
 export default plugins;
 
@@ -135,6 +144,22 @@ function activateEditorServices(app: JupyterFrontEnd): IEditorServices {
   return editorServices;
 }
 
+/**
+ * Simplest implementation of the CodeMirror singleton provider.
+ */
+class CodeMirrorSingleton implements ICodeMirror {
+  get CodeMirror() {
+    return CodeMirror;
+  }
+}
+
+/**
+ * Set up the CodeMirror singleton.
+ */
+function activateCodeMirror(app: JupyterFrontEnd): ICodeMirror {
+  return new CodeMirrorSingleton();
+}
+
 /**
  * Set up the editor widget menu and commands.
  */

+ 3 - 1
packages/codemirror/src/index.ts

@@ -13,6 +13,8 @@ export * from './factory';
 export * from './mimetype';
 export * from './syntaxstatus';
 
+export * from './tokens';
+
 /**
  * The default editor services.
  */
@@ -23,7 +25,7 @@ export const editorServices: IEditorServices = {
 
 /**
  * FIXME-TRANS: Maybe an option to be able to pass a translator to the factories?
- * 
+ *
 
 export function getEditorServices(translator: ITranslator): IEditorServices {
   return {

+ 23 - 0
packages/codemirror/src/tokens.ts

@@ -0,0 +1,23 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import { Token } from '@lumino/coreutils';
+
+import CodeMirror from 'codemirror';
+
+/* tslint:disable */
+/**
+ * The CodeMirror token.
+ */
+export const ICodeMirror = new Token<ICodeMirror>(
+  '@jupyterlab/codemirror:ICodeMirror'
+);
+/* tslint:enable */
+
+/** The CodeMirror interface. */
+export interface ICodeMirror {
+  /**
+   * A singleton CodeMirror module, rexported.
+   */
+  CodeMirror: typeof CodeMirror;
+}