Skip to content

Commit 7170fb6

Browse files
Register file type in frontend plugin
Signed-off-by: Andy Jakubowski <hello@andyjakubowski.com>
1 parent 66efbc3 commit 7170fb6

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

src/index.ts

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

6-
import { requestAPI } from './handler';
6+
import { NotebookPanel, NotebookWidgetFactory } from '@jupyterlab/notebook';
7+
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
8+
import { IEditorServices } from '@jupyterlab/codeeditor';
9+
10+
const factoryName = 'Deepnote Notebook';
711

8-
/**
9-
* Initialization data for the jupyterlab-deepnote extension.
10-
*/
1112
const plugin: JupyterFrontEndPlugin<void> = {
12-
id: 'jupyterlab-deepnote:plugin',
13-
description: 'A Deepnote extension for JupyterLab',
13+
id: 'deepnote-jupyter-extension:plugin',
14+
description: 'Open .deepnote files as notebooks.',
1415
autoStart: true,
15-
activate: (app: JupyterFrontEnd) => {
16-
console.log('JupyterLab extension jupyterlab-deepnote is activated!');
16+
requires: [IRenderMimeRegistry, IEditorServices],
17+
activate: (
18+
app: JupyterFrontEnd,
19+
rendermime: IRenderMimeRegistry,
20+
editorServices: IEditorServices
21+
) => {
22+
// 1) File type
23+
app.docRegistry.addFileType(
24+
{
25+
name: 'deepnote',
26+
displayName: 'Deepnote Notebook',
27+
extensions: ['.deepnote'],
28+
mimeTypes: ['text/yaml', 'application/x-yaml'],
29+
fileFormat: 'text',
30+
contentType: 'notebook'
31+
},
32+
[factoryName]
33+
);
34+
35+
// 2) Widget factory that reuses the stock notebook UI
36+
const contentFactory = new NotebookPanel.ContentFactory({
37+
editorFactory: editorServices.factoryService.newInlineEditor
38+
});
39+
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+
});
1749

18-
requestAPI<any>('get-example')
19-
.then(data => {
20-
console.log(data);
21-
})
22-
.catch(reason => {
23-
console.error(
24-
`The jupyterlab_deepnote server extension appears to be missing.\n${reason}`
25-
);
26-
});
50+
app.docRegistry.addWidgetFactory(widgetFactory);
2751
}
2852
};
2953

0 commit comments

Comments
 (0)