@jupyterlab/notebook-extension 4.0.0-alpha.19 → 4.0.0-alpha.20
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/lib/index.js +112 -80
- package/lib/index.js.map +1 -1
- package/package.json +39 -37
- package/schema/panel.json +1 -1
- package/schema/tracker.json +9 -143
- package/src/index.ts +3439 -0
- package/src/nboutput.ts +75 -0
- package/style/index.css +2 -1
- package/style/index.js +2 -1
package/lib/index.js
CHANGED
|
@@ -9,6 +9,8 @@ import { createToolbarFactory, Dialog, ICommandPalette, IKernelStatusModel, Inpu
|
|
|
9
9
|
import { MarkdownCell } from '@jupyterlab/cells';
|
|
10
10
|
import { IEditorServices, IPositionModel } from '@jupyterlab/codeeditor';
|
|
11
11
|
import { PageConfig } from '@jupyterlab/coreutils';
|
|
12
|
+
import { IEditorExtensionRegistry, IEditorLanguageRegistry } from '@jupyterlab/codemirror';
|
|
13
|
+
import { ICompletionProviderManager } from '@jupyterlab/completer';
|
|
12
14
|
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
13
15
|
import { ToolbarItems as DocToolbarItems } from '@jupyterlab/docmanager-extension';
|
|
14
16
|
import { ISearchProviderRegistry } from '@jupyterlab/documentsearch';
|
|
@@ -24,8 +26,7 @@ import { IStateDB } from '@jupyterlab/statedb';
|
|
|
24
26
|
import { IStatusBar } from '@jupyterlab/statusbar';
|
|
25
27
|
import { ITableOfContentsRegistry } from '@jupyterlab/toc';
|
|
26
28
|
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
27
|
-
import { addAboveIcon, addBelowIcon, buildIcon, copyIcon, cutIcon, duplicateIcon, fastForwardIcon, moveDownIcon, moveUpIcon, notebookIcon, pasteIcon } from '@jupyterlab/ui-components';
|
|
28
|
-
import { ICompletionProviderManager } from '@jupyterlab/completer';
|
|
29
|
+
import { addAboveIcon, addBelowIcon, buildIcon, copyIcon, cutIcon, duplicateIcon, fastForwardIcon, IFormRendererRegistry, moveDownIcon, moveUpIcon, notebookIcon, pasteIcon } from '@jupyterlab/ui-components';
|
|
29
30
|
import { ArrayExt } from '@lumino/algorithm';
|
|
30
31
|
import { JSONExt, UUID } from '@lumino/coreutils';
|
|
31
32
|
import { DisposableSet } from '@lumino/disposable';
|
|
@@ -151,7 +152,7 @@ const SIDE_BY_SIDE_STYLE_ID = 'jp-NotebookExtension-sideBySideMargins';
|
|
|
151
152
|
const trackerPlugin = {
|
|
152
153
|
id: '@jupyterlab/notebook-extension:tracker',
|
|
153
154
|
provides: INotebookTracker,
|
|
154
|
-
requires: [INotebookWidgetFactory],
|
|
155
|
+
requires: [INotebookWidgetFactory, IEditorExtensionRegistry],
|
|
155
156
|
optional: [
|
|
156
157
|
ICommandPalette,
|
|
157
158
|
IDefaultFileBrowser,
|
|
@@ -161,7 +162,8 @@ const trackerPlugin = {
|
|
|
161
162
|
IRouter,
|
|
162
163
|
ISettingRegistry,
|
|
163
164
|
ISessionContextDialogs,
|
|
164
|
-
ITranslator
|
|
165
|
+
ITranslator,
|
|
166
|
+
IFormRendererRegistry
|
|
165
167
|
],
|
|
166
168
|
activate: activateNotebookHandler,
|
|
167
169
|
autoStart: true
|
|
@@ -187,7 +189,13 @@ const tools = {
|
|
|
187
189
|
provides: INotebookTools,
|
|
188
190
|
id: '@jupyterlab/notebook-extension:tools',
|
|
189
191
|
autoStart: true,
|
|
190
|
-
requires: [
|
|
192
|
+
requires: [
|
|
193
|
+
INotebookTracker,
|
|
194
|
+
IEditorServices,
|
|
195
|
+
IEditorLanguageRegistry,
|
|
196
|
+
IStateDB,
|
|
197
|
+
ITranslator
|
|
198
|
+
],
|
|
191
199
|
optional: [IPropertyInspectorProvider]
|
|
192
200
|
};
|
|
193
201
|
/**
|
|
@@ -357,43 +365,53 @@ export const exportPlugin = {
|
|
|
357
365
|
((_a = item.submenu) === null || _a === void 0 ? void 0 : _a.id) === 'jp-mainmenu-file-notebookexport';
|
|
358
366
|
})) === null || _a === void 0 ? void 0 : _a.submenu;
|
|
359
367
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
formatList.forEach(function (key) {
|
|
366
|
-
const capCaseKey = trans.__(key[0].toUpperCase() + key.substr(1));
|
|
367
|
-
const labelStr = formatLabels[key] ? formatLabels[key] : capCaseKey;
|
|
368
|
-
let args = {
|
|
369
|
-
format: key,
|
|
370
|
-
label: labelStr,
|
|
371
|
-
isPalette: false
|
|
372
|
-
};
|
|
373
|
-
if (FORMAT_EXCLUDE.indexOf(key) === -1) {
|
|
374
|
-
if (exportTo) {
|
|
375
|
-
exportTo.addItem({
|
|
376
|
-
command: CommandIDs.exportToFormat,
|
|
377
|
-
args: args
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
if (palette) {
|
|
381
|
-
args = {
|
|
382
|
-
format: key,
|
|
383
|
-
label: labelStr,
|
|
384
|
-
isPalette: true
|
|
385
|
-
};
|
|
386
|
-
const category = trans.__('Notebook Operations');
|
|
387
|
-
palette.addItem({
|
|
388
|
-
command: CommandIDs.exportToFormat,
|
|
389
|
-
category,
|
|
390
|
-
args
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
});
|
|
368
|
+
let formatsInitialized = false;
|
|
369
|
+
/** Request formats only when a notebook might use them. */
|
|
370
|
+
const maybeInitializeFormats = async () => {
|
|
371
|
+
if (formatsInitialized) {
|
|
372
|
+
return;
|
|
395
373
|
}
|
|
396
|
-
|
|
374
|
+
tracker.widgetAdded.disconnect(maybeInitializeFormats);
|
|
375
|
+
formatsInitialized = true;
|
|
376
|
+
const response = await services.nbconvert.getExportFormats(false);
|
|
377
|
+
if (!response) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
const formatLabels = Private.getFormatLabels(translator);
|
|
381
|
+
// Convert export list to palette and menu items.
|
|
382
|
+
const formatList = Object.keys(response);
|
|
383
|
+
formatList.forEach(function (key) {
|
|
384
|
+
const capCaseKey = trans.__(key[0].toUpperCase() + key.substr(1));
|
|
385
|
+
const labelStr = formatLabels[key] ? formatLabels[key] : capCaseKey;
|
|
386
|
+
let args = {
|
|
387
|
+
format: key,
|
|
388
|
+
label: labelStr,
|
|
389
|
+
isPalette: false
|
|
390
|
+
};
|
|
391
|
+
if (FORMAT_EXCLUDE.indexOf(key) === -1) {
|
|
392
|
+
if (exportTo) {
|
|
393
|
+
exportTo.addItem({
|
|
394
|
+
command: CommandIDs.exportToFormat,
|
|
395
|
+
args: args
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
if (palette) {
|
|
399
|
+
args = {
|
|
400
|
+
format: key,
|
|
401
|
+
label: labelStr,
|
|
402
|
+
isPalette: true
|
|
403
|
+
};
|
|
404
|
+
const category = trans.__('Notebook Operations');
|
|
405
|
+
palette.addItem({
|
|
406
|
+
command: CommandIDs.exportToFormat,
|
|
407
|
+
category,
|
|
408
|
+
args
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
};
|
|
414
|
+
tracker.widgetAdded.connect(maybeInitializeFormats);
|
|
397
415
|
}
|
|
398
416
|
};
|
|
399
417
|
/**
|
|
@@ -593,15 +611,15 @@ export default plugins;
|
|
|
593
611
|
/**
|
|
594
612
|
* Activate the notebook tools extension.
|
|
595
613
|
*/
|
|
596
|
-
function activateNotebookTools(app, tracker, editorServices, state, translator, inspectorProvider) {
|
|
614
|
+
function activateNotebookTools(app, tracker, editorServices, languages, state, translator, inspectorProvider) {
|
|
597
615
|
const trans = translator.load('jupyterlab');
|
|
598
616
|
const id = 'notebook-tools';
|
|
599
617
|
const notebookTools = new NotebookTools({ tracker, translator });
|
|
600
|
-
const activeCellTool = new NotebookTools.ActiveCellTool();
|
|
618
|
+
const activeCellTool = new NotebookTools.ActiveCellTool(languages);
|
|
601
619
|
const editable = NotebookTools.createEditableToggle(translator);
|
|
602
620
|
const slideShow = NotebookTools.createSlideShowSelector(translator);
|
|
603
621
|
const tocBaseNumbering = NotebookTools.createToCBaseNumbering(translator);
|
|
604
|
-
const editorFactory = editorServices.factoryService.newInlineEditor;
|
|
622
|
+
const editorFactory = options => editorServices.factoryService.newInlineEditor(options);
|
|
605
623
|
const cellMetadataEditor = new NotebookTools.CellMetadataEditorTool({
|
|
606
624
|
editorFactory,
|
|
607
625
|
collapsed: false,
|
|
@@ -629,41 +647,44 @@ function activateNotebookTools(app, tracker, editorServices, state, translator,
|
|
|
629
647
|
};
|
|
630
648
|
const optionsMap = {};
|
|
631
649
|
optionsMap.None = null;
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
* (returned from nbconvert's export list)
|
|
637
|
-
*/
|
|
638
|
-
const rawFormatExclude = [
|
|
639
|
-
'pdf',
|
|
640
|
-
'slides',
|
|
641
|
-
'script',
|
|
642
|
-
'notebook',
|
|
643
|
-
'custom'
|
|
644
|
-
];
|
|
645
|
-
let optionValueArray = [
|
|
646
|
-
[trans.__('PDF'), 'pdf'],
|
|
647
|
-
[trans.__('Slides'), 'slides'],
|
|
648
|
-
[trans.__('Script'), 'script'],
|
|
649
|
-
[trans.__('Notebook'), 'notebook'],
|
|
650
|
-
[trans.__('Custom'), 'custom']
|
|
651
|
-
];
|
|
652
|
-
// convert exportList to palette and menu items
|
|
653
|
-
const formatList = Object.keys(response);
|
|
654
|
-
const formatLabels = Private.getFormatLabels(translator);
|
|
655
|
-
formatList.forEach(function (key) {
|
|
656
|
-
if (rawFormatExclude.indexOf(key) === -1) {
|
|
657
|
-
const altOption = trans.__(key[0].toUpperCase() + key.substr(1));
|
|
658
|
-
const option = formatLabels[key] ? formatLabels[key] : altOption;
|
|
659
|
-
const mimeTypeValue = response[key].output_mimetype;
|
|
660
|
-
optionValueArray.push([option, mimeTypeValue]);
|
|
661
|
-
}
|
|
662
|
-
});
|
|
663
|
-
const nbConvert = NotebookTools.createNBConvertSelector(optionValueArray, translator);
|
|
664
|
-
notebookTools.addItem({ tool: nbConvert, section: 'common', rank: 3 });
|
|
650
|
+
let formatsInitialized = false;
|
|
651
|
+
async function maybeInitializeFormats() {
|
|
652
|
+
if (formatsInitialized) {
|
|
653
|
+
return;
|
|
665
654
|
}
|
|
666
|
-
|
|
655
|
+
tracker.widgetAdded.disconnect(maybeInitializeFormats);
|
|
656
|
+
formatsInitialized = true;
|
|
657
|
+
const response = await services.nbconvert.getExportFormats(false);
|
|
658
|
+
if (!response) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* The excluded Cell Inspector Raw NbConvert Formats
|
|
663
|
+
* (returned from nbconvert's export list)
|
|
664
|
+
*/
|
|
665
|
+
const rawFormatExclude = ['pdf', 'slides', 'script', 'notebook', 'custom'];
|
|
666
|
+
let optionValueArray = [
|
|
667
|
+
[trans.__('PDF'), 'pdf'],
|
|
668
|
+
[trans.__('Slides'), 'slides'],
|
|
669
|
+
[trans.__('Script'), 'script'],
|
|
670
|
+
[trans.__('Notebook'), 'notebook'],
|
|
671
|
+
[trans.__('Custom'), 'custom']
|
|
672
|
+
];
|
|
673
|
+
// convert exportList to palette and menu items
|
|
674
|
+
const formatList = Object.keys(response);
|
|
675
|
+
const formatLabels = Private.getFormatLabels(translator);
|
|
676
|
+
formatList.forEach(function (key) {
|
|
677
|
+
if (rawFormatExclude.indexOf(key) === -1) {
|
|
678
|
+
const altOption = trans.__(key[0].toUpperCase() + key.substr(1));
|
|
679
|
+
const option = formatLabels[key] ? formatLabels[key] : altOption;
|
|
680
|
+
const mimeTypeValue = response[key].output_mimetype;
|
|
681
|
+
optionValueArray.push([option, mimeTypeValue]);
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
const nbConvert = NotebookTools.createNBConvertSelector(optionValueArray, translator);
|
|
685
|
+
notebookTools.addItem({ tool: nbConvert, section: 'common', rank: 3 });
|
|
686
|
+
}
|
|
687
|
+
tracker.widgetAdded.connect(maybeInitializeFormats);
|
|
667
688
|
notebookTools.title.icon = buildIcon;
|
|
668
689
|
notebookTools.title.caption = trans.__('Notebook Tools');
|
|
669
690
|
notebookTools.id = id;
|
|
@@ -1004,7 +1025,7 @@ function activateCopyOutput(app, translator, tracker) {
|
|
|
1004
1025
|
/**
|
|
1005
1026
|
* Activate the notebook handler extension.
|
|
1006
1027
|
*/
|
|
1007
|
-
function activateNotebookHandler(app, factory, palette, defaultBrowser, launcher, restorer, mainMenu, router, settingRegistry, sessionDialogs, translator) {
|
|
1028
|
+
function activateNotebookHandler(app, factory, extensions, palette, defaultBrowser, launcher, restorer, mainMenu, router, settingRegistry, sessionDialogs, translator, formRegistry) {
|
|
1008
1029
|
translator = translator !== null && translator !== void 0 ? translator : nullTranslator;
|
|
1009
1030
|
const trans = translator.load('jupyterlab');
|
|
1010
1031
|
const services = app.serviceManager;
|
|
@@ -1054,7 +1075,10 @@ function activateNotebookHandler(app, factory, palette, defaultBrowser, launcher
|
|
|
1054
1075
|
void settings.set('rawCellConfig', rawConfig);
|
|
1055
1076
|
},
|
|
1056
1077
|
label: trans.__('Auto Close Brackets for All Notebook Cell Types'),
|
|
1057
|
-
isToggled: () => ['codeCellConfig', 'markdownCellConfig', 'rawCellConfig'].some(x =>
|
|
1078
|
+
isToggled: () => ['codeCellConfig', 'markdownCellConfig', 'rawCellConfig'].some(x => {
|
|
1079
|
+
var _a;
|
|
1080
|
+
return ((_a = settings.get(x).composite.autoClosingBrackets) !== null && _a !== void 0 ? _a : extensions.baseConfiguration['autoClosingBrackets']) === true;
|
|
1081
|
+
})
|
|
1058
1082
|
});
|
|
1059
1083
|
commands.addCommand(CommandIDs.setSideBySideRatio, {
|
|
1060
1084
|
label: trans.__('Set side-by-side ratio'),
|
|
@@ -1081,6 +1105,14 @@ function activateNotebookHandler(app, factory, palette, defaultBrowser, launcher
|
|
|
1081
1105
|
kernelShutdown: factory.shutdownOnClose
|
|
1082
1106
|
});
|
|
1083
1107
|
});
|
|
1108
|
+
if (formRegistry) {
|
|
1109
|
+
const CMRenderer = formRegistry.getRenderer('@jupyterlab/codemirror-extension:plugin.defaultConfig');
|
|
1110
|
+
if (CMRenderer) {
|
|
1111
|
+
formRegistry.addRenderer('@jupyterlab/notebook-extension:tracker.codeCellConfig', CMRenderer);
|
|
1112
|
+
formRegistry.addRenderer('@jupyterlab/notebook-extension:tracker.markdownCellConfig', CMRenderer);
|
|
1113
|
+
formRegistry.addRenderer('@jupyterlab/notebook-extension:tracker.rawCellConfig', CMRenderer);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1084
1116
|
// Handle state restoration.
|
|
1085
1117
|
if (restorer) {
|
|
1086
1118
|
void restorer.restore(tracker, {
|