|
@@ -50,12 +50,8 @@ const plugin: JupyterFrontEndPlugin<IMarkdownViewerTracker> = {
|
|
|
activate,
|
|
|
id: '@jupyterlab/markdownviewer-extension:plugin',
|
|
|
provides: IMarkdownViewerTracker,
|
|
|
- requires: [
|
|
|
- ILayoutRestorer,
|
|
|
- IRenderMimeRegistry,
|
|
|
- ISettingRegistry,
|
|
|
- ITranslator
|
|
|
- ],
|
|
|
+ requires: [IRenderMimeRegistry, ITranslator],
|
|
|
+ optional: [ILayoutRestorer, ISettingRegistry],
|
|
|
autoStart: true
|
|
|
};
|
|
|
|
|
@@ -64,10 +60,10 @@ const plugin: JupyterFrontEndPlugin<IMarkdownViewerTracker> = {
|
|
|
*/
|
|
|
function activate(
|
|
|
app: JupyterFrontEnd,
|
|
|
- restorer: ILayoutRestorer,
|
|
|
rendermime: IRenderMimeRegistry,
|
|
|
- settingRegistry: ISettingRegistry,
|
|
|
- translator: ITranslator
|
|
|
+ translator: ITranslator,
|
|
|
+ restorer: ILayoutRestorer | null,
|
|
|
+ settingRegistry: ISettingRegistry | null
|
|
|
): IMarkdownViewerTracker {
|
|
|
const trans = translator.load('jupyterlab');
|
|
|
const { commands, docRegistry } = app;
|
|
@@ -93,28 +89,27 @@ function activate(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Update the setting values.
|
|
|
- */
|
|
|
- function updateSettings(settings: ISettingRegistry.ISettings) {
|
|
|
- config = settings.composite as Partial<MarkdownViewer.IConfig>;
|
|
|
- tracker.forEach(widget => {
|
|
|
- updateWidget(widget.content);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // Fetch the initial state of the settings.
|
|
|
- settingRegistry
|
|
|
- .load(plugin.id)
|
|
|
- .then((settings: ISettingRegistry.ISettings) => {
|
|
|
- settings.changed.connect(() => {
|
|
|
+ if (settingRegistry) {
|
|
|
+ const updateSettings = (settings: ISettingRegistry.ISettings) => {
|
|
|
+ config = settings.composite as Partial<MarkdownViewer.IConfig>;
|
|
|
+ tracker.forEach(widget => {
|
|
|
+ updateWidget(widget.content);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // Fetch the initial state of the settings.
|
|
|
+ settingRegistry
|
|
|
+ .load(plugin.id)
|
|
|
+ .then((settings: ISettingRegistry.ISettings) => {
|
|
|
+ settings.changed.connect(() => {
|
|
|
+ updateSettings(settings);
|
|
|
+ });
|
|
|
updateSettings(settings);
|
|
|
+ })
|
|
|
+ .catch((reason: Error) => {
|
|
|
+ console.error(reason.message);
|
|
|
});
|
|
|
- updateSettings(settings);
|
|
|
- })
|
|
|
- .catch((reason: Error) => {
|
|
|
- console.error(reason.message);
|
|
|
- });
|
|
|
+ }
|
|
|
|
|
|
// Register the MarkdownViewer factory.
|
|
|
const factory = new MarkdownViewerFactory({
|
|
@@ -136,11 +131,13 @@ function activate(
|
|
|
docRegistry.addWidgetFactory(factory);
|
|
|
|
|
|
// Handle state restoration.
|
|
|
- void restorer.restore(tracker, {
|
|
|
- command: 'docmanager:open',
|
|
|
- args: widget => ({ path: widget.context.path, factory: FACTORY }),
|
|
|
- name: widget => widget.context.path
|
|
|
- });
|
|
|
+ if (restorer) {
|
|
|
+ void restorer.restore(tracker, {
|
|
|
+ command: 'docmanager:open',
|
|
|
+ args: widget => ({ path: widget.context.path, factory: FACTORY }),
|
|
|
+ name: widget => widget.context.path
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
commands.addCommand(CommandIDs.markdownPreview, {
|
|
|
label: trans.__('Markdown Preview'),
|