@jupyter-notebook/docmanager-extension 7.7.0-beta.0 → 7.7.0-beta.1

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.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module docmanager-extension
4
+ */
1
5
  import { JupyterFrontEndPlugin } from '@jupyterlab/application';
2
6
  /**
3
7
  * Export the plugins as default.
package/lib/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
+ /**
4
+ * @packageDocumentation
5
+ * @module docmanager-extension
6
+ */
3
7
  import { PathExt, URLExt } from '@jupyterlab/coreutils';
4
8
  import { IDocumentWidgetOpener } from '@jupyterlab/docmanager';
5
9
  import { INotebookPathOpener, INotebookShell, defaultNotebookPathOpener, } from '@jupyter-notebook/application';
@@ -42,12 +46,12 @@ const opener = {
42
46
  }
43
47
  route = 'notebooks';
44
48
  }
45
- // append ?factory only if it's not the default
49
+ // append ?open-with only if it's not the default
46
50
  const defaultFactory = docRegistry.defaultWidgetFactory(path);
47
51
  let searchParams = undefined;
48
- if (widgetName !== defaultFactory.name) {
52
+ if (widgetName !== 'default' && widgetName !== defaultFactory.name) {
49
53
  searchParams = new URLSearchParams({
50
- factory: widgetName,
54
+ 'open-with': widgetName,
51
55
  });
52
56
  }
53
57
  // Require both flags: `notebookStartsKernel=False` only sets
@@ -77,7 +81,9 @@ const opener = {
77
81
  ...widget.title.dataset,
78
82
  };
79
83
  if (!widget.isAttached) {
80
- app.shell.add(widget, 'main', options || {});
84
+ // The document of the page goes to the main area, whatever the
85
+ // layout setting of its widget type: the page shows only that area.
86
+ app.shell.add(widget, 'main', ref === '_noref' ? { ...options, type: undefined } : options || {});
81
87
  }
82
88
  app.shell.activateById(widget.id);
83
89
  this._opened.emit(widget);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter-notebook/docmanager-extension",
3
- "version": "7.7.0-beta.0",
3
+ "version": "7.7.0-beta.1",
4
4
  "description": "Jupyter Notebook - Document Manager Extension",
5
5
  "homepage": "https://github.com/jupyter/notebook",
6
6
  "bugs": {
@@ -28,7 +28,8 @@
28
28
  "lib/*.js",
29
29
  "schema/*.json",
30
30
  "style/**/*.css",
31
- "style/index.js"
31
+ "style/index.js",
32
+ "src/**/*.{ts,tsx}"
32
33
  ],
33
34
  "scripts": {
34
35
  "build": "tsc -b",
@@ -38,13 +39,11 @@
38
39
  "watch": "tsc -b --watch"
39
40
  },
40
41
  "dependencies": {
41
- "@jupyter-notebook/application": "^7.7.0-beta.0",
42
- "@jupyterlab/application": "~4.7.0-beta.0",
43
- "@jupyterlab/coreutils": "~6.7.0-beta.0",
44
- "@jupyterlab/docmanager": "~4.7.0-beta.0",
45
- "@jupyterlab/docregistry": "~4.7.0-beta.0",
46
- "@jupyterlab/services": "~7.7.0-beta.0",
47
- "@lumino/algorithm": "^2.0.4",
42
+ "@jupyter-notebook/application": "^7.7.0-beta.1",
43
+ "@jupyterlab/application": "~4.7.0-beta.1",
44
+ "@jupyterlab/coreutils": "~6.7.0-beta.1",
45
+ "@jupyterlab/docmanager": "~4.7.0-beta.1",
46
+ "@jupyterlab/docregistry": "~4.7.0-beta.1",
48
47
  "@lumino/signaling": "^2.1.5"
49
48
  },
50
49
  "devDependencies": {
package/src/index.ts ADDED
@@ -0,0 +1,138 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ /**
4
+ * @packageDocumentation
5
+ * @module docmanager-extension
6
+ */
7
+
8
+ import {
9
+ JupyterFrontEnd,
10
+ JupyterFrontEndPlugin,
11
+ } from '@jupyterlab/application';
12
+
13
+ import { PathExt, URLExt } from '@jupyterlab/coreutils';
14
+
15
+ import { IDocumentWidgetOpener } from '@jupyterlab/docmanager';
16
+
17
+ import { IDocumentWidget, DocumentRegistry } from '@jupyterlab/docregistry';
18
+
19
+ import {
20
+ INotebookPathOpener,
21
+ INotebookShell,
22
+ defaultNotebookPathOpener,
23
+ } from '@jupyter-notebook/application';
24
+
25
+ import { Signal } from '@lumino/signaling';
26
+
27
+ /**
28
+ * A plugin to open documents in a new browser tab.
29
+ *
30
+ */
31
+ const opener: JupyterFrontEndPlugin<IDocumentWidgetOpener> = {
32
+ id: '@jupyter-notebook/docmanager-extension:opener',
33
+ autoStart: true,
34
+ optional: [INotebookPathOpener, INotebookShell],
35
+ provides: IDocumentWidgetOpener,
36
+ description: 'Open documents in a new browser tab',
37
+ activate: (
38
+ app: JupyterFrontEnd,
39
+ notebookPathOpener: INotebookPathOpener | null,
40
+ notebookShell: INotebookShell | null
41
+ ) => {
42
+ const baseUrl = app.serviceManager.serverSettings.baseUrl;
43
+ const docRegistry = app.docRegistry;
44
+ const pathOpener = notebookPathOpener ?? defaultNotebookPathOpener;
45
+ let id = 0;
46
+ return new (class {
47
+ async open(
48
+ widget: IDocumentWidget,
49
+ options?: DocumentRegistry.IOpenOptions
50
+ ) {
51
+ const widgetName = options?.type ?? '';
52
+ const ref = options?.ref;
53
+ // check if there is an setting override and if it would add the widget in the main area
54
+ const userLayoutArea = notebookShell?.userLayout?.[widgetName]?.area;
55
+
56
+ if (ref !== '_noref' && userLayoutArea === undefined) {
57
+ const path = widget.context.path;
58
+ const ext = PathExt.extname(path);
59
+ let route = 'edit';
60
+ if (
61
+ (widgetName === 'default' && ext === '.ipynb') ||
62
+ widgetName.includes('Notebook')
63
+ ) {
64
+ // make sure to save the notebook before opening it in a new tab
65
+ // so the kernel info is saved (if created from the New dropdown)
66
+ if (widget.context.sessionContext.kernelPreference.name) {
67
+ await widget.context.save();
68
+ }
69
+ route = 'notebooks';
70
+ }
71
+ // append ?open-with only if it's not the default
72
+ const defaultFactory = docRegistry.defaultWidgetFactory(path);
73
+ let searchParams = undefined;
74
+ if (widgetName !== 'default' && widgetName !== defaultFactory.name) {
75
+ searchParams = new URLSearchParams({
76
+ 'open-with': widgetName,
77
+ });
78
+ }
79
+ // Require both flags: `notebookStartsKernel=False` only sets
80
+ // `shouldStart: false` and must still reuse a running session.
81
+ if (
82
+ route === 'notebooks' &&
83
+ widget.context.sessionContext.kernelPreference.shouldStart ===
84
+ false &&
85
+ widget.context.sessionContext.kernelPreference.shouldReuse === false
86
+ ) {
87
+ searchParams ??= new URLSearchParams();
88
+ searchParams.set('kernel', 'none');
89
+ }
90
+
91
+ pathOpener.open({
92
+ prefix: URLExt.join(baseUrl, route),
93
+ path,
94
+ searchParams,
95
+ });
96
+
97
+ // dispose the widget since it is not used on this page
98
+ widget.dispose();
99
+ return;
100
+ }
101
+
102
+ // otherwise open the document on the current page
103
+
104
+ if (!widget.id) {
105
+ widget.id = `document-manager-${++id}`;
106
+ }
107
+ widget.title.dataset = {
108
+ type: 'document-title',
109
+ ...widget.title.dataset,
110
+ };
111
+ if (!widget.isAttached) {
112
+ // The document of the page goes to the main area, whatever the
113
+ // layout setting of its widget type: the page shows only that area.
114
+ app.shell.add(
115
+ widget,
116
+ 'main',
117
+ ref === '_noref' ? { ...options, type: undefined } : options || {}
118
+ );
119
+ }
120
+ app.shell.activateById(widget.id);
121
+ this._opened.emit(widget);
122
+ }
123
+
124
+ get opened() {
125
+ return this._opened;
126
+ }
127
+
128
+ private _opened = new Signal<this, IDocumentWidget>(this);
129
+ })();
130
+ },
131
+ };
132
+
133
+ /**
134
+ * Export the plugins as default.
135
+ */
136
+ const plugins: JupyterFrontEndPlugin<any>[] = [opener];
137
+
138
+ export default plugins;
package/style/index.css CHANGED
@@ -1 +1,7 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ /* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
1
7
  @import url('./base.css');
package/style/index.js CHANGED
@@ -1 +1,8 @@
1
+ /*-----------------------------------------------------------------------------
2
+ | Copyright (c) Jupyter Development Team.
3
+ | Distributed under the terms of the Modified BSD License.
4
+ |----------------------------------------------------------------------------*/
5
+
6
+ /* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
7
+
1
8
  import './base.css';