@jupyter-notebook/application-extension 7.7.0-alpha.0 → 7.7.0-alpha.2

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
@@ -8,10 +8,11 @@ import { IDocumentManager, renameDialog } from '@jupyterlab/docmanager';
8
8
  import { DocumentWidget } from '@jupyterlab/docregistry';
9
9
  import { IMainMenu } from '@jupyterlab/mainmenu';
10
10
  import { ILatexTypesetter, IMarkdownParser, IRenderMimeRegistry, RenderMimeRegistry, standardRendererFactories, } from '@jupyterlab/rendermime';
11
- import { ISettingRegistry } from '@jupyterlab/settingregistry';
11
+ import { ISettingConnector, ISettingRegistry, } from '@jupyterlab/settingregistry';
12
12
  import { ITranslator, nullTranslator } from '@jupyterlab/translation';
13
13
  import { NotebookApp, NotebookShell, INotebookShell, SidePanelPalette, INotebookPathOpener, defaultNotebookPathOpener, } from '@jupyter-notebook/application';
14
14
  import { jupyterIcon } from '@jupyter-notebook/ui-components';
15
+ import { SettingConnector } from './settingconnector';
15
16
  import { PromiseDelegate } from '@lumino/coreutils';
16
17
  import { DisposableDelegate, DisposableSet, } from '@lumino/disposable';
17
18
  import { Menu, Widget } from '@lumino/widgets';
@@ -113,7 +114,7 @@ const logo = {
113
114
  description: 'The logo plugin.',
114
115
  autoStart: true,
115
116
  activate: (app) => {
116
- const baseUrl = PageConfig.getBaseUrl();
117
+ const baseUrl = app.serviceManager.serverSettings.baseUrl;
117
118
  const node = document.createElement('a');
118
119
  node.href = `${baseUrl}tree`;
119
120
  node.target = '_blank';
@@ -177,9 +178,31 @@ const opener = {
177
178
  });
178
179
  }
179
180
  const factory = (_a = urlParams.get('factory')) !== null && _a !== void 0 ? _a : defaultFactory;
180
- docManager.open(file, factory, undefined, {
181
+ const kernelPreference = urlParams.get('kernel') === 'none'
182
+ ? { shouldStart: false, shouldReuse: false }
183
+ : undefined;
184
+ const widget = docManager.openOrReveal(file, factory, undefined, {
181
185
  ref: '_noref',
182
- });
186
+ }, kernelPreference);
187
+ if (kernelPreference && widget) {
188
+ const { sessionContext } = widget.context;
189
+ /**
190
+ * `kernel=none` only describes how to open the notebook. Drop it
191
+ * as soon as a kernel runs, so a reload reconnects to that session.
192
+ */
193
+ const clearNoKernelQuery = () => {
194
+ var _a;
195
+ if (!((_a = sessionContext.session) === null || _a === void 0 ? void 0 : _a.kernel)) {
196
+ return;
197
+ }
198
+ const url = new URL(window.location.href);
199
+ url.searchParams.delete('kernel');
200
+ window.history.replaceState(window.history.state, '', url.toString());
201
+ sessionContext.kernelChanged.disconnect(clearNoKernelQuery);
202
+ };
203
+ sessionContext.kernelChanged.connect(clearNoKernelQuery);
204
+ clearNoKernelQuery();
205
+ }
183
206
  });
184
207
  },
185
208
  describedBy: {
@@ -256,7 +279,7 @@ const pages = {
256
279
  optional: [ICommandPalette],
257
280
  activate: (app, translator, palette) => {
258
281
  const trans = translator.load('notebook');
259
- const baseUrl = PageConfig.getBaseUrl();
282
+ const baseUrl = app.serviceManager.serverSettings.baseUrl;
260
283
  app.commands.addCommand(CommandIDs.openLab, {
261
284
  label: trans.__('Open JupyterLab'),
262
285
  execute: () => {
@@ -274,7 +297,7 @@ const pages = {
274
297
  label: trans.__('File Browser'),
275
298
  execute: () => {
276
299
  if (page === 'tree') {
277
- app.commands.execute('filebrowser:activate');
300
+ app.commands.execute('filebrowser:open-directory');
278
301
  }
279
302
  else {
280
303
  window.open(URLExt.join(baseUrl, 'tree'));
@@ -350,7 +373,7 @@ const rendermime = {
350
373
  return docManager.services.contents
351
374
  .get(path, { content: false })
352
375
  .then((model) => {
353
- const baseUrl = PageConfig.getBaseUrl();
376
+ const baseUrl = app.serviceManager.serverSettings.baseUrl;
354
377
  opener.open({
355
378
  prefix: URLExt.join(baseUrl, 'tree'),
356
379
  path: model.path,
@@ -714,7 +737,7 @@ const sidePanelVisibility = {
714
737
  * id, widget ID to activate in the side panel
715
738
  */
716
739
  app.commands.addCommand(CommandIDs.togglePanel, {
717
- label: (args) => args['title'],
740
+ label: (args) => trans.__('Show %1', args['title']),
718
741
  caption: (args) => {
719
742
  // We do not substitute the parameter into the string because the parameter is not
720
743
  // localized (e.g., it is always 'left') even though the string is localized.
@@ -795,7 +818,7 @@ const sidePanelVisibility = {
795
818
  },
796
819
  title: {
797
820
  type: 'string',
798
- description: 'The title shown for the side panel entry.',
821
+ description: 'The title of the side panel widget.',
799
822
  },
800
823
  id: {
801
824
  type: 'string',
@@ -815,38 +838,38 @@ const sidePanelVisibility = {
815
838
  *
816
839
  * @param area - 'left' or 'right', the area of the side panel.
817
840
  * @param entryLabel - the name of the main entry in the View menu for that side panel.
818
- * @returns - The disposable menu added to the View menu or null.
819
841
  */
820
842
  const updateMenu = (area, entryLabel) => {
821
843
  var _a;
822
844
  if (menu === null) {
823
- return null;
845
+ return;
824
846
  }
825
847
  // Remove the previous menu entry for this side panel.
826
848
  (_a = sidePanelMenu[area]) === null || _a === void 0 ? void 0 : _a.dispose();
849
+ sidePanelMenu[area] = null;
850
+ // Nothing to add to the View menu if the side panel has no widget.
851
+ const widgets = Array.from(notebookShell.widgets(area));
852
+ if (widgets.length === 0) {
853
+ return;
854
+ }
827
855
  // Creates a new menu entry and populates it with side panel widgets.
828
856
  const newMenu = new Menu({ commands: app.commands });
829
857
  newMenu.title.label = entryLabel;
830
- const widgets = notebookShell.widgets(area);
831
- let menuToAdd = false;
832
858
  for (const widget of widgets) {
833
859
  newMenu.addItem({
834
860
  command: CommandIDs.togglePanel,
835
861
  args: {
836
862
  side: area,
837
- title: `Show ${widget.title.caption}`,
863
+ title: widget.title.caption,
838
864
  id: widget.id,
839
865
  },
840
866
  });
841
- menuToAdd = true;
842
- }
843
- // If there are widgets, add the menu to the main menu entry.
844
- if (menuToAdd) {
845
- sidePanelMenu[area] = menu.viewMenu.addItem({
846
- type: 'submenu',
847
- submenu: newMenu,
848
- });
849
867
  }
868
+ // Add the menu to the main menu entry.
869
+ sidePanelMenu[area] = menu.viewMenu.addItem({
870
+ type: 'submenu',
871
+ submenu: newMenu,
872
+ });
850
873
  };
851
874
  app.restored.then(() => {
852
875
  // Create menu entries for the left and right panel.
@@ -1058,6 +1081,21 @@ const zen = {
1058
1081
  }
1059
1082
  },
1060
1083
  };
1084
+ /**
1085
+ * A plugin providing a custom setting connector to override the default
1086
+ * values of some of the JupyterLab plugin settings, for example to open
1087
+ * the help (pager payloads) in the down area by default, like in the
1088
+ * Classic Notebook.
1089
+ */
1090
+ const settingsConnector = {
1091
+ id: '@jupyter-notebook/application-extension:settings-connector',
1092
+ description: 'Provides a custom setting connector overriding some default setting values.',
1093
+ autoStart: true,
1094
+ provides: ISettingConnector,
1095
+ activate: (app) => {
1096
+ return new SettingConnector(app.serviceManager.settings);
1097
+ },
1098
+ };
1061
1099
  /**
1062
1100
  * Export the plugins as default.
1063
1101
  */
@@ -1072,6 +1110,7 @@ const plugins = [
1072
1110
  pathOpener,
1073
1111
  paths,
1074
1112
  rendermime,
1113
+ settingsConnector,
1075
1114
  shell,
1076
1115
  sidePanelVisibility,
1077
1116
  shortcuts,
@@ -0,0 +1,22 @@
1
+ import { ISettingRegistry, SettingConnector as BaseSettingConnector } from '@jupyterlab/settingregistry';
2
+ /**
3
+ * A data connector for fetching settings.
4
+ *
5
+ * #### Notes
6
+ * This connector extends the default JupyterLab setting connector with
7
+ * Jupyter Notebook-specific overrides.
8
+ */
9
+ export declare class SettingConnector extends BaseSettingConnector {
10
+ /**
11
+ * Fetch settings for a plugin.
12
+ * @param id - The plugin ID
13
+ */
14
+ fetch(id: string): Promise<ISettingRegistry.IPlugin | undefined>;
15
+ list(query: 'ids'): Promise<{
16
+ ids: string[];
17
+ }>;
18
+ list(query: 'active' | 'all'): Promise<{
19
+ ids: string[];
20
+ values: ISettingRegistry.IPlugin[];
21
+ }>;
22
+ }
@@ -0,0 +1,92 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { PageConfig } from '@jupyterlab/coreutils';
4
+ import { SettingConnector as BaseSettingConnector, } from '@jupyterlab/settingregistry';
5
+ /**
6
+ * The default setting values overridden in Jupyter Notebook, mapping
7
+ * a plugin identifier to the overridden properties.
8
+ */
9
+ const SETTING_OVERRIDES = {
10
+ // Use a different set of file browser defaults than JupyterLab.
11
+ '@jupyterlab/filebrowser-extension:browser': {
12
+ showFileCheckboxes: true,
13
+ showFileSizeColumn: true,
14
+ singleClickNavigation: true,
15
+ sortNotebooksFirst: true,
16
+ },
17
+ // Open the help (pager payloads) in the down area by default,
18
+ // like in the Classic Notebook.
19
+ '@jupyterlab/notebook-extension:tracker': {
20
+ helpInBottomPanel: true,
21
+ },
22
+ };
23
+ const FILE_EDITOR_PLUGIN_ID = '@jupyterlab/fileeditor-extension:plugin';
24
+ const SYNTAX_HIGHLIGHTING_SUBMENU_ID = 'jp-mainmenu-view-codemirror-language';
25
+ /**
26
+ * A data connector for fetching settings.
27
+ *
28
+ * #### Notes
29
+ * This connector extends the default JupyterLab setting connector with
30
+ * Jupyter Notebook-specific overrides.
31
+ */
32
+ export class SettingConnector extends BaseSettingConnector {
33
+ /**
34
+ * Fetch settings for a plugin.
35
+ * @param id - The plugin ID
36
+ */
37
+ async fetch(id) {
38
+ const plugin = await super.fetch(id);
39
+ return plugin && Private.applyOverrides(plugin);
40
+ }
41
+ async list(query = 'all') {
42
+ if (query === 'ids') {
43
+ return super.list(query);
44
+ }
45
+ const { ids, values } = await super.list(query);
46
+ return { ids, values: values.map(Private.applyOverrides) };
47
+ }
48
+ }
49
+ /**
50
+ * A namespace for private module data.
51
+ */
52
+ var Private;
53
+ (function (Private) {
54
+ function applyOverrides(plugin) {
55
+ return hideSyntaxHighlightingMenu(overrideDefaults(plugin));
56
+ }
57
+ Private.applyOverrides = applyOverrides;
58
+ /**
59
+ * Override the default values of the plugin settings listed
60
+ * in `SETTING_OVERRIDES`.
61
+ */
62
+ function overrideDefaults(plugin) {
63
+ const overrides = SETTING_OVERRIDES[plugin.id];
64
+ const properties = plugin.schema.properties;
65
+ if (!overrides || !properties) {
66
+ return plugin;
67
+ }
68
+ for (const [property, value] of Object.entries(overrides)) {
69
+ if (property in properties) {
70
+ properties[property].default = value;
71
+ }
72
+ }
73
+ return plugin;
74
+ }
75
+ function hideSyntaxHighlightingMenu(plugin) {
76
+ var _a, _b, _c, _d;
77
+ const page = PageConfig.getOption('notebookPage');
78
+ if (plugin.id !== FILE_EDITOR_PLUGIN_ID || page === 'edit') {
79
+ return plugin;
80
+ }
81
+ const menus = (_b = (_a = plugin.schema['jupyter.lab.menus']) === null || _a === void 0 ? void 0 : _a.main) !== null && _b !== void 0 ? _b : [];
82
+ for (const menu of menus) {
83
+ for (const item of (_c = menu.items) !== null && _c !== void 0 ? _c : []) {
84
+ if (item.type === 'submenu' &&
85
+ ((_d = item.submenu) === null || _d === void 0 ? void 0 : _d.id) === SYNTAX_HIGHLIGHTING_SUBMENU_ID) {
86
+ item.disabled = true;
87
+ }
88
+ }
89
+ }
90
+ return plugin;
91
+ }
92
+ })(Private || (Private = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter-notebook/application-extension",
3
- "version": "7.7.0-alpha.0",
3
+ "version": "7.7.0-alpha.2",
4
4
  "description": "Jupyter Notebook - Application Extension",
5
5
  "homepage": "https://github.com/jupyter/notebook",
6
6
  "bugs": {
@@ -38,19 +38,19 @@
38
38
  "watch": "tsc -b --watch"
39
39
  },
40
40
  "dependencies": {
41
- "@jupyter-notebook/application": "^7.7.0-alpha.0",
42
- "@jupyter-notebook/ui-components": "^7.7.0-alpha.0",
43
- "@jupyterlab/application": "~4.7.0-alpha.0",
44
- "@jupyterlab/apputils": "~4.8.0-alpha.0",
45
- "@jupyterlab/codeeditor": "~4.7.0-alpha.0",
46
- "@jupyterlab/console": "~4.7.0-alpha.0",
47
- "@jupyterlab/coreutils": "~6.7.0-alpha.0",
48
- "@jupyterlab/docmanager": "~4.7.0-alpha.0",
49
- "@jupyterlab/docregistry": "~4.7.0-alpha.0",
50
- "@jupyterlab/mainmenu": "~4.7.0-alpha.0",
51
- "@jupyterlab/rendermime": "~4.7.0-alpha.0",
52
- "@jupyterlab/settingregistry": "~4.7.0-alpha.0",
53
- "@jupyterlab/translation": "~4.7.0-alpha.0",
41
+ "@jupyter-notebook/application": "^7.7.0-alpha.2",
42
+ "@jupyter-notebook/ui-components": "^7.7.0-alpha.2",
43
+ "@jupyterlab/application": "~4.7.0-alpha.2",
44
+ "@jupyterlab/apputils": "~4.8.0-alpha.2",
45
+ "@jupyterlab/codeeditor": "~4.7.0-alpha.2",
46
+ "@jupyterlab/console": "~4.7.0-alpha.2",
47
+ "@jupyterlab/coreutils": "~6.7.0-alpha.2",
48
+ "@jupyterlab/docmanager": "~4.7.0-alpha.2",
49
+ "@jupyterlab/docregistry": "~4.7.0-alpha.2",
50
+ "@jupyterlab/mainmenu": "~4.7.0-alpha.2",
51
+ "@jupyterlab/rendermime": "~4.7.0-alpha.2",
52
+ "@jupyterlab/settingregistry": "~4.7.0-alpha.2",
53
+ "@jupyterlab/translation": "~4.7.0-alpha.2",
54
54
  "@lumino/coreutils": "^2.2.2",
55
55
  "@lumino/disposable": "^2.1.5",
56
56
  "@lumino/widgets": "^2.7.2"
package/schema/shell.json CHANGED
@@ -20,20 +20,34 @@
20
20
  "definitions": {
21
21
  "layout": {
22
22
  "type": "object",
23
- "properties": {
23
+ "patternProperties": {
24
24
  "[\\w-]+": {
25
25
  "type": "object",
26
26
  "properties": {
27
27
  "area": {
28
+ "type": "string",
28
29
  "oneOf": [
30
+ { "const": "main", "title": "Main" },
31
+ { "const": "top", "title": "Top" },
32
+ { "const": "menu", "title": "Menu" },
29
33
  { "const": "left", "title": "Left" },
30
- { "const": "right", "title": "Right" }
34
+ { "const": "right", "title": "Right" },
35
+ { "const": "down", "title": "Down" }
31
36
  ]
37
+ },
38
+ "options": {
39
+ "$ref": "#/definitions/options"
32
40
  }
33
41
  },
34
42
  "additionalProperties": false
35
43
  }
36
44
  }
45
+ },
46
+ "options": {
47
+ "type": "object",
48
+ "properties": {
49
+ "rank": { "type": "number", "minimum": 0 }
50
+ }
37
51
  }
38
52
  }
39
53
  }