Prechádzať zdrojové kódy

Modernize clipboard plugin.

Afshin Darian 8 rokov pred
rodič
commit
c1d67fe8f3
2 zmenil súbory, kde vykonal 33 pridanie a 11 odobranie
  1. 5 5
      src/clipboard/index.ts
  2. 28 6
      src/clipboard/plugin.ts

+ 5 - 5
src/clipboard/index.ts

@@ -37,16 +37,16 @@ function generateClipboardEvent(node: HTMLElement, type='copy'): void {
   // http://stackoverflow.com/a/5210367
 
   // Identify selected text.
-  var sel = window.getSelection();
+  let sel = window.getSelection();
 
   // Save the current selection.
-  var savedRanges: any[] = [];
-  for (var i = 0, len = sel.rangeCount; i < len; ++i) {
+  let savedRanges: any[] = [];
+  for (let i = 0, len = sel.rangeCount; i < len; ++i) {
     savedRanges[i] = sel.getRangeAt(i).cloneRange();
   }
 
   // Select the node content.
-  var range = document.createRange();
+  let range = document.createRange();
   range.selectNodeContents(node);
   sel.removeAllRanges();
   sel.addRange(range);
@@ -57,7 +57,7 @@ function generateClipboardEvent(node: HTMLElement, type='copy'): void {
   // Restore the previous selection.
   sel = window.getSelection();
   sel.removeAllRanges();
-  for (var i = 0, len = savedRanges.length; i < len; ++i) {
+  for (let i = 0, len = savedRanges.length; i < len; ++i) {
     sel.addRange(savedRanges[i]);
   }
 }

+ 28 - 6
src/clipboard/plugin.ts

@@ -2,18 +2,40 @@
 // Distributed under the terms of the Modified BSD License.
 
 import {
-  MimeData as IClipboard
-} from 'phosphor-dragdrop';
+  MimeData
+} from 'phosphor/lib/core/mimedata';
+
+import {
+  Token
+} from 'phosphor/lib/core/token';
+
+import {
+  JupyterLabPlugin
+} from '../application';
+
+
+/* tslint:disable */
+/**
+ * The clipboard token.
+ */
+export
+const IClipboard = new Token<IClipboard>('jupyter.services.main-menu');
+/* tslint:enable */
+
+
+/**
+ * The clipboard interface.
+ */
+export
+interface IClipboard extends MimeData {}
 
 
 /**
  * The clipboard provider.
  */
 export
-const clipboardProvider = {
+const clipboardProvider: JupyterLabPlugin<IClipboard> = {
   id: 'jupyter.services.clipboard',
   provides: IClipboard,
-  resolve: () => {
-    return new IClipboard();
-  }
+  activate: (): IClipboard => new MimeData()
 };