-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.tsx
107 lines (97 loc) · 2.45 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import {
ICommandPalette,
MainAreaWidget,
ReactWidget
} from '@jupyterlab/apputils';
import * as Icons from '@jupyterlab/ui-components';
import {
ABCWidgetFactory,
DocumentRegistry,
DocumentWidget,
IDocumentWidget
} from '@jupyterlab/docregistry';
import { Widget } from '@lumino/widgets';
import React from 'react';
import { TodoCenter } from './TodoCenter';
/**
* Initialization data for the jupyterlab-todo extension.
*/
const plugin: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-todo:plugin',
autoStart: true,
requires: [ICommandPalette],
activate: async (app: JupyterFrontEnd, palette: ICommandPalette) => {
const content: Widget = new MyWidget();
const widget = new MainAreaWidget({ content });
widget.id = 'todo-jupyterlab';
widget.title.closable = true;
widget.title.icon = Icons.jupyterFaviconIcon;
app.shell.add(widget, 'right', { rank: 500 });
const ft: DocumentRegistry.IFileType = {
name: 'todo',
contentType: 'file',
fileFormat: 'text',
displayName: 'To Do File',
extensions: ['.todo'],
mimeTypes: ['text/plain']
};
app.docRegistry.addFileType(ft);
const factory = new TodoWidgetFactory({
name: 'TODOCENTER',
fileTypes: ['todo'],
defaultFor: ['todo'],
readOnly: true
});
app.docRegistry.addWidgetFactory(factory);
}
}
/**
* A todo widget.
*/
class TodoWidget extends Widget {
constructor(context: DocumentRegistry.Context) {
super();
this.context = context;
void context.ready.then(() => {
console.log('context is read');
});
}
/**
* The todo widget's context.
*/
readonly context: DocumentRegistry.Context;
}
/**
* A widget factory for todo files.
*/
class TodoWidgetFactory extends ABCWidgetFactory<
IDocumentWidget<TodoWidget>
> {
/**
* Create a new widget given a context.
*/
protected createNewWidget(
context: DocumentRegistry.IContext<DocumentRegistry.IModel>
): IDocumentWidget<TodoWidget> {
console.log('context', context);
const content = new TodoWidget(context);
const widget = new DocumentWidget({ content, context });
return widget;
}
}
class MyWidget extends ReactWidget {
render() {
return (
<div>
<TodoCenter />
</div>
)
}
}
export default plugin;