Skip to content

Commit 8140281

Browse files
authored
Merge pull request #21 from DenisaCG/launcher
added Blockly to launcher
2 parents 4680034 + 4a5d535 commit 8140281

File tree

10 files changed

+1097
-869
lines changed

10 files changed

+1097
-869
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Repo: https://github.com/google/blockly
1313

1414
## Requirements
1515

16-
* JupyterLab >= 4.0.0a0
16+
* JupyterLab == 3.4
1717

1818
## Install
1919

@@ -45,7 +45,7 @@ The `jlpm` command is JupyterLab's pinned version of
4545
`yarn` or `npm` in lieu of `jlpm` below.
4646

4747
```bash
48-
micromamba create -n blockly -c conda-forge python nodejs yarn jupyterlab==3.3 jupyter-packaging
48+
micromamba create -n blockly -c conda-forge python nodejs yarn jupyterlab==3.4 jupyter-packaging
4949
micromamba activate blockly
5050
# Clone the repo to your local environment
5151
# Change directory to the jupyterlab_blockly directory

package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,24 @@
4646
"postinstall": "patch-package"
4747
},
4848
"dependencies": {
49-
"@jupyterlab/application": "^3.3",
50-
"@jupyterlab/apputils": "^3.3",
51-
"@jupyterlab/docregistry": "^3.3",
52-
"@jupyterlab/outputarea": "^3.3",
53-
"@jupyterlab/rendermime": "^3.3",
54-
"@lumino/algorithm": "^1.9.1",
55-
"@lumino/coreutils": "^1.12.0",
56-
"@lumino/messaging": "^1.10.1",
57-
"@lumino/signaling": "^1.10.1",
58-
"@lumino/widgets": "^1.31.1",
49+
"@jupyterlab/application": "^3.4",
50+
"@jupyterlab/apputils": "^3.4",
51+
"@jupyterlab/docregistry": "^3.4",
52+
"@jupyterlab/filebrowser": "^3.4",
53+
"@jupyterlab/launcher": "^3.4",
54+
"@jupyterlab/outputarea": "^3.4",
55+
"@jupyterlab/rendermime": "^3.4",
56+
"@lumino/algorithm": "^1.9.0",
57+
"@lumino/coreutils": "^1.11.0",
58+
"@lumino/messaging": "^1.10.0",
59+
"@lumino/signaling": "^1.10.0",
60+
"@lumino/widgets": "^1.30.0",
5961
"blockly": "^7.20211209.2",
6062
"patch-package": "^6.4.7",
6163
"postinstall-postinstall": "^2.1.0"
6264
},
6365
"devDependencies": {
64-
"@jupyterlab/builder": "^3.3",
66+
"@jupyterlab/builder": "^3.4",
6567
"@typescript-eslint/eslint-plugin": "^5.12.1",
6668
"@typescript-eslint/parser": "^5.12.1",
6769
"eslint": "^8.9.0",

src/icons.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { LabIcon } from '@jupyterlab/ui-components';
2+
3+
import blockly_logo from '/style/icons/blockly_logo.svg';
4+
5+
export const blockly_icon = new LabIcon({
6+
name: 'blockly:icon/logo',
7+
svgstr: blockly_logo
8+
});

src/index.ts

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,43 @@ import {
55
} from '@jupyterlab/application';
66
import { WidgetTracker } from '@jupyterlab/apputils';
77
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
8+
import { ICommandPalette } from '@jupyterlab/apputils';
9+
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
10+
import { ILauncher } from '@jupyterlab/launcher';
811

912
import { BlocklyEditorFactory } from './factory';
1013
import { IBlocklyManager } from './token';
1114
import { BlocklyEditor } from './widget';
1215

16+
import { blockly_icon } from './icons';
17+
1318
/**
1419
* The name of the factory that creates the editor widgets.
1520
*/
1621
const FACTORY = 'Blockly editor';
1722

23+
const PALETTE_CATEGORY = 'Blockly editor';
24+
25+
namespace CommandIDs {
26+
export const createNew = 'blockly:create-new-blockly-file';
27+
}
28+
1829
/**
1930
* Initialization data for the jupyterlab-blocky extension.
2031
*/
2132
const plugin: JupyterFrontEndPlugin<IBlocklyManager> = {
2233
id: 'jupyterlab-blocky:plugin',
2334
autoStart: true,
24-
requires: [ILayoutRestorer, IRenderMimeRegistry],
35+
requires: [ILayoutRestorer, IRenderMimeRegistry, IFileBrowserFactory],
36+
optional: [ILauncher, ICommandPalette],
2537
provides: IBlocklyManager,
2638
activate: (
2739
app: JupyterFrontEnd,
2840
restorer: ILayoutRestorer,
29-
rendermime: IRenderMimeRegistry
41+
rendermime: IRenderMimeRegistry,
42+
browserFactory: IFileBrowserFactory,
43+
launcher: ILauncher | null,
44+
palette: ICommandPalette | null
3045
): IBlocklyManager => {
3146
console.log('JupyterLab extension jupyterlab-blocky is activated!');
3247

@@ -46,6 +61,9 @@ const plugin: JupyterFrontEndPlugin<IBlocklyManager> = {
4661
});
4762
}
4863

64+
const { commands } = app;
65+
const command = CommandIDs.createNew;
66+
4967
// Creating the widget factory to register it so the document manager knows about
5068
// our new DocumentWidget
5169
const widgetFactory = new BlocklyEditorFactory({
@@ -69,6 +87,9 @@ const plugin: JupyterFrontEndPlugin<IBlocklyManager> = {
6987

7088
// Add the widget to the tracker when it's created
7189
widgetFactory.widgetCreated.connect((sender, widget) => {
90+
// Adding the Blockly icon for the widget so it appears next to the file name.
91+
widget.title.icon = blockly_icon;
92+
7293
// Notify the instance tracker if restore data needs to update.
7394
widget.context.pathChanged.connect(() => {
7495
tracker.save(widget);
@@ -78,6 +99,50 @@ const plugin: JupyterFrontEndPlugin<IBlocklyManager> = {
7899
// Registering the widget factory
79100
app.docRegistry.addWidgetFactory(widgetFactory);
80101

102+
commands.addCommand(command, {
103+
label: args =>
104+
args['isPalette'] ? 'New Blockly Editor' : 'Blockly Editor',
105+
caption: 'Create a new Blockly Editor',
106+
icon: args => (args['isPalette'] ? null : blockly_icon),
107+
execute: async args => {
108+
// Get the directory in which the Blockly file must be created;
109+
// otherwise take the current filebrowser directory
110+
const cwd =
111+
args['cwd'] || browserFactory.tracker.currentWidget.model.path;
112+
113+
// Create a new untitled Blockly file
114+
const model = await commands.execute('docmanager:new-untitled', {
115+
path: cwd,
116+
type: 'file',
117+
ext: '.json'
118+
});
119+
120+
// Open the newly created file with the 'Editor'
121+
return commands.execute('docmanager:open', {
122+
path: model.path,
123+
factory: FACTORY
124+
});
125+
}
126+
});
127+
128+
// Add the command to the launcher
129+
if (launcher) {
130+
launcher.add({
131+
command,
132+
category: 'Other',
133+
rank: 1
134+
});
135+
}
136+
137+
// Add the command to the palette
138+
if (palette) {
139+
palette.addItem({
140+
command,
141+
args: { isPalette: true },
142+
category: PALETTE_CATEGORY
143+
});
144+
}
145+
81146
return widgetFactory.manager;
82147
}
83148
};

src/layout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ export class BlocklyLayout extends PanelLayout {
5454
}
5555

5656
set workspace(workspace: PartialJSONValue) {
57+
const data = workspace === null ? { variables: [] } : workspace;
5758
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5859
// @ts-ignore
59-
Blockly.serialization.workspaces.load(workspace, this._workspace);
60+
Blockly.serialization.workspaces.load(data, this._workspace);
6061
}
6162

6263
/**

src/svg.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Jupyter Development Team.
2+
// Distributed under the terms of the Modified BSD License.
3+
4+
// including this file in a package allows for the use of import statements
5+
// with svg files. Example: `import xSvg from 'path/xSvg.svg'`
6+
7+
// for use with raw-loader in Webpack.
8+
// The svg will be imported as a raw string
9+
10+
declare module '*.svg' {
11+
const value: string;
12+
export default value;
13+
}

style/icons/blockly_logo.svg

Lines changed: 76 additions & 0 deletions
Loading

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"target": "es2017",
1818
"types": []
1919
},
20-
"include": ["src/**/*.ts"],
20+
"include": ["src/**/*.ts", "style/icons"],
2121
"exclude": ["node_modules"]
2222
}

0 commit comments

Comments
 (0)