@jupyter-notebook/notebook-extension 7.0.0-alpha.13 → 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
  */
@@ -279,6 +280,27 @@ const notebookToolsWidget = {
279
280
  shell.currentChanged.connect(onChange);
280
281
  }
281
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
+ };
282
304
  /**
283
305
  * Export the plugins as default.
284
306
  */
@@ -287,6 +309,7 @@ const plugins = [
287
309
  kernelLogo,
288
310
  kernelStatus,
289
311
  scrollOutput,
290
- notebookToolsWidget
312
+ notebookToolsWidget,
313
+ trusted
291
314
  ];
292
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.13",
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,11 +35,10 @@
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.13",
41
+ "@jupyter-notebook/application": "^7.0.0-alpha.14",
43
42
  "@jupyterlab/application": "^4.0.0-alpha.19",
44
43
  "@jupyterlab/apputils": "^4.0.0-alpha.19",
45
44
  "@jupyterlab/cells": "^4.0.0-alpha.19",
@@ -52,7 +51,7 @@
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
@@ -220,6 +220,19 @@ body[data-notebook='notebooks']
220
220
  animation: 0.5s fade-out forwards;
221
221
  }
222
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
+
223
236
  @keyframes fade-out {
224
237
  0% {
225
238
  opacity: 1;