UNPKG

2.69 kBJavaScriptView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3import { sessionContextDialogs } from '@jupyterlab/apputils';
4import { ABCWidgetFactory } from '@jupyterlab/docregistry';
5import { ToolbarItems } from './default-toolbar';
6import { NotebookPanel } from './panel';
7import { StaticNotebook } from './widget';
8/**
9 * A widget factory for notebook panels.
10 */
11export class NotebookWidgetFactory extends ABCWidgetFactory {
12 /**
13 * Construct a new notebook widget factory.
14 *
15 * @param options - The options used to construct the factory.
16 */
17 constructor(options) {
18 super(options);
19 this.rendermime = options.rendermime;
20 this.contentFactory =
21 options.contentFactory || NotebookPanel.defaultContentFactory;
22 this.mimeTypeService = options.mimeTypeService;
23 this._editorConfig =
24 options.editorConfig || StaticNotebook.defaultEditorConfig;
25 this._notebookConfig =
26 options.notebookConfig || StaticNotebook.defaultNotebookConfig;
27 this._sessionDialogs = options.sessionDialogs || sessionContextDialogs;
28 }
29 /**
30 * A configuration object for cell editor settings.
31 */
32 get editorConfig() {
33 return this._editorConfig;
34 }
35 set editorConfig(value) {
36 this._editorConfig = value;
37 }
38 /**
39 * A configuration object for notebook settings.
40 */
41 get notebookConfig() {
42 return this._notebookConfig;
43 }
44 set notebookConfig(value) {
45 this._notebookConfig = value;
46 }
47 /**
48 * Create a new widget.
49 *
50 * #### Notes
51 * The factory will start the appropriate kernel.
52 */
53 createNewWidget(context, source) {
54 const nbOptions = {
55 rendermime: source
56 ? source.content.rendermime
57 : this.rendermime.clone({ resolver: context.urlResolver }),
58 contentFactory: this.contentFactory,
59 mimeTypeService: this.mimeTypeService,
60 editorConfig: source ? source.content.editorConfig : this._editorConfig,
61 notebookConfig: source
62 ? source.content.notebookConfig
63 : this._notebookConfig,
64 translator: this.translator
65 };
66 const content = this.contentFactory.createNotebook(nbOptions);
67 return new NotebookPanel({ context, content });
68 }
69 /**
70 * Default factory for toolbar items to be added after the widget is created.
71 */
72 defaultToolbarFactory(widget) {
73 return ToolbarItems.getDefaultItems(widget, this._sessionDialogs, this.translator);
74 }
75}
76//# sourceMappingURL=widgetfactory.js.map
\No newline at end of file