Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
id: 'jupyter.extensions.hub-extension',
requires: [JupyterFrontEnd.IPaths, ICommandPalette, IMainMenu],
autoStart: true
};
/**
* The default JupyterLab connection lost provider. This may be overridden
* to provide custom behavior when a connection to the server is lost.
*
* If the application is being deployed within a JupyterHub context,
* this will provide a dialog that prompts the user to restart the server.
* Otherwise, it shows an error dialog.
*/
const connectionlost: JupyterFrontEndPlugin = {
id: '@jupyterlab/apputils-extension:connectionlost',
requires: [JupyterFrontEnd.IPaths],
activate: (
app: JupyterFrontEnd,
paths: JupyterFrontEnd.IPaths
): IConnectionLost => {
const hubPrefix = paths.urls.hubPrefix || '';
const baseUrl = paths.urls.base;
// Return the default error message if not running on JupyterHub.
if (!hubPrefix) {
return ConnectionLost;
}
// If we are running on JupyterHub, return a dialog
// that prompts the user to restart their server.
let showingError = false;
const onConnectionLost: IConnectionLost = async (
activate: async (app: JupyterFrontEnd): Promise => {
const connector = app.serviceManager.settings;
const plugins = (await connector.list()).values;
return new SettingRegistry({ connector, plugins });
},
autoStart: true,
provides: ISettingRegistry
};
/**
* The default theme manager provider.
*/
const themes: JupyterFrontEndPlugin = {
id: '@jupyterlab/apputils-extension:themes',
requires: [ISettingRegistry, JupyterFrontEnd.IPaths],
optional: [ISplashScreen],
activate: (
app: JupyterFrontEnd,
settings: ISettingRegistry,
paths: JupyterFrontEnd.IPaths,
splash: ISplashScreen | null
): IThemeManager => {
const host = app.shell;
const commands = app.commands;
const url = URLExt.join(paths.urls.base, paths.urls.themes);
const key = themes.id;
const manager = new ThemeManager({ key, host, settings, splash, url });
// Keep a synchronously set reference to the current theme,
// since the asynchronous setting of the theme in `changeTheme`
// can lead to an incorrect toggle on the currently used theme.
namespace CommandIDs {
export const changeTheme = 'apputils:change-theme';
export const themeScrollbars = 'apputils:theme-scrollbars';
export const incrFontSize = 'apputils:incr-font-size';
export const decrFontSize = 'apputils:decr-font-size';
}
/**
* The default theme manager provider.
*/
export const themesPlugin: JupyterFrontEndPlugin = {
id: '@jupyterlab/apputils-extension:themes',
requires: [ISettingRegistry, JupyterFrontEnd.IPaths],
optional: [ISplashScreen],
activate: (
app: JupyterFrontEnd,
settings: ISettingRegistry,
paths: JupyterFrontEnd.IPaths,
splash: ISplashScreen | null
): IThemeManager => {
const host = app.shell;
const commands = app.commands;
const url = URLExt.join(paths.urls.base, paths.urls.themes);
const key = themesPlugin.id;
const manager = new ThemeManager({ key, host, settings, splash, url });
// Keep a synchronously set reference to the current theme,
// since the asynchronous setting of the theme in `changeTheme`
// can lead to an incorrect toggle on the currently used theme.
restorer.save(labShell.saveLayout());
});
});
return restorer;
},
autoStart: true,
provides: ILayoutRestorer
};
/**
* The default URL router provider.
*/
const router: JupyterFrontEndPlugin = {
id: '@jupyterlab/application-extension:router',
requires: [JupyterFrontEnd.IPaths],
activate: (app: JupyterFrontEnd, paths: JupyterFrontEnd.IPaths) => {
const { commands } = app;
const base = paths.urls.base;
const router = new Router({ base, commands });
app.started.then(() => {
// Route the very first request on load.
router.route();
// Route all pop state events.
window.addEventListener('popstate', () => {
router.route();
});
});
return router;
console.warn('Tree routing failed.', error);
}
}
});
router.register({ command: CommandIDs.tree, pattern: treePattern });
router.register({ command: CommandIDs.tree, pattern: workspacePattern });
}
};
/**
* The default URL not found extension.
*/
const notfound: JupyterFrontEndPlugin = {
id: '@jupyterlab/application-extension:notfound',
requires: [JupyterFrontEnd.IPaths, IRouter],
activate: (
_: JupyterFrontEnd,
paths: JupyterFrontEnd.IPaths,
router: IRouter
) => {
const bad = paths.urls.notFound;
if (!bad) {
return;
}
const base = router.base;
const message = `
The path: ${bad} was not found. JupyterLab redirected to: ${base}
`;
provides: JupyterLab.IInfo
};
/**
* The default JupyterLab paths dictionary provider.
*/
const paths: JupyterFrontEndPlugin = {
id: '@jupyterlab/apputils-extension:paths',
activate: (app: JupyterFrontEnd): JupyterFrontEnd.IPaths => {
if (!(app instanceof JupyterLab)) {
throw new Error(`${paths.id} must be activated in JupyterLab.`);
}
return app.paths;
},
autoStart: true,
provides: JupyterFrontEnd.IPaths
};
/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin[] = [
main,
layout,
router,
tree,
notfound,
busy,
sidebar,
shell,
status,
info,
if (printFunction) {
await printFunction();
}
}
});
}
};
/**
* The default state database for storing application state.
*/
const state: JupyterFrontEndPlugin = {
id: '@jupyterlab/apputils-extension:state',
autoStart: true,
provides: IStateDB,
requires: [JupyterFrontEnd.IPaths, IRouter, IWindowResolver],
optional: [ISplashScreen],
activate: (
app: JupyterFrontEnd,
paths: JupyterFrontEnd.IPaths,
router: IRouter,
resolver: IWindowResolver,
splash: ISplashScreen | null
) => {
let debouncer: number;
let resolved = false;
const { commands, serviceManager } = app;
const { workspaces } = serviceManager;
const workspace = resolver.name;
const transform = new PromiseDelegate();
const db = new StateDB({