Skip to content
Merged
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
7 changes: 7 additions & 0 deletions demo/jupyter-lite.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
"hideTopbar": true,
"slidesTheme": "sky"
}
},
"labConfig": {
"setSingleMode": true,
"hideLeftPanel": true,
"hideRightPanel": true,
"hideStatusbar": true,
"hideHeader": false
}
},
"disabledExtensions": [
Expand Down
27 changes: 10 additions & 17 deletions src/document/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import {
ISpectaShell
} from '../token';
import {
configLabLayout,
createFileBrowser,
hideAppLoadingIndicator,
isSpectaApp,
readSpectaConfig,
registerDocumentFactory
} from '../tool';

Expand Down Expand Up @@ -99,25 +101,16 @@ export const spectaOpener: JupyterFrontEndPlugin<void, ILabShell> = {
}
app.restored.then(async () => {
const labShell = app.shell;

if (PathExt.extname(path) === '.ipynb') {
await app.commands.execute('application:set-mode', {
mode: 'single-document'
const commands = app.commands;
const spectaConfig = readSpectaConfig({});

await configLabLayout({
config: spectaConfig.labConfig,
labShell,
commands
});
labShell.collapseLeft();
labShell.collapseRight();
if (labShell.isSideTabBarVisible('right')) {
labShell.toggleSideTabBarVisibility('right');
}
if (labShell.isSideTabBarVisible('left')) {
labShell.toggleSideTabBarVisibility('left');
}
if (labShell.isTopInSimpleModeVisible()) {
await app.commands.execute('application:toggle-header');
}
const statusBar = document.getElementById('jp-bottom-panel');
if (statusBar && statusBar.clientHeight !== 0) {
await app.commands.execute('statusbar:toggle');
}
const widget = docManager.openOrReveal(path, 'specta');
if (widget) {
app.shell.add(widget, 'main');
Expand Down
7 changes: 7 additions & 0 deletions src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export interface ISpectaAppConfig {
hideTopbar?: boolean;
slidesTheme?: string;
loadingName?: string;
labConfig?: {
setSingleMode?: boolean;
hideLeftPanel?: boolean;
hideRightPanel?: boolean;
hideStatusbar?: boolean;
hideHeader?: boolean;
};
}

export interface ISpectaCellConfig {
Expand Down
52 changes: 51 additions & 1 deletion src/tool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JupyterFrontEnd } from '@jupyterlab/application';
import { ILabShell, JupyterFrontEnd } from '@jupyterlab/application';
import { IThemeManager, WidgetTracker } from '@jupyterlab/apputils';
import { IEditorServices } from '@jupyterlab/codeeditor';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
Expand All @@ -7,6 +7,7 @@ import { ICell, INotebookMetadata } from '@jupyterlab/nbformat';
import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { Contents } from '@jupyterlab/services';
import { CommandRegistry } from '@lumino/commands';

import { NotebookGridWidgetFactory } from './document/factory';
import { SpectaWidgetFactory } from './specta_widget_factory';
Expand Down Expand Up @@ -237,3 +238,52 @@ export function setRevealTheme(themeName: string) {
// Set or update href to new theme
themeLink.href = getSpectaAssetUrl(`reveal.js/${themeName}.css`);
}

export async function configLabLayout(options: {
config?: ISpectaAppConfig['labConfig'];
labShell: ILabShell;
commands: CommandRegistry;
}): Promise<void> {
const { config, labShell, commands } = options;
if (!config) {
return;
}
console.log('vvvvvvvvvvv', config);
const {
setSingleMode,
hideLeftPanel,
hideRightPanel,
hideStatusbar,
hideHeader
} = config;
if (setSingleMode) {
await commands.execute('application:set-mode', {
mode: 'single-document'
});
}
if (hideLeftPanel) {
labShell.collapseLeft();
if (labShell.isSideTabBarVisible('left')) {
labShell.toggleSideTabBarVisibility('left');
}
}
if (hideRightPanel) {
labShell.collapseRight();
if (labShell.isSideTabBarVisible('right')) {
labShell.toggleSideTabBarVisibility('right');
}
}
if (hideHeader) {
if (labShell.isTopInSimpleModeVisible()) {
await commands.execute('application:toggle-header');
}
}
if (hideStatusbar) {
const statusBar = document.getElementById('jp-main-statusbar');
console.log('statusBar.clientHeight', statusBar?.clientHeight);
if (statusBar && !statusBar.classList.contains('lm-mod-hidden')) {
console.log('toggle status');
await commands.execute('statusbar:toggle');
}
}
}