Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/specta_cell_output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export class SpectaCellOutput extends Panel {
cellIdentity,
cell,
sourceCell,
savedOutput,
info,
cellConfig
}: {
cellIdentity: string;
cell: Widget;
sourceCell?: Widget;
savedOutput?: Widget;
info: ICellInfo;
cellConfig: Required<ISpectaCellConfig>;
}) {
Expand Down Expand Up @@ -49,7 +51,12 @@ export class SpectaCellOutput extends Panel {
this.cellIdentity = cellIdentity;
this._info = info ?? {};
if (info.cellModel?.cell_type === 'code') {
if (showOutput) {
if (savedOutput) {
savedOutput.addClass('specta-item-widget');
cell.hide();
content.addWidget(savedOutput);
this._placeholder = savedOutput;
} else if (showOutput) {
this._placeholder = ReactWidget.create(<RandomSkeleton />);
this._placeholder.addClass('specta-cell-placeholder');
this.addWidget(this._placeholder);
Expand All @@ -72,6 +79,7 @@ export class SpectaCellOutput extends Panel {
if (this._placeholder) {
this._placeholder?.dispose();
}
this._cellOutput.show();
}

private _info: ICellInfo = {};
Expand Down
32 changes: 27 additions & 5 deletions src/specta_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ import {
ISpectaSnapshotData,
SPECTA_SNAPSHOT_KEY,
WIDGET_STATE_MIMETYPE,
WIDGET_VIEW_MIMETYPE,
parseSnapshot,
snapshotHash
} from './snapshot';

import { ISignal, Signal } from '@lumino/signaling';
import { INotebookContent } from '@jupyterlab/nbformat';
import { INotebookContent, IOutput } from '@jupyterlab/nbformat';
import { IAppModel, ISpectaAppConfig, ISpectaSnapshotStatus } from './token';

export class AppModel implements IAppModel {
Expand Down Expand Up @@ -185,7 +186,8 @@ export class AppModel implements IAppModel {
editorServices: this.options.editorServices
});
(this.options.tracker as any).add(this._notebookPanel);
await this._sandboxContext.sessionContext.initialize();
// Render the saved outputs while the kernel starts
this._sessionReady = this._sandboxContext.sessionContext.initialize();
}
this._snapshotChanged.emit();
}
Expand Down Expand Up @@ -221,9 +223,20 @@ export class AppModel implements IAppModel {
}

const outputareamodel = new OutputAreaModel({ trusted: true });

if (this._staticRender && cellModelJson.outputs) {
outputareamodel.fromJSON(cellModelJson.outputs as any);
const outputs = (cellModelJson.outputs ?? []) as IOutput[];

let savedOutput: SimplifiedOutputArea | undefined;
if (this._staticRender) {
outputareamodel.fromJSON(outputs);
} else if (
cellConfig.showOutput &&
outputs.length &&
!Private.hasWidgetView(outputs)
) {
savedOutput = new SimplifiedOutputArea({
model: new OutputAreaModel({ trusted: true, values: outputs }),
rendermime: this.options.rendermime
});
}
const out = new SimplifiedOutputArea({
model: outputareamodel,
Expand All @@ -234,6 +247,7 @@ export class AppModel implements IAppModel {
cellIdentity: cellModel.id,
cell: out,
sourceCell,
savedOutput,
cellConfig,
info
});
Expand Down Expand Up @@ -343,6 +357,7 @@ export class AppModel implements IAppModel {
} else {
await this._kernelReady.promise;
}
await this._sessionReady;
const output = outputWrapper.cellOutput as SimplifiedOutputArea;

const source = cell.sharedModel.source;
Expand Down Expand Up @@ -408,6 +423,7 @@ export class AppModel implements IAppModel {
}

private _kernelReady = new PromiseDelegate<void>();
private _sessionReady: Promise<unknown> = Promise.resolve();

private _notebookPanel?: NotebookPanel;
private _sandboxContext?: DocumentRegistry.IContext<INotebookModel>;
Expand Down Expand Up @@ -449,4 +465,10 @@ namespace Private {
elements[i].remove();
}
}

export function hasWidgetView(outputs: IOutput[]): boolean {
return outputs.some(
output => (output.data as any)?.[WIDGET_VIEW_MIMETYPE] !== undefined
);
}
}
Loading