@jupyterlab/debugger 4.0.0-alpha.9 → 4.0.0-beta.0

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.
Files changed (119) hide show
  1. package/lib/debugger.d.ts +3 -1
  2. package/lib/debugger.js +5 -3
  3. package/lib/debugger.js.map +1 -1
  4. package/lib/dialogs/evaluate.d.ts +5 -0
  5. package/lib/dialogs/evaluate.js +16 -6
  6. package/lib/dialogs/evaluate.js.map +1 -1
  7. package/lib/factory.d.ts +1 -1
  8. package/lib/factory.js +15 -9
  9. package/lib/factory.js.map +1 -1
  10. package/lib/handler.js +15 -7
  11. package/lib/handler.js.map +1 -1
  12. package/lib/handlers/console.js +9 -3
  13. package/lib/handlers/console.js.map +1 -1
  14. package/lib/handlers/editor.d.ts +26 -12
  15. package/lib/handlers/editor.js +166 -89
  16. package/lib/handlers/editor.js.map +1 -1
  17. package/lib/handlers/file.js +6 -2
  18. package/lib/handlers/file.js.map +1 -1
  19. package/lib/handlers/notebook.d.ts +0 -7
  20. package/lib/handlers/notebook.js +11 -17
  21. package/lib/handlers/notebook.js.map +1 -1
  22. package/lib/icons.d.ts +2 -1
  23. package/lib/icons.js +6 -1
  24. package/lib/icons.js.map +1 -1
  25. package/lib/model.js +1 -0
  26. package/lib/model.js.map +1 -1
  27. package/lib/panels/breakpoints/index.d.ts +2 -2
  28. package/lib/panels/breakpoints/index.js +9 -7
  29. package/lib/panels/breakpoints/index.js.map +1 -1
  30. package/lib/panels/breakpoints/pauseonexceptions.d.ts +53 -0
  31. package/lib/panels/breakpoints/pauseonexceptions.js +98 -0
  32. package/lib/panels/breakpoints/pauseonexceptions.js.map +1 -0
  33. package/lib/panels/callstack/index.d.ts +1 -1
  34. package/lib/panels/kernelSources/body.d.ts +5 -7
  35. package/lib/panels/kernelSources/body.js +37 -47
  36. package/lib/panels/kernelSources/body.js.map +1 -1
  37. package/lib/panels/kernelSources/filter.d.ts +1 -2
  38. package/lib/panels/kernelSources/filter.js +2 -2
  39. package/lib/panels/kernelSources/filter.js.map +1 -1
  40. package/lib/panels/kernelSources/index.js +1 -1
  41. package/lib/panels/kernelSources/index.js.map +1 -1
  42. package/lib/panels/kernelSources/model.d.ts +10 -1
  43. package/lib/panels/kernelSources/model.js +19 -1
  44. package/lib/panels/kernelSources/model.js.map +1 -1
  45. package/lib/panels/sources/body.js +5 -3
  46. package/lib/panels/sources/body.js.map +1 -1
  47. package/lib/panels/variables/grid.d.ts +10 -0
  48. package/lib/panels/variables/grid.js +28 -351
  49. package/lib/panels/variables/grid.js.map +1 -1
  50. package/lib/panels/variables/gridpanel.d.ts +140 -0
  51. package/lib/panels/variables/gridpanel.js +363 -0
  52. package/lib/panels/variables/gridpanel.js.map +1 -0
  53. package/lib/panels/variables/mimerenderer.js +9 -1
  54. package/lib/panels/variables/mimerenderer.js.map +1 -1
  55. package/lib/panels/variables/scope.js +4 -0
  56. package/lib/panels/variables/scope.js.map +1 -1
  57. package/lib/panels/variables/tree.d.ts +1 -0
  58. package/lib/panels/variables/tree.js +136 -47
  59. package/lib/panels/variables/tree.js.map +1 -1
  60. package/lib/service.d.ts +20 -6
  61. package/lib/service.js +84 -59
  62. package/lib/service.js.map +1 -1
  63. package/lib/session.d.ts +20 -6
  64. package/lib/session.js +59 -11
  65. package/lib/session.js.map +1 -1
  66. package/lib/sidebar.js +1 -1
  67. package/lib/sources.d.ts +2 -2
  68. package/lib/sources.js +32 -17
  69. package/lib/sources.js.map +1 -1
  70. package/lib/tokens.d.ts +57 -13
  71. package/lib/tokens.js.map +1 -1
  72. package/package.json +38 -46
  73. package/src/config.ts +78 -0
  74. package/src/debugger.ts +154 -0
  75. package/src/dialogs/evaluate.ts +144 -0
  76. package/src/factory.ts +72 -0
  77. package/src/handler.ts +528 -0
  78. package/src/handlers/console.ts +118 -0
  79. package/src/handlers/editor.ts +469 -0
  80. package/src/handlers/file.ts +86 -0
  81. package/src/handlers/notebook.ts +128 -0
  82. package/src/hash.ts +69 -0
  83. package/src/icons.ts +64 -0
  84. package/src/index.ts +16 -0
  85. package/src/model.ts +155 -0
  86. package/src/panels/breakpoints/body.tsx +145 -0
  87. package/src/panels/breakpoints/index.ts +116 -0
  88. package/src/panels/breakpoints/model.ts +74 -0
  89. package/src/panels/breakpoints/pauseonexceptions.tsx +141 -0
  90. package/src/panels/callstack/body.tsx +96 -0
  91. package/src/panels/callstack/index.ts +152 -0
  92. package/src/panels/callstack/model.ts +86 -0
  93. package/src/panels/kernelSources/body.tsx +139 -0
  94. package/src/panels/kernelSources/filter.tsx +44 -0
  95. package/src/panels/kernelSources/index.tsx +106 -0
  96. package/src/panels/kernelSources/model.ts +160 -0
  97. package/src/panels/sources/body.ts +161 -0
  98. package/src/panels/sources/index.tsx +85 -0
  99. package/src/panels/sources/model.ts +94 -0
  100. package/src/panels/sources/sourcepath.tsx +28 -0
  101. package/src/panels/variables/grid.ts +144 -0
  102. package/src/panels/variables/gridpanel.ts +455 -0
  103. package/src/panels/variables/index.ts +199 -0
  104. package/src/panels/variables/mimerenderer.ts +125 -0
  105. package/src/panels/variables/model.ts +61 -0
  106. package/src/panels/variables/scope.tsx +132 -0
  107. package/src/panels/variables/tree.tsx +521 -0
  108. package/src/service.ts +1009 -0
  109. package/src/session.ts +342 -0
  110. package/src/sidebar.ts +194 -0
  111. package/src/sources.ts +327 -0
  112. package/src/svg.d.ts +9 -0
  113. package/src/tokens.ts +1071 -0
  114. package/style/breakpoints.css +21 -12
  115. package/style/icons/exceptions.svg +10 -0
  116. package/style/index.css +1 -1
  117. package/style/index.js +1 -1
  118. package/style/kernelSources.css +3 -0
  119. package/style/variables.css +68 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyterlab/debugger",
3
- "version": "4.0.0-alpha.9",
3
+ "version": "4.0.0-beta.0",
4
4
  "description": "JupyterLab - Debugger Extension",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -34,67 +34,59 @@
34
34
  "schema/*.json",
35
35
  "style/**/*.css",
36
36
  "style/**/*.svg",
37
- "style/index.js"
37
+ "style/index.js",
38
+ "src/**/*.{ts,tsx}"
38
39
  ],
39
40
  "scripts": {
40
41
  "build": "tsc -b",
41
42
  "build:test": "tsc --build tsconfig.test.json",
42
43
  "clean": "rimraf lib && rimraf tsconfig.tsbuildinfo && rimraf tsconfig.test.tsbuildinfo && rimraf tests/build",
43
44
  "docs": "typedoc --options tdoptions.json --theme ../../typedoc-theme src",
44
- "test": "jest",
45
- "test:cov": "jest --collect-coverage",
45
+ "test": "jest -i",
46
+ "test:cov": "jest -i --collect-coverage",
46
47
  "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
47
48
  "test:debug:watch": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
48
49
  "watch": "tsc -b --watch"
49
50
  },
50
51
  "dependencies": {
51
- "@jupyterlab/application": "^4.0.0-alpha.9",
52
- "@jupyterlab/apputils": "^4.0.0-alpha.9",
53
- "@jupyterlab/cells": "^4.0.0-alpha.9",
54
- "@jupyterlab/codeeditor": "^4.0.0-alpha.9",
55
- "@jupyterlab/codemirror": "^4.0.0-alpha.9",
56
- "@jupyterlab/console": "^4.0.0-alpha.9",
57
- "@jupyterlab/coreutils": "^6.0.0-alpha.9",
58
- "@jupyterlab/docregistry": "^4.0.0-alpha.9",
59
- "@jupyterlab/fileeditor": "^4.0.0-alpha.9",
60
- "@jupyterlab/notebook": "^4.0.0-alpha.9",
61
- "@jupyterlab/observables": "^5.0.0-alpha.9",
62
- "@jupyterlab/rendermime": "^4.0.0-alpha.9",
63
- "@jupyterlab/services": "^7.0.0-alpha.9",
64
- "@jupyterlab/translation": "^4.0.0-alpha.9",
65
- "@jupyterlab/ui-components": "^4.0.0-alpha.24",
66
- "@lumino/algorithm": "^1.9.1",
67
- "@lumino/commands": "^1.20.0",
68
- "@lumino/coreutils": "^1.12.0",
69
- "@lumino/datagrid": "^0.35.1",
70
- "@lumino/disposable": "^1.10.1",
71
- "@lumino/messaging": "^1.10.1",
72
- "@lumino/polling": "^1.10.0",
73
- "@lumino/signaling": "^1.10.1",
74
- "@lumino/widgets": "^1.31.1",
52
+ "@codemirror/state": "^6.2.0",
53
+ "@codemirror/view": "^6.7.0",
54
+ "@jupyter/ydoc": "^0.3.4",
55
+ "@jupyterlab/application": "^4.0.0-beta.0",
56
+ "@jupyterlab/apputils": "^4.0.0-beta.0",
57
+ "@jupyterlab/cells": "^4.0.0-beta.0",
58
+ "@jupyterlab/codeeditor": "^4.0.0-beta.0",
59
+ "@jupyterlab/codemirror": "^4.0.0-beta.0",
60
+ "@jupyterlab/console": "^4.0.0-beta.0",
61
+ "@jupyterlab/coreutils": "^6.0.0-beta.0",
62
+ "@jupyterlab/docregistry": "^4.0.0-beta.0",
63
+ "@jupyterlab/fileeditor": "^4.0.0-beta.0",
64
+ "@jupyterlab/notebook": "^4.0.0-beta.0",
65
+ "@jupyterlab/observables": "^5.0.0-beta.0",
66
+ "@jupyterlab/rendermime": "^4.0.0-beta.0",
67
+ "@jupyterlab/services": "^7.0.0-beta.0",
68
+ "@jupyterlab/translation": "^4.0.0-beta.0",
69
+ "@jupyterlab/ui-components": "^4.0.0-beta.0",
70
+ "@lumino/algorithm": "^2.0.0",
71
+ "@lumino/commands": "^2.0.0",
72
+ "@lumino/coreutils": "^2.0.0",
73
+ "@lumino/datagrid": "^2.0.0",
74
+ "@lumino/disposable": "^2.0.0",
75
+ "@lumino/messaging": "^2.0.0",
76
+ "@lumino/polling": "^2.0.0",
77
+ "@lumino/signaling": "^2.0.0",
78
+ "@lumino/widgets": "^2.0.0",
75
79
  "@vscode/debugprotocol": "^1.51.0",
76
- "codemirror": "~5.61.0",
77
- "react": "^17.0.1"
80
+ "react": "^18.2.0"
78
81
  },
79
82
  "devDependencies": {
80
- "@babel/core": "^7.10.2",
81
- "@babel/preset-env": "^7.10.2",
82
- "@jupyterlab/testutils": "^4.0.0-alpha.9",
83
- "@types/codemirror": "^0.0.109",
84
- "@types/jest": "^26.0.10",
85
- "@types/react-dom": "^17.0.0",
86
- "@types/text-encoding": "^0.0.35",
83
+ "@jupyterlab/testing": "^4.0.0-beta.0",
84
+ "@types/jest": "^29.2.0",
87
85
  "canvas": "^2.9.1",
88
- "jest": "^26.4.2",
89
- "jest-junit": "^11.1.0",
90
- "jest-raw-loader": "^1.0.1",
91
- "jest-summary-reporter": "^0.0.2",
86
+ "jest": "^29.2.0",
92
87
  "rimraf": "~3.0.0",
93
- "shell-quote": "^1.7.2",
94
- "text-encoding": "^0.7.0",
95
- "ts-jest": "^26.3.0",
96
- "typedoc": "~0.22.10",
97
- "typescript": "~4.6.3"
88
+ "typedoc": "~0.23.25",
89
+ "typescript": "~5.0.2"
98
90
  },
99
91
  "publishConfig": {
100
92
  "access": "public"
package/src/config.ts ADDED
@@ -0,0 +1,78 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import { murmur2 } from './hash';
5
+
6
+ import { IDebugger } from './tokens';
7
+
8
+ /**
9
+ * A class that holds debugger configuration for all kernels.
10
+ */
11
+ export class DebuggerConfig implements IDebugger.IConfig {
12
+ /**
13
+ * Returns an id based on the given code.
14
+ *
15
+ * @param code The source code.
16
+ * @param kernel The kernel name from current session.
17
+ */
18
+ getCodeId(code: string, kernel: string): string {
19
+ const fileParams = this._fileParams.get(kernel);
20
+
21
+ if (!fileParams) {
22
+ throw new Error(`Kernel (${kernel}) has no tmp file params.`);
23
+ }
24
+
25
+ const hash = this._hashMethods.get(kernel);
26
+
27
+ if (!hash) {
28
+ throw new Error(`Kernel (${kernel}) has no hashing params.`);
29
+ }
30
+
31
+ const { prefix, suffix } = fileParams;
32
+ return `${prefix}${hash(code)}${suffix}`;
33
+ }
34
+
35
+ /**
36
+ * Sets the hash parameters for a kernel.
37
+ *
38
+ * @param params - Hashing parameters for a kernel.
39
+ */
40
+ setHashParams(params: IDebugger.IConfig.HashParams): void {
41
+ const { kernel, method, seed } = params;
42
+ if (!kernel) {
43
+ throw new TypeError(`Kernel name is not defined.`);
44
+ }
45
+ switch (method) {
46
+ case 'Murmur2':
47
+ this._hashMethods.set(kernel, code => murmur2(code, seed).toString());
48
+ break;
49
+ default:
50
+ throw new Error(`Hash method (${method}) is not supported.`);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Sets the parameters used by the kernel to create temp files (e.g. cells).
56
+ *
57
+ * @param params - Temporary file prefix and suffix for a kernel.
58
+ */
59
+ setTmpFileParams(params: IDebugger.IConfig.FileParams): void {
60
+ const { kernel, prefix, suffix } = params;
61
+ if (!kernel) {
62
+ throw new TypeError(`Kernel name is not defined.`);
63
+ }
64
+ this._fileParams.set(kernel, { kernel, prefix, suffix });
65
+ }
66
+
67
+ /**
68
+ * Gets the parameters used for the temp files (e.e. cells) for a kernel.
69
+ *
70
+ * @param kernel - The kernel name from current session.
71
+ */
72
+ getTmpFileParams(kernel: string): IDebugger.IConfig.FileParams {
73
+ return this._fileParams.get(kernel)!;
74
+ }
75
+
76
+ private _fileParams = new Map<string, IDebugger.IConfig.FileParams>();
77
+ private _hashMethods = new Map<string, (code: string) => string>();
78
+ }
@@ -0,0 +1,154 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import { codeIcon, runIcon, stopIcon } from '@jupyterlab/ui-components';
5
+
6
+ import { DebuggerConfig } from './config';
7
+
8
+ import { DebuggerEvaluateDialog } from './dialogs/evaluate';
9
+
10
+ import { ReadOnlyEditorFactory as EditorFactory } from './factory';
11
+
12
+ import { DebuggerHandler } from './handler';
13
+
14
+ import { EditorHandler as DebuggerEditorHandler } from './handlers/editor';
15
+
16
+ import {
17
+ closeAllIcon as closeAll,
18
+ pauseIcon as pause,
19
+ stepIntoIcon as stepInto,
20
+ stepOutIcon as stepOut,
21
+ stepOverIcon as stepOver,
22
+ variableIcon as variable,
23
+ viewBreakpointIcon as viewBreakpoint
24
+ } from './icons';
25
+
26
+ import { DebuggerModel } from './model';
27
+
28
+ import { VariablesBodyGrid } from './panels/variables/grid';
29
+
30
+ import { VariableMimeRenderer } from './panels/variables/mimerenderer';
31
+
32
+ import { DebuggerService } from './service';
33
+
34
+ import { DebuggerSession } from './session';
35
+
36
+ import { DebuggerSidebar } from './sidebar';
37
+
38
+ import { DebuggerSources } from './sources';
39
+
40
+ /**
41
+ * A namespace for `Debugger` statics.
42
+ */
43
+ export namespace Debugger {
44
+ /**
45
+ * Debugger configuration for all kernels.
46
+ */
47
+ export class Config extends DebuggerConfig {}
48
+
49
+ /**
50
+ * A handler for a CodeEditor.IEditor.
51
+ */
52
+ export class EditorHandler extends DebuggerEditorHandler {}
53
+
54
+ /**
55
+ * A handler for debugging a widget.
56
+ */
57
+ export class Handler extends DebuggerHandler {}
58
+
59
+ /**
60
+ * A model for a debugger.
61
+ */
62
+ export class Model extends DebuggerModel {}
63
+
64
+ /**
65
+ * A widget factory for read only editors.
66
+ */
67
+ export class ReadOnlyEditorFactory extends EditorFactory {}
68
+
69
+ /**
70
+ * The main IDebugger implementation.
71
+ */
72
+ export class Service extends DebuggerService {}
73
+
74
+ /**
75
+ * A concrete implementation of IDebugger.ISession.
76
+ */
77
+ export class Session extends DebuggerSession {}
78
+
79
+ /**
80
+ * The debugger sidebar UI.
81
+ */
82
+ export class Sidebar extends DebuggerSidebar {}
83
+
84
+ /**
85
+ * The source and editor manager for a debugger instance.
86
+ */
87
+ export class Sources extends DebuggerSources {}
88
+
89
+ /**
90
+ * A data grid that displays variables in a debugger session.
91
+ */
92
+ export class VariablesGrid extends VariablesBodyGrid {}
93
+
94
+ /**
95
+ * A widget to display data according to its mime type
96
+ */
97
+ export class VariableRenderer extends VariableMimeRenderer {}
98
+
99
+ /**
100
+ * The command IDs used by the debugger plugin.
101
+ */
102
+ export namespace CommandIDs {
103
+ export const debugContinue = 'debugger:continue';
104
+
105
+ export const terminate = 'debugger:terminate';
106
+
107
+ export const next = 'debugger:next';
108
+
109
+ export const showPanel = 'debugger:show-panel';
110
+
111
+ export const stepIn = 'debugger:stepIn';
112
+
113
+ export const stepOut = 'debugger:stepOut';
114
+
115
+ export const inspectVariable = 'debugger:inspect-variable';
116
+
117
+ export const renderMimeVariable = 'debugger:render-mime-variable';
118
+
119
+ export const evaluate = 'debugger:evaluate';
120
+
121
+ export const restartDebug = 'debugger:restart-debug';
122
+
123
+ export const pauseOnExceptions = 'debugger:pause-on-exceptions';
124
+
125
+ export const copyToClipboard = 'debugger:copy-to-clipboard';
126
+ }
127
+
128
+ /**
129
+ * The debugger user interface icons.
130
+ */
131
+ export namespace Icons {
132
+ export const closeAllIcon = closeAll;
133
+ export const evaluateIcon = codeIcon;
134
+ export const continueIcon = runIcon;
135
+ export const pauseIcon = pause;
136
+ export const stepIntoIcon = stepInto;
137
+ export const stepOutIcon = stepOut;
138
+ export const stepOverIcon = stepOver;
139
+ export const terminateIcon = stopIcon;
140
+ export const variableIcon = variable;
141
+ export const viewBreakpointIcon = viewBreakpoint;
142
+ export const pauseOnExceptionsIcon = pause;
143
+ }
144
+
145
+ /**
146
+ * The debugger dialog helpers.
147
+ */
148
+ export namespace Dialogs {
149
+ /**
150
+ * Open a code prompt in a dialog.
151
+ */
152
+ export const getCode = DebuggerEvaluateDialog.getCode;
153
+ }
154
+ }
@@ -0,0 +1,144 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+
6
+ import { Dialog } from '@jupyterlab/apputils';
7
+
8
+ import { Cell, CodeCell, CodeCellModel } from '@jupyterlab/cells';
9
+
10
+ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
11
+
12
+ import { Message } from '@lumino/messaging';
13
+
14
+ import { Widget } from '@lumino/widgets';
15
+
16
+ /**
17
+ * A namespace for DebuggerEvaluateDialog statics.
18
+ */
19
+ export namespace DebuggerEvaluateDialog {
20
+ /**
21
+ * Instantiation options for the evaluate dialog.
22
+ */
23
+ export interface IOptions {
24
+ /**
25
+ * The top level text for the dialog. Defaults to an empty string.
26
+ */
27
+ title: string;
28
+
29
+ /**
30
+ * Cell content factory.
31
+ */
32
+ contentFactory: Cell.IContentFactory;
33
+
34
+ /**
35
+ * The mime renderer for the cell widget.
36
+ */
37
+ rendermime: IRenderMimeRegistry;
38
+
39
+ /**
40
+ * The mime type for the cell widget content.
41
+ */
42
+ mimeType?: string;
43
+
44
+ /**
45
+ * Label for ok button.
46
+ */
47
+ okLabel?: string;
48
+
49
+ /**
50
+ * Label for cancel button.
51
+ */
52
+ cancelLabel?: string;
53
+ }
54
+
55
+ /**
56
+ * Create and show a dialog to prompt user for code.
57
+ *
58
+ * @param options - The dialog setup options.
59
+ *
60
+ * @returns A promise that resolves with whether the dialog was accepted
61
+ */
62
+ export function getCode(options: IOptions): Promise<Dialog.IResult<string>> {
63
+ const dialog = new EvaluateDialog({
64
+ ...options,
65
+ body: new EvaluateDialogBody(options),
66
+ buttons: [
67
+ Dialog.cancelButton({ label: options.cancelLabel }),
68
+ Dialog.okButton({ label: options.okLabel })
69
+ ]
70
+ });
71
+ return dialog.launch();
72
+ }
73
+ }
74
+
75
+ /**
76
+ * A dialog to prompt users for code to evaluate.
77
+ */
78
+ class EvaluateDialog extends Dialog<string> {
79
+ /**
80
+ * Handle the DOM events for the Evaluate dialog.
81
+ *
82
+ * @param event The DOM event sent to the dialog widget
83
+ */
84
+ handleEvent(event: Event): void {
85
+ if (event.type === 'keydown') {
86
+ const keyboardEvent = event as KeyboardEvent;
87
+ const { code, shiftKey } = keyboardEvent;
88
+ if (shiftKey && code === 'Enter') {
89
+ return this.resolve();
90
+ }
91
+ if (code === 'Enter') {
92
+ return;
93
+ }
94
+ }
95
+ super.handleEvent(event);
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Widget body with a code cell prompt in a dialog
101
+ */
102
+ class EvaluateDialogBody extends Widget implements Dialog.IBodyWidget<string> {
103
+ /**
104
+ * CodePromptDialog constructor
105
+ *
106
+ * @param options Constructor options
107
+ */
108
+ constructor(options: DebuggerEvaluateDialog.IOptions) {
109
+ super();
110
+
111
+ const { contentFactory, rendermime, mimeType } = options;
112
+
113
+ const model = new CodeCellModel();
114
+ model.mimeType = mimeType ?? '';
115
+ this._prompt = new CodeCell({
116
+ contentFactory,
117
+ rendermime,
118
+ model,
119
+ placeholder: false
120
+ }).initializeState();
121
+
122
+ // explicitly remove the prompt in front of the input area
123
+ this._prompt.inputArea!.promptNode.remove();
124
+
125
+ this.node.appendChild(this._prompt.node);
126
+ }
127
+
128
+ /**
129
+ * Get the text specified by the user
130
+ */
131
+ getValue(): string {
132
+ return this._prompt.model.sharedModel.getSource();
133
+ }
134
+
135
+ /**
136
+ * A message handler invoked on an `'after-attach'` message.
137
+ */
138
+ protected onAfterAttach(msg: Message): void {
139
+ super.onAfterAttach(msg);
140
+ this._prompt.activate();
141
+ }
142
+
143
+ private _prompt: CodeCell;
144
+ }
package/src/factory.ts ADDED
@@ -0,0 +1,72 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import {
5
+ CodeEditor,
6
+ CodeEditorWrapper,
7
+ IEditorServices
8
+ } from '@jupyterlab/codeeditor';
9
+ import { IDebugger } from './tokens';
10
+
11
+ /**
12
+ * A widget factory for read only editors.
13
+ */
14
+ export class ReadOnlyEditorFactory {
15
+ /**
16
+ * Construct a new editor widget factory.
17
+ *
18
+ * @param options The instantiation options for a ReadOnlyEditorFactory.
19
+ */
20
+ constructor(options: ReadOnlyEditorFactory.IOptions) {
21
+ this._services = options.editorServices;
22
+ }
23
+
24
+ /**
25
+ * Create a new CodeEditorWrapper given a Source.
26
+ *
27
+ * @param source The source to create a new editor for.
28
+ */
29
+ createNewEditor(source: IDebugger.Source): CodeEditorWrapper {
30
+ const { content, mimeType, path } = source;
31
+ const factory = this._services.factoryService.newInlineEditor;
32
+ const mimeTypeService = this._services.mimeTypeService;
33
+ const model = new CodeEditor.Model({
34
+ mimeType: mimeType || mimeTypeService.getMimeTypeByFilePath(path)
35
+ });
36
+ model.sharedModel.source = content;
37
+ const editor = new CodeEditorWrapper({
38
+ editorOptions: {
39
+ config: {
40
+ readOnly: true,
41
+ lineNumbers: true
42
+ }
43
+ },
44
+ model,
45
+ factory
46
+ });
47
+ editor.node.setAttribute('data-jp-debugger', 'true');
48
+
49
+ editor.disposed.connect(() => {
50
+ model.dispose();
51
+ });
52
+
53
+ return editor;
54
+ }
55
+
56
+ private _services: IEditorServices;
57
+ }
58
+
59
+ /**
60
+ * The namespace for `ReadOnlyEditorFactory` class statics.
61
+ */
62
+ export namespace ReadOnlyEditorFactory {
63
+ /**
64
+ * The options used to create a read only editor widget factory.
65
+ */
66
+ export interface IOptions {
67
+ /**
68
+ * The editor services used by the factory.
69
+ */
70
+ editorServices: IEditorServices;
71
+ }
72
+ }