jupyter-specta 0.3.2 → 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.
- package/README.md +1 -0
- package/lib/specta_model.d.ts +3 -0
- package/lib/specta_model.js +8 -0
- package/lib/specta_widget.d.ts +7 -1
- package/lib/specta_widget.js +70 -21
- package/lib/token.d.ts +1 -0
- package/lib/tool.js +0 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ Specta can be configured using the typicall JupyterLite configuration file: `jup
|
|
|
69
69
|
The following options are available:
|
|
70
70
|
|
|
71
71
|
- `defaultLayout`: The default layout when opening a file.
|
|
72
|
+
- `executionDelay`: Delay (in miliseconds) before executing cells.
|
|
72
73
|
- `hideTopbar`: Boolean flag to show or hide the top bar.
|
|
73
74
|
- `topBar`: Configuration for the top bar.
|
|
74
75
|
- `slidesTheme`: The theme for the slides layout. The list of available themes can be found [here](https://revealjs.com/themes/).
|
package/lib/specta_model.d.ts
CHANGED
|
@@ -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 {
|
package/lib/specta_model.js
CHANGED
|
@@ -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) {
|
package/lib/specta_widget.d.ts
CHANGED
|
@@ -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;
|
package/lib/specta_widget.js
CHANGED
|
@@ -20,10 +20,22 @@ export class AppWidget extends Panel {
|
|
|
20
20
|
// Not a specta app, add spinner
|
|
21
21
|
this.addSpinner();
|
|
22
22
|
}
|
|
23
|
-
this._model.initialize().then(() => {
|
|
24
|
-
this.
|
|
23
|
+
this._model.initialize().then(async () => {
|
|
24
|
+
let waitTime = this._spectaAppConfig.executionDelay;
|
|
25
|
+
if (!waitTime) {
|
|
26
|
+
waitTime = 100;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.log(`Waiting for ${waitTime}ms`);
|
|
30
|
+
}
|
|
31
|
+
await new Promise(resolve => setTimeout(resolve, parseInt(waitTime + '')));
|
|
32
|
+
await this.render();
|
|
33
|
+
emitResizeEvent();
|
|
25
34
|
});
|
|
26
35
|
this._layoutRegistry.selectedLayoutChanged.connect(this._onSelectedLayoutChanged, this);
|
|
36
|
+
this._model.fileChanged.connect((_, newCells) => {
|
|
37
|
+
this.rerender(newCells);
|
|
38
|
+
});
|
|
27
39
|
}
|
|
28
40
|
/**
|
|
29
41
|
* A promise that is fulfilled when the model is ready.
|
|
@@ -47,6 +59,18 @@ export class AppWidget extends Panel {
|
|
|
47
59
|
loaderHost.node.appendChild(text);
|
|
48
60
|
this.addWidget(loaderHost);
|
|
49
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
|
+
}
|
|
50
74
|
dispose() {
|
|
51
75
|
if (this.isDisposed) {
|
|
52
76
|
return;
|
|
@@ -54,10 +78,11 @@ export class AppWidget extends Panel {
|
|
|
54
78
|
this._model.dispose();
|
|
55
79
|
super.dispose();
|
|
56
80
|
}
|
|
57
|
-
async
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
async generateOutputs(cellList) {
|
|
82
|
+
const outs = [];
|
|
83
|
+
if (!cellList) {
|
|
84
|
+
return outs;
|
|
85
|
+
}
|
|
61
86
|
for (const cell of cellList) {
|
|
62
87
|
const src = cell.sharedModel.source;
|
|
63
88
|
if (src.length === 0) {
|
|
@@ -65,29 +90,53 @@ export class AppWidget extends Panel {
|
|
|
65
90
|
}
|
|
66
91
|
const el = this._model.createCell(cell);
|
|
67
92
|
this._model.executeCell(cell, el);
|
|
68
|
-
|
|
93
|
+
outs.push(el);
|
|
69
94
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const spectaLayout =
|
|
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();
|
|
83
109
|
await spectaLayout.render({
|
|
84
110
|
host: this._host,
|
|
85
111
|
items: this._outputs,
|
|
86
|
-
notebook: (
|
|
112
|
+
notebook: (_a = this._model.context) === null || _a === void 0 ? void 0 : _a.model.toJSON(),
|
|
87
113
|
readyCallback,
|
|
88
114
|
spectaConfig: this._spectaAppConfig
|
|
89
115
|
});
|
|
90
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
|
+
}
|
|
91
140
|
onCloseRequest(msg) {
|
|
92
141
|
this._model.dispose();
|
|
93
142
|
super.onCloseRequest(msg);
|
package/lib/token.d.ts
CHANGED
package/lib/tool.js
CHANGED
|
@@ -187,7 +187,6 @@ export async function configLabLayout(options) {
|
|
|
187
187
|
if (!config) {
|
|
188
188
|
return;
|
|
189
189
|
}
|
|
190
|
-
console.log('vvvvvvvvvvv', config);
|
|
191
190
|
const { setSingleMode, hideLeftPanel, hideRightPanel, hideStatusbar, hideHeader } = config;
|
|
192
191
|
if (setSingleMode) {
|
|
193
192
|
await commands.execute('application:set-mode', {
|
|
@@ -213,9 +212,7 @@ export async function configLabLayout(options) {
|
|
|
213
212
|
}
|
|
214
213
|
if (hideStatusbar) {
|
|
215
214
|
const statusBar = document.getElementById('jp-main-statusbar');
|
|
216
|
-
console.log('statusBar.clientHeight', statusBar === null || statusBar === void 0 ? void 0 : statusBar.clientHeight);
|
|
217
215
|
if (statusBar && !statusBar.classList.contains('lm-mod-hidden')) {
|
|
218
|
-
console.log('toggle status');
|
|
219
216
|
await commands.execute('statusbar:toggle');
|
|
220
217
|
}
|
|
221
218
|
}
|