From 32901449b96627bee4df3ed6349c8cf3488951f7 Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Thu, 7 Feb 2019 11:06:16 -0800 Subject: [PATCH] Updates for JupyterLab 1.0-prelease. --- README.md | 2 +- package.json | 18 ++++----- src/index.ts | 29 +++++++------- src/pagenumber.tsx | 97 ++++++++++++++++++++++++++-------------------- tslint.json | 2 +- 5 files changed, 83 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 5bf59a5..e8c3b47 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ For more advanced usage documentation, see [here](docs/advanced.md). ## Requirements -- JupyterLab 0.35 +- JupyterLab 1.0 - Python >= 3.6 - An application that can compile `.tex` files to PDF (e.g., `pdflatex`, `xelatex`; use `pdflatex.exe` on Windows with MiKTeX). This application must be available as a command in the same environment as the notebook server. - An application that can process `.bib` files for producing bibliographies. As with the LaTeX command, this must be available in the same environment as the notebook server. diff --git a/package.json b/package.json index 5bfbe1f..129bb1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jupyterlab/latex", - "version": "0.6.1", + "version": "1.0.0-pre", "description": "JupyterLab extension for running LaTeX", "author": "M Pacer & Ian Rose", "files": [ @@ -34,14 +34,14 @@ "watch": "tsc -w" }, "dependencies": { - "@jupyterlab/application": "^0.19.1", - "@jupyterlab/apputils": "^0.19.1", - "@jupyterlab/codeeditor": "^0.19.1", - "@jupyterlab/coreutils": "^2.2.1", - "@jupyterlab/docmanager": "^0.19.1", - "@jupyterlab/docregistry": "^0.19.1", - "@jupyterlab/fileeditor": "^0.19.1", - "@jupyterlab/services": "^3.2.1", + "@jupyterlab/application": "^1.0.0-alpha.3", + "@jupyterlab/apputils": "^1.0.0-alpha.3", + "@jupyterlab/codeeditor": "^1.0.0-alpha.3", + "@jupyterlab/coreutils": "^3.0.0-alpha.3", + "@jupyterlab/docmanager": "^1.0.0-alpha.3", + "@jupyterlab/docregistry": "^1.0.0-alpha.3", + "@jupyterlab/fileeditor": "^1.0.0-alpha.3", + "@jupyterlab/services": "^4.0.0-alpha.3", "@phosphor/coreutils": "^1.3.0", "@phosphor/disposable": "^1.1.2", "@phosphor/domutils": "^1.1.2", diff --git a/src/index.ts b/src/index.ts index 0347366..2132cd4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,9 +2,10 @@ // Distributed under the terms of the Modified BSD License. import { + ILabShell, ILayoutRestorer, - JupyterLab, - JupyterLabPlugin + JupyterFrontEnd, + JupyterFrontEndPlugin } from '@jupyterlab/application'; import { @@ -87,13 +88,14 @@ type ISynctexViewOptions = CodeEditor.IPosition; type ISynctexEditOptions = PDFJSViewer.IPosition; /** - * The JupyterLab plugin for the LaTeX extension. + * The JupyterFrontEnd plugin for the LaTeX extension. */ -const latexPlugin: JupyterLabPlugin = { +const latexPlugin: JupyterFrontEndPlugin = { id: latexPluginId, requires: [ IDocumentManager, IEditorTracker, + ILabShell, ILayoutRestorer, IPDFJSTracker, ISettingRegistry, @@ -199,9 +201,10 @@ function synctexViewRequest( * Activate the file browser. */ function activateLatexPlugin( - app: JupyterLab, + app: JupyterFrontEnd, manager: IDocumentManager, editorTracker: IEditorTracker, + shell: ILabShell, restorer: ILayoutRestorer, pdfTracker: IPDFJSTracker, settingRegistry: ISettingRegistry, @@ -293,7 +296,7 @@ function activateLatexPlugin( errorPanel = null; }); // Add the error panel to the main area. - app.shell.addToMainArea(errorPanel, { + shell.add(errorPanel, 'main', { ref: widget.id, mode: 'split-bottom' }); @@ -330,9 +333,9 @@ function activateLatexPlugin( // Run an initial latexRequest so that the appropriate files exist, // then open them. onFileChanged().then(() => { - if (!errorPanel) { - findOpenOrRevealPDF(); - } + if (!errorPanel) { + findOpenOrRevealPDF(); + } }); const cleanupPreviews = () => { @@ -427,7 +430,7 @@ function activateLatexPlugin( * Add commands, keyboard shortcuts, and menu items for SyncTeX-related things. */ function addSynctexCommands( - app: JupyterLab, + app: JupyterFrontEnd, editorTracker: IEditorTracker, pdfTracker: IPDFJSTracker, serverSettings: ServerConnection.ISettings @@ -578,7 +581,7 @@ const FACTORY = 'PDFJS'; /** * The pdf file handler extension. */ -const pdfjsPlugin: JupyterLabPlugin = { +const pdfjsPlugin: JupyterFrontEndPlugin = { activate: activatePDFJS, id: '@jupyterlab/pdfjs-extension:plugin', requires: [ILayoutRestorer], @@ -587,7 +590,7 @@ const pdfjsPlugin: JupyterLabPlugin = { }; function activatePDFJS( - app: JupyterLab, + app: JupyterFrontEnd, restorer: ILayoutRestorer ): IPDFJSTracker { const namespace = 'pdfjs-widget'; @@ -631,7 +634,7 @@ function activatePDFJS( /** * Export the plugins as default. */ -const plugins: JupyterLabPlugin[] = [latexPlugin, pdfjsPlugin]; +const plugins: JupyterFrontEndPlugin[] = [latexPlugin, pdfjsPlugin]; export default plugins; /** diff --git a/src/pagenumber.tsx b/src/pagenumber.tsx index aac50e4..faaf85e 100644 --- a/src/pagenumber.tsx +++ b/src/pagenumber.tsx @@ -1,47 +1,15 @@ -import { ReactElementWidget } from '@jupyterlab/apputils'; +import { ReactWidget } from '@jupyterlab/apputils'; import * as React from 'react'; -/** - * React properties for page number component. - */ -interface IProps { - /** - * The PDF viewer. - */ - viewer: any; -} - -/** - * React state for page number component. - */ -interface IState { - /** - * The label of the current page. - */ - currentPageLabel?: string; - - /** - * The index of the current page in the document. - */ - currentPageNumber: number; - - /** - * The number of pages of the document. - */ - pagesCount: number; - - /** - * The string inserted by user in the input element. - */ - userInput: string | null; -} - /** * Page number React component. */ -class PageNumberComponent extends React.Component { - public state: IState = { +class PageNumberComponent extends React.Component< + PageNumberComponent.IProps, + PageNumberComponent.IState +> { + public state: PageNumberComponent.IState = { currentPageNumber: 0, pagesCount: 0, userInput: null @@ -163,11 +131,58 @@ class PageNumberComponent extends React.Component { } } +/** + * A namespace for PageNumberComponent statics. + */ +export namespace PageNumberComponent { + /** + * React properties for page number component. + */ + export interface IProps { + /** + * The PDF viewer. + */ + viewer: any; + } + + /** + * React state for page number component. + */ + export interface IState { + /** + * The label of the current page. + */ + currentPageLabel?: string; + + /** + * The index of the current page in the document. + */ + currentPageNumber: number; + + /** + * The number of pages of the document. + */ + pagesCount: number; + + /** + * The string inserted by user in the input element. + */ + userInput: string | null; + } +} + /** * Phosphor Widget version of PageNumberComponent. */ -export class PageNumberWidget extends ReactElementWidget { - constructor(props: IProps) { - super(); +export class PageNumberWidget extends ReactWidget { + constructor(props: PageNumberComponent.IProps) { + super(); + this._props = props; } + + render() { + return ; + } + + private _props: PageNumberComponent.IProps; } diff --git a/tslint.json b/tslint.json index f75f9a3..7e8e4b8 100644 --- a/tslint.json +++ b/tslint.json @@ -60,7 +60,7 @@ "check-whitespace" ], "one-variable-per-declaration": [true, "ignore-for-loop"], - "quotemark": [true, "single", "avoid-escape"], + "quotemark": [true, "single", "avoid-escape", "jsx-double"], "radix": true, "semicolon": [true, "always", "ignore-bound-class-methods"], "switch-default": true,