Skip to content

Commit 391bb7d

Browse files
Conditionally render toolbar item
Signed-off-by: Andy Jakubowski <[email protected]>
1 parent 61f0c09 commit 391bb7d

File tree

6 files changed

+49
-26
lines changed

6 files changed

+49
-26
lines changed

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ _src_path: https://github.com/jupyterlab/extension-template
44
author_email: [email protected]
55
author_name: Andy Jakubowski
66
has_binder: false
7-
has_settings: false
7+
has_settings: true
88
kind: frontend-and-server
99
labextension_name: jupyterlab-deepnote
1010
project_short_description: A Deepnote extension for JupyterLab

jupyterlab_deepnote/contents.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def get(self, path, content=True, type=None, format=None, require_hash=False):
6363
model["type"] = "notebook"
6464
model["format"] = "json"
6565
model["content"] = nb_node
66+
model["writable"] = False
6667
self.mark_trusted_cells(nb_node, path)
6768
self.validate_notebook_model(model, validation_error={})
6869

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"files": [
2020
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
2121
"style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
22-
"src/**/*.{ts,tsx}"
22+
"src/**/*.{ts,tsx}",
23+
"schema/*.json"
2324
],
2425
"main": "lib/index.js",
2526
"types": "lib/index.d.ts",
@@ -59,7 +60,9 @@
5960
"@jupyterlab/application": "^4.0.0",
6061
"@jupyterlab/coreutils": "^6.0.0",
6162
"@jupyterlab/notebook": "^4.4.7",
62-
"@jupyterlab/services": "^7.0.0"
63+
"@jupyterlab/services": "^7.0.0",
64+
"@jupyterlab/settingregistry": "^4.0.0",
65+
"@lumino/widgets": "^2.7.1"
6366
},
6467
"devDependencies": {
6568
"@jupyterlab/builder": "^4.0.0",
@@ -109,7 +112,8 @@
109112
}
110113
},
111114
"extension": true,
112-
"outputDir": "jupyterlab_deepnote/labextension"
115+
"outputDir": "jupyterlab_deepnote/labextension",
116+
"schemaDir": "schema"
113117
},
114118
"eslintIgnore": [
115119
"node_modules",

schema/plugin.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"jupyter.lab.shortcuts": [],
3+
"jupyter.lab.toolbars": {
4+
"Notebook": [{ "name": "deepnote:switch-notebook", "rank": 1 }]
5+
},
6+
"title": "jupyterlab-deepnote",
7+
"description": "jupyterlab-deepnote settings.",
8+
"type": "object",
9+
"properties": {},
10+
"additionalProperties": false
11+
}

src/index.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ import {
33
JupyterFrontEndPlugin
44
} from '@jupyterlab/application';
55

6-
import { NotebookPanel, NotebookWidgetFactory } from '@jupyterlab/notebook';
76
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
87
import { IEditorServices } from '@jupyterlab/codeeditor';
9-
10-
const factoryName = 'Deepnote Notebook';
8+
import { IToolbarWidgetRegistry, ToolbarButton } from '@jupyterlab/apputils';
9+
import { NotebookPanel } from '@jupyterlab/notebook';
10+
import { Widget } from '@lumino/widgets';
1111

1212
const plugin: JupyterFrontEndPlugin<void> = {
1313
id: 'jupyterlab-deepnote:plugin',
1414
description: 'Open .deepnote files as notebooks.',
1515
autoStart: true,
16-
requires: [IRenderMimeRegistry, IEditorServices],
16+
requires: [IRenderMimeRegistry, IEditorServices, IToolbarWidgetRegistry],
1717
activate: (
1818
app: JupyterFrontEnd,
1919
rendermime: IRenderMimeRegistry,
20-
editorServices: IEditorServices
20+
editorServices: IEditorServices,
21+
toolbarRegistry: IToolbarWidgetRegistry
2122
) => {
2223
// 1) File type
2324
app.docRegistry.addFileType(
@@ -27,27 +28,31 @@ const plugin: JupyterFrontEndPlugin<void> = {
2728
extensions: ['.deepnote'],
2829
mimeTypes: ['text/yaml', 'application/x-yaml'],
2930
fileFormat: 'text',
30-
contentType: 'notebook'
31+
contentType: 'file'
3132
},
32-
[factoryName]
33+
['Notebook']
3334
);
3435

35-
// 2) Widget factory that reuses the stock notebook UI
36-
const contentFactory = new NotebookPanel.ContentFactory({
37-
editorFactory: editorServices.factoryService.newInlineEditor
38-
});
36+
app.docRegistry.setDefaultWidgetFactory('deepnote', 'Notebook');
3937

40-
const widgetFactory = new NotebookWidgetFactory({
41-
name: factoryName,
42-
modelName: 'notebook', // built-in notebook model
43-
fileTypes: ['deepnote'],
44-
defaultFor: ['deepnote'],
45-
rendermime,
46-
contentFactory,
47-
mimeTypeService: editorServices.mimeTypeService
48-
});
38+
toolbarRegistry.addFactory<NotebookPanel>(
39+
'Notebook',
40+
'deepnote:switch-notebook',
41+
panel => {
42+
if (!panel.context.path.endsWith('.deepnote')) {
43+
return new Widget(); // don’t render for .ipynb or others
44+
}
4945

50-
app.docRegistry.addWidgetFactory(widgetFactory);
46+
return new ToolbarButton({
47+
className: 'debug-deepnote-button',
48+
label: 'Deepnote',
49+
tooltip: 'Do a Deepnote action',
50+
onClick: () => {
51+
console.log('clicked for', panel.context.path);
52+
}
53+
});
54+
}
55+
);
5156
}
5257
};
5358

yarn.lock

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ __metadata:
25022502
languageName: node
25032503
linkType: hard
25042504

2505-
"@jupyterlab/settingregistry@npm:^4.4.7":
2505+
"@jupyterlab/settingregistry@npm:^4.0.0, @jupyterlab/settingregistry@npm:^4.4.7":
25062506
version: 4.4.7
25072507
resolution: "@jupyterlab/settingregistry@npm:4.4.7"
25082508
dependencies:
@@ -6799,7 +6799,9 @@ __metadata:
67996799
"@jupyterlab/coreutils": ^6.0.0
68006800
"@jupyterlab/notebook": ^4.4.7
68016801
"@jupyterlab/services": ^7.0.0
6802+
"@jupyterlab/settingregistry": ^4.0.0
68026803
"@jupyterlab/testutils": ^4.0.0
6804+
"@lumino/widgets": ^2.7.1
68036805
"@types/jest": ^29.2.0
68046806
"@types/json-schema": ^7.0.11
68056807
"@types/react": ^18.0.26

0 commit comments

Comments
 (0)