1 |
|
2 |
|
3 | import { ABCWidgetFactory } from '@jupyterlab/docregistry';
|
4 | import { NotebookPanel } from './panel';
|
5 | import { StaticNotebook } from './widget';
|
6 | import { NotebookHistory } from './history';
|
7 |
|
8 |
|
9 |
|
10 | export class NotebookWidgetFactory extends ABCWidgetFactory {
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 | constructor(options) {
|
17 | super(options);
|
18 | this.rendermime = options.rendermime;
|
19 | this.contentFactory = options.contentFactory;
|
20 | this.mimeTypeService = options.mimeTypeService;
|
21 | this._editorConfig =
|
22 | options.editorConfig || StaticNotebook.defaultEditorConfig;
|
23 | this._notebookConfig =
|
24 | options.notebookConfig || StaticNotebook.defaultNotebookConfig;
|
25 | }
|
26 | |
27 |
|
28 |
|
29 | get editorConfig() {
|
30 | return this._editorConfig;
|
31 | }
|
32 | set editorConfig(value) {
|
33 | this._editorConfig = value;
|
34 | }
|
35 | |
36 |
|
37 |
|
38 | get notebookConfig() {
|
39 | return this._notebookConfig;
|
40 | }
|
41 | set notebookConfig(value) {
|
42 | this._notebookConfig = value;
|
43 | }
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | createNewWidget(context, source) {
|
51 | const translator = context.translator;
|
52 | const kernelHistory = new NotebookHistory({
|
53 | sessionContext: context.sessionContext,
|
54 | translator: translator
|
55 | });
|
56 | const nbOptions = {
|
57 | rendermime: source
|
58 | ? source.content.rendermime
|
59 | : this.rendermime.clone({ resolver: context.urlResolver }),
|
60 | contentFactory: this.contentFactory,
|
61 | mimeTypeService: this.mimeTypeService,
|
62 | editorConfig: source ? source.content.editorConfig : this._editorConfig,
|
63 | notebookConfig: source
|
64 | ? source.content.notebookConfig
|
65 | : this._notebookConfig,
|
66 | translator,
|
67 | kernelHistory
|
68 | };
|
69 | const content = this.contentFactory.createNotebook(nbOptions);
|
70 | return new NotebookPanel({ context, content });
|
71 | }
|
72 | }
|
73 |
|
\ | No newline at end of file |