@jupyterlab/fileeditor 4.0.0-alpha.2 → 4.0.0-alpha.20

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 (51) hide show
  1. package/lib/fileeditorlspadapter.d.ts +96 -0
  2. package/lib/fileeditorlspadapter.js +175 -0
  3. package/lib/fileeditorlspadapter.js.map +1 -0
  4. package/lib/index.d.ts +4 -0
  5. package/lib/index.js +4 -0
  6. package/lib/index.js.map +1 -1
  7. package/lib/searchprovider.d.ts +59 -0
  8. package/lib/searchprovider.js +76 -0
  9. package/lib/searchprovider.js.map +1 -0
  10. package/lib/syntaxstatus.d.ts +74 -0
  11. package/lib/syntaxstatus.js +151 -0
  12. package/lib/syntaxstatus.js.map +1 -0
  13. package/lib/tabspacestatus.d.ts +8 -12
  14. package/lib/tabspacestatus.js +23 -27
  15. package/lib/tabspacestatus.js.map +1 -1
  16. package/lib/toc/factory.d.ts +25 -0
  17. package/lib/toc/factory.js +32 -0
  18. package/lib/toc/factory.js.map +1 -0
  19. package/lib/toc/index.d.ts +4 -0
  20. package/lib/toc/index.js +7 -0
  21. package/lib/toc/index.js.map +1 -0
  22. package/lib/toc/latex.d.ts +48 -0
  23. package/lib/toc/latex.js +117 -0
  24. package/lib/toc/latex.js.map +1 -0
  25. package/lib/toc/markdown.d.ts +44 -0
  26. package/lib/toc/markdown.js +68 -0
  27. package/lib/toc/markdown.js.map +1 -0
  28. package/lib/toc/python.d.ts +44 -0
  29. package/lib/toc/python.js +116 -0
  30. package/lib/toc/python.js.map +1 -0
  31. package/lib/tokens.js +0 -2
  32. package/lib/tokens.js.map +1 -1
  33. package/lib/widget.d.ts +12 -35
  34. package/lib/widget.js +45 -105
  35. package/lib/widget.js.map +1 -1
  36. package/package.json +25 -21
  37. package/src/fileeditorlspadapter.ts +225 -0
  38. package/src/index.ts +14 -0
  39. package/src/searchprovider.ts +106 -0
  40. package/src/syntaxstatus.tsx +217 -0
  41. package/src/tabspacestatus.tsx +166 -0
  42. package/src/toc/factory.ts +72 -0
  43. package/src/toc/index.ts +7 -0
  44. package/src/toc/latex.ts +145 -0
  45. package/src/toc/markdown.ts +90 -0
  46. package/src/toc/python.ts +143 -0
  47. package/src/tokens.ts +20 -0
  48. package/src/widget.ts +267 -0
  49. package/style/base.css +8 -3
  50. package/style/index.css +4 -0
  51. package/style/index.js +4 -0
package/src/widget.ts ADDED
@@ -0,0 +1,267 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+
4
+ import {
5
+ CodeEditor,
6
+ CodeEditorWrapper,
7
+ IEditorMimeTypeService,
8
+ IEditorServices
9
+ } from '@jupyterlab/codeeditor';
10
+ import {
11
+ ABCWidgetFactory,
12
+ DocumentRegistry,
13
+ DocumentWidget,
14
+ IDocumentWidget
15
+ } from '@jupyterlab/docregistry';
16
+ import { textEditorIcon } from '@jupyterlab/ui-components';
17
+ import { PromiseDelegate } from '@lumino/coreutils';
18
+ import { Message } from '@lumino/messaging';
19
+ import { StackedLayout, Widget } from '@lumino/widgets';
20
+
21
+ /**
22
+ * The data attribute added to a widget that can run code.
23
+ */
24
+ const CODE_RUNNER = 'jpCodeRunner';
25
+
26
+ /**
27
+ * The data attribute added to a widget that can undo.
28
+ */
29
+ const UNDOER = 'jpUndoer';
30
+
31
+ /**
32
+ * A widget for editors.
33
+ */
34
+ export class FileEditor extends Widget {
35
+ /**
36
+ * Construct a new editor widget.
37
+ */
38
+ constructor(options: FileEditor.IOptions) {
39
+ super();
40
+ this.addClass('jp-FileEditor');
41
+
42
+ const context = (this._context = options.context);
43
+ this._mimeTypeService = options.mimeTypeService;
44
+
45
+ const editorWidget = (this._editorWidget = new CodeEditorWrapper({
46
+ factory: options.factory,
47
+ model: context.model,
48
+ editorOptions: {
49
+ config: FileEditor.defaultEditorConfig
50
+ }
51
+ }));
52
+ this._editorWidget.addClass('jp-FileEditorCodeWrapper');
53
+ this._editorWidget.node.dataset[CODE_RUNNER] = 'true';
54
+ this._editorWidget.node.dataset[UNDOER] = 'true';
55
+
56
+ this.editor = editorWidget.editor;
57
+ this.model = editorWidget.model;
58
+
59
+ void context.ready.then(() => {
60
+ this._onContextReady();
61
+ });
62
+
63
+ // Listen for changes to the path.
64
+ this._onPathChanged();
65
+ context.pathChanged.connect(this._onPathChanged, this);
66
+
67
+ const layout = (this.layout = new StackedLayout());
68
+ layout.addWidget(editorWidget);
69
+ }
70
+
71
+ /**
72
+ * Get the context for the editor widget.
73
+ */
74
+ get context(): DocumentRegistry.Context {
75
+ return this._context;
76
+ }
77
+
78
+ /**
79
+ * A promise that resolves when the file editor is ready.
80
+ */
81
+ get ready(): Promise<void> {
82
+ return this._ready.promise;
83
+ }
84
+
85
+ /**
86
+ * Handle the DOM events for the widget.
87
+ *
88
+ * @param event - The DOM event sent to the widget.
89
+ *
90
+ * #### Notes
91
+ * This method implements the DOM `EventListener` interface and is
92
+ * called in response to events on the widget's node. It should
93
+ * not be called directly by user code.
94
+ */
95
+ handleEvent(event: Event): void {
96
+ if (!this.model) {
97
+ return;
98
+ }
99
+ switch (event.type) {
100
+ case 'mousedown':
101
+ this._ensureFocus();
102
+ break;
103
+ default:
104
+ break;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Handle `after-attach` messages for the widget.
110
+ */
111
+ protected onAfterAttach(msg: Message): void {
112
+ super.onAfterAttach(msg);
113
+ const node = this.node;
114
+ node.addEventListener('mousedown', this);
115
+ }
116
+
117
+ /**
118
+ * Handle `before-detach` messages for the widget.
119
+ */
120
+ protected onBeforeDetach(msg: Message): void {
121
+ const node = this.node;
122
+ node.removeEventListener('mousedown', this);
123
+ }
124
+
125
+ /**
126
+ * Handle `'activate-request'` messages.
127
+ */
128
+ protected onActivateRequest(msg: Message): void {
129
+ this._ensureFocus();
130
+ }
131
+
132
+ /**
133
+ * Ensure that the widget has focus.
134
+ */
135
+ private _ensureFocus(): void {
136
+ if (!this.editor.hasFocus()) {
137
+ this.editor.focus();
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Handle actions that should be taken when the context is ready.
143
+ */
144
+ private _onContextReady(): void {
145
+ if (this.isDisposed) {
146
+ return;
147
+ }
148
+
149
+ // Prevent the initial loading from disk from being in the editor history.
150
+ this.editor.clearHistory();
151
+ // Resolve the ready promise.
152
+ this._ready.resolve(undefined);
153
+ }
154
+
155
+ /**
156
+ * Handle a change to the path.
157
+ */
158
+ private _onPathChanged(): void {
159
+ const editor = this.editor;
160
+ const localPath = this._context.localPath;
161
+
162
+ editor.model.mimeType =
163
+ this._mimeTypeService.getMimeTypeByFilePath(localPath);
164
+ }
165
+
166
+ model: CodeEditor.IModel;
167
+ editor: CodeEditor.IEditor;
168
+ private _context: DocumentRegistry.Context;
169
+ private _editorWidget: CodeEditorWrapper;
170
+ private _mimeTypeService: IEditorMimeTypeService;
171
+ private _ready = new PromiseDelegate<void>();
172
+ }
173
+
174
+ /**
175
+ * The namespace for editor widget statics.
176
+ */
177
+ export namespace FileEditor {
178
+ /**
179
+ * The options used to create an editor widget.
180
+ */
181
+ export interface IOptions {
182
+ /**
183
+ * A code editor factory.
184
+ */
185
+ factory: CodeEditor.Factory;
186
+
187
+ /**
188
+ * The mime type service for the editor.
189
+ */
190
+ mimeTypeService: IEditorMimeTypeService;
191
+
192
+ /**
193
+ * The document context associated with the editor.
194
+ */
195
+ context: DocumentRegistry.CodeContext;
196
+ }
197
+
198
+ /**
199
+ * File editor default configuration.
200
+ */
201
+ export const defaultEditorConfig: Record<string, any> = {
202
+ lineNumbers: true,
203
+ scrollPastEnd: true
204
+ };
205
+ }
206
+
207
+ /**
208
+ * A widget factory for editors.
209
+ */
210
+ export class FileEditorFactory extends ABCWidgetFactory<
211
+ IDocumentWidget<FileEditor>,
212
+ DocumentRegistry.ICodeModel
213
+ > {
214
+ /**
215
+ * Construct a new editor widget factory.
216
+ */
217
+ constructor(options: FileEditorFactory.IOptions) {
218
+ super(options.factoryOptions);
219
+ this._services = options.editorServices;
220
+ }
221
+
222
+ /**
223
+ * Create a new widget given a context.
224
+ */
225
+ protected createNewWidget(
226
+ context: DocumentRegistry.CodeContext
227
+ ): IDocumentWidget<FileEditor> {
228
+ const func = this._services.factoryService.newDocumentEditor;
229
+ const factory: CodeEditor.Factory = options => {
230
+ // Use same id as document factory
231
+ return func(options);
232
+ };
233
+ const content = new FileEditor({
234
+ factory,
235
+ context,
236
+ mimeTypeService: this._services.mimeTypeService
237
+ });
238
+
239
+ content.title.icon = textEditorIcon;
240
+ const widget = new DocumentWidget({ content, context });
241
+ return widget;
242
+ }
243
+
244
+ private _services: IEditorServices;
245
+ }
246
+
247
+ /**
248
+ * The namespace for `FileEditorFactory` class statics.
249
+ */
250
+ export namespace FileEditorFactory {
251
+ /**
252
+ * The options used to create an editor widget factory.
253
+ */
254
+ export interface IOptions {
255
+ /**
256
+ * The editor services used by the factory.
257
+ */
258
+ editorServices: IEditorServices;
259
+
260
+ /**
261
+ * The factory options associated with the factory.
262
+ */
263
+ factoryOptions: DocumentRegistry.IWidgetFactoryOptions<
264
+ IDocumentWidget<FileEditor>
265
+ >;
266
+ }
267
+ }
package/style/base.css CHANGED
@@ -3,9 +3,6 @@
3
3
  | Distributed under the terms of the Modified BSD License.
4
4
  |----------------------------------------------------------------------------*/
5
5
 
6
- .jp-FileEditor {
7
- }
8
-
9
6
  /*-----------------------------------------------------------------------------
10
7
  | Presentation Mode (.jp-mod-presentationMode)
11
8
  |----------------------------------------------------------------------------*/
@@ -13,3 +10,11 @@
13
10
  .jp-mod-presentationMode .jp-FileEditor {
14
11
  --jp-code-font-size: var(--jp-code-presentation-font-size);
15
12
  }
13
+
14
+ .jp-FileEditorCodeWrapper {
15
+ overflow: auto;
16
+ }
17
+
18
+ .jp-FileEditorCodeWrapper .cm-editor {
19
+ height: 100%;
20
+ }
package/style/index.css CHANGED
@@ -8,6 +8,10 @@
8
8
  @import url('~@jupyterlab/ui-components/style/index.css');
9
9
  @import url('~@jupyterlab/apputils/style/index.css');
10
10
  @import url('~@jupyterlab/codeeditor/style/index.css');
11
+ @import url('~@jupyterlab/documentsearch/style/index.css');
12
+ @import url('~@jupyterlab/codemirror/style/index.css');
11
13
  @import url('~@jupyterlab/docregistry/style/index.css');
14
+ @import url('~@jupyterlab/lsp/style/index.css');
15
+ @import url('~@jupyterlab/toc/style/index.css');
12
16
 
13
17
  @import url('./base.css');
package/style/index.js CHANGED
@@ -8,6 +8,10 @@ import '@lumino/widgets/style/index.js';
8
8
  import '@jupyterlab/ui-components/style/index.js';
9
9
  import '@jupyterlab/apputils/style/index.js';
10
10
  import '@jupyterlab/codeeditor/style/index.js';
11
+ import '@jupyterlab/documentsearch/style/index.js';
12
+ import '@jupyterlab/codemirror/style/index.js';
11
13
  import '@jupyterlab/docregistry/style/index.js';
14
+ import '@jupyterlab/lsp/style/index.js';
15
+ import '@jupyterlab/toc/style/index.js';
12
16
 
13
17
  import './base.css';