From eea30e3d722e143769d9e51617568942fa105e54 Mon Sep 17 00:00:00 2001 From: RRosio Date: Tue, 26 Sep 2023 07:57:59 -0700 Subject: [PATCH] adding classic shortcuts extension --- app/package.json | 3 + packages/_metapackage/package.json | 1 + packages/_metapackage/src/index.ts | 1 + packages/_metapackage/tsconfig.json | 1 + .../classic-shortcuts-extension/package.json | 57 ++++++++++ .../schema/plugin.json | 44 ++++++++ .../classic-shortcuts-extension/src/index.tsx | 106 ++++++++++++++++++ .../style/base.css | 0 .../style/index.css | 1 + .../style/index.js | 1 + .../classic-shortcuts-extension/tsconfig.json | 8 ++ 11 files changed, 223 insertions(+) create mode 100644 packages/classic-shortcuts-extension/package.json create mode 100644 packages/classic-shortcuts-extension/schema/plugin.json create mode 100644 packages/classic-shortcuts-extension/src/index.tsx create mode 100644 packages/classic-shortcuts-extension/style/base.css create mode 100644 packages/classic-shortcuts-extension/style/index.css create mode 100644 packages/classic-shortcuts-extension/style/index.js create mode 100644 packages/classic-shortcuts-extension/tsconfig.json diff --git a/app/package.json b/app/package.json index 90e116dec6..bd42dfc731 100644 --- a/app/package.json +++ b/app/package.json @@ -14,6 +14,7 @@ "@codemirror/view": "~6.15.3", "@jupyter-notebook/application": "~7.0.4", "@jupyter-notebook/application-extension": "~7.0.4", + "@jupyter-notebook/classic-shortcuts-extension": "~7.0.4", "@jupyter-notebook/console-extension": "~7.0.4", "@jupyter-notebook/docmanager-extension": "~7.0.4", "@jupyter-notebook/documentsearch-extension": "~7.0.4", @@ -118,6 +119,7 @@ "dependencies": { "@jupyter-notebook/application": "^7.0.4", "@jupyter-notebook/application-extension": "^7.0.4", + "@jupyter-notebook/classic-shortcuts-extension": "7.0.4", "@jupyter-notebook/console-extension": "^7.0.4", "@jupyter-notebook/docmanager-extension": "^7.0.4", "@jupyter-notebook/documentsearch-extension": "^7.0.4", @@ -205,6 +207,7 @@ "plugins": { "/": { "@jupyter-notebook/application-extension": true, + "@jupyter-notebook/classic-shortcuts-extension": true, "@jupyter-notebook/console-extension": true, "@jupyter-notebook/docmanager-extension": true, "@jupyter-notebook/documentsearch-extension": true, diff --git a/packages/_metapackage/package.json b/packages/_metapackage/package.json index 8ae6558278..97407e57c9 100644 --- a/packages/_metapackage/package.json +++ b/packages/_metapackage/package.json @@ -22,6 +22,7 @@ "dependencies": { "@jupyter-notebook/application": "^7.0.4", "@jupyter-notebook/application-extension": "^7.0.4", + "@jupyter-notebook/classic-shortcuts-extension": "^7.0.4", "@jupyter-notebook/console-extension": "^7.0.4", "@jupyter-notebook/docmanager-extension": "^7.0.4", "@jupyter-notebook/documentsearch-extension": "^7.0.4", diff --git a/packages/_metapackage/src/index.ts b/packages/_metapackage/src/index.ts index c41bc6c855..95e549544f 100644 --- a/packages/_metapackage/src/index.ts +++ b/packages/_metapackage/src/index.ts @@ -1,5 +1,6 @@ import '@jupyter-notebook/application'; import '@jupyter-notebook/application-extension'; +import '@jupyter-notebook/classic-shortcuts-extension'; import '@jupyter-notebook/console-extension'; import '@jupyter-notebook/docmanager-extension'; import '@jupyter-notebook/documentsearch-extension'; diff --git a/packages/_metapackage/tsconfig.json b/packages/_metapackage/tsconfig.json index c8938dcdaa..30145e4fb3 100644 --- a/packages/_metapackage/tsconfig.json +++ b/packages/_metapackage/tsconfig.json @@ -8,6 +8,7 @@ "references": [ { "path": "../application" }, { "path": "../application-extension" }, + { "path": "../classic-shortcuts-extension" }, { "path": "../console-extension" }, { "path": "../docmanager-extension" }, { "path": "../documentsearch-extension" }, diff --git a/packages/classic-shortcuts-extension/package.json b/packages/classic-shortcuts-extension/package.json new file mode 100644 index 0000000000..1fe50c28c8 --- /dev/null +++ b/packages/classic-shortcuts-extension/package.json @@ -0,0 +1,57 @@ +{ + "name": "@jupyter-notebook/classic-shortcuts-extension", + "version": "7.0.4", + "description": "Jupyter Notebook - Classic Shortcuts Extension", + "homepage": "https://github.com/jupyter/notebook", + "bugs": { + "url": "https://github.com/jupyter/notebook/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/jupyter/notebook.git" + }, + "license": "BSD-3-Clause", + "author": "Project Jupyter", + "sideEffects": [ + "style/**/*.css", + "style/index.js" + ], + "main": "lib/index.js", + "types": "lib/index.d.ts", + "style": "style/index.css", + "directories": { + "lib": "lib/" + }, + "files": [ + "lib/*.d.ts", + "lib/*.js.map", + "lib/*.js", + "schema/*.json", + "style/**/*.css", + "style/index.js" + ], + "scripts": { + "build": "tsc -b", + "build:prod": "tsc -b", + "clean": "rimraf lib && rimraf tsconfig.tsbuildinfo", + "docs": "typedoc src", + "watch": "tsc -b --watch" + }, + "dependencies": { + "@jupyter-notebook/application": "^7.0.4", + "@jupyterlab/application": "^4.0.6", + "@jupyterlab/apputils": "^4.1.6" + }, + "devDependencies": { + "rimraf": "^3.0.2", + "typescript": "~5.0.2" + }, + "publishConfig": { + "access": "public" + }, + "jupyterlab": { + "extension": true, + "schemaDir": "schema" + }, + "styleModule": "style/index.js" +} diff --git a/packages/classic-shortcuts-extension/schema/plugin.json b/packages/classic-shortcuts-extension/schema/plugin.json new file mode 100644 index 0000000000..d4b72a41cc --- /dev/null +++ b/packages/classic-shortcuts-extension/schema/plugin.json @@ -0,0 +1,44 @@ +{ + "jupyter.lab.shortcuts": [ + { + "command": "documentsearch:startWithReplace", + "keys": ["F"], + "selector": ".jp-mod-searchable :focus:not(:read-write)" + }, + { + "command": "apputils:display-shortcuts", + "keys": ["H"], + "selector": "body :focus:not(:read-write)" + }, + { + "command": "apputils:activate-command-palette", + "keys": ["P"], + "selector": "body :focus:not(:read-write)" + }, + { + "command": "classic:toggle-output-scrolling", + "keys": ["Shift O"], + "selector": "body :focus:not(:read-write)" + }, + { + "command": "classic:toggle-collapse-output", + "keys": ["O"], + "selector": "body :focus:not(:read-write)" + }, + { + "command": "notebook:toggle-all-cell-line-numbers", + "keys": ["L"], + "selector": "body :focus:not(:read-write)" + }, + { + "command": "filebrowser:paste", + "keys": ["Shift V"], + "selector": ".jp-DirListing-content .jp-DirListing-itemText" + } + ], + "title": "Jupyter Notebook Classic Shortcuts Extension Entries", + "description": "Jupyter Notebook Classic Shortcuts Extension Entries", + "type": "object", + "properties": {}, + "additionalProperties": false +} diff --git a/packages/classic-shortcuts-extension/src/index.tsx b/packages/classic-shortcuts-extension/src/index.tsx new file mode 100644 index 0000000000..fd18cea140 --- /dev/null +++ b/packages/classic-shortcuts-extension/src/index.tsx @@ -0,0 +1,106 @@ +import { + JupyterFrontEnd, + JupyterFrontEndPlugin, +} from '@jupyterlab/application'; + +import { ICommandPalette } from '@jupyterlab/apputils'; + +/** + * Initialization the functionality for the Classic Shortcuts extension. + */ +const classicShortcutsPlugin: JupyterFrontEndPlugin = { + id: 'classic-shortcuts:plugin', + description: 'A JupyterLab extension.', + autoStart: false, + requires: [ICommandPalette], + activate: (app: JupyterFrontEnd, palette: ICommandPalette) => { + const { commands } = app; + + const toggle_collapse_output_command = 'classic:toggle-collapse-output'; + const toggle_autoscroll_output_command = 'classic:toggle-output-scrolling'; + const toggle_line_numbers_command = 'classic:toggle-line-numbers'; + + // Add a command to enable/disable collapse output + commands.addCommand(toggle_collapse_output_command, { + label: 'Execute classic:toggle-collapse-output Command', + caption: 'Execute classic:toggle-collapse-output Command', + execute: (args: any) => { + console.log('classic:toggle-collapse-output has been called'); + + const searchActive = document.querySelector( + '.jp-mod-active.jp-mod-selected' + ); + if (searchActive?.children) { + for (let i = 0; i < searchActive?.children.length; i++) { + const outputArea = searchActive.children[i].querySelector( + '.jp-Cell-outputArea' + ); + const placeholderArea = searchActive.children[i].querySelector( + '.jp-OutputPlaceholder' + ); + + if (outputArea) { + commands.execute('notebook:hide-cell-outputs'); + } + + if (placeholderArea) { + commands.execute('notebook:show-cell-outputs'); + } + } + } + }, + }); + + // Add a command to enable/disable autscroll output + commands.addCommand(toggle_autoscroll_output_command, { + label: 'Execute classic:toggle-output-scrolling Command', + caption: 'Execute classic:toggle-output-scrolling Command', + execute: (args: any) => { + console.log('classic:toggle-output-scrolling has been called.'); + // if the output has auto-scroll enabled, disable it and vice-versa + const searchActive = document.querySelector( + '.jp-mod-active.jp-mod-selected.jp-mod-outputsScrolled' + ); + if (searchActive) { + commands.execute('notebook:disable-output-scrolling'); + } else { + commands.execute('notebook:enable-output-scrolling'); + } + }, + }); + + // Add a command to enable/disable line numbers + commands.addCommand(toggle_line_numbers_command, { + label: 'Execute classic:toggle-line-numbers Command', + caption: 'Execute classic:toggle-line-numbers Command', + execute: (args: any) => { + console.log('classic:toggle-line-numbers has been called.'); + // if the output has auto-scroll enabled, disable it and vice-versa + const searchActive = document.querySelector( + '.jp-mod-active.jp-mod-selected' + ); + if (searchActive) { + commands.execute('notebook:disable-output-scrolling'); + } + }, + }); + + // Add the commands to the command palette + const category = 'Classic Notebook Shortcuts'; + palette.addItem({ + command: toggle_collapse_output_command, + category, + args: { origin: 'from palette ' }, + }); + + palette.addItem({ + command: toggle_autoscroll_output_command, + category, + args: { origin: 'from palette ' }, + }); + + console.log('Classic Shortcuts extension is activated!'); + }, +}; + +export default classicShortcutsPlugin; diff --git a/packages/classic-shortcuts-extension/style/base.css b/packages/classic-shortcuts-extension/style/base.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/classic-shortcuts-extension/style/index.css b/packages/classic-shortcuts-extension/style/index.css new file mode 100644 index 0000000000..f5246e6669 --- /dev/null +++ b/packages/classic-shortcuts-extension/style/index.css @@ -0,0 +1 @@ +@import url('./base.css'); diff --git a/packages/classic-shortcuts-extension/style/index.js b/packages/classic-shortcuts-extension/style/index.js new file mode 100644 index 0000000000..a028a76408 --- /dev/null +++ b/packages/classic-shortcuts-extension/style/index.js @@ -0,0 +1 @@ +import './base.css'; diff --git a/packages/classic-shortcuts-extension/tsconfig.json b/packages/classic-shortcuts-extension/tsconfig.json new file mode 100644 index 0000000000..703dc74a95 --- /dev/null +++ b/packages/classic-shortcuts-extension/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfigbase", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src" + }, + "include": ["src/**/*"] + }