Skip to content

Commit

Permalink
Merge pull request #1 from osscar-org/develop
Browse files Browse the repository at this point in the history
New extension for the JLab2.1
  • Loading branch information
dou-du authored May 23, 2020
2 parents 4075af0 + 17f417a commit 694b90d
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
dist
coverage
**/*.d.ts
tests
32 changes: 32 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/interface-name-prefix': [
'error',
{ prefixWithI: 'always' }
],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/quotes': [
'error',
'single',
{ avoidEscape: true, allowTemplateLiterals: false }
],
curly: ['error', 'all'],
eqeqeq: 'error',
'prefer-arrow-callback': 'error'
}
};
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ jobs:
python-version: '3.7'
architecture: 'x64'
- name: Install dependencies
run: python -m pip install jupyterlab==1.2.6
run: python -m pip install jupyterlab==2.1.2
- name: Build the extension
run: |
jlpm && jlpm run build
jlpm
jlpm run eslint:check
jupyter labextension install .
python -m jupyterlab.browser_check
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
**/node_modules
**/lib
**/package.json
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2020, Dou Du All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Binary file removed OSSCAR-logo.png
Binary file not shown.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ https://github.com/AixViPMaP/jlab-hide-code

## Requirements

* JupyterLab >= 1.2
* JupyterLab < 2.0
* JupyterLab >= 2.0


## Install
Expand Down
27 changes: 20 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jupyterlab-hide-code",
"version": "0.1.0",
"description": "A button in JupyterLab to hide the code cells.",
"description": "A JupyterLab extension to run and hide code cells. ",
"keywords": [
"jupyter",
"jupyterlab",
Expand All @@ -25,27 +25,40 @@
"url": "https://github.com/osscar-org/jupyterlab-hide-code.git"
},
"scripts": {

"build": "tsc",
"clean": "rimraf lib tsconfig.tsbuildinfo",

"eslint": "eslint . --ext .ts,.tsx --fix",
"eslint:check": "eslint . --ext .ts,.tsx",
"prepare": "jlpm run clean && jlpm run build",
"watch": "tsc -w"
},
"dependencies": {
"@jupyterlab/application": "^1.2.1",
"@jupyterlab/apputils": "^1.2.1",
"@jupyterlab/services": "^4.2.0",
"@jupyterlab/docregistry": "^1.2.1",
"@jupyterlab/notebook": "^1.2.1",
"@phosphor/disposable": "^1.3.1"
"@jupyterlab/application": "^2.1.0",
"@jupyterlab/apputils": "^2.1.0",
"@jupyterlab/services": "^5.1.0",
"@jupyterlab/docregistry": "^2.1.0",
"@jupyterlab/notebook": "^2.1.0",
"@lumino/disposable": "^1.3.5",
"@lumino/widgets": "^1.11.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",

"prettier": "1.16.4",
"rimraf": "^2.6.1",
"typescript": "~3.7.0"
},
"sideEffects": [
"style/*.css"
],
"jupyterlab": {

"extension": true
}
}
96 changes: 45 additions & 51 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,88 @@
import {
IDisposable, DisposableDelegate
} from '@phosphor/disposable';
import { IDisposable, DisposableDelegate } from '@lumino/disposable';

import {
PanelLayout
} from '@phosphor/widgets';
import { PanelLayout } from '@lumino/widgets';

import {
JupyterFrontEnd, JupyterFrontEndPlugin
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';

import {
ToolbarButton
} from '@jupyterlab/apputils';
import { ToolbarButton } from '@jupyterlab/apputils';

import {
DocumentRegistry
} from '@jupyterlab/docregistry';
import { DocumentRegistry } from '@jupyterlab/docregistry';

import {
NotebookActions, NotebookPanel, INotebookModel
NotebookActions,
NotebookPanel,
INotebookModel
} from '@jupyterlab/notebook';

import '../style/index.css';

const plugin: JupyterFrontEndPlugin<void> = {
id: 'jlab-hide-code:buttonPlugin',
autoStart: true,
activate
activate
};


export
class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {

createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {

let hideInputCode = () => {
NotebookActions.runAll(panel.content, context.session);
export class ButtonExtension
implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
createNew(
panel: NotebookPanel,
context: DocumentRegistry.IContext<INotebookModel>
): IDisposable {
const hideInputCode = () => {
NotebookActions.runAll(panel.content, context.sessionContext);

panel.content.widgets.forEach(cell => {
if (cell.model.type === 'code'){
let layout = cell.layout as PanelLayout;
layout.widgets[1].hide();
}
});
if (cell.model.type === 'code') {
const layout = cell.layout as PanelLayout;
layout.widgets[1].hide();
}
});
buttonHideInput.hide();
buttonShowInput.show();
buttonShowInput.show();
};
let showInputCode = () => {

const showInputCode = () => {
panel.content.widgets.forEach(cell => {
if (cell.model.type === 'code'){
let layout = cell.layout as PanelLayout;
layout.widgets[1].show();
}
});
if (cell.model.type === 'code') {
const layout = cell.layout as PanelLayout;
layout.widgets[1].show();
}
});

buttonHideInput.show();
buttonShowInput.hide();
};
let buttonHideInput = new ToolbarButton({
buttonShowInput.hide();
};

const buttonHideInput = new ToolbarButton({
className: 'myButton',
iconClassName: 'fa fa-eye-slash',
iconClass: 'fa fa-sm fa-eye-slash fontawesome-colors',
onClick: hideInputCode,
tooltip: 'Hide Input'
});
let buttonShowInput = new ToolbarButton({

const buttonShowInput = new ToolbarButton({
className: 'myButton',
iconClassName: 'fa fa-eye',
iconClass: 'fa fa-sm fa-eye fontawesome-colors',
onClick: showInputCode,
tooltip: 'Show Input'
tooltip: 'Show Input'
});

buttonShowInput.hide();
buttonShowInput.hide();

panel.toolbar.insertItem(9, 'hideInput', buttonHideInput);
panel.toolbar.insertItem(9, 'showInput', buttonShowInput);
panel.toolbar.insertItem(11, 'hideInput', buttonHideInput);
panel.toolbar.insertItem(11, 'showInput', buttonShowInput);

return new DisposableDelegate(() => {
buttonHideInput.dispose();
buttonShowInput.dispose();
buttonShowInput.dispose();
});
}

}

function activate(app: JupyterFrontEnd) {
app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension());
};
}

export default plugin;
3 changes: 3 additions & 0 deletions style/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.fontawesome-colors {
color: gray;
}

0 comments on commit 694b90d

Please sign in to comment.