UNPKG

2.47 kBJavaScriptView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3import { ABCWidgetFactory } from '@jupyterlab/docregistry';
4import { NotebookPanel } from './panel';
5import { StaticNotebook } from './widget';
6import { NotebookHistory } from './history';
7/**
8 * A widget factory for notebook panels.
9 */
10export class NotebookWidgetFactory extends ABCWidgetFactory {
11 /**
12 * Construct a new notebook widget factory.
13 *
14 * @param options - The options used to construct the factory.
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 * A configuration object for cell editor settings.
28 */
29 get editorConfig() {
30 return this._editorConfig;
31 }
32 set editorConfig(value) {
33 this._editorConfig = value;
34 }
35 /**
36 * A configuration object for notebook settings.
37 */
38 get notebookConfig() {
39 return this._notebookConfig;
40 }
41 set notebookConfig(value) {
42 this._notebookConfig = value;
43 }
44 /**
45 * Create a new widget.
46 *
47 * #### Notes
48 * The factory will start the appropriate kernel.
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//# sourceMappingURL=widgetfactory.js.map
\No newline at end of file