@jupyterlab/fileeditor 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 (49) 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 +60 -0
  8. package/lib/searchprovider.js +80 -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/widget.d.ts +4 -0
  32. package/lib/widget.js +21 -4
  33. package/lib/widget.js.map +1 -1
  34. package/package.json +26 -21
  35. package/src/fileeditorlspadapter.ts +225 -0
  36. package/src/index.ts +14 -0
  37. package/src/searchprovider.ts +115 -0
  38. package/src/syntaxstatus.tsx +217 -0
  39. package/src/tabspacestatus.tsx +166 -0
  40. package/src/toc/factory.ts +72 -0
  41. package/src/toc/index.ts +7 -0
  42. package/src/toc/latex.ts +145 -0
  43. package/src/toc/markdown.ts +90 -0
  44. package/src/toc/python.ts +143 -0
  45. package/src/tokens.ts +20 -0
  46. package/src/widget.ts +267 -0
  47. package/style/base.css +8 -0
  48. package/style/index.css +4 -0
  49. package/style/index.js +4 -0
@@ -0,0 +1,96 @@
1
+ import { CodeMirrorEditor } from '@jupyterlab/codemirror';
2
+ import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
3
+ import { Document, IAdapterOptions, IVirtualPosition, VirtualDocument, WidgetLSPAdapter } from '@jupyterlab/lsp';
4
+ import { FileEditor } from './widget';
5
+ export interface IFileEditorAdapterOptions extends IAdapterOptions {
6
+ /**
7
+ * The document registry instance.
8
+ */
9
+ docRegistry: DocumentRegistry;
10
+ }
11
+ export declare class FileEditorAdapter extends WidgetLSPAdapter<IDocumentWidget<FileEditor>> {
12
+ constructor(editorWidget: IDocumentWidget<FileEditor>, options: IFileEditorAdapterOptions);
13
+ /**
14
+ * The wrapped `FileEditor` widget.
15
+ */
16
+ readonly editor: FileEditor;
17
+ /**
18
+ * Promise that resolves once the adapter is initialized
19
+ */
20
+ get ready(): Promise<void>;
21
+ /**
22
+ * Get current path of the document.
23
+ */
24
+ get documentPath(): string;
25
+ /**
26
+ * Get the mime type of the document.
27
+ */
28
+ get mimeType(): string;
29
+ /**
30
+ * Get the file extension of the document.
31
+ */
32
+ get languageFileExtension(): string;
33
+ /**
34
+ * Get the CM editor
35
+ */
36
+ get ceEditor(): CodeMirrorEditor;
37
+ /**
38
+ * Get the activated CM editor.
39
+ */
40
+ get activeEditor(): Document.IEditor;
41
+ /**
42
+ * Get the inner HTMLElement of the document widget.
43
+ */
44
+ get wrapperElement(): HTMLElement;
45
+ /**
46
+ * Get current path of the document.
47
+ */
48
+ get path(): string;
49
+ /**
50
+ * Get the list of CM editors in the document, there is only one editor
51
+ * in the case of file editor.
52
+ */
53
+ get editors(): Document.ICodeBlockOptions[];
54
+ /**
55
+ * Dispose the widget.
56
+ */
57
+ dispose(): void;
58
+ /**
59
+ * Generate the virtual document associated with the document.
60
+ */
61
+ createVirtualDocument(): VirtualDocument;
62
+ /**
63
+ * Get the index of editor from the cursor position in the virtual
64
+ * document. Since there is only one editor, this method always return
65
+ * 0
66
+ *
67
+ * @param position - the position of cursor in the virtual document.
68
+ * @return {number} - index of the virtual editor
69
+ */
70
+ getEditorIndexAt(position: IVirtualPosition): number;
71
+ /**
72
+ * Get the index of input editor
73
+ *
74
+ * @param ceEditor - instance of the code editor
75
+ */
76
+ getEditorIndex(ceEditor: Document.IEditor): number;
77
+ /**
78
+ * Get the wrapper of input editor.
79
+ *
80
+ * @param ceEditor
81
+ * @return {HTMLElement}
82
+ */
83
+ getEditorWrapper(ceEditor: Document.IEditor): HTMLElement;
84
+ /**
85
+ * Initialization function called once the editor and the LSP connection
86
+ * manager is ready. This function will create the virtual document and
87
+ * connect various signals.
88
+ */
89
+ protected initOnceReady(): Promise<void>;
90
+ /**
91
+ * The document registry instance.
92
+ */
93
+ private readonly _docRegistry;
94
+ private readonly _virtualEditor;
95
+ private _readyDelegate;
96
+ }
@@ -0,0 +1,175 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { VirtualDocument, WidgetLSPAdapter } from '@jupyterlab/lsp';
4
+ import { PromiseDelegate } from '@lumino/coreutils';
5
+ export class FileEditorAdapter extends WidgetLSPAdapter {
6
+ constructor(editorWidget, options) {
7
+ const { docRegistry, ...others } = options;
8
+ super(editorWidget, others);
9
+ this._readyDelegate = new PromiseDelegate();
10
+ this.editor = editorWidget.content;
11
+ this._docRegistry = docRegistry;
12
+ // Ensure editor uniqueness
13
+ this._virtualEditor = Object.freeze({
14
+ getEditor: () => this.editor.editor,
15
+ ready: () => Promise.resolve(this.editor.editor),
16
+ reveal: () => Promise.resolve(this.editor.editor)
17
+ });
18
+ Promise.all([this.editor.context.ready, this.connectionManager.ready])
19
+ .then(async () => {
20
+ await this.initOnceReady();
21
+ this._readyDelegate.resolve();
22
+ })
23
+ .catch(console.error);
24
+ }
25
+ /**
26
+ * Promise that resolves once the adapter is initialized
27
+ */
28
+ get ready() {
29
+ return this._readyDelegate.promise;
30
+ }
31
+ /**
32
+ * Get current path of the document.
33
+ */
34
+ get documentPath() {
35
+ return this.widget.context.path;
36
+ }
37
+ /**
38
+ * Get the mime type of the document.
39
+ */
40
+ get mimeType() {
41
+ var _a;
42
+ const mimeTypeFromModel = this.editor.model.mimeType;
43
+ const codeMirrorMimeType = Array.isArray(mimeTypeFromModel)
44
+ ? (_a = mimeTypeFromModel[0]) !== null && _a !== void 0 ? _a : 'text/plain'
45
+ : mimeTypeFromModel;
46
+ const contentsModel = this.editor.context.contentsModel;
47
+ // when MIME type is not known it defaults to 'text/plain',
48
+ // so if it is different we can accept it as it is
49
+ if (codeMirrorMimeType != 'text/plain') {
50
+ return codeMirrorMimeType;
51
+ }
52
+ else if (contentsModel) {
53
+ // a script that does not have a MIME type known by the editor
54
+ // (no syntax highlight mode), can still be known by the document
55
+ // registry (and this is arguably easier to extend).
56
+ let fileType = this._docRegistry.getFileTypeForModel(contentsModel);
57
+ return fileType.mimeTypes[0];
58
+ }
59
+ else {
60
+ // "text/plain" this is
61
+ return codeMirrorMimeType;
62
+ }
63
+ }
64
+ /**
65
+ * Get the file extension of the document.
66
+ */
67
+ get languageFileExtension() {
68
+ let parts = this.documentPath.split('.');
69
+ return parts[parts.length - 1];
70
+ }
71
+ /**
72
+ * Get the CM editor
73
+ */
74
+ get ceEditor() {
75
+ return this.editor.editor;
76
+ }
77
+ /**
78
+ * Get the activated CM editor.
79
+ */
80
+ get activeEditor() {
81
+ return this._virtualEditor;
82
+ }
83
+ /**
84
+ * Get the inner HTMLElement of the document widget.
85
+ */
86
+ get wrapperElement() {
87
+ return this.widget.node;
88
+ }
89
+ /**
90
+ * Get current path of the document.
91
+ */
92
+ get path() {
93
+ return this.widget.context.path;
94
+ }
95
+ /**
96
+ * Get the list of CM editors in the document, there is only one editor
97
+ * in the case of file editor.
98
+ */
99
+ get editors() {
100
+ var _a, _b;
101
+ return [
102
+ {
103
+ ceEditor: this._virtualEditor,
104
+ type: 'code',
105
+ value: (_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.model.sharedModel.getSource()) !== null && _b !== void 0 ? _b : ''
106
+ }
107
+ ];
108
+ }
109
+ /**
110
+ * Dispose the widget.
111
+ */
112
+ dispose() {
113
+ if (this.isDisposed) {
114
+ return;
115
+ }
116
+ this.editor.model.mimeTypeChanged.disconnect(this.reloadConnection);
117
+ super.dispose();
118
+ }
119
+ /**
120
+ * Generate the virtual document associated with the document.
121
+ */
122
+ createVirtualDocument() {
123
+ return new VirtualDocument({
124
+ language: this.language,
125
+ foreignCodeExtractors: this.options.foreignCodeExtractorsManager,
126
+ path: this.documentPath,
127
+ fileExtension: this.languageFileExtension,
128
+ // notebooks are continuous, each cell is dependent on the previous one
129
+ standalone: true,
130
+ // notebooks are not supported by LSP servers
131
+ hasLspSupportedFile: true
132
+ });
133
+ }
134
+ /**
135
+ * Get the index of editor from the cursor position in the virtual
136
+ * document. Since there is only one editor, this method always return
137
+ * 0
138
+ *
139
+ * @param position - the position of cursor in the virtual document.
140
+ * @return {number} - index of the virtual editor
141
+ */
142
+ getEditorIndexAt(position) {
143
+ return 0;
144
+ }
145
+ /**
146
+ * Get the index of input editor
147
+ *
148
+ * @param ceEditor - instance of the code editor
149
+ */
150
+ getEditorIndex(ceEditor) {
151
+ return 0;
152
+ }
153
+ /**
154
+ * Get the wrapper of input editor.
155
+ *
156
+ * @param ceEditor
157
+ * @return {HTMLElement}
158
+ */
159
+ getEditorWrapper(ceEditor) {
160
+ return this.wrapperElement;
161
+ }
162
+ /**
163
+ * Initialization function called once the editor and the LSP connection
164
+ * manager is ready. This function will create the virtual document and
165
+ * connect various signals.
166
+ */
167
+ async initOnceReady() {
168
+ this.initVirtual();
169
+ // connect the document, but do not open it as the adapter will handle this
170
+ // after registering all features
171
+ await this.connectDocument(this.virtualDocument, false);
172
+ this.editor.model.mimeTypeChanged.connect(this.reloadConnection, this);
173
+ }
174
+ }
175
+ //# sourceMappingURL=fileeditorlspadapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileeditorlspadapter.js","sourceRoot":"","sources":["../src/fileeditorlspadapter.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAI3D,OAAO,EAIL,eAAe,EACf,gBAAgB,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAWpD,MAAM,OAAO,iBAAkB,SAAQ,gBAEtC;IACC,YACE,YAAyC,EACzC,OAAkC;QAElC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC;QAC3C,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAgMtB,mBAAc,GAAG,IAAI,eAAe,EAAQ,CAAC;QA/LnD,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAEhC,2BAA2B;QAC3B,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;YAClC,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM;YACnC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YAChD,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;SAClD,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;aACnE,IAAI,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,IAAI,CA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AC;IACX,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,QAA0B;QACvC,OAAO,CAAC,CAAC;IACX,CAAC;IAED;;;;;OAKG;IACH,gBAAgB,CAAC,QAA0B;QACzC,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,aAAa;QAC3B,IAAI,CAAC,WAAW,EAAE,CAAC;QAEnB,2EAA2E;QAC3E,iCAAiC;QACjC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,eAAgB,EAAE,KAAK,CAAC,CAAC;QAEzD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;IACzE,CAAC;CAQF"}
package/lib/index.d.ts CHANGED
@@ -2,6 +2,10 @@
2
2
  * @packageDocumentation
3
3
  * @module fileeditor
4
4
  */
5
+ export * from './fileeditorlspadapter';
6
+ export * from './searchprovider';
7
+ export * from './syntaxstatus';
5
8
  export * from './tabspacestatus';
9
+ export * from './toc';
6
10
  export * from './tokens';
7
11
  export * from './widget';
package/lib/index.js CHANGED
@@ -4,7 +4,11 @@
4
4
  * @packageDocumentation
5
5
  * @module fileeditor
6
6
  */
7
+ export * from './fileeditorlspadapter';
8
+ export * from './searchprovider';
9
+ export * from './syntaxstatus';
7
10
  export * from './tabspacestatus';
11
+ export * from './toc';
8
12
  export * from './tokens';
9
13
  export * from './widget';
10
14
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAC3D;;;GAGG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { MainAreaWidget } from '@jupyterlab/apputils';
2
+ import { CodeMirrorEditor, EditorSearchProvider } from '@jupyterlab/codemirror';
3
+ import { CodeEditor } from '@jupyterlab/codeeditor';
4
+ import { IFilters, IReplaceOptionsSupport, ISearchProvider } from '@jupyterlab/documentsearch';
5
+ import { ITranslator } from '@jupyterlab/translation';
6
+ import { Widget } from '@lumino/widgets';
7
+ import { FileEditor } from './widget';
8
+ /**
9
+ * Helper type
10
+ */
11
+ export type FileEditorPanel = MainAreaWidget<FileEditor>;
12
+ /**
13
+ * File editor search provider
14
+ */
15
+ export declare class FileEditorSearchProvider extends EditorSearchProvider<CodeEditor.IModel> implements ISearchProvider {
16
+ protected widget: FileEditorPanel;
17
+ /**
18
+ * Constructor
19
+ * @param widget File editor panel
20
+ */
21
+ constructor(widget: FileEditorPanel);
22
+ get isReadOnly(): boolean;
23
+ /**
24
+ * Support for options adjusting replacement behavior.
25
+ */
26
+ get replaceOptionsSupport(): IReplaceOptionsSupport;
27
+ /**
28
+ * Text editor
29
+ */
30
+ get editor(): CodeMirrorEditor;
31
+ /**
32
+ * Editor content model
33
+ */
34
+ get model(): CodeEditor.IModel;
35
+ startQuery(query: RegExp, filters: IFilters | undefined): Promise<void>;
36
+ /**
37
+ * Instantiate a search provider for the widget.
38
+ *
39
+ * #### Notes
40
+ * The widget provided is always checked using `isApplicable` before calling
41
+ * this factory.
42
+ *
43
+ * @param widget The widget to search on
44
+ * @param translator [optional] The translator object
45
+ *
46
+ * @returns The search provider on the widget
47
+ */
48
+ static createNew(widget: FileEditorPanel, translator?: ITranslator): ISearchProvider;
49
+ /**
50
+ * Report whether or not this provider has the ability to search on the given object
51
+ */
52
+ static isApplicable(domain: Widget): domain is FileEditorPanel;
53
+ /**
54
+ * Get an initial query value if applicable so that it can be entered
55
+ * into the search box as an initial query
56
+ *
57
+ * @returns Initial value used to populate the search box.
58
+ */
59
+ getInitialQuery(): string;
60
+ }
@@ -0,0 +1,80 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { MainAreaWidget } from '@jupyterlab/apputils';
4
+ import { CodeMirrorEditor, EditorSearchProvider } from '@jupyterlab/codemirror';
5
+ import { FileEditor } from './widget';
6
+ /**
7
+ * File editor search provider
8
+ */
9
+ export class FileEditorSearchProvider extends EditorSearchProvider {
10
+ /**
11
+ * Constructor
12
+ * @param widget File editor panel
13
+ */
14
+ constructor(widget) {
15
+ super();
16
+ this.widget = widget;
17
+ }
18
+ get isReadOnly() {
19
+ return this.editor.getOption('readOnly');
20
+ }
21
+ /**
22
+ * Support for options adjusting replacement behavior.
23
+ */
24
+ get replaceOptionsSupport() {
25
+ return {
26
+ preserveCase: true
27
+ };
28
+ }
29
+ /**
30
+ * Text editor
31
+ */
32
+ get editor() {
33
+ return this.widget.content.editor;
34
+ }
35
+ /**
36
+ * Editor content model
37
+ */
38
+ get model() {
39
+ return this.widget.content.model;
40
+ }
41
+ async startQuery(query, filters) {
42
+ await super.startQuery(query, filters);
43
+ await this.highlightNext(false, true);
44
+ }
45
+ /**
46
+ * Instantiate a search provider for the widget.
47
+ *
48
+ * #### Notes
49
+ * The widget provided is always checked using `isApplicable` before calling
50
+ * this factory.
51
+ *
52
+ * @param widget The widget to search on
53
+ * @param translator [optional] The translator object
54
+ *
55
+ * @returns The search provider on the widget
56
+ */
57
+ static createNew(widget, translator) {
58
+ return new FileEditorSearchProvider(widget);
59
+ }
60
+ /**
61
+ * Report whether or not this provider has the ability to search on the given object
62
+ */
63
+ static isApplicable(domain) {
64
+ return (domain instanceof MainAreaWidget &&
65
+ domain.content instanceof FileEditor &&
66
+ domain.content.editor instanceof CodeMirrorEditor);
67
+ }
68
+ /**
69
+ * Get an initial query value if applicable so that it can be entered
70
+ * into the search box as an initial query
71
+ *
72
+ * @returns Initial value used to populate the search box.
73
+ */
74
+ getInitialQuery() {
75
+ const cm = this.editor;
76
+ const selection = cm.state.sliceDoc(cm.state.selection.main.from, cm.state.selection.main.to);
77
+ return selection;
78
+ }
79
+ }
80
+ //# sourceMappingURL=searchprovider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchprovider.js","sourceRoot":"","sources":["../src/searchprovider.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAShF,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAOtC;;GAEG;AACH,MAAM,OAAO,wBACX,SAAQ,oBAAuC;IAG/C;;;OAGG;IACH,YAAsB,MAAuB;QAC3C,KAAK,EAAE,CAAC;QADY,WAAM,GAAN,MAAM,CAAiB;IAE7C,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAY,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,IAAI,qBAAqB;QACvB,OAAO;YACL,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAA0B,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,UAAU,CACd,KAAa,EACb,OAA6B;QAE7B,MAAM,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACvC,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,SAAS,CACd,MAAuB,EACvB,UAAwB;QAExB,OAAO,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,MAAc;QAChC,OAAO,CACL,MAAM,YAAY,cAAc;YAChC,MAAM,CAAC,OAAO,YAAY,UAAU;YACpC,MAAM,CAAC,OAAO,CAAC,MAAM,YAAY,gBAAgB,CAClD,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,eAAe;QACb,MAAM,EAAE,GAAG,IAAI,CAAC,MAA0B,CAAC;QAC3C,MAAM,SAAS,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CACjC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAC5B,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAC3B,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,74 @@
1
+ import { CodeEditor } from '@jupyterlab/codeeditor';
2
+ import { IEditorLanguageRegistry } from '@jupyterlab/codemirror';
3
+ import { ITranslator } from '@jupyterlab/translation';
4
+ import { VDomModel, VDomRenderer } from '@jupyterlab/ui-components';
5
+ import { CommandRegistry } from '@lumino/commands';
6
+ /**
7
+ * StatusBar item to change the language syntax highlighting of the file editor.
8
+ */
9
+ export declare class EditorSyntaxStatus extends VDomRenderer<EditorSyntaxStatus.Model> {
10
+ /**
11
+ * Construct a new VDomRenderer for the status item.
12
+ */
13
+ constructor(options: EditorSyntaxStatus.IOptions);
14
+ /**
15
+ * Render the status item.
16
+ */
17
+ render(): JSX.Element | null;
18
+ /**
19
+ * Create a menu for selecting the language of the editor.
20
+ */
21
+ private _handleClick;
22
+ protected translator: ITranslator;
23
+ private _commands;
24
+ private _popup;
25
+ }
26
+ /**
27
+ * A namespace for EditorSyntax statics.
28
+ */
29
+ export declare namespace EditorSyntaxStatus {
30
+ /**
31
+ * A VDomModel for the current editor/mode combination.
32
+ */
33
+ class Model extends VDomModel {
34
+ languages: IEditorLanguageRegistry;
35
+ constructor(languages: IEditorLanguageRegistry);
36
+ /**
37
+ * The current editor language. If no editor is present,
38
+ * returns the empty string.
39
+ */
40
+ get language(): string;
41
+ /**
42
+ * The current editor for the application editor tracker.
43
+ */
44
+ get editor(): CodeEditor.IEditor | null;
45
+ set editor(editor: CodeEditor.IEditor | null);
46
+ /**
47
+ * If the editor mode changes, update the model.
48
+ */
49
+ private _onMIMETypeChange;
50
+ /**
51
+ * Trigger a rerender of the model.
52
+ */
53
+ private _triggerChange;
54
+ private _language;
55
+ private _editor;
56
+ }
57
+ /**
58
+ * Options for the EditorSyntax status item.
59
+ */
60
+ interface IOptions {
61
+ /**
62
+ * The application command registry.
63
+ */
64
+ commands: CommandRegistry;
65
+ /**
66
+ * Editor languages.
67
+ */
68
+ languages: IEditorLanguageRegistry;
69
+ /**
70
+ * The language translator.
71
+ */
72
+ translator?: ITranslator;
73
+ }
74
+ }
@@ -0,0 +1,151 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { IEditorMimeTypeService } from '@jupyterlab/codeeditor';
6
+ import { showPopup, TextItem } from '@jupyterlab/statusbar';
7
+ import { nullTranslator } from '@jupyterlab/translation';
8
+ import { VDomModel, VDomRenderer } from '@jupyterlab/ui-components';
9
+ import { Menu } from '@lumino/widgets';
10
+ import React from 'react';
11
+ /**
12
+ * A pure function that returns a tsx component for an editor syntax item.
13
+ *
14
+ * @param props: the props for the component.
15
+ *
16
+ * @returns an editor syntax component.
17
+ */
18
+ function EditorSyntaxComponent(props) {
19
+ return React.createElement(TextItem, { source: props.language, onClick: props.handleClick });
20
+ }
21
+ /**
22
+ * StatusBar item to change the language syntax highlighting of the file editor.
23
+ */
24
+ export class EditorSyntaxStatus extends VDomRenderer {
25
+ /**
26
+ * Construct a new VDomRenderer for the status item.
27
+ */
28
+ constructor(options) {
29
+ var _a;
30
+ super(new EditorSyntaxStatus.Model(options.languages));
31
+ /**
32
+ * Create a menu for selecting the language of the editor.
33
+ */
34
+ this._handleClick = () => {
35
+ const languageMenu = new Menu({ commands: this._commands });
36
+ const command = 'fileeditor:change-language';
37
+ if (this._popup) {
38
+ this._popup.dispose();
39
+ }
40
+ this.model.languages
41
+ .getLanguages()
42
+ .sort((a, b) => {
43
+ var _a, _b;
44
+ const aName = (_a = a.displayName) !== null && _a !== void 0 ? _a : a.name;
45
+ const bName = (_b = b.displayName) !== null && _b !== void 0 ? _b : b.name;
46
+ return aName.localeCompare(bName);
47
+ })
48
+ .forEach(spec => {
49
+ var _a;
50
+ if (spec.name.toLowerCase().indexOf('brainf') === 0) {
51
+ return;
52
+ }
53
+ const args = {
54
+ name: spec.name,
55
+ displayName: (_a = spec.displayName) !== null && _a !== void 0 ? _a : spec.name
56
+ };
57
+ languageMenu.addItem({
58
+ command,
59
+ args
60
+ });
61
+ });
62
+ this._popup = showPopup({
63
+ body: languageMenu,
64
+ anchor: this,
65
+ align: 'left'
66
+ });
67
+ };
68
+ this._popup = null;
69
+ this._commands = options.commands;
70
+ this.translator = (_a = options.translator) !== null && _a !== void 0 ? _a : nullTranslator;
71
+ const trans = this.translator.load('jupyterlab');
72
+ this.addClass('jp-mod-highlighted');
73
+ this.title.caption = trans.__('Change text editor syntax highlighting');
74
+ }
75
+ /**
76
+ * Render the status item.
77
+ */
78
+ render() {
79
+ if (!this.model) {
80
+ return null;
81
+ }
82
+ return (React.createElement(EditorSyntaxComponent, { language: this.model.language, handleClick: this._handleClick }));
83
+ }
84
+ }
85
+ /**
86
+ * A namespace for EditorSyntax statics.
87
+ */
88
+ (function (EditorSyntaxStatus) {
89
+ /**
90
+ * A VDomModel for the current editor/mode combination.
91
+ */
92
+ class Model extends VDomModel {
93
+ constructor(languages) {
94
+ super();
95
+ this.languages = languages;
96
+ /**
97
+ * If the editor mode changes, update the model.
98
+ */
99
+ this._onMIMETypeChange = (mode, change) => {
100
+ var _a;
101
+ const oldLanguage = this._language;
102
+ const spec = this.languages.findByMIME(change.newValue);
103
+ this._language = (_a = spec === null || spec === void 0 ? void 0 : spec.name) !== null && _a !== void 0 ? _a : IEditorMimeTypeService.defaultMimeType;
104
+ this._triggerChange(oldLanguage, this._language);
105
+ };
106
+ this._language = '';
107
+ this._editor = null;
108
+ }
109
+ /**
110
+ * The current editor language. If no editor is present,
111
+ * returns the empty string.
112
+ */
113
+ get language() {
114
+ return this._language;
115
+ }
116
+ /**
117
+ * The current editor for the application editor tracker.
118
+ */
119
+ get editor() {
120
+ return this._editor;
121
+ }
122
+ set editor(editor) {
123
+ var _a;
124
+ const oldEditor = this._editor;
125
+ if (oldEditor !== null) {
126
+ oldEditor.model.mimeTypeChanged.disconnect(this._onMIMETypeChange);
127
+ }
128
+ const oldLanguage = this._language;
129
+ this._editor = editor;
130
+ if (this._editor === null) {
131
+ this._language = '';
132
+ }
133
+ else {
134
+ const spec = this.languages.findByMIME(this._editor.model.mimeType);
135
+ this._language = (_a = spec === null || spec === void 0 ? void 0 : spec.name) !== null && _a !== void 0 ? _a : IEditorMimeTypeService.defaultMimeType;
136
+ this._editor.model.mimeTypeChanged.connect(this._onMIMETypeChange);
137
+ }
138
+ this._triggerChange(oldLanguage, this._language);
139
+ }
140
+ /**
141
+ * Trigger a rerender of the model.
142
+ */
143
+ _triggerChange(oldState, newState) {
144
+ if (oldState !== newState) {
145
+ this.stateChanged.emit(void 0);
146
+ }
147
+ }
148
+ }
149
+ EditorSyntaxStatus.Model = Model;
150
+ })(EditorSyntaxStatus || (EditorSyntaxStatus = {}));
151
+ //# sourceMappingURL=syntaxstatus.js.map