Skip to content

Commit dcb1fa6

Browse files
authored
Merge pull request #181 from jupyterlab/fix/update-3.1
Use the new menu definition from settings
2 parents fe27afb + 08067fc commit dcb1fa6

File tree

84 files changed

+637
-547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+637
-547
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jlpm run build
6666
jupyter lab
6767
```
6868

69-
The examples currently target **JupyterLab 3.x**.
69+
The examples currently target **JupyterLab 3.1 or later**.
7070

7171
If you would like to use the examples with JupyterLab 2.x, check out the [2.x branch](https://github.com/jupyterlab/extension-examples/tree/2.x).
7272

command-palette/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
},
1919
"files": [
2020
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
21-
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
22-
"style/index.js"
21+
"style/**/*.{css,eot,js,gif,html,jpg,json,png,svg,woff2,ttf}"
2322
],
2423
"main": "lib/index.js",
2524
"types": "lib/index.d.ts",

command-palette/ui-tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jlpm run build:prod
1919
2. Execute the docker stack in the example folder:
2020

2121
```
22-
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env build
22+
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env build --no-cache
2323
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env run --rm e2e
2424
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env down
2525
```
@@ -107,7 +107,7 @@ docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.
107107
jupyter lab --ServerApp.token= --ServerApp.password=
108108
```
109109

110-
3. Launch the code generator tool:
110+
3. Launch the debug tool:
111111

112112
```
113113
cd ui-tests

commands/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
},
1919
"files": [
2020
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
21-
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
22-
"style/index.js"
21+
"style/**/*.{css,eot,js,gif,html,jpg,json,png,svg,woff2,ttf}"
2322
],
2423
"main": "lib/index.js",
2524
"types": "lib/index.d.ts",

commands/ui-tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jlpm run build:prod
1919
2. Execute the docker stack in the example folder:
2020

2121
```
22-
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env build
22+
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env build --no-cache
2323
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env run --rm e2e
2424
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env down
2525
```
@@ -107,7 +107,7 @@ docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.
107107
jupyter lab --ServerApp.token= --ServerApp.password=
108108
```
109109

110-
3. Launch the code generator tool:
110+
3. Launch the debug tool:
111111

112112
```
113113
cd ui-tests

completer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fetch(
124124
[_JupyterLab_'s completer-extension](https://github.com/jupyterlab/jupyterlab/tree/master/packages/completer-extension) includes a notebooks plugin that registers notebooks for code completion. Your extension will override the notebooks plugin's behavior, so you can [disable notebooks](https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html#disabling-other-extensions) in your `.package.json`:
125125
126126
```json5
127-
// package.json#L83-L90
127+
// package.json#L81-L88
128128

129129
"jupyterlab": {
130130
"extension": true,

completer/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
},
1919
"files": [
2020
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
21-
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
22-
"style/index.js"
21+
"style/**/*.{css,eot,js,gif,html,jpg,json,png,svg,woff2,ttf}"
2322
],
2423
"main": "lib/index.js",
2524
"types": "lib/index.d.ts",
@@ -52,7 +51,6 @@
5251
"@jupyterlab/codeeditor": "^3.1.0",
5352
"@jupyterlab/completer": "^3.1.0",
5453
"@jupyterlab/launcher": "^3.1.0",
55-
"@jupyterlab/mainmenu": "^3.1.0",
5654
"@jupyterlab/notebook": "^3.1.0",
5755
"@jupyterlab/outputarea": "^3.1.0",
5856
"@jupyterlab/statedb": "^3.1.0",

completer/ui-tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jlpm run build:prod
1919
2. Execute the docker stack in the example folder:
2020

2121
```
22-
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env build
22+
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env build --no-cache
2323
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env run --rm e2e
2424
docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.env down
2525
```
@@ -107,7 +107,7 @@ docker-compose -f ../end-to-end-tests/docker-compose.yml --env-file ./ui-tests/.
107107
jupyter lab --ServerApp.token= --ServerApp.password=
108108
```
109109

110-
3. Launch the code generator tool:
110+
3. Launch the debug tool:
111111

112112
```
113113
cd ui-tests

context-menu/README.md

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a basic example to show how to add a new entry to an existent context me
66

77
![context menu example](preview.gif)
88

9-
In JupyterLab plugins can expose context menus to offer an easy way to execute commands and perform actions. In this example, you will learn how to add a new entry to the file browser context menu, and at the same time how to register a new file type.
9+
In JupyterLab plugins can expose context menus to offer an easy way to execute commands and perform actions. In this example, you will learn how to add a new entry to the file browser context menu to be displayed on files with extension `.example`.
1010

1111
> It is strongly recommended to read [commands](https://github.com/jupyterlab/extension-examples/tree/master/commands) example before diving into this one.
1212
@@ -18,50 +18,23 @@ First of all, you will start looking into the declaration of the extension:
1818

1919
<!-- prettier-ignore-start -->
2020
```ts
21-
// src/index.ts#L9-L14
21+
// src/index.ts#L9-L13
2222

2323
const extension: JupyterFrontEndPlugin<void> = {
2424
id: 'context-menu',
2525
autoStart: true,
2626
requires: [IFileBrowserFactory],
27-
optional: [],
2827
activate: (app: JupyterFrontEnd, factory: IFileBrowserFactory) => {
2928
```
3029
<!-- prettier-ignore-end -->
3130
3231
For this extension, you need to require `IFileBrowserFactory` to track the file browser item clicked by the user.
3332
34-
The example shows you how to create a new file type and add the entry to the context menu only to this file type. The first step is optional, you can also add your button to an existing file type (or all of them!).
35-
36-
To register a new file type, you need to call the `addFileType()` method of `docRegistry` property present in the `JupyterFrontEnd` object. This method requires an `IFileType` object with some properties to define your file type. The most important are:
37-
38-
- `name`: the new file type.
39-
- `extension`: the list of extensions.
40-
- `fileFormat`: the file content format (_base64_, _json_ or _text_).
41-
- `contentType`: the file type (_directory_, _notebook_ or _file_).
42-
- `mimeType`: the content mime type.
33+
The first step is to define the command that will be executed when clicking on the context menu entry. If you want to access the item information, you need to use the `IFileBrowserFactory` object to obtain the file browser selected item.
4334
4435
<!-- prettier-ignore-start -->
4536
```ts
46-
// src/index.ts#L15-L23
47-
48-
app.docRegistry.addFileType({
49-
name: 'example',
50-
icon: runIcon,
51-
displayName: 'Example File',
52-
extensions: ['.example'],
53-
fileFormat: 'text',
54-
contentType: 'file',
55-
mimeTypes: ['text/plain'],
56-
});
57-
```
58-
<!-- prettier-ignore-end -->
59-
60-
The next step is to define the command that will be executed when clicking on the context menu entry. If you want to access the item information, you need to use the `IFileBrowserFactory` object to obtain the file browser selected item.
61-
62-
<!-- prettier-ignore-start -->
63-
```ts
64-
// src/index.ts#L25-L38
37+
// src/index.ts#L14-L27
6538

6639
app.commands.addCommand('jlab-examples/context-menu:open', {
6740
label: 'Example',
@@ -80,24 +53,32 @@ app.commands.addCommand('jlab-examples/context-menu:open', {
8053
```
8154
<!-- prettier-ignore-end -->
8255
83-
Finally, you can add the command to a context menu using the `addItem()` method present in the `contextMenu` property. This method requires an `IItemOptions` object with the following properties:
56+
Then, you can add the command to a context menu using the settings file.
57+
You will need to define a context menu item under the property `context` of the special key
58+
`jupyter.lab.menus`. And the properties of the context menu item are:
8459
8560
- `command`: the command to execute.
86-
- `selector`: the CSS classes of the element where you want to add the entry.
87-
- `rank`: the position in the context menu
61+
- `selector`: the CSS classes of the element on which you want to add the entry.
62+
- `rank`: (optional) number to order the context menu entries
8863
8964
<!-- prettier-ignore-start -->
90-
```ts
91-
// src/index.ts#L40-L44
92-
93-
app.contextMenu.addItem({
94-
command: 'jlab-examples/context-menu:open',
95-
selector: '.jp-DirListing-item[data-file-type="example"]',
96-
rank: 0,
97-
});
65+
```json5
66+
// schema/plugin.json#L4-L12
67+
68+
"jupyter.lab.menus": {
69+
"context": [
70+
{
71+
"command": "jlab-examples/context-menu:open",
72+
"selector": ".jp-DirListing-item[data-file-type=\"text\"]",
73+
"rank": 0
74+
}
75+
]
76+
},
9877
```
9978
<!-- prettier-ignore-end -->
10079
101-
The `selector` can be any valid [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors). In this case, the first part is the CSS class that identifies the file browser items `.jp-DirListing-item` and the second part `[data-file-type="example"]` is a attribute value to be found on the item. You can omit the second part to add the button to every file type.
80+
The `selector` can be any valid [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors). In this case, the first part is the CSS class that identifies the file browser items `.jp-DirListing-item` and the second part `[data-file-type="text"]` is a attribute value to be found on the item; the `data-file-type` attribute is set with the file type name or `text` for generic files. You can omit the second part to add the command to every file type.
10281
10382
You can find some of the CSS classes that identify different widgets in JupyterLab in the [developer documentation](https://jupyterlab.readthedocs.io/en/stable/developer/css.html#commonly-used-css-selectors).
83+
84+
> See also the [documentation](https://jupyterlab.readthedocs.io/en/stable/extension/extension_points.html#context-menu).

context-menu/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
},
1919
"files": [
2020
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
21-
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
22-
"style/index.js"
21+
"style/**/*.{css,eot,js,gif,html,jpg,json,png,svg,woff2,ttf}",
22+
"schema/**/*.json"
2323
],
2424
"main": "lib/index.js",
2525
"types": "lib/index.d.ts",
@@ -73,7 +73,8 @@
7373
],
7474
"jupyterlab": {
7575
"extension": true,
76-
"outputDir": "jupyterlab_examples_context_menu/labextension"
76+
"outputDir": "jupyterlab_examples_context_menu/labextension",
77+
"schemaDir": "schema"
7778
},
7879
"styleModule": "style/index.js"
7980
}

0 commit comments

Comments
 (0)