@jupyterlab/notebook-extension 4.0.0-alpha.1 → 4.0.0-alpha.12

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 CHANGED
@@ -5,23 +5,27 @@
5
5
  * @module notebook-extension
6
6
  */
7
7
  import { ILabShell, ILayoutRestorer } from '@jupyterlab/application';
8
- import { createToolbarFactory, Dialog, ICommandPalette, InputDialog, ISessionContextDialogs, IToolbarWidgetRegistry, MainAreaWidget, sessionContextDialogs, showDialog, Toolbar, WidgetTracker } from '@jupyterlab/apputils';
8
+ import { createToolbarFactory, Dialog, ICommandPalette, IKernelStatusModel, InputDialog, ISanitizer, ISessionContextDialogs, IToolbarWidgetRegistry, MainAreaWidget, sessionContextDialogs, showDialog, Toolbar, WidgetTracker } from '@jupyterlab/apputils';
9
9
  import { MarkdownCell } from '@jupyterlab/cells';
10
- import { IEditorServices } from '@jupyterlab/codeeditor';
10
+ import { IEditorServices, IPositionModel } from '@jupyterlab/codeeditor';
11
11
  import { PageConfig } from '@jupyterlab/coreutils';
12
12
  import { IDocumentManager } from '@jupyterlab/docmanager';
13
13
  import { ToolbarItems as DocToolbarItems } from '@jupyterlab/docmanager-extension';
14
+ import { ISearchProviderRegistry } from '@jupyterlab/documentsearch';
14
15
  import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
15
16
  import { ILauncher } from '@jupyterlab/launcher';
17
+ import { ILSPCodeExtractorsManager, ILSPDocumentConnectionManager, ILSPFeatureManager } from '@jupyterlab/lsp';
16
18
  import { IMainMenu } from '@jupyterlab/mainmenu';
17
- import { CommandEditStatus, ExecutionIndicator, INotebookTools, INotebookTracker, INotebookWidgetFactory, NotebookActions, NotebookModelFactory, NotebookPanel, NotebookTools, NotebookTracker, NotebookTrustStatus, NotebookWidgetFactory, StaticNotebook, ToolbarItems } from '@jupyterlab/notebook';
19
+ import { CommandEditStatus, ExecutionIndicator, INotebookTools, INotebookTracker, INotebookWidgetFactory, NotebookActions, NotebookAdapter, NotebookModelFactory, NotebookPanel, NotebookSearchProvider, NotebookToCFactory, NotebookTools, NotebookTracker, NotebookTrustStatus, NotebookWidgetFactory, StaticNotebook, ToolbarItems } from '@jupyterlab/notebook';
18
20
  import { IPropertyInspectorProvider } from '@jupyterlab/property-inspector';
19
- import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
21
+ import { IMarkdownParser, IRenderMimeRegistry } from '@jupyterlab/rendermime';
20
22
  import { ISettingRegistry } from '@jupyterlab/settingregistry';
21
23
  import { IStateDB } from '@jupyterlab/statedb';
22
24
  import { IStatusBar } from '@jupyterlab/statusbar';
25
+ import { ITableOfContentsRegistry } from '@jupyterlab/toc';
23
26
  import { ITranslator, nullTranslator } from '@jupyterlab/translation';
24
- import { addIcon, buildIcon, copyIcon, cutIcon, notebookIcon, pasteIcon } from '@jupyterlab/ui-components';
27
+ import { addAboveIcon, addBelowIcon, buildIcon, copyIcon, cutIcon, duplicateIcon, moveDownIcon, moveUpIcon, notebookIcon, pasteIcon } from '@jupyterlab/ui-components';
28
+ import { ICompletionProviderManager } from '@jupyterlab/completer';
25
29
  import { ArrayExt } from '@lumino/algorithm';
26
30
  import { JSONExt, UUID } from '@lumino/coreutils';
27
31
  import { DisposableSet } from '@lumino/disposable';
@@ -64,6 +68,7 @@ var CommandIDs;
64
68
  CommandIDs.copy = 'notebook:copy-cell';
65
69
  CommandIDs.pasteAbove = 'notebook:paste-cell-above';
66
70
  CommandIDs.pasteBelow = 'notebook:paste-cell-below';
71
+ CommandIDs.duplicateBelow = 'notebook:duplicate-below';
67
72
  CommandIDs.pasteAndReplace = 'notebook:paste-and-replace-cell';
68
73
  CommandIDs.moveUp = 'notebook:move-cell-up';
69
74
  CommandIDs.moveDown = 'notebook:move-cell-down';
@@ -73,6 +78,10 @@ var CommandIDs;
73
78
  CommandIDs.insertBelow = 'notebook:insert-cell-below';
74
79
  CommandIDs.selectAbove = 'notebook:move-cursor-up';
75
80
  CommandIDs.selectBelow = 'notebook:move-cursor-down';
81
+ CommandIDs.selectHeadingAboveOrCollapse = 'notebook:move-cursor-heading-above-or-collapse';
82
+ CommandIDs.selectHeadingBelowOrExpand = 'notebook:move-cursor-heading-below-or-expand';
83
+ CommandIDs.insertHeadingAbove = 'notebook:insert-heading-above';
84
+ CommandIDs.insertHeadingBelow = 'notebook:insert-heading-below';
76
85
  CommandIDs.extendAbove = 'notebook:extend-marked-cells-above';
77
86
  CommandIDs.extendTop = 'notebook:extend-marked-cells-top';
78
87
  CommandIDs.extendBelow = 'notebook:extend-marked-cells-below';
@@ -104,17 +113,20 @@ var CommandIDs;
104
113
  CommandIDs.showOutput = 'notebook:show-cell-outputs';
105
114
  CommandIDs.hideAllOutputs = 'notebook:hide-all-cell-outputs';
106
115
  CommandIDs.showAllOutputs = 'notebook:show-all-cell-outputs';
107
- CommandIDs.toggleRenderSideBySide = 'notebook:toggle-render-side-by-side';
116
+ CommandIDs.toggleRenderSideBySideCurrentNotebook = 'notebook:toggle-render-side-by-side-current';
108
117
  CommandIDs.setSideBySideRatio = 'notebook:set-side-by-side-ratio';
109
118
  CommandIDs.enableOutputScrolling = 'notebook:enable-output-scrolling';
110
119
  CommandIDs.disableOutputScrolling = 'notebook:disable-output-scrolling';
111
120
  CommandIDs.selectLastRunCell = 'notebook:select-last-run-cell';
112
121
  CommandIDs.replaceSelection = 'notebook:replace-selection';
113
122
  CommandIDs.autoClosingBrackets = 'notebook:toggle-autoclosing-brackets';
114
- CommandIDs.toggleCollapseCmd = 'Collapsible_Headings:Toggle_Collapse';
115
- CommandIDs.collapseAllCmd = 'Collapsible_Headings:Collapse_All';
116
- CommandIDs.expandAllCmd = 'Collapsible_Headings:Expand_All';
123
+ CommandIDs.toggleCollapseCmd = 'notebook:toggle-heading-collapse';
124
+ CommandIDs.collapseAllCmd = 'notebook:collapse-all-headings';
125
+ CommandIDs.expandAllCmd = 'notebook:expand-all-headings';
117
126
  CommandIDs.copyToClipboard = 'notebook:copy-to-clipboard';
127
+ CommandIDs.invokeCompleter = 'completer:invoke-notebook';
128
+ CommandIDs.selectCompleter = 'completer:select-notebook';
129
+ CommandIDs.tocRunCells = 'toc:run-cells';
118
130
  })(CommandIDs || (CommandIDs = {}));
119
131
  /**
120
132
  * The name of the factory that creates notebooks.
@@ -129,6 +141,10 @@ const FORMAT_EXCLUDE = ['notebook', 'python', 'custom'];
129
141
  * Setting Id storing the customized toolbar definition.
130
142
  */
131
143
  const PANEL_SETTINGS = '@jupyterlab/notebook-extension:panel';
144
+ /**
145
+ * The id to use on the style tag for the side by side margins.
146
+ */
147
+ const SIDE_BY_SIDE_STYLE_ID = 'jp-NotebookExtension-sideBySideMargins';
132
148
  /**
133
149
  * The notebook widget tracker provider.
134
150
  */
@@ -299,6 +315,9 @@ export const exportPlugin = {
299
315
  };
300
316
  commands.addCommand(CommandIDs.exportToFormat, {
301
317
  label: args => {
318
+ if (args.label === undefined) {
319
+ return trans.__('Save and Export Notebook to the given `format`.');
320
+ }
302
321
  const formatLabel = args['label'];
303
322
  return args['isPalette']
304
323
  ? trans.__('Save and Export Notebook: %1', formatLabel)
@@ -446,11 +465,96 @@ const codeConsolePlugin = {
446
465
  * A plugin to copy CodeCell outputs.
447
466
  */
448
467
  const copyOutputPlugin = {
449
- id: '@jupyterlab/notebook-extensions:copy-output',
468
+ id: '@jupyterlab/notebook-extension:copy-output',
450
469
  activate: activateCopyOutput,
451
470
  requires: [ITranslator, INotebookTracker],
452
471
  autoStart: true
453
472
  };
473
+ /**
474
+ * Kernel status indicator.
475
+ */
476
+ const kernelStatus = {
477
+ id: '@jupyterlab/notebook-extension:kernel-status',
478
+ activate: (app, tracker, kernelStatus) => {
479
+ const provider = (widget) => {
480
+ let session = null;
481
+ if (widget && tracker.has(widget)) {
482
+ return widget.sessionContext;
483
+ }
484
+ return session;
485
+ };
486
+ kernelStatus.addSessionProvider(provider);
487
+ },
488
+ requires: [INotebookTracker, IKernelStatusModel],
489
+ autoStart: true
490
+ };
491
+ /**
492
+ * Cursor position.
493
+ */
494
+ const lineColStatus = {
495
+ id: '@jupyterlab/notebook-extension:cursor-position',
496
+ activate: (app, tracker, positionModel) => {
497
+ let previousWidget = null;
498
+ const provider = (widget) => {
499
+ var _a, _b, _c, _d;
500
+ let editor = null;
501
+ if (widget !== previousWidget) {
502
+ previousWidget === null || previousWidget === void 0 ? void 0 : previousWidget.content.activeCellChanged.disconnect(positionModel.update);
503
+ previousWidget = null;
504
+ if (widget && tracker.has(widget)) {
505
+ widget.content.activeCellChanged.connect(positionModel.update);
506
+ editor = (_b = (_a = widget.content.activeCell) === null || _a === void 0 ? void 0 : _a.editor) !== null && _b !== void 0 ? _b : null;
507
+ previousWidget = widget;
508
+ }
509
+ }
510
+ else if (widget) {
511
+ editor = (_d = (_c = widget.content.activeCell) === null || _c === void 0 ? void 0 : _c.editor) !== null && _d !== void 0 ? _d : null;
512
+ }
513
+ return editor;
514
+ };
515
+ positionModel.addEditorProvider(provider);
516
+ },
517
+ requires: [INotebookTracker, IPositionModel],
518
+ autoStart: true
519
+ };
520
+ const completerPlugin = {
521
+ id: '@jupyterlab/notebook-extension:completer',
522
+ requires: [INotebookTracker],
523
+ optional: [ICompletionProviderManager, ITranslator],
524
+ activate: activateNotebookCompleterService,
525
+ autoStart: true
526
+ };
527
+ /**
528
+ * A plugin to search notebook documents
529
+ */
530
+ const searchProvider = {
531
+ id: '@jupyterlab/notebook-extension:search',
532
+ requires: [ISearchProviderRegistry],
533
+ autoStart: true,
534
+ activate: (app, registry) => {
535
+ registry.add('jp-notebookSearchProvider', NotebookSearchProvider);
536
+ }
537
+ };
538
+ const tocPlugin = {
539
+ id: '@jupyterlab/notebook-extension:toc',
540
+ requires: [INotebookTracker, ITableOfContentsRegistry, ISanitizer],
541
+ optional: [IMarkdownParser],
542
+ autoStart: true,
543
+ activate: (app, tracker, tocRegistry, sanitizer, mdParser) => {
544
+ tocRegistry.add(new NotebookToCFactory(tracker, mdParser, sanitizer));
545
+ }
546
+ };
547
+ const languageServerPlugin = {
548
+ id: '@jupyterlab/notebook-extension:language-server',
549
+ requires: [
550
+ INotebookTracker,
551
+ ILSPDocumentConnectionManager,
552
+ ILSPFeatureManager,
553
+ ILSPCodeExtractorsManager
554
+ ],
555
+ activate: activateNotebookLanguageServer,
556
+ autoStart: true
557
+ };
454
558
  /**
455
559
  * Export the plugins as default.
456
560
  */
@@ -466,7 +570,13 @@ const plugins = [
466
570
  logNotebookOutput,
467
571
  clonedOutputsPlugin,
468
572
  codeConsolePlugin,
469
- copyOutputPlugin
573
+ copyOutputPlugin,
574
+ kernelStatus,
575
+ lineColStatus,
576
+ completerPlugin,
577
+ searchProvider,
578
+ tocPlugin,
579
+ languageServerPlugin
470
580
  ];
471
581
  export default plugins;
472
582
  /**
@@ -479,6 +589,7 @@ function activateNotebookTools(app, tracker, editorServices, state, translator,
479
589
  const activeCellTool = new NotebookTools.ActiveCellTool();
480
590
  const editable = NotebookTools.createEditableToggle(translator);
481
591
  const slideShow = NotebookTools.createSlideShowSelector(translator);
592
+ const tocBaseNumbering = NotebookTools.createToCBaseNumbering(translator);
482
593
  const editorFactory = editorServices.factoryService.newInlineEditor;
483
594
  const cellMetadataEditor = new NotebookTools.CellMetadataEditorTool({
484
595
  editorFactory,
@@ -548,6 +659,7 @@ function activateNotebookTools(app, tracker, editorServices, state, translator,
548
659
  notebookTools.addItem({ tool: activeCellTool, section: 'common', rank: 1 });
549
660
  notebookTools.addItem({ tool: editable, section: 'common', rank: 2 });
550
661
  notebookTools.addItem({ tool: slideShow, section: 'common', rank: 3 });
662
+ notebookTools.addItem({ tool: tocBaseNumbering, section: 'common', rank: 4 });
551
663
  notebookTools.addItem({
552
664
  tool: cellMetadataEditor,
553
665
  section: 'advanced',
@@ -571,13 +683,16 @@ function activateNotebookTools(app, tracker, editorServices, state, translator,
571
683
  * Activate the notebook widget factory.
572
684
  */
573
685
  function activateWidgetFactory(app, contentFactory, editorServices, rendermime, sessionContextDialogs, toolbarRegistry, translator, settingRegistry) {
686
+ const preferKernelOption = PageConfig.getOption('notebookStartsKernel');
687
+ // If the option is not set, assume `true`
688
+ const preferKernelValue = preferKernelOption === '' || preferKernelOption.toLowerCase() === 'true';
574
689
  const { commands } = app;
575
690
  let toolbarFactory;
576
691
  // Register notebook toolbar widgets
577
- toolbarRegistry.registerFactory(FACTORY, 'save', panel => DocToolbarItems.createSaveButton(commands, panel.context.fileChanged));
578
- toolbarRegistry.registerFactory(FACTORY, 'cellType', panel => ToolbarItems.createCellTypeItem(panel, translator));
579
- toolbarRegistry.registerFactory(FACTORY, 'kernelName', panel => Toolbar.createKernelNameItem(panel.sessionContext, sessionContextDialogs, translator));
580
- toolbarRegistry.registerFactory(FACTORY, 'executionProgress', panel => {
692
+ toolbarRegistry.addFactory(FACTORY, 'save', panel => DocToolbarItems.createSaveButton(commands, panel.context.fileChanged));
693
+ toolbarRegistry.addFactory(FACTORY, 'cellType', panel => ToolbarItems.createCellTypeItem(panel, translator));
694
+ toolbarRegistry.addFactory(FACTORY, 'kernelName', panel => Toolbar.createKernelNameItem(panel.sessionContext, sessionContextDialogs, translator));
695
+ toolbarRegistry.addFactory(FACTORY, 'executionProgress', panel => {
581
696
  return ExecutionIndicator.createExecutionIndicatorItem(panel, translator, settingRegistry === null || settingRegistry === void 0 ? void 0 : settingRegistry.load(trackerPlugin.id));
582
697
  });
583
698
  if (settingRegistry) {
@@ -591,7 +706,7 @@ function activateWidgetFactory(app, contentFactory, editorServices, rendermime,
591
706
  fileTypes: ['notebook'],
592
707
  modelName: 'notebook',
593
708
  defaultFor: ['notebook'],
594
- preferKernel: true,
709
+ preferKernel: preferKernelValue,
595
710
  canStartKernel: true,
596
711
  rendermime,
597
712
  contentFactory,
@@ -629,7 +744,7 @@ function activateClonedOutputs(app, docManager, notebookTracker, translator, res
629
744
  return Private.isEnabledAndSingleSelected(shell, notebookTracker);
630
745
  };
631
746
  commands.addCommand(CommandIDs.createOutputView, {
632
- label: trans.__('Create New View for Output'),
747
+ label: trans.__('Create New View for Cell Output'),
633
748
  execute: async (args) => {
634
749
  var _a;
635
750
  let cell;
@@ -662,7 +777,8 @@ function activateClonedOutputs(app, docManager, notebookTracker, translator, res
662
777
  const widget = new MainAreaWidget({ content });
663
778
  current.context.addSibling(widget, {
664
779
  ref: current.id,
665
- mode: 'split-bottom'
780
+ mode: 'split-bottom',
781
+ type: 'Cloned Output'
666
782
  });
667
783
  const updateCloned = () => {
668
784
  void clonedOutputs.save(widget);
@@ -875,52 +991,69 @@ function activateNotebookHandler(app, factory, translator, palette, browserFacto
875
991
  const isEnabled = () => {
876
992
  return Private.isEnabled(shell, tracker);
877
993
  };
994
+ const setSideBySideOutputRatio = (sideBySideOutputRatio) => document.documentElement.style.setProperty('--jp-side-by-side-output-size', `${sideBySideOutputRatio}fr`);
878
995
  // Fetch settings if possible.
879
996
  const fetchSettings = settingRegistry
880
997
  ? settingRegistry.load(trackerPlugin.id)
881
998
  : Promise.reject(new Error(`No setting registry for ${trackerPlugin.id}`));
882
- // Handle state restoration.
883
- if (restorer) {
884
- fetchSettings
885
- .then(settings => {
999
+ fetchSettings
1000
+ .then(settings => {
1001
+ updateConfig(settings);
1002
+ settings.changed.connect(() => {
886
1003
  updateConfig(settings);
887
- settings.changed.connect(() => {
888
- updateConfig(settings);
889
- });
890
- commands.addCommand(CommandIDs.autoClosingBrackets, {
891
- execute: args => {
892
- var _a;
893
- const codeConfig = settings.get('codeCellConfig')
894
- .composite;
895
- const markdownConfig = settings.get('markdownCellConfig')
896
- .composite;
897
- const rawConfig = settings.get('rawCellConfig')
898
- .composite;
899
- const anyToggled = codeConfig.autoClosingBrackets ||
900
- markdownConfig.autoClosingBrackets ||
901
- rawConfig.autoClosingBrackets;
902
- const toggled = !!((_a = args['force']) !== null && _a !== void 0 ? _a : !anyToggled);
903
- [
904
- codeConfig.autoClosingBrackets,
905
- markdownConfig.autoClosingBrackets,
906
- rawConfig.autoClosingBrackets
907
- ] = [toggled, toggled, toggled];
908
- void settings.set('codeCellConfig', codeConfig);
909
- void settings.set('markdownCellConfig', markdownConfig);
910
- void settings.set('rawCellConfig', rawConfig);
911
- },
912
- label: trans.__('Auto Close Brackets for All Notebook Cell Types'),
913
- isToggled: () => ['codeCellConfig', 'markdownCellConfig', 'rawCellConfig'].some(x => settings.get(x).composite.autoClosingBrackets)
914
- });
915
- })
916
- .catch((reason) => {
917
- console.warn(reason.message);
918
- updateTracker({
919
- editorConfig: factory.editorConfig,
920
- notebookConfig: factory.notebookConfig,
921
- kernelShutdown: factory.shutdownOnClose
922
- });
923
1004
  });
1005
+ commands.addCommand(CommandIDs.autoClosingBrackets, {
1006
+ execute: args => {
1007
+ var _a;
1008
+ const codeConfig = settings.get('codeCellConfig')
1009
+ .composite;
1010
+ const markdownConfig = settings.get('markdownCellConfig')
1011
+ .composite;
1012
+ const rawConfig = settings.get('rawCellConfig')
1013
+ .composite;
1014
+ const anyToggled = codeConfig.autoClosingBrackets ||
1015
+ markdownConfig.autoClosingBrackets ||
1016
+ rawConfig.autoClosingBrackets;
1017
+ const toggled = !!((_a = args['force']) !== null && _a !== void 0 ? _a : !anyToggled);
1018
+ [
1019
+ codeConfig.autoClosingBrackets,
1020
+ markdownConfig.autoClosingBrackets,
1021
+ rawConfig.autoClosingBrackets
1022
+ ] = [toggled, toggled, toggled];
1023
+ void settings.set('codeCellConfig', codeConfig);
1024
+ void settings.set('markdownCellConfig', markdownConfig);
1025
+ void settings.set('rawCellConfig', rawConfig);
1026
+ },
1027
+ label: trans.__('Auto Close Brackets for All Notebook Cell Types'),
1028
+ isToggled: () => ['codeCellConfig', 'markdownCellConfig', 'rawCellConfig'].some(x => settings.get(x).composite.autoClosingBrackets)
1029
+ });
1030
+ commands.addCommand(CommandIDs.setSideBySideRatio, {
1031
+ label: trans.__('Set side-by-side ratio'),
1032
+ execute: args => {
1033
+ InputDialog.getNumber({
1034
+ title: trans.__('Width of the output in side-by-side mode'),
1035
+ value: settings.get('sideBySideOutputRatio').composite
1036
+ })
1037
+ .then(result => {
1038
+ setSideBySideOutputRatio(result.value);
1039
+ if (result.value) {
1040
+ void settings.set('sideBySideOutputRatio', result.value);
1041
+ }
1042
+ })
1043
+ .catch(console.error);
1044
+ }
1045
+ });
1046
+ })
1047
+ .catch((reason) => {
1048
+ console.warn(reason.message);
1049
+ updateTracker({
1050
+ editorConfig: factory.editorConfig,
1051
+ notebookConfig: factory.notebookConfig,
1052
+ kernelShutdown: factory.shutdownOnClose
1053
+ });
1054
+ });
1055
+ // Handle state restoration.
1056
+ if (restorer) {
924
1057
  void restorer.restore(tracker, {
925
1058
  command: 'docmanager:open',
926
1059
  args: panel => ({ path: panel.context.path, factory: FACTORY }),
@@ -978,19 +1111,35 @@ function activateNotebookHandler(app, factory, translator, palette, browserFacto
978
1111
  recordTiming: settings.get('recordTiming').composite,
979
1112
  numberCellsToRenderDirectly: settings.get('numberCellsToRenderDirectly')
980
1113
  .composite,
1114
+ remainingTimeBeforeRescheduling: settings.get('remainingTimeBeforeRescheduling').composite,
981
1115
  renderCellOnIdle: settings.get('renderCellOnIdle').composite,
982
1116
  observedTopMargin: settings.get('observedTopMargin').composite,
983
1117
  observedBottomMargin: settings.get('observedBottomMargin')
984
1118
  .composite,
985
1119
  maxNumberOutputs: settings.get('maxNumberOutputs').composite,
986
- disableDocumentWideUndoRedo: settings.get('experimentalDisableDocumentWideUndoRedo').composite
1120
+ showEditorForReadOnlyMarkdown: settings.get('showEditorForReadOnlyMarkdown').composite,
1121
+ disableDocumentWideUndoRedo: settings.get('experimentalDisableDocumentWideUndoRedo').composite,
1122
+ renderingLayout: settings.get('renderingLayout').composite,
1123
+ sideBySideLeftMarginOverride: settings.get('sideBySideLeftMarginOverride')
1124
+ .composite,
1125
+ sideBySideRightMarginOverride: settings.get('sideBySideRightMarginOverride').composite,
1126
+ sideBySideOutputRatio: settings.get('sideBySideOutputRatio')
1127
+ .composite
987
1128
  };
1129
+ setSideBySideOutputRatio(factory.notebookConfig.sideBySideOutputRatio);
1130
+ const sideBySideMarginStyle = `.jp-mod-sideBySide.jp-Notebook .jp-Notebook-cell {
1131
+ margin-left: ${factory.notebookConfig.sideBySideLeftMarginOverride} !important;
1132
+ margin-right: ${factory.notebookConfig.sideBySideRightMarginOverride} !important;`;
1133
+ const sideBySideMarginTag = document.getElementById(SIDE_BY_SIDE_STYLE_ID);
1134
+ if (sideBySideMarginTag) {
1135
+ sideBySideMarginTag.innerText = sideBySideMarginStyle;
1136
+ }
1137
+ else {
1138
+ document.head.insertAdjacentHTML('beforeend', `<style id="${SIDE_BY_SIDE_STYLE_ID}">${sideBySideMarginStyle}}</style>`);
1139
+ }
988
1140
  factory.shutdownOnClose = settings.get('kernelShutdown')
989
1141
  .composite;
990
1142
  modelFactory.disableDocumentWideUndoRedo = settings.get('experimentalDisableDocumentWideUndoRedo').composite;
991
- Private.renderSideBySide = !settings.get('sideBySideRendering')
992
- .composite;
993
- commands.execute(CommandIDs.toggleRenderSideBySide);
994
1143
  updateTracker({
995
1144
  editorConfig: factory.editorConfig,
996
1145
  notebookConfig: factory.notebookConfig,
@@ -1073,6 +1222,84 @@ function activateNotebookHandler(app, factory, translator, palette, browserFacto
1073
1222
  }
1074
1223
  return tracker;
1075
1224
  }
1225
+ /**
1226
+ * Activate the completer service for notebook.
1227
+ */
1228
+ function activateNotebookCompleterService(app, notebooks, manager, translator) {
1229
+ if (!manager) {
1230
+ return;
1231
+ }
1232
+ const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
1233
+ app.commands.addCommand(CommandIDs.invokeCompleter, {
1234
+ label: trans.__('Display the completion helper.'),
1235
+ execute: args => {
1236
+ var _a;
1237
+ const panel = notebooks.currentWidget;
1238
+ if (panel && ((_a = panel.content.activeCell) === null || _a === void 0 ? void 0 : _a.model.type) === 'code') {
1239
+ manager.invoke(panel.id);
1240
+ }
1241
+ }
1242
+ });
1243
+ app.commands.addCommand(CommandIDs.selectCompleter, {
1244
+ label: trans.__('Select the completion suggestion.'),
1245
+ execute: () => {
1246
+ const id = notebooks.currentWidget && notebooks.currentWidget.id;
1247
+ if (id) {
1248
+ return manager.select(id);
1249
+ }
1250
+ }
1251
+ });
1252
+ app.commands.addKeyBinding({
1253
+ command: CommandIDs.selectCompleter,
1254
+ keys: ['Enter'],
1255
+ selector: '.jp-Notebook .jp-mod-completer-active'
1256
+ });
1257
+ const updateCompleter = async (_, notebook) => {
1258
+ var _a, _b;
1259
+ const completerContext = {
1260
+ editor: (_b = (_a = notebook.content.activeCell) === null || _a === void 0 ? void 0 : _a.editor) !== null && _b !== void 0 ? _b : null,
1261
+ session: notebook.sessionContext.session,
1262
+ widget: notebook
1263
+ };
1264
+ await manager.updateCompleter(completerContext);
1265
+ notebook.content.activeCellChanged.connect((_, cell) => {
1266
+ const newCompleterContext = {
1267
+ editor: cell.editor,
1268
+ session: notebook.sessionContext.session,
1269
+ widget: notebook
1270
+ };
1271
+ manager.updateCompleter(newCompleterContext).catch(console.error);
1272
+ });
1273
+ notebook.sessionContext.sessionChanged.connect(() => {
1274
+ var _a, _b;
1275
+ const newCompleterContext = {
1276
+ editor: (_b = (_a = notebook.content.activeCell) === null || _a === void 0 ? void 0 : _a.editor) !== null && _b !== void 0 ? _b : null,
1277
+ session: notebook.sessionContext.session,
1278
+ widget: notebook
1279
+ };
1280
+ manager.updateCompleter(newCompleterContext).catch(console.error);
1281
+ });
1282
+ };
1283
+ notebooks.widgetAdded.connect(updateCompleter);
1284
+ manager.activeProvidersChanged.connect(() => {
1285
+ notebooks.forEach(panel => {
1286
+ updateCompleter(undefined, panel).catch(e => console.error(e));
1287
+ });
1288
+ });
1289
+ }
1290
+ /**
1291
+ * Activate the language server for notebook.
1292
+ */
1293
+ function activateNotebookLanguageServer(app, notebooks, connectionManager, featureManager, codeExtractorManager) {
1294
+ notebooks.widgetAdded.connect(async (_, notebook) => {
1295
+ const adapter = new NotebookAdapter(notebook, {
1296
+ connectionManager,
1297
+ featureManager,
1298
+ foreignCodeExtractorsManager: codeExtractorManager
1299
+ });
1300
+ connectionManager.registerAdapter(notebook.context.path, adapter);
1301
+ });
1302
+ }
1076
1303
  // Get the current widget and activate unless the args specify otherwise.
1077
1304
  function getCurrent(tracker, shell, args) {
1078
1305
  const widget = tracker.currentWidget;
@@ -1266,7 +1493,8 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1266
1493
  isEnabled
1267
1494
  });
1268
1495
  commands.addCommand(CommandIDs.restartClear, {
1269
- label: trans.__('Restart Kernel and Clear All Outputs…'),
1496
+ label: trans.__('Restart Kernel and Clear Outputs of All Cells…'),
1497
+ caption: trans.__('Restart the kernel and clear all outputs of all cells'),
1270
1498
  execute: async () => {
1271
1499
  const restarted = await commands.execute(CommandIDs.restart, {
1272
1500
  activate: false
@@ -1305,7 +1533,8 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1305
1533
  isEnabled
1306
1534
  });
1307
1535
  commands.addCommand(CommandIDs.clearAllOutputs, {
1308
- label: trans.__('Clear All Outputs'),
1536
+ label: trans.__('Clear Outputs of All Cells'),
1537
+ caption: trans.__('Clear all outputs of all cells'),
1309
1538
  execute: args => {
1310
1539
  const current = getCurrent(tracker, shell, args);
1311
1540
  if (current) {
@@ -1315,7 +1544,7 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1315
1544
  isEnabled
1316
1545
  });
1317
1546
  commands.addCommand(CommandIDs.clearOutputs, {
1318
- label: trans.__('Clear Outputs'),
1547
+ label: trans.__('Clear Cell Output'),
1319
1548
  caption: trans.__('Clear outputs for the selected cells'),
1320
1549
  execute: args => {
1321
1550
  const current = getCurrent(tracker, shell, args);
@@ -1416,6 +1645,18 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1416
1645
  },
1417
1646
  isEnabled
1418
1647
  });
1648
+ commands.addCommand(CommandIDs.duplicateBelow, {
1649
+ label: trans.__('Duplicate Cells Below'),
1650
+ caption: trans.__('Copy the selected cells and paste them below the selection'),
1651
+ execute: args => {
1652
+ const current = getCurrent(tracker, shell, args);
1653
+ if (current) {
1654
+ NotebookActions.duplicate(current.content, 'belowSelected');
1655
+ }
1656
+ },
1657
+ icon: args => (args.toolbar ? duplicateIcon : ''),
1658
+ isEnabled
1659
+ });
1419
1660
  commands.addCommand(CommandIDs.pasteAndReplace, {
1420
1661
  label: trans.__('Paste Cells and Replace'),
1421
1662
  execute: args => {
@@ -1484,6 +1725,7 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1484
1725
  return NotebookActions.insertAbove(current.content);
1485
1726
  }
1486
1727
  },
1728
+ icon: args => (args.toolbar ? addAboveIcon : undefined),
1487
1729
  isEnabled
1488
1730
  });
1489
1731
  commands.addCommand(CommandIDs.insertBelow, {
@@ -1495,7 +1737,7 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1495
1737
  return NotebookActions.insertBelow(current.content);
1496
1738
  }
1497
1739
  },
1498
- icon: args => (args.toolbar ? addIcon : undefined),
1740
+ icon: args => (args.toolbar ? addBelowIcon : undefined),
1499
1741
  isEnabled
1500
1742
  });
1501
1743
  commands.addCommand(CommandIDs.selectAbove, {
@@ -1518,6 +1760,46 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1518
1760
  },
1519
1761
  isEnabled
1520
1762
  });
1763
+ commands.addCommand(CommandIDs.insertHeadingAbove, {
1764
+ label: trans.__('Insert Heading Above Current Heading'),
1765
+ execute: args => {
1766
+ const current = getCurrent(tracker, shell, args);
1767
+ if (current) {
1768
+ return NotebookActions.insertSameLevelHeadingAbove(current.content);
1769
+ }
1770
+ },
1771
+ isEnabled
1772
+ });
1773
+ commands.addCommand(CommandIDs.insertHeadingBelow, {
1774
+ label: trans.__('Insert Heading Below Current Heading'),
1775
+ execute: args => {
1776
+ const current = getCurrent(tracker, shell, args);
1777
+ if (current) {
1778
+ return NotebookActions.insertSameLevelHeadingBelow(current.content);
1779
+ }
1780
+ },
1781
+ isEnabled
1782
+ });
1783
+ commands.addCommand(CommandIDs.selectHeadingAboveOrCollapse, {
1784
+ label: trans.__('Select Heading Above or Collapse Heading'),
1785
+ execute: args => {
1786
+ const current = getCurrent(tracker, shell, args);
1787
+ if (current) {
1788
+ return NotebookActions.selectHeadingAboveOrCollapseHeading(current.content);
1789
+ }
1790
+ },
1791
+ isEnabled
1792
+ });
1793
+ commands.addCommand(CommandIDs.selectHeadingBelowOrExpand, {
1794
+ label: trans.__('Select Heading Below or Expand Heading'),
1795
+ execute: args => {
1796
+ const current = getCurrent(tracker, shell, args);
1797
+ if (current) {
1798
+ return NotebookActions.selectHeadingBelowOrExpandHeading(current.content);
1799
+ }
1800
+ },
1801
+ isEnabled
1802
+ });
1521
1803
  commands.addCommand(CommandIDs.extendAbove, {
1522
1804
  label: trans.__('Extend Selection Above'),
1523
1805
  execute: args => {
@@ -1586,7 +1868,8 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1586
1868
  return NotebookActions.moveUp(current.content);
1587
1869
  }
1588
1870
  },
1589
- isEnabled
1871
+ isEnabled,
1872
+ icon: args => (args.toolbar ? moveUpIcon : undefined)
1590
1873
  });
1591
1874
  commands.addCommand(CommandIDs.moveDown, {
1592
1875
  label: trans.__('Move Cells Down'),
@@ -1596,7 +1879,8 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1596
1879
  return NotebookActions.moveDown(current.content);
1597
1880
  }
1598
1881
  },
1599
- isEnabled
1882
+ isEnabled,
1883
+ icon: args => (args.toolbar ? moveDownIcon : undefined)
1600
1884
  });
1601
1885
  commands.addCommand(CommandIDs.toggleAllLines, {
1602
1886
  label: trans.__('Show Line Numbers'),
@@ -1846,40 +2130,26 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1846
2130
  },
1847
2131
  isEnabled
1848
2132
  });
1849
- commands.addCommand(CommandIDs.toggleRenderSideBySide, {
1850
- label: trans.__('Render Side-by-side'),
2133
+ commands.addCommand(CommandIDs.toggleRenderSideBySideCurrentNotebook, {
2134
+ label: trans.__('Render Side-by-Side'),
1851
2135
  execute: args => {
1852
- Private.renderSideBySide = !Private.renderSideBySide;
1853
- tracker.forEach(widget => {
1854
- if (widget) {
1855
- if (Private.renderSideBySide) {
1856
- return NotebookActions.renderSideBySide(widget.content);
1857
- }
1858
- return NotebookActions.renderNotSideBySide(widget.content);
1859
- }
1860
- });
1861
- tracker.currentChanged.connect(() => {
1862
- if (Private.renderSideBySide && tracker.currentWidget) {
1863
- return NotebookActions.renderSideBySide(tracker.currentWidget.content);
2136
+ const current = getCurrent(tracker, shell, args);
2137
+ if (current) {
2138
+ if (current.content.renderingLayout === 'side-by-side') {
2139
+ return NotebookActions.renderDefault(current.content);
1864
2140
  }
1865
- });
2141
+ return NotebookActions.renderSideBySide(current.content);
2142
+ }
1866
2143
  },
1867
- isToggled: () => Private.renderSideBySide,
1868
- isEnabled
1869
- });
1870
- commands.addCommand(CommandIDs.setSideBySideRatio, {
1871
- label: trans.__('Set side-by-side ratio'),
1872
- execute: args => {
1873
- InputDialog.getNumber({
1874
- title: trans.__('Width of the output in side-by-side mode'),
1875
- value: 1
1876
- })
1877
- .then(result => {
1878
- if (result.value) {
1879
- document.documentElement.style.setProperty('--jp-side-by-side-output-size', `${result.value}fr`);
1880
- }
1881
- })
1882
- .catch(console.error);
2144
+ isEnabled,
2145
+ isToggled: args => {
2146
+ const current = getCurrent(tracker, shell, Object.assign(Object.assign({}, args), { activate: false }));
2147
+ if (current) {
2148
+ return current.content.renderingLayout === 'side-by-side';
2149
+ }
2150
+ else {
2151
+ return false;
2152
+ }
1883
2153
  }
1884
2154
  });
1885
2155
  commands.addCommand(CommandIDs.showAllOutputs, {
@@ -1934,7 +2204,7 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1934
2204
  isEnabled
1935
2205
  });
1936
2206
  commands.addCommand(CommandIDs.toggleCollapseCmd, {
1937
- label: 'Toggle Collapse Notebook Heading',
2207
+ label: trans.__('Toggle Collapse Notebook Heading'),
1938
2208
  execute: args => {
1939
2209
  const current = getCurrent(tracker, shell, args);
1940
2210
  if (current) {
@@ -1944,16 +2214,16 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1944
2214
  isEnabled: isEnabledAndHeadingSelected
1945
2215
  });
1946
2216
  commands.addCommand(CommandIDs.collapseAllCmd, {
1947
- label: 'Collapse All Cells',
2217
+ label: trans.__('Collapse All Headings'),
1948
2218
  execute: args => {
1949
2219
  const current = getCurrent(tracker, shell, args);
1950
2220
  if (current) {
1951
- return NotebookActions.collapseAll(current.content);
2221
+ return NotebookActions.collapseAllHeadings(current.content);
1952
2222
  }
1953
2223
  }
1954
2224
  });
1955
2225
  commands.addCommand(CommandIDs.expandAllCmd, {
1956
- label: 'Expand All Headings',
2226
+ label: trans.__('Expand All Headings'),
1957
2227
  execute: args => {
1958
2228
  const current = getCurrent(tracker, shell, args);
1959
2229
  if (current) {
@@ -1961,6 +2231,33 @@ function addCommands(app, tracker, translator, sessionDialogs, isEnabled) {
1961
2231
  }
1962
2232
  }
1963
2233
  });
2234
+ commands.addCommand(CommandIDs.tocRunCells, {
2235
+ label: trans.__('Select and Run Cell(s) for this Heading'),
2236
+ execute: args => {
2237
+ const current = getCurrent(tracker, shell, Object.assign({ activate: false }, args));
2238
+ if (current === null) {
2239
+ return;
2240
+ }
2241
+ const activeCell = current.content.activeCell;
2242
+ let lastIndex = current.content.activeCellIndex;
2243
+ if (activeCell instanceof MarkdownCell) {
2244
+ const cells = current.content.widgets;
2245
+ const level = activeCell.headingInfo.level;
2246
+ for (let i = current.content.activeCellIndex + 1; i < cells.length; i++) {
2247
+ const cell = cells[i];
2248
+ if (cell instanceof MarkdownCell &&
2249
+ // cell.headingInfo.level === -1 if no heading
2250
+ cell.headingInfo.level >= 0 &&
2251
+ cell.headingInfo.level <= level) {
2252
+ break;
2253
+ }
2254
+ lastIndex = i;
2255
+ }
2256
+ }
2257
+ current.content.extendContiguousSelectionTo(lastIndex);
2258
+ void NotebookActions.run(current.content, current.sessionContext);
2259
+ }
2260
+ });
1964
2261
  }
1965
2262
  /**
1966
2263
  * Populate the application's command palette with notebook commands.
@@ -2024,6 +2321,10 @@ function populatePalette(palette, translator) {
2024
2321
  CommandIDs.insertBelow,
2025
2322
  CommandIDs.selectAbove,
2026
2323
  CommandIDs.selectBelow,
2324
+ CommandIDs.selectHeadingAboveOrCollapse,
2325
+ CommandIDs.selectHeadingBelowOrExpand,
2326
+ CommandIDs.insertHeadingAbove,
2327
+ CommandIDs.insertHeadingBelow,
2027
2328
  CommandIDs.extendAbove,
2028
2329
  CommandIDs.extendTop,
2029
2330
  CommandIDs.extendBelow,
@@ -2046,7 +2347,7 @@ function populatePalette(palette, translator) {
2046
2347
  CommandIDs.showOutput,
2047
2348
  CommandIDs.hideAllOutputs,
2048
2349
  CommandIDs.showAllOutputs,
2049
- CommandIDs.toggleRenderSideBySide,
2350
+ CommandIDs.toggleRenderSideBySideCurrentNotebook,
2050
2351
  CommandIDs.setSideBySideRatio,
2051
2352
  CommandIDs.enableOutputScrolling,
2052
2353
  CommandIDs.disableOutputScrolling
@@ -2151,7 +2452,8 @@ var Private;
2151
2452
  preferredLanguage: widget.context.model.defaultKernelLanguage,
2152
2453
  activate: activate,
2153
2454
  ref: widget.id,
2154
- insertMode: 'split-bottom'
2455
+ insertMode: 'split-bottom',
2456
+ type: 'Linked Console'
2155
2457
  };
2156
2458
  return commands.execute('console:create', options);
2157
2459
  }
@@ -2270,6 +2572,5 @@ var Private;
2270
2572
  }
2271
2573
  }
2272
2574
  Private.ClonedOutputArea = ClonedOutputArea;
2273
- Private.renderSideBySide = false;
2274
2575
  })(Private || (Private = {}));
2275
2576
  //# sourceMappingURL=index.js.map