jupyter-specta 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
6
6
  import { ServiceManager } from '@jupyterlab/services';
7
7
  import { IExecuteReplyMsg } from '@jupyterlab/services/lib/kernel/messages';
8
8
  import { SpectaCellOutput } from './specta_cell_output';
9
+ import { ISignal } from '@lumino/signaling';
9
10
  export declare class AppModel {
10
11
  private options;
11
12
  constructor(options: AppModel.IOptions);
@@ -13,6 +14,7 @@ export declare class AppModel {
13
14
  * Whether the handler is disposed.
14
15
  */
15
16
  get isDisposed(): boolean;
17
+ get fileChanged(): ISignal<this, CellList>;
16
18
  dispose(): void;
17
19
  get rendermime(): IRenderMimeRegistry;
18
20
  get cells(): CellList | undefined;
@@ -27,6 +29,7 @@ export declare class AppModel {
27
29
  private _isDisposed;
28
30
  private _manager;
29
31
  private _kernelPreference;
32
+ private _fileChanged;
30
33
  }
31
34
  export declare namespace AppModel {
32
35
  interface IOptions {
@@ -3,10 +3,12 @@ import { OutputAreaModel, SimplifiedOutputArea } from '@jupyterlab/outputarea';
3
3
  import { createNotebookContext, createNotebookPanel } from './create_notebook_panel';
4
4
  import { SpectaCellOutput } from './specta_cell_output';
5
5
  import { emitResizeEvent, readCellConfig } from './tool';
6
+ import { Signal } from '@lumino/signaling';
6
7
  export class AppModel {
7
8
  constructor(options) {
8
9
  this.options = options;
9
10
  this._isDisposed = false;
11
+ this._fileChanged = new Signal(this);
10
12
  this._notebookModelJson = options.context.model.toJSON();
11
13
  this._kernelPreference = {
12
14
  shouldStart: true,
@@ -17,6 +19,9 @@ export class AppModel {
17
19
  language: options.context.model.defaultKernelLanguage
18
20
  };
19
21
  this._manager = options.manager;
22
+ options.context.fileChanged.connect(e => {
23
+ this._fileChanged.emit(e.model.cells);
24
+ });
20
25
  }
21
26
  /**
22
27
  * Whether the handler is disposed.
@@ -24,6 +29,9 @@ export class AppModel {
24
29
  get isDisposed() {
25
30
  return this._isDisposed;
26
31
  }
32
+ get fileChanged() {
33
+ return this._fileChanged;
34
+ }
27
35
  dispose() {
28
36
  var _a, _b;
29
37
  if (this.isDisposed) {
@@ -1,7 +1,9 @@
1
+ import { CellList } from '@jupyterlab/notebook';
1
2
  import { Message } from '@lumino/messaging';
2
3
  import { Panel } from '@lumino/widgets';
4
+ import { SpectaCellOutput } from './specta_cell_output';
3
5
  import { AppModel } from './specta_model';
4
- import { ISpectaAppConfig, ISpectaLayoutRegistry } from './token';
6
+ import { ISpectaAppConfig, ISpectaLayout, ISpectaLayoutRegistry } from './token';
5
7
  export declare class AppWidget extends Panel {
6
8
  constructor(options: AppWidget.IOptions);
7
9
  /**
@@ -10,8 +12,12 @@ export declare class AppWidget extends Panel {
10
12
  get ready(): Promise<void>;
11
13
  get model(): AppModel;
12
14
  addSpinner(): void;
15
+ removeSpinner(): void;
13
16
  dispose(): void;
17
+ generateOutputs(cellList?: CellList): Promise<SpectaCellOutput[]>;
18
+ getLayout(): ISpectaLayout;
14
19
  render(): Promise<void>;
20
+ rerender(newCells: CellList): Promise<void>;
15
21
  protected onCloseRequest(msg: Message): void;
16
22
  private _onSelectedLayoutChanged;
17
23
  private _model;
@@ -29,9 +29,13 @@ export class AppWidget extends Panel {
29
29
  console.log(`Waiting for ${waitTime}ms`);
30
30
  }
31
31
  await new Promise(resolve => setTimeout(resolve, parseInt(waitTime + '')));
32
- this.render().catch(console.error).then(emitResizeEvent);
32
+ await this.render();
33
+ emitResizeEvent();
33
34
  });
34
35
  this._layoutRegistry.selectedLayoutChanged.connect(this._onSelectedLayoutChanged, this);
36
+ this._model.fileChanged.connect((_, newCells) => {
37
+ this.rerender(newCells);
38
+ });
35
39
  }
36
40
  /**
37
41
  * A promise that is fulfilled when the model is ready.
@@ -55,6 +59,18 @@ export class AppWidget extends Panel {
55
59
  loaderHost.node.appendChild(text);
56
60
  this.addWidget(loaderHost);
57
61
  }
62
+ removeSpinner() {
63
+ if (this._loaderHost) {
64
+ this._loaderHost.node.style.opacity = '0';
65
+ setTimeout(() => {
66
+ var _a;
67
+ (_a = this.layout) === null || _a === void 0 ? void 0 : _a.removeWidget(this._loaderHost);
68
+ }, 100);
69
+ }
70
+ else {
71
+ hideAppLoadingIndicator();
72
+ }
73
+ }
58
74
  dispose() {
59
75
  if (this.isDisposed) {
60
76
  return;
@@ -62,10 +78,11 @@ export class AppWidget extends Panel {
62
78
  this._model.dispose();
63
79
  super.dispose();
64
80
  }
65
- async render() {
66
- var _a, _b, _c, _d, _e;
67
- const cellList = (_a = this._model.cells) !== null && _a !== void 0 ? _a : [];
68
- const layout = (_c = (_b = this._spectaAppConfig) === null || _b === void 0 ? void 0 : _b.defaultLayout) !== null && _c !== void 0 ? _c : 'default';
81
+ async generateOutputs(cellList) {
82
+ const outs = [];
83
+ if (!cellList) {
84
+ return outs;
85
+ }
69
86
  for (const cell of cellList) {
70
87
  const src = cell.sharedModel.source;
71
88
  if (src.length === 0) {
@@ -73,29 +90,53 @@ export class AppWidget extends Panel {
73
90
  }
74
91
  const el = this._model.createCell(cell);
75
92
  this._model.executeCell(cell, el);
76
- this._outputs.push(el);
93
+ outs.push(el);
77
94
  }
78
- const readyCallback = async () => {
79
- if (this._loaderHost) {
80
- this._loaderHost.node.style.opacity = '0';
81
- setTimeout(() => {
82
- var _a;
83
- (_a = this.layout) === null || _a === void 0 ? void 0 : _a.removeWidget(this._loaderHost);
84
- }, 100);
85
- }
86
- else {
87
- hideAppLoadingIndicator();
88
- }
89
- };
90
- const spectaLayout = (_d = this._layoutRegistry.get(layout)) !== null && _d !== void 0 ? _d : this._layoutRegistry.getDefaultLayout();
95
+ return outs;
96
+ }
97
+ getLayout() {
98
+ var _a, _b, _c;
99
+ const layout = (_b = (_a = this._spectaAppConfig) === null || _a === void 0 ? void 0 : _a.defaultLayout) !== null && _b !== void 0 ? _b : 'default';
100
+ const spectaLayout = (_c = this._layoutRegistry.get(layout)) !== null && _c !== void 0 ? _c : this._layoutRegistry.getDefaultLayout();
101
+ return spectaLayout;
102
+ }
103
+ async render() {
104
+ var _a;
105
+ const cellList = this._model.cells;
106
+ this._outputs = await this.generateOutputs(cellList);
107
+ const spectaLayout = this.getLayout();
108
+ const readyCallback = async () => this.removeSpinner();
91
109
  await spectaLayout.render({
92
110
  host: this._host,
93
111
  items: this._outputs,
94
- notebook: (_e = this._model.context) === null || _e === void 0 ? void 0 : _e.model.toJSON(),
112
+ notebook: (_a = this._model.context) === null || _a === void 0 ? void 0 : _a.model.toJSON(),
95
113
  readyCallback,
96
114
  spectaConfig: this._spectaAppConfig
97
115
  });
98
116
  }
117
+ async rerender(newCells) {
118
+ var _a;
119
+ this.addSpinner();
120
+ for (const element of this._outputs) {
121
+ element.dispose();
122
+ }
123
+ const currentEls = [...this._host.widgets];
124
+ currentEls.forEach(el => {
125
+ var _a;
126
+ (_a = this._host.layout) === null || _a === void 0 ? void 0 : _a.removeWidget(el);
127
+ });
128
+ this._outputs = await this.generateOutputs(newCells);
129
+ const spectaLayout = this.getLayout();
130
+ await spectaLayout.render({
131
+ host: this._host,
132
+ items: this._outputs,
133
+ notebook: (_a = this._model.context) === null || _a === void 0 ? void 0 : _a.model.toJSON(),
134
+ readyCallback: async () => { },
135
+ spectaConfig: this._spectaAppConfig
136
+ });
137
+ emitResizeEvent();
138
+ this.removeSpinner();
139
+ }
99
140
  onCloseRequest(msg) {
100
141
  this._model.dispose();
101
142
  super.onCloseRequest(msg);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jupyter-specta",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/trungleduc/specta",