@jupyter-notebook/notebook-extension 7.0.0-alpha.12 → 7.0.0-alpha.14

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
@@ -9,6 +9,7 @@ import { ITranslator } from '@jupyterlab/translation';
9
9
  import { INotebookShell } from '@jupyter-notebook/application';
10
10
  import { Poll } from '@lumino/polling';
11
11
  import { Widget } from '@lumino/widgets';
12
+ import { TrustedComponent } from './trusted';
12
13
  /**
13
14
  * The class for kernel status errors.
14
15
  */
@@ -90,23 +91,27 @@ const kernelLogo = {
90
91
  const { serviceManager } = app;
91
92
  const node = document.createElement('div');
92
93
  const img = document.createElement('img');
93
- node.appendChild(img);
94
94
  const onChange = async () => {
95
95
  var _a, _b, _c, _d, _e;
96
96
  const current = shell.currentWidget;
97
97
  if (!(current instanceof NotebookPanel)) {
98
98
  return;
99
99
  }
100
+ if (!node.hasChildNodes()) {
101
+ node.appendChild(img);
102
+ }
100
103
  await current.sessionContext.ready;
101
104
  current.sessionContext.kernelChanged.disconnect(onChange);
102
105
  current.sessionContext.kernelChanged.connect(onChange);
103
106
  const name = (_c = (_b = (_a = current.sessionContext.session) === null || _a === void 0 ? void 0 : _a.kernel) === null || _b === void 0 ? void 0 : _b.name) !== null && _c !== void 0 ? _c : '';
104
107
  const spec = (_e = (_d = serviceManager.kernelspecs) === null || _d === void 0 ? void 0 : _d.specs) === null || _e === void 0 ? void 0 : _e.kernelspecs[name];
105
108
  if (!spec) {
109
+ node.childNodes[0].remove();
106
110
  return;
107
111
  }
108
112
  const kernelIconUrl = spec.resources['logo-64x64'];
109
113
  if (!kernelIconUrl) {
114
+ node.childNodes[0].remove();
110
115
  return;
111
116
  }
112
117
  img.src = kernelIconUrl;
@@ -275,6 +280,27 @@ const notebookToolsWidget = {
275
280
  shell.currentChanged.connect(onChange);
276
281
  }
277
282
  };
283
+ /**
284
+ * A plugin that adds a Trusted indicator to the menu area
285
+ */
286
+ const trusted = {
287
+ id: '@jupyter-notebook/notebook-extension:trusted',
288
+ autoStart: true,
289
+ requires: [INotebookShell, ITranslator],
290
+ activate: (app, notebookShell, translator) => {
291
+ const onChange = async () => {
292
+ const current = notebookShell.currentWidget;
293
+ if (!(current instanceof NotebookPanel)) {
294
+ return;
295
+ }
296
+ const notebook = current.content;
297
+ await current.context.ready;
298
+ const widget = TrustedComponent.create({ notebook, translator });
299
+ notebookShell.add(widget, 'menu', { rank: 11000 });
300
+ };
301
+ notebookShell.currentChanged.connect(onChange);
302
+ }
303
+ };
278
304
  /**
279
305
  * Export the plugins as default.
280
306
  */
@@ -283,6 +309,7 @@ const plugins = [
283
309
  kernelLogo,
284
310
  kernelStatus,
285
311
  scrollOutput,
286
- notebookToolsWidget
312
+ notebookToolsWidget,
313
+ trusted
287
314
  ];
288
315
  export default plugins;
@@ -0,0 +1,18 @@
1
+ import { ReactWidget } from '@jupyterlab/apputils';
2
+ import { Notebook } from '@jupyterlab/notebook';
3
+ import { ITranslator } from '@jupyterlab/translation';
4
+ /**
5
+ * A namespace for TrustedComponent statics.
6
+ */
7
+ export declare namespace TrustedComponent {
8
+ /**
9
+ * Create a new TrustedComponent
10
+ *
11
+ * @param notebook The notebook
12
+ * @param translator The translator
13
+ */
14
+ const create: ({ notebook, translator }: {
15
+ notebook: Notebook;
16
+ translator: ITranslator;
17
+ }) => ReactWidget;
18
+ }
package/lib/trusted.js ADDED
@@ -0,0 +1,70 @@
1
+ import { ReactWidget } from '@jupyterlab/apputils';
2
+ import { NotebookActions } from '@jupyterlab/notebook';
3
+ import { toArray } from '@lumino/algorithm';
4
+ import React, { useEffect, useState } from 'react';
5
+ /**
6
+ * Check if a notebook is trusted
7
+ * @param notebook The notebook to check
8
+ * @returns true if the notebook is trusted, false otherwise
9
+ */
10
+ const isTrusted = (notebook) => {
11
+ const model = notebook.model;
12
+ if (!model) {
13
+ return false;
14
+ }
15
+ const cells = toArray(model.cells);
16
+ const trusted = cells.reduce((accum, current) => {
17
+ if (current.trusted) {
18
+ return accum + 1;
19
+ }
20
+ else {
21
+ return accum;
22
+ }
23
+ }, 0);
24
+ const total = cells.length;
25
+ return trusted === total;
26
+ };
27
+ /**
28
+ * A React component to display the Trusted badge in the menu bar.
29
+ * @param notebook The Notebook
30
+ * @param translator The Translation service
31
+ */
32
+ const TrustedButton = ({ notebook, translator }) => {
33
+ const trans = translator.load('notebook');
34
+ const [trusted, setTrusted] = useState(isTrusted(notebook));
35
+ const checkTrust = () => {
36
+ const v = isTrusted(notebook);
37
+ setTrusted(v);
38
+ };
39
+ const trust = async () => {
40
+ await NotebookActions.trust(notebook, translator);
41
+ checkTrust();
42
+ };
43
+ useEffect(() => {
44
+ notebook.modelContentChanged.connect(checkTrust);
45
+ notebook.activeCellChanged.connect(checkTrust);
46
+ checkTrust();
47
+ return () => {
48
+ notebook.modelContentChanged.disconnect(checkTrust);
49
+ notebook.activeCellChanged.disconnect(checkTrust);
50
+ };
51
+ });
52
+ return (React.createElement("button", { className: 'jp-NotebookTrustedStatus', style: !trusted ? { cursor: 'pointer' } : { cursor: 'help' }, onClick: () => !trusted && trust(), title: trusted
53
+ ? trans.__('JavaScript enabled for notebook display')
54
+ : trans.__('JavaScript disabled for notebook display') }, trusted ? trans.__('Trusted') : trans.__('Not Trusted')));
55
+ };
56
+ /**
57
+ * A namespace for TrustedComponent statics.
58
+ */
59
+ export var TrustedComponent;
60
+ (function (TrustedComponent) {
61
+ /**
62
+ * Create a new TrustedComponent
63
+ *
64
+ * @param notebook The notebook
65
+ * @param translator The translator
66
+ */
67
+ TrustedComponent.create = ({ notebook, translator }) => {
68
+ return ReactWidget.create(React.createElement(TrustedButton, { notebook: notebook, translator: translator }));
69
+ };
70
+ })(TrustedComponent || (TrustedComponent = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter-notebook/notebook-extension",
3
- "version": "7.0.0-alpha.12",
3
+ "version": "7.0.0-alpha.14",
4
4
  "description": "Jupyter Notebook - Notebook Extension",
5
5
  "homepage": "https://github.com/jupyter/notebook",
6
6
  "bugs": {
@@ -35,24 +35,23 @@
35
35
  "build:prod": "tsc -b",
36
36
  "clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
37
37
  "docs": "typedoc src",
38
- "prepublishOnly": "npm run build",
39
38
  "watch": "tsc -b --watch"
40
39
  },
41
40
  "dependencies": {
42
- "@jupyter-notebook/application": "^7.0.0-alpha.12",
43
- "@jupyterlab/application": "^4.0.0-alpha.18",
44
- "@jupyterlab/apputils": "^4.0.0-alpha.18",
45
- "@jupyterlab/cells": "^4.0.0-alpha.18",
46
- "@jupyterlab/docmanager": "^4.0.0-alpha.18",
47
- "@jupyterlab/notebook": "^4.0.0-alpha.18",
48
- "@jupyterlab/settingregistry": "^4.0.0-alpha.18",
49
- "@jupyterlab/translation": "^4.0.0-alpha.18",
41
+ "@jupyter-notebook/application": "^7.0.0-alpha.14",
42
+ "@jupyterlab/application": "^4.0.0-alpha.19",
43
+ "@jupyterlab/apputils": "^4.0.0-alpha.19",
44
+ "@jupyterlab/cells": "^4.0.0-alpha.19",
45
+ "@jupyterlab/docmanager": "^4.0.0-alpha.19",
46
+ "@jupyterlab/notebook": "^4.0.0-alpha.19",
47
+ "@jupyterlab/settingregistry": "^4.0.0-alpha.19",
48
+ "@jupyterlab/translation": "^4.0.0-alpha.19",
50
49
  "@lumino/polling": "^2.0.0-beta.1",
51
50
  "@lumino/widgets": "^2.0.0-beta.1"
52
51
  },
53
52
  "devDependencies": {
54
53
  "rimraf": "^3.0.2",
55
- "typescript": "~4.9.3"
54
+ "typescript": "5.0.0-beta"
56
55
  },
57
56
  "publishConfig": {
58
57
  "access": "public"
package/style/base.css CHANGED
@@ -132,6 +132,10 @@ body[data-format='mobile'] .jp-Notebook > *:first-child {
132
132
  margin-top: 0;
133
133
  }
134
134
 
135
+ body[data-format='mobile'] .jp-ToolbarButton .jp-DebuggerBugButton {
136
+ display: none;
137
+ }
138
+
135
139
  /* Virtual Notebook fixes */
136
140
 
137
141
  body[data-notebook='notebooks'] .jp-WindowedPanel-window {
@@ -216,6 +220,19 @@ body[data-notebook='notebooks']
216
220
  animation: 0.5s fade-out forwards;
217
221
  }
218
222
 
223
+ .jp-NotebookTrustedStatus {
224
+ background: var(--jp-layout-color1);
225
+ color: var(--jp-ui-font-color1);
226
+ margin-top: 4px;
227
+ margin-bottom: 4px;
228
+ border: solid 1px var(--jp-border-color2);
229
+ cursor: help;
230
+ }
231
+
232
+ .jp-NotebookTrustedStatus-not-trusted {
233
+ cursor: pointer;
234
+ }
235
+
219
236
  @keyframes fade-out {
220
237
  0% {
221
238
  opacity: 1;