@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.
- package/lib/fileeditorlspadapter.d.ts +96 -0
- package/lib/fileeditorlspadapter.js +175 -0
- package/lib/fileeditorlspadapter.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/searchprovider.d.ts +59 -0
- package/lib/searchprovider.js +76 -0
- package/lib/searchprovider.js.map +1 -0
- package/lib/syntaxstatus.d.ts +74 -0
- package/lib/syntaxstatus.js +151 -0
- package/lib/syntaxstatus.js.map +1 -0
- package/lib/tabspacestatus.d.ts +8 -12
- package/lib/tabspacestatus.js +23 -27
- package/lib/tabspacestatus.js.map +1 -1
- package/lib/toc/factory.d.ts +25 -0
- package/lib/toc/factory.js +32 -0
- package/lib/toc/factory.js.map +1 -0
- package/lib/toc/index.d.ts +4 -0
- package/lib/toc/index.js +7 -0
- package/lib/toc/index.js.map +1 -0
- package/lib/toc/latex.d.ts +48 -0
- package/lib/toc/latex.js +117 -0
- package/lib/toc/latex.js.map +1 -0
- package/lib/toc/markdown.d.ts +44 -0
- package/lib/toc/markdown.js +68 -0
- package/lib/toc/markdown.js.map +1 -0
- package/lib/toc/python.d.ts +44 -0
- package/lib/toc/python.js +116 -0
- package/lib/toc/python.js.map +1 -0
- package/lib/tokens.js +0 -2
- package/lib/tokens.js.map +1 -1
- package/lib/widget.d.ts +12 -35
- package/lib/widget.js +45 -105
- package/lib/widget.js.map +1 -1
- package/package.json +25 -21
- package/src/fileeditorlspadapter.ts +225 -0
- package/src/index.ts +14 -0
- package/src/searchprovider.ts +106 -0
- package/src/syntaxstatus.tsx +217 -0
- package/src/tabspacestatus.tsx +166 -0
- package/src/toc/factory.ts +72 -0
- package/src/toc/index.ts +7 -0
- package/src/toc/latex.ts +145 -0
- package/src/toc/markdown.ts +90 -0
- package/src/toc/python.ts +143 -0
- package/src/tokens.ts +20 -0
- package/src/widget.ts +267 -0
- package/style/base.css +8 -3
- package/style/index.css +4 -0
- package/style/index.js +4 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
import { TableOfContentsModel } from '@jupyterlab/toc';
|
|
4
|
+
import { EditorTableOfContentsFactory } from './factory';
|
|
5
|
+
/**
|
|
6
|
+
* Regular expression to create the outline
|
|
7
|
+
*/
|
|
8
|
+
let KEYWORDS;
|
|
9
|
+
try {
|
|
10
|
+
// https://github.com/tc39/proposal-regexp-match-indices was accepted
|
|
11
|
+
// in May 2021 (https://github.com/tc39/proposals/blob/main/finished-proposals.md)
|
|
12
|
+
// So we will fallback to the polyfill regexp-match-indices if not available
|
|
13
|
+
KEYWORDS = new RegExp('^\\s*(class |def |from |import )', 'd');
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
KEYWORDS = new RegExp('^\\s*(class |def |from |import )');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Table of content model for Python files.
|
|
20
|
+
*/
|
|
21
|
+
export class PythonTableOfContentsModel extends TableOfContentsModel {
|
|
22
|
+
/**
|
|
23
|
+
* Type of document supported by the model.
|
|
24
|
+
*
|
|
25
|
+
* #### Notes
|
|
26
|
+
* A `data-document-type` attribute with this value will be set
|
|
27
|
+
* on the tree view `.jp-TableOfContents-content[data-document-type="..."]`
|
|
28
|
+
*/
|
|
29
|
+
get documentType() {
|
|
30
|
+
return 'python';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Produce the headings for a document.
|
|
34
|
+
*
|
|
35
|
+
* @returns The list of new headings or `null` if nothing needs to be updated.
|
|
36
|
+
*/
|
|
37
|
+
async getHeadings() {
|
|
38
|
+
if (!this.isActive) {
|
|
39
|
+
return Promise.resolve(null);
|
|
40
|
+
}
|
|
41
|
+
// Split the text into lines:
|
|
42
|
+
const lines = this.widget.content.model.sharedModel
|
|
43
|
+
.getSource()
|
|
44
|
+
.split('\n');
|
|
45
|
+
// Iterate over the lines to get the heading level and text for each line:
|
|
46
|
+
let headings = new Array();
|
|
47
|
+
let processingImports = false;
|
|
48
|
+
let indent = 1;
|
|
49
|
+
let lineIdx = -1;
|
|
50
|
+
for (const line of lines) {
|
|
51
|
+
lineIdx++;
|
|
52
|
+
let hasKeyword;
|
|
53
|
+
if (KEYWORDS.flags.includes('d')) {
|
|
54
|
+
hasKeyword = KEYWORDS.exec(line);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const { default: execWithIndices } = await import('regexp-match-indices');
|
|
58
|
+
hasKeyword = execWithIndices(KEYWORDS, line);
|
|
59
|
+
}
|
|
60
|
+
if (hasKeyword) {
|
|
61
|
+
// Index 0 contains the spaces, index 1 is the keyword group
|
|
62
|
+
const [start] = hasKeyword.indices[1];
|
|
63
|
+
if (indent === 1 && start > 0) {
|
|
64
|
+
indent = start;
|
|
65
|
+
}
|
|
66
|
+
const isImport = ['from ', 'import '].includes(hasKeyword[1]);
|
|
67
|
+
if (isImport && processingImports) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
processingImports = isImport;
|
|
71
|
+
const level = 1 + start / indent;
|
|
72
|
+
if (level > this.configuration.maximalDepth) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
headings.push({
|
|
76
|
+
text: line.slice(start),
|
|
77
|
+
level,
|
|
78
|
+
line: lineIdx
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return Promise.resolve(headings);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Table of content model factory for Python files.
|
|
87
|
+
*/
|
|
88
|
+
export class PythonTableOfContentsFactory extends EditorTableOfContentsFactory {
|
|
89
|
+
/**
|
|
90
|
+
* Whether the factory can handle the widget or not.
|
|
91
|
+
*
|
|
92
|
+
* @param widget - widget
|
|
93
|
+
* @returns boolean indicating a ToC can be generated
|
|
94
|
+
*/
|
|
95
|
+
isApplicable(widget) {
|
|
96
|
+
var _a, _b;
|
|
97
|
+
const isApplicable = super.isApplicable(widget);
|
|
98
|
+
if (isApplicable) {
|
|
99
|
+
let mime = (_b = (_a = widget.content) === null || _a === void 0 ? void 0 : _a.model) === null || _b === void 0 ? void 0 : _b.mimeType;
|
|
100
|
+
return (mime &&
|
|
101
|
+
(mime === 'application/x-python-code' || mime === 'text/x-python'));
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Create a new table of contents model for the widget
|
|
107
|
+
*
|
|
108
|
+
* @param widget - widget
|
|
109
|
+
* @param configuration - Table of contents configuration
|
|
110
|
+
* @returns The table of contents model
|
|
111
|
+
*/
|
|
112
|
+
_createNew(widget, configuration) {
|
|
113
|
+
return new PythonTableOfContentsModel(widget, configuration);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=python.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python.js","sourceRoot":"","sources":["../../src/toc/python.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAK3D,OAAO,EAAmB,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGxE,OAAO,EAAE,4BAA4B,EAAkB,MAAM,WAAW,CAAC;AAEzE;;GAEG;AACH,IAAI,QAAgB,CAAC;AACrB,IAAI;IACF,qEAAqE;IACrE,kFAAkF;IAClF,4EAA4E;IAC5E,QAAQ,GAAG,IAAI,MAAM,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;CAChE;AAAC,WAAM;IACN,QAAQ,GAAG,IAAI,MAAM,CAAC,kCAAkC,CAAC,CAAC;CAC3D;AAED;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,oBAG/C;IACC;;;;;;OAMG;IACH,IAAI,YAAY;QAC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gBAC9D,IAAI,QAAQ,IAAI,iBAAiB,EAAE;oBACjC,SAAS;iBACV;gBACD,iBAAiB,GAAG,QAAQ,CAAC;gBAE7B,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,MAAM,CAAC;gBAEjC,IAAI,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;oBAC3C,SAAS;iBACV;gBAED,QAAQ,CAAC,IAAI,CAAC;oBACZ,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;oBACvB,KAAK;oBACL,IAAI,EAAE,OAAO;iBACd,CAAC,CAAC;aACJ;SACF;QAED,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,4BAA6B,SAAQ,4BAA4B;IAC5E;;;;;OAKG;IACH,YAAY,CAAC,MAAc;;QACzB,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAEhD,IAAI,YAAY,EAAE;YAChB,IAAI,IAAI,GAAG,MAAA,MAAC,MAAc,CAAC,OAAO,0CAAE,KAAK,0CAAE,QAAQ,CAAC;YACpD,OAAO,CACL,IAAI;gBACJ,CAAC,IAAI,KAAK,2BAA2B,IAAI,IAAI,KAAK,eAAe,CAAC,CACnE,CAAC;SACH;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACO,UAAU,CAClB,MAAmC,EACnC,aAAuC;QAEvC,OAAO,IAAI,0BAA0B,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC/D,CAAC;CACF"}
|
package/lib/tokens.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
3
|
import { Token } from '@lumino/coreutils';
|
|
4
|
-
/* tslint:disable */
|
|
5
4
|
/**
|
|
6
5
|
* The editor tracker token.
|
|
7
6
|
*/
|
|
8
7
|
export const IEditorTracker = new Token('@jupyterlab/fileeditor:IEditorTracker');
|
|
9
|
-
/* tslint:enable */
|
|
10
8
|
//# sourceMappingURL=tokens.js.map
|
package/lib/tokens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAI3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAS1C
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAI3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAS1C;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,KAAK,CACrC,uCAAuC,CACxC,CAAC"}
|
package/lib/widget.d.ts
CHANGED
|
@@ -1,39 +1,7 @@
|
|
|
1
|
-
import { CodeEditor,
|
|
1
|
+
import { CodeEditor, IEditorMimeTypeService, IEditorServices } from '@jupyterlab/codeeditor';
|
|
2
2
|
import { ABCWidgetFactory, DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
|
|
3
3
|
import { Message } from '@lumino/messaging';
|
|
4
4
|
import { Widget } from '@lumino/widgets';
|
|
5
|
-
/**
|
|
6
|
-
* A code editor wrapper for the file editor.
|
|
7
|
-
*/
|
|
8
|
-
export declare class FileEditorCodeWrapper extends CodeEditorWrapper {
|
|
9
|
-
/**
|
|
10
|
-
* Construct a new editor widget.
|
|
11
|
-
*/
|
|
12
|
-
constructor(options: FileEditor.IOptions);
|
|
13
|
-
/**
|
|
14
|
-
* Get the context for the editor widget.
|
|
15
|
-
*/
|
|
16
|
-
get context(): DocumentRegistry.Context;
|
|
17
|
-
/**
|
|
18
|
-
* A promise that resolves when the file editor is ready.
|
|
19
|
-
*/
|
|
20
|
-
get ready(): Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Handle actions that should be taken when the context is ready.
|
|
23
|
-
*/
|
|
24
|
-
private _onContextReady;
|
|
25
|
-
/**
|
|
26
|
-
* Handle a change in context model content.
|
|
27
|
-
*/
|
|
28
|
-
private _onContentChanged;
|
|
29
|
-
/**
|
|
30
|
-
* Handle a change to the collaborators on the model
|
|
31
|
-
* by updating UI elements associated with them.
|
|
32
|
-
*/
|
|
33
|
-
private _onCollaboratorsChanged;
|
|
34
|
-
protected _context: DocumentRegistry.Context;
|
|
35
|
-
private _ready;
|
|
36
|
-
}
|
|
37
5
|
/**
|
|
38
6
|
* A widget for editors.
|
|
39
7
|
*/
|
|
@@ -77,15 +45,20 @@ export declare class FileEditor extends Widget {
|
|
|
77
45
|
* Ensure that the widget has focus.
|
|
78
46
|
*/
|
|
79
47
|
private _ensureFocus;
|
|
48
|
+
/**
|
|
49
|
+
* Handle actions that should be taken when the context is ready.
|
|
50
|
+
*/
|
|
51
|
+
private _onContextReady;
|
|
80
52
|
/**
|
|
81
53
|
* Handle a change to the path.
|
|
82
54
|
*/
|
|
83
55
|
private _onPathChanged;
|
|
84
|
-
private editorWidget;
|
|
85
56
|
model: CodeEditor.IModel;
|
|
86
57
|
editor: CodeEditor.IEditor;
|
|
87
|
-
|
|
58
|
+
private _context;
|
|
59
|
+
private _editorWidget;
|
|
88
60
|
private _mimeTypeService;
|
|
61
|
+
private _ready;
|
|
89
62
|
}
|
|
90
63
|
/**
|
|
91
64
|
* The namespace for editor widget statics.
|
|
@@ -108,6 +81,10 @@ export declare namespace FileEditor {
|
|
|
108
81
|
*/
|
|
109
82
|
context: DocumentRegistry.CodeContext;
|
|
110
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* File editor default configuration.
|
|
86
|
+
*/
|
|
87
|
+
const defaultEditorConfig: Record<string, any>;
|
|
111
88
|
}
|
|
112
89
|
/**
|
|
113
90
|
* A widget factory for editors.
|
package/lib/widget.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
import {
|
|
3
|
+
import { CodeEditorWrapper } from '@jupyterlab/codeeditor';
|
|
4
4
|
import { ABCWidgetFactory, DocumentWidget } from '@jupyterlab/docregistry';
|
|
5
5
|
import { textEditorIcon } from '@jupyterlab/ui-components';
|
|
6
6
|
import { PromiseDelegate } from '@lumino/coreutils';
|
|
@@ -13,105 +13,6 @@ const CODE_RUNNER = 'jpCodeRunner';
|
|
|
13
13
|
* The data attribute added to a widget that can undo.
|
|
14
14
|
*/
|
|
15
15
|
const UNDOER = 'jpUndoer';
|
|
16
|
-
/**
|
|
17
|
-
* A code editor wrapper for the file editor.
|
|
18
|
-
*/
|
|
19
|
-
export class FileEditorCodeWrapper extends CodeEditorWrapper {
|
|
20
|
-
/**
|
|
21
|
-
* Construct a new editor widget.
|
|
22
|
-
*/
|
|
23
|
-
constructor(options) {
|
|
24
|
-
super({
|
|
25
|
-
factory: options.factory,
|
|
26
|
-
model: options.context.model
|
|
27
|
-
});
|
|
28
|
-
this._ready = new PromiseDelegate();
|
|
29
|
-
const context = (this._context = options.context);
|
|
30
|
-
const editor = this.editor;
|
|
31
|
-
this.addClass('jp-FileEditorCodeWrapper');
|
|
32
|
-
this.node.dataset[CODE_RUNNER] = 'true';
|
|
33
|
-
this.node.dataset[UNDOER] = 'true';
|
|
34
|
-
editor.model.value.text = context.model.toString();
|
|
35
|
-
void context.ready.then(() => {
|
|
36
|
-
this._onContextReady();
|
|
37
|
-
});
|
|
38
|
-
if (context.model.modelDB.isCollaborative) {
|
|
39
|
-
const modelDB = context.model.modelDB;
|
|
40
|
-
void modelDB.connected.then(() => {
|
|
41
|
-
const collaborators = modelDB.collaborators;
|
|
42
|
-
if (!collaborators) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
// Setup the selection style for collaborators
|
|
46
|
-
const localCollaborator = collaborators.localCollaborator;
|
|
47
|
-
this.editor.uuid = localCollaborator.sessionId;
|
|
48
|
-
this.editor.selectionStyle = Object.assign(Object.assign({}, CodeEditor.defaultSelectionStyle), { color: localCollaborator.color });
|
|
49
|
-
collaborators.changed.connect(this._onCollaboratorsChanged, this);
|
|
50
|
-
// Trigger an initial onCollaboratorsChanged event.
|
|
51
|
-
this._onCollaboratorsChanged();
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get the context for the editor widget.
|
|
57
|
-
*/
|
|
58
|
-
get context() {
|
|
59
|
-
return this._context;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* A promise that resolves when the file editor is ready.
|
|
63
|
-
*/
|
|
64
|
-
get ready() {
|
|
65
|
-
return this._ready.promise;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Handle actions that should be taken when the context is ready.
|
|
69
|
-
*/
|
|
70
|
-
_onContextReady() {
|
|
71
|
-
if (this.isDisposed) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const contextModel = this._context.model;
|
|
75
|
-
const editor = this.editor;
|
|
76
|
-
const editorModel = editor.model;
|
|
77
|
-
// Set the editor model value.
|
|
78
|
-
editorModel.value.text = contextModel.toString();
|
|
79
|
-
// Prevent the initial loading from disk from being in the editor history.
|
|
80
|
-
editor.clearHistory();
|
|
81
|
-
// Wire signal connections.
|
|
82
|
-
contextModel.contentChanged.connect(this._onContentChanged, this);
|
|
83
|
-
// Resolve the ready promise.
|
|
84
|
-
this._ready.resolve(undefined);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Handle a change in context model content.
|
|
88
|
-
*/
|
|
89
|
-
_onContentChanged() {
|
|
90
|
-
const editorModel = this.editor.model;
|
|
91
|
-
const oldValue = editorModel.value.text;
|
|
92
|
-
const newValue = this._context.model.toString();
|
|
93
|
-
if (oldValue !== newValue) {
|
|
94
|
-
editorModel.value.text = newValue;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Handle a change to the collaborators on the model
|
|
99
|
-
* by updating UI elements associated with them.
|
|
100
|
-
*/
|
|
101
|
-
_onCollaboratorsChanged() {
|
|
102
|
-
// If there are selections corresponding to non-collaborators,
|
|
103
|
-
// they are stale and should be removed.
|
|
104
|
-
const collaborators = this._context.model.modelDB.collaborators;
|
|
105
|
-
if (!collaborators) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
for (const key of this.editor.model.selections.keys()) {
|
|
109
|
-
if (!collaborators.has(key)) {
|
|
110
|
-
this.editor.model.selections.delete(key);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
16
|
/**
|
|
116
17
|
* A widget for editors.
|
|
117
18
|
*/
|
|
@@ -121,15 +22,28 @@ export class FileEditor extends Widget {
|
|
|
121
22
|
*/
|
|
122
23
|
constructor(options) {
|
|
123
24
|
super();
|
|
25
|
+
this._ready = new PromiseDelegate();
|
|
124
26
|
this.addClass('jp-FileEditor');
|
|
125
27
|
const context = (this._context = options.context);
|
|
126
28
|
this._mimeTypeService = options.mimeTypeService;
|
|
127
|
-
const editorWidget = (this.
|
|
29
|
+
const editorWidget = (this._editorWidget = new CodeEditorWrapper({
|
|
30
|
+
factory: options.factory,
|
|
31
|
+
model: context.model,
|
|
32
|
+
editorOptions: {
|
|
33
|
+
config: FileEditor.defaultEditorConfig
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
this._editorWidget.addClass('jp-FileEditorCodeWrapper');
|
|
37
|
+
this._editorWidget.node.dataset[CODE_RUNNER] = 'true';
|
|
38
|
+
this._editorWidget.node.dataset[UNDOER] = 'true';
|
|
128
39
|
this.editor = editorWidget.editor;
|
|
129
40
|
this.model = editorWidget.model;
|
|
41
|
+
void context.ready.then(() => {
|
|
42
|
+
this._onContextReady();
|
|
43
|
+
});
|
|
130
44
|
// Listen for changes to the path.
|
|
131
|
-
context.pathChanged.connect(this._onPathChanged, this);
|
|
132
45
|
this._onPathChanged();
|
|
46
|
+
context.pathChanged.connect(this._onPathChanged, this);
|
|
133
47
|
const layout = (this.layout = new StackedLayout());
|
|
134
48
|
layout.addWidget(editorWidget);
|
|
135
49
|
}
|
|
@@ -137,13 +51,13 @@ export class FileEditor extends Widget {
|
|
|
137
51
|
* Get the context for the editor widget.
|
|
138
52
|
*/
|
|
139
53
|
get context() {
|
|
140
|
-
return this.
|
|
54
|
+
return this._context;
|
|
141
55
|
}
|
|
142
56
|
/**
|
|
143
57
|
* A promise that resolves when the file editor is ready.
|
|
144
58
|
*/
|
|
145
59
|
get ready() {
|
|
146
|
-
return this.
|
|
60
|
+
return this._ready.promise;
|
|
147
61
|
}
|
|
148
62
|
/**
|
|
149
63
|
* Handle the DOM events for the widget.
|
|
@@ -196,15 +110,40 @@ export class FileEditor extends Widget {
|
|
|
196
110
|
this.editor.focus();
|
|
197
111
|
}
|
|
198
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Handle actions that should be taken when the context is ready.
|
|
115
|
+
*/
|
|
116
|
+
_onContextReady() {
|
|
117
|
+
if (this.isDisposed) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// Prevent the initial loading from disk from being in the editor history.
|
|
121
|
+
this.editor.clearHistory();
|
|
122
|
+
// Resolve the ready promise.
|
|
123
|
+
this._ready.resolve(undefined);
|
|
124
|
+
}
|
|
199
125
|
/**
|
|
200
126
|
* Handle a change to the path.
|
|
201
127
|
*/
|
|
202
128
|
_onPathChanged() {
|
|
203
129
|
const editor = this.editor;
|
|
204
130
|
const localPath = this._context.localPath;
|
|
205
|
-
editor.model.mimeType =
|
|
131
|
+
editor.model.mimeType =
|
|
132
|
+
this._mimeTypeService.getMimeTypeByFilePath(localPath);
|
|
206
133
|
}
|
|
207
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* The namespace for editor widget statics.
|
|
137
|
+
*/
|
|
138
|
+
(function (FileEditor) {
|
|
139
|
+
/**
|
|
140
|
+
* File editor default configuration.
|
|
141
|
+
*/
|
|
142
|
+
FileEditor.defaultEditorConfig = {
|
|
143
|
+
lineNumbers: true,
|
|
144
|
+
scrollPastEnd: true
|
|
145
|
+
};
|
|
146
|
+
})(FileEditor || (FileEditor = {}));
|
|
208
147
|
/**
|
|
209
148
|
* A widget factory for editors.
|
|
210
149
|
*/
|
|
@@ -222,6 +161,7 @@ export class FileEditorFactory extends ABCWidgetFactory {
|
|
|
222
161
|
createNewWidget(context) {
|
|
223
162
|
const func = this._services.factoryService.newDocumentEditor;
|
|
224
163
|
const factory = options => {
|
|
164
|
+
// Use same id as document factory
|
|
225
165
|
return func(options);
|
|
226
166
|
};
|
|
227
167
|
const content = new FileEditor({
|
package/lib/widget.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,
|
|
1
|
+
{"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAEL,iBAAiB,EAGlB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,gBAAgB,EAEhB,cAAc,EAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,GAAG,cAAc,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,MAAM;IACpC;;OAEG;IACH,YAAY,OAA4B;QACtC,KAAK,EAAE,CAAC;QAoIF,WAAM,GAAG,I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|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.20",
|
|
4
4
|
"description": "JupyterLab - Editor Widget",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -23,11 +23,10 @@
|
|
|
23
23
|
"lib": "lib/"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
|
-
"lib
|
|
27
|
-
"lib/*.js.map",
|
|
28
|
-
"lib/*.js",
|
|
26
|
+
"lib/**/*.{d.ts,js,js.map}",
|
|
29
27
|
"style/*.css",
|
|
30
|
-
"style/index.js"
|
|
28
|
+
"style/index.js",
|
|
29
|
+
"src/**/*.{ts,tsx}"
|
|
31
30
|
],
|
|
32
31
|
"scripts": {
|
|
33
32
|
"build": "tsc -b",
|
|
@@ -41,25 +40,30 @@
|
|
|
41
40
|
"watch": "tsc -b --watch"
|
|
42
41
|
},
|
|
43
42
|
"dependencies": {
|
|
44
|
-
"@jupyterlab/apputils": "^4.0.0-alpha.
|
|
45
|
-
"@jupyterlab/codeeditor": "^4.0.0-alpha.
|
|
46
|
-
"@jupyterlab/
|
|
47
|
-
"@jupyterlab/
|
|
48
|
-
"@jupyterlab/
|
|
49
|
-
"@jupyterlab/
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
43
|
+
"@jupyterlab/apputils": "^4.0.0-alpha.20",
|
|
44
|
+
"@jupyterlab/codeeditor": "^4.0.0-alpha.20",
|
|
45
|
+
"@jupyterlab/codemirror": "^4.0.0-alpha.20",
|
|
46
|
+
"@jupyterlab/coreutils": "^6.0.0-alpha.20",
|
|
47
|
+
"@jupyterlab/docregistry": "^4.0.0-alpha.20",
|
|
48
|
+
"@jupyterlab/documentsearch": "^4.0.0-alpha.20",
|
|
49
|
+
"@jupyterlab/lsp": "^4.0.0-alpha.20",
|
|
50
|
+
"@jupyterlab/statusbar": "^4.0.0-alpha.20",
|
|
51
|
+
"@jupyterlab/toc": "^6.0.0-alpha.20",
|
|
52
|
+
"@jupyterlab/translation": "^4.0.0-alpha.20",
|
|
53
|
+
"@jupyterlab/ui-components": "^4.0.0-alpha.35",
|
|
54
|
+
"@lumino/commands": "^2.0.0-rc.0",
|
|
55
|
+
"@lumino/coreutils": "^2.0.0-rc.0",
|
|
56
|
+
"@lumino/messaging": "^2.0.0-rc.0",
|
|
57
|
+
"@lumino/widgets": "^2.0.0-rc.0",
|
|
58
|
+
"react": "^18.2.0",
|
|
59
|
+
"regexp-match-indices": "^1.0.2"
|
|
54
60
|
},
|
|
55
61
|
"devDependencies": {
|
|
56
|
-
"@jupyterlab/
|
|
57
|
-
"@types/jest": "^
|
|
58
|
-
"jest": "^26.4.2",
|
|
62
|
+
"@jupyterlab/testing": "^4.0.0-alpha.20",
|
|
63
|
+
"@types/jest": "^29.2.0",
|
|
59
64
|
"rimraf": "~3.0.0",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"typescript": "~4.5.2"
|
|
65
|
+
"typedoc": "~0.23.25",
|
|
66
|
+
"typescript": "~5.0.0-beta"
|
|
63
67
|
},
|
|
64
68
|
"publishConfig": {
|
|
65
69
|
"access": "public"
|