@jupyterlab/codemirror 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 (78) hide show
  1. package/lib/codemirror-ipythongfm.d.ts +9 -3
  2. package/lib/codemirror-ipythongfm.js +52 -30
  3. package/lib/codemirror-ipythongfm.js.map +1 -1
  4. package/lib/commands.d.ts +13 -0
  5. package/lib/commands.js +32 -0
  6. package/lib/commands.js.map +1 -0
  7. package/lib/editor.d.ts +48 -279
  8. package/lib/editor.js +220 -818
  9. package/lib/editor.js.map +1 -1
  10. package/lib/extension.d.ts +236 -0
  11. package/lib/extension.js +687 -0
  12. package/lib/extension.js.map +1 -0
  13. package/lib/extensions/customStyle.d.ts +25 -0
  14. package/lib/extensions/customStyle.js +51 -0
  15. package/lib/extensions/customStyle.js.map +1 -0
  16. package/lib/extensions/index.d.ts +3 -0
  17. package/lib/extensions/index.js +8 -0
  18. package/lib/extensions/index.js.map +1 -0
  19. package/lib/extensions/rulers.d.ts +8 -0
  20. package/lib/extensions/rulers.js +85 -0
  21. package/lib/extensions/rulers.js.map +1 -0
  22. package/lib/extensions/ybinding.d.ts +125 -0
  23. package/lib/extensions/ybinding.js +213 -0
  24. package/lib/extensions/ybinding.js.map +1 -0
  25. package/lib/factory.d.ts +15 -5
  26. package/lib/factory.js +53 -24
  27. package/lib/factory.js.map +1 -1
  28. package/lib/index.d.ts +7 -19
  29. package/lib/index.js +7 -23
  30. package/lib/index.js.map +1 -1
  31. package/lib/language.d.ts +96 -0
  32. package/lib/language.js +1690 -0
  33. package/lib/language.js.map +1 -0
  34. package/lib/mimetype.d.ts +3 -0
  35. package/lib/mimetype.js +16 -5
  36. package/lib/mimetype.js.map +1 -1
  37. package/lib/searchprovider.d.ts +197 -0
  38. package/lib/searchprovider.js +550 -0
  39. package/lib/searchprovider.js.map +1 -0
  40. package/lib/theme.d.ts +57 -0
  41. package/lib/theme.js +194 -0
  42. package/lib/theme.js.map +1 -0
  43. package/lib/token.d.ts +375 -0
  44. package/lib/token.js +18 -0
  45. package/lib/token.js.map +1 -0
  46. package/package.json +45 -41
  47. package/src/codemirror-ipythongfm.ts +109 -0
  48. package/src/commands.ts +34 -0
  49. package/src/editor.ts +783 -0
  50. package/src/extension.ts +878 -0
  51. package/src/extensions/customStyle.ts +79 -0
  52. package/src/extensions/index.ts +8 -0
  53. package/src/extensions/rulers.ts +112 -0
  54. package/src/extensions/ybinding.ts +267 -0
  55. package/src/factory.ts +100 -0
  56. package/src/index.ts +17 -0
  57. package/src/language.ts +1729 -0
  58. package/src/mimetype.ts +54 -0
  59. package/src/searchprovider.ts +700 -0
  60. package/src/theme.ts +219 -0
  61. package/src/token.ts +436 -0
  62. package/src/typings.d.ts +13 -0
  63. package/style/base.css +22 -162
  64. package/style/index.css +1 -7
  65. package/style/index.js +1 -7
  66. package/lib/codemirror-ipython.d.ts +0 -2
  67. package/lib/codemirror-ipython.js +0 -30
  68. package/lib/codemirror-ipython.js.map +0 -1
  69. package/lib/mode.d.ts +0 -81
  70. package/lib/mode.js +0 -149
  71. package/lib/mode.js.map +0 -1
  72. package/lib/syntaxstatus.d.ts +0 -67
  73. package/lib/syntaxstatus.js +0 -140
  74. package/lib/syntaxstatus.js.map +0 -1
  75. package/lib/tokens.d.ts +0 -18
  76. package/lib/tokens.js +0 -9
  77. package/lib/tokens.js.map +0 -1
  78. package/typings/codemirror/codemirror.d.ts +0 -227
package/lib/theme.js ADDED
@@ -0,0 +1,194 @@
1
+ // Copyright (c) Jupyter Development Team.
2
+ // Distributed under the terms of the Modified BSD License.
3
+ import { defaultHighlightStyle, HighlightStyle, syntaxHighlighting } from '@codemirror/language';
4
+ import { EditorView } from '@codemirror/view';
5
+ import { nullTranslator } from '@jupyterlab/translation';
6
+ import { tags as t } from '@lezer/highlight';
7
+ export const jupyterEditorTheme = EditorView.theme({
8
+ /**
9
+ * CodeMirror themes are handling the background/color in this way. This works
10
+ * fine for CodeMirror editors outside the notebook, but the notebook styles
11
+ * these things differently.
12
+ */
13
+ '&': {
14
+ background: 'var(--jp-layout-color0)',
15
+ color: 'var(--jp-content-font-color1)'
16
+ },
17
+ /* In the notebook, we want this styling to be handled by its container */
18
+ '.jp-CodeConsole &, .jp-Notebook &': {
19
+ background: 'transparent'
20
+ },
21
+ '.cm-content': {
22
+ caretColor: 'var(--jp-editor-cursor-color)'
23
+ },
24
+ '.cm-cursor, .cm-dropCursor': {
25
+ borderLeft: 'var(--jp-code-cursor-width0) solid var(--jp-editor-cursor-color)'
26
+ },
27
+ '.cm-selectionBackground, .cm-content ::selection': {
28
+ backgroundColor: 'var(--jp-editor-selected-background)'
29
+ },
30
+ '&.cm-focused .cm-selectionBackground': {
31
+ backgroundColor: 'var(--jp-editor-selected-focused-background)'
32
+ },
33
+ '.cm-gutters': {
34
+ borderRight: '1px solid var(--jp-border-color2)',
35
+ backgroundColor: 'var(--jp-layout-color2)'
36
+ },
37
+ '.cm-gutter, .cm-activeLine': {
38
+ backgroundColor: 'var(--jp-layout-color2)'
39
+ },
40
+ '.cm-searchMatch': {
41
+ backgroundColor: 'var(--jp-search-unselected-match-background-color)',
42
+ color: 'var(--jp-search-unselected-match-color)'
43
+ },
44
+ '.cm-searchMatch.cm-searchMatch-selected': {
45
+ backgroundColor: 'var(--jp-search-selected-match-background-color) !important',
46
+ color: 'var(--jp-search-selected-match-color) !important'
47
+ }
48
+ });
49
+ // The list of available tags for syntax highlighting is available at
50
+ // https://lezer.codemirror.net/docs/ref/#highlight.tags
51
+ export const jupyterHighlightStyle = HighlightStyle.define([
52
+ // Order matters - a rule will override the previous ones; important for example for in headings styles.
53
+ { tag: t.meta, color: 'var(--jp-mirror-editor-meta-color)' },
54
+ { tag: t.heading, color: 'var(--jp-mirror-editor-header-color)' },
55
+ {
56
+ tag: [t.heading1, t.heading2, t.heading3, t.heading4],
57
+ color: 'var(--jp-mirror-editor-header-color)',
58
+ fontWeight: 'bold'
59
+ },
60
+ {
61
+ tag: t.keyword,
62
+ color: 'var(--jp-mirror-editor-keyword-color)',
63
+ fontWeight: 'bold'
64
+ },
65
+ { tag: t.atom, color: 'var(--jp-mirror-editor-atom-color)' },
66
+ { tag: t.number, color: 'var(--jp-mirror-editor-number-color)' },
67
+ {
68
+ tag: [t.definition(t.name), t.function(t.definition(t.variableName))],
69
+ color: 'var(--jp-mirror-editor-def-color)'
70
+ },
71
+ {
72
+ tag: t.standard(t.variableName),
73
+ color: 'var(--jp-mirror-editor-builtin-color)'
74
+ },
75
+ {
76
+ tag: [t.special(t.variableName), t.self],
77
+ color: 'var(--jp-mirror-editor-variable-2-color)'
78
+ },
79
+ { tag: t.punctuation, color: 'var(--jp-mirror-editor-punctuation-color)' },
80
+ { tag: t.propertyName, color: 'var(--jp-mirror-editor-property-color)' },
81
+ {
82
+ tag: t.operator,
83
+ color: 'var(--jp-mirror-editor-operator-color)',
84
+ fontWeight: 'bold'
85
+ },
86
+ {
87
+ tag: t.comment,
88
+ color: 'var(--jp-mirror-editor-comment-color)',
89
+ fontStyle: 'italic'
90
+ },
91
+ { tag: t.string, color: 'var(--jp-mirror-editor-string-color)' },
92
+ {
93
+ tag: [t.labelName, t.monospace, t.special(t.string)],
94
+ color: 'var(--jp-mirror-editor-string-2-color)'
95
+ },
96
+ { tag: t.bracket, color: 'var(--jp-mirror-editor-bracket-color)' },
97
+ { tag: t.tagName, color: 'var(--jp-mirror-editor-tag-color)' },
98
+ { tag: t.attributeName, color: 'var(--jp-mirror-editor-attribute-color)' },
99
+ { tag: t.quote, color: 'var(--jp-mirror-editor-quote-color)' },
100
+ {
101
+ tag: t.link,
102
+ color: 'var(--jp-mirror-editor-link-color)',
103
+ textDecoration: 'underline'
104
+ },
105
+ { tag: [t.separator, t.derefOperator, t.paren], color: '' },
106
+ { tag: t.strong, fontWeight: 'bold' },
107
+ { tag: t.emphasis, fontStyle: 'italic' },
108
+ { tag: t.strikethrough, textDecoration: 'line-through' }
109
+ ]);
110
+ /**
111
+ * JupyterLab CodeMirror 6 theme
112
+ */
113
+ export const jupyterTheme = [
114
+ jupyterEditorTheme,
115
+ syntaxHighlighting(jupyterHighlightStyle)
116
+ ];
117
+ /**
118
+ * CodeMirror 6 theme registry
119
+ */
120
+ export class EditorThemeRegistry {
121
+ constructor() {
122
+ /**
123
+ * CodeMirror 6 themes
124
+ */
125
+ this._themeMap = new Map([
126
+ ['jupyter', Object.freeze({ name: 'jupyter', theme: jupyterTheme })]
127
+ ]);
128
+ }
129
+ /**
130
+ * Get all themes
131
+ */
132
+ get themes() {
133
+ return Array.from(this._themeMap.values());
134
+ }
135
+ /**
136
+ * Get the default CodeMirror 6 theme for JupyterLab
137
+ *
138
+ * @returns Default theme
139
+ */
140
+ defaultTheme() {
141
+ return this._themeMap.get('jupyter').theme;
142
+ }
143
+ /**
144
+ * Register a new theme.
145
+ *
146
+ * @param theme Codemirror 6 theme
147
+ */
148
+ addTheme(theme) {
149
+ if (this._themeMap.has(theme.name)) {
150
+ throw new Error(`A theme named '${theme.name}' is already registered.`);
151
+ }
152
+ this._themeMap.set(theme.name, { displayName: theme.name, ...theme });
153
+ }
154
+ /**
155
+ * Get a theme.
156
+ *
157
+ * #### Notes
158
+ * It falls back to the default theme
159
+ *
160
+ * @param name Theme name
161
+ * @returns Theme extension
162
+ */
163
+ getTheme(name) {
164
+ var _a;
165
+ const ext = (_a = this._themeMap.get(name)) === null || _a === void 0 ? void 0 : _a.theme;
166
+ return ext !== null && ext !== void 0 ? ext : this.defaultTheme();
167
+ }
168
+ }
169
+ /**
170
+ * EditorThemeRegistry namespace
171
+ */
172
+ (function (EditorThemeRegistry) {
173
+ /**
174
+ * Get the default editor themes.
175
+ *
176
+ * @param translator Application translator
177
+ * @returns Default CodeMirror 6 themes
178
+ */
179
+ function getDefaultThemes(translator) {
180
+ const trans = (translator !== null && translator !== void 0 ? translator : nullTranslator).load('jupyterlab');
181
+ return [
182
+ Object.freeze({
183
+ name: 'codemirror',
184
+ displayName: trans.__('codemirror'),
185
+ theme: [
186
+ EditorView.baseTheme({}),
187
+ syntaxHighlighting(defaultHighlightStyle)
188
+ ]
189
+ })
190
+ ];
191
+ }
192
+ EditorThemeRegistry.getDefaultThemes = getDefaultThemes;
193
+ })(EditorThemeRegistry || (EditorThemeRegistry = {}));
194
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAe,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAG7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC,KAAK,CAAC;IACjD;;;;OAIG;IACH,GAAG,EAAE;QACH,UAAU,EAAE,yBAAyB;QACrC,KAAK,EAAE,+BAA+B;KACvC;IAED,0EAA0E;IAC1E,mCAAmC,EAAE;QACnC,UAAU,EAAE,aAAa;KAC1B;IAED,aAAa,EAAE;QACb,UAAU,EAAE,+BAA+B;KAC5C;IAED,4BAA4B,EAAE;QAC5B,UAAU,EACR,kEAAkE;KACrE;IAED,kDAAkD,EAAE;QAClD,eAAe,EAAE,sCAAsC;KACxD;IAED,sCAAsC,EAAE;QACtC,eAAe,EAAE,8CAA8C;KAChE;IAED,aAAa,EAAE;QACb,WAAW,EAAE,mCAAmC;QAChD,eAAe,EAAE,yBAAyB;KAC3C;IAED,4BAA4B,EAAE;QAC5B,eAAe,EAAE,yBAAyB;KAC3C;IAED,iBAAiB,EAAE;QACjB,eAAe,EAAE,oDAAoD;QACrE,KAAK,EAAE,yCAAyC;KACjD;IAED,yCAAyC,EAAE;QACzC,eAAe,EACb,6DAA6D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AE,CAAC;IACpC,CAAC;CACF;AAED;;GAEG;AACH,WAAiB,mBAAmB;IAClC;;;;;OAKG;IACH,SAAgB,gBAAgB,CAC9B,UAA+B;QAE/B,MAAM,KAAK,GAAG,CAAC,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,cAAc,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChE,OAAO;YACL,MAAM,CAAC,MAAM,CAAC;gBACZ,IAAI,EAAE,YAAY;gBAClB,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC;gBACnC,KAAK,EAAE;oBACL,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;oBACxB,kBAAkB,CAAC,qBAAqB,CAAC;iBAC1C;aACF,CAAC;SACH,CAAC;IACJ,CAAC;IAde,oCAAgB,mBAc/B,CAAA;AACH,CAAC,EAtBgB,mBAAmB,KAAnB,mBAAmB,QAsBnC"}
package/lib/token.d.ts ADDED
@@ -0,0 +1,375 @@
1
+ import type { LanguageSupport } from '@codemirror/language';
2
+ import type { Extension, StateEffect } from '@codemirror/state';
3
+ import type { EditorView } from '@codemirror/view';
4
+ import type { CodeEditor } from '@jupyterlab/codeeditor';
5
+ import type { ITranslator } from '@jupyterlab/translation';
6
+ import { ReadonlyJSONObject, Token } from '@lumino/coreutils';
7
+ import type { IDisposable } from '@lumino/disposable';
8
+ import type { ISignal } from '@lumino/signaling';
9
+ /**
10
+ * Dynamically configurable editor extension interface.
11
+ */
12
+ export interface IConfigurableExtension<T> {
13
+ /**
14
+ * Create an editor extension for the provided value.
15
+ *
16
+ * @param value Editor extension parameter value
17
+ * @returns The editor extension
18
+ */
19
+ instance(value: T): Extension;
20
+ /**
21
+ * Reconfigure an editor extension.
22
+ *
23
+ * ### Notes
24
+ * Return `null` if the value does not trigger
25
+ * a state effect. In particular for immutable extension.
26
+ *
27
+ * @param value Editor extension value
28
+ * @returns Editor state effect
29
+ */
30
+ reconfigure(value: T): StateEffect<T> | null;
31
+ }
32
+ /**
33
+ * Editor language token.
34
+ */
35
+ export declare const IEditorExtensionRegistry: Token<IEditorExtensionRegistry>;
36
+ /**
37
+ * Interface of CodeMirror editor extensions handler
38
+ *
39
+ * ### Notes
40
+ * This handler is instantiated for each editor to manage its own
41
+ * set of extensions.
42
+ */
43
+ export interface IExtensionsHandler extends IDisposable {
44
+ /**
45
+ * Signal triggered when the editor configuration changes.
46
+ * It provides the mapping of the new configuration (only those that changed).
47
+ *
48
+ * It should result in a call to `IExtensionsHandler.reconfigureExtensions`.
49
+ */
50
+ readonly configChanged: ISignal<this, Record<string, any>>;
51
+ /**
52
+ * Get a config option for the editor.
53
+ */
54
+ getOption(option: string): unknown;
55
+ /**
56
+ * Whether the option exists or not.
57
+ */
58
+ hasOption(option: string): boolean;
59
+ /**
60
+ * Set a config option for the editor.
61
+ *
62
+ * You will need to reconfigure the editor extensions by listening
63
+ * to `IExtensionsHandler.configChanged`.
64
+ */
65
+ setOption(option: string, value: unknown): void;
66
+ /**
67
+ * Set config options for the editor.
68
+ *
69
+ * You will need to reconfigure the editor extensions by listening
70
+ * to `IExtensionsHandler.configChanged`.
71
+ *
72
+ * This method is preferred when setting several options. The
73
+ * options are set within an operation, which only performs
74
+ * the costly update at the end, and not after every option
75
+ * is set.
76
+ */
77
+ setOptions(options: Record<string, any>): void;
78
+ /**
79
+ * Returns the list of initial extensions of an editor.
80
+ *
81
+ * @returns The initial editor extensions
82
+ */
83
+ getInitialExtensions(): Extension[];
84
+ /**
85
+ * Appends extensions to the top-level configuration of the
86
+ * editor.
87
+ *
88
+ * @alpha
89
+ * @param view Editor view
90
+ * @param extension Editor extension to inject
91
+ */
92
+ injectExtension(view: EditorView, extension: Extension): void;
93
+ /**
94
+ * Reconfigures the extension mapped with key with the provided value.
95
+ *
96
+ * @param view Editor view
97
+ * @param key Parameter unique key
98
+ * @param value Parameter value to be applied
99
+ */
100
+ reconfigureExtension<T>(view: EditorView, key: string, value: T): void;
101
+ /**
102
+ * Reconfigures all the extensions mapped with the options from the
103
+ * provided partial configuration.
104
+ *
105
+ * @param view Editor view
106
+ * @param configuration Editor configuration
107
+ */
108
+ reconfigureExtensions(view: EditorView, configuration: Record<string, any>): void;
109
+ }
110
+ /**
111
+ * Editor extension factory interface.
112
+ *
113
+ * @template T Extension parameter type.
114
+ */
115
+ export interface IEditorExtensionFactory<T = undefined> {
116
+ /**
117
+ * Editor extension unique identifier.
118
+ */
119
+ readonly name: string;
120
+ /**
121
+ * Extension factory.
122
+ *
123
+ * @param options
124
+ * @returns The extension builder or null if the extension is not active for that document
125
+ */
126
+ readonly factory: (options: IEditorExtensionFactory.IOptions) => IConfigurableExtension<T> | null;
127
+ /**
128
+ * Extension default value
129
+ *
130
+ * ### Notes
131
+ * If undefined but has a schema, the default value will be `null` to be JSON serializable.
132
+ */
133
+ readonly default?: T;
134
+ /**
135
+ * JSON schema defining the configurable option through user settings.
136
+ *
137
+ * If this is defined, every time the setting changes, `IConfigurableExtension.reconfigure`
138
+ * will be called with the new setting value.
139
+ *
140
+ * ### Notes
141
+ * If no default value is provided, `IEditorExtensionFactory.default` will be used.
142
+ * If the extension is to be handled by the code only, this should not be defined.
143
+ */
144
+ readonly schema?: ReadonlyJSONObject;
145
+ }
146
+ /**
147
+ * CodeMirror extension factory namespace
148
+ */
149
+ export declare namespace IEditorExtensionFactory {
150
+ /**
151
+ * CodeMirror extension factory options
152
+ */
153
+ interface IOptions {
154
+ /**
155
+ * Whether the editor will be inline or not.
156
+ */
157
+ inline: boolean;
158
+ /**
159
+ * The model used by the editor.
160
+ */
161
+ model: CodeEditor.IModel;
162
+ }
163
+ }
164
+ /**
165
+ * Interface for generating editor configuration registry.
166
+ */
167
+ export interface IEditorExtensionRegistry {
168
+ /**
169
+ * Base editor configuration
170
+ *
171
+ * This is the default configuration.
172
+ */
173
+ readonly baseConfiguration: Record<string, any>;
174
+ /**
175
+ * Add a default editor extension
176
+ *
177
+ * @template T Extension parameter type
178
+ * @param factory Extension factory
179
+ */
180
+ addExtension<T>(factory: IEditorExtensionFactory<T>): void;
181
+ /**
182
+ * Create a new extensions handler for an editor
183
+ *
184
+ * @param options Extensions options and initial editor configuration
185
+ */
186
+ createNew(options: IEditorExtensionFactory.IOptions & {
187
+ /**
188
+ * The configuration options for the editor.
189
+ */
190
+ config?: Record<string, any>;
191
+ }): IExtensionsHandler;
192
+ }
193
+ /**
194
+ * Editor factory constructor options
195
+ */
196
+ export interface IEditorFactoryOptions {
197
+ /**
198
+ * Editor extensions registry
199
+ */
200
+ extensions?: IEditorExtensionRegistry;
201
+ /**
202
+ * Editor languages registry
203
+ */
204
+ languages?: IEditorLanguageRegistry;
205
+ /**
206
+ * Application translation registry
207
+ */
208
+ translator?: ITranslator;
209
+ }
210
+ /**
211
+ * Editor language token.
212
+ */
213
+ export declare const IEditorLanguageRegistry: Token<IEditorLanguageRegistry>;
214
+ /**
215
+ * The interface of a codemirror language specification.
216
+ */
217
+ export interface IEditorLanguage {
218
+ /**
219
+ * Language name.
220
+ */
221
+ readonly name: string;
222
+ /**
223
+ * Language displayed name.
224
+ */
225
+ readonly displayName?: string;
226
+ /**
227
+ * Language name alias.
228
+ */
229
+ readonly alias?: readonly string[];
230
+ /**
231
+ * Language mime types.
232
+ */
233
+ readonly mime: string | readonly string[];
234
+ /**
235
+ * Language support loader.
236
+ */
237
+ readonly load?: () => Promise<LanguageSupport>;
238
+ /**
239
+ * Supported file extensions.
240
+ */
241
+ readonly extensions?: readonly string[];
242
+ /**
243
+ * Filename expression supported by the language.
244
+ */
245
+ readonly filename?: RegExp;
246
+ /**
247
+ * CodeMirror language support.
248
+ *
249
+ * ### Notes
250
+ * It can provided directly or it will be obtained using `load`.
251
+ */
252
+ support?: LanguageSupport;
253
+ }
254
+ /**
255
+ * Editor language interface
256
+ */
257
+ export interface IEditorLanguageRegistry {
258
+ /**
259
+ * Register a new language for CodeMirror
260
+ *
261
+ * @param language Language to register
262
+ */
263
+ addLanguage(language: IEditorLanguage): void;
264
+ /**
265
+ * Find a codemirror language by name or CodeMirror spec.
266
+ *
267
+ * @param language The CodeMirror language
268
+ * @param fallback Whether to fallback to default mimetype spec or not
269
+ * @returns The language or null
270
+ */
271
+ findBest(language: string | IEditorLanguage, fallback?: boolean): IEditorLanguage | null;
272
+ /**
273
+ * Find a codemirror language by MIME.
274
+ *
275
+ * @param mime Mime type to look for
276
+ * @returns The language or null
277
+ */
278
+ findByMIME(mime: string | readonly string[]): IEditorLanguage | null;
279
+ /**
280
+ * Find a codemirror language by name.
281
+ *
282
+ * @param name The language name
283
+ * @returns The language or null
284
+ */
285
+ findByName(name: string): IEditorLanguage | null;
286
+ /**
287
+ * Find a codemirror language by extension.
288
+ *
289
+ * @param ext The extension name
290
+ * @returns The language or null
291
+ */
292
+ findByExtension(ext: string | readonly string[]): IEditorLanguage | null;
293
+ /**
294
+ * Find a codemirror language by filename.
295
+ *
296
+ * @param name File name
297
+ * @returns The language or null
298
+ */
299
+ findByFileName(name: string): IEditorLanguage | null;
300
+ /**
301
+ * Load a CodeMirror language specified by name or Codemirror spec.
302
+ *
303
+ * @param language - The language to ensure. If it is a string, uses {@link findBest}
304
+ * to get the appropriate spec.
305
+ *
306
+ * @returns A promise that resolves when the language is available.
307
+ */
308
+ getLanguage(language: string | IEditorLanguage): Promise<IEditorLanguage | null>;
309
+ /**
310
+ * Get the raw list of available languages specs.
311
+ *
312
+ * @returns The available languages
313
+ */
314
+ getLanguages(): IEditorLanguage[];
315
+ /**
316
+ * Parse and style a string.
317
+ *
318
+ * @param code Code to highlight
319
+ * @param language Code language
320
+ * @param el HTML element into which the highlighted code will be inserted
321
+ */
322
+ highlight(code: string, language: IEditorLanguage | null, el: HTMLElement): Promise<void>;
323
+ }
324
+ /**
325
+ * Editor theme token.
326
+ */
327
+ export declare const IEditorThemeRegistry: Token<IEditorThemeRegistry>;
328
+ /**
329
+ * Editor theme interface
330
+ */
331
+ export interface IEditorTheme {
332
+ /**
333
+ * Theme unique identifier
334
+ */
335
+ readonly name: string;
336
+ /**
337
+ * Theme name
338
+ */
339
+ readonly displayName?: string;
340
+ /**
341
+ * Editor extension for the theme
342
+ */
343
+ readonly theme: Extension;
344
+ }
345
+ /**
346
+ * Theme editor registry interface
347
+ */
348
+ export interface IEditorThemeRegistry {
349
+ /**
350
+ * Register a new theme.
351
+ *
352
+ * @param theme Codemirror 6 theme
353
+ */
354
+ addTheme(theme: IEditorTheme): void;
355
+ /**
356
+ * Get the default CodeMirror 6 theme for JupyterLab
357
+ *
358
+ * @returns Default theme as a CodeMirror extension
359
+ */
360
+ defaultTheme(): Extension;
361
+ /**
362
+ * Get a theme.
363
+ *
364
+ * #### Notes
365
+ * It falls back to the default theme
366
+ *
367
+ * @param name Theme name
368
+ * @returns Theme extension
369
+ */
370
+ getTheme(name: string): Extension;
371
+ /**
372
+ * Get all themes
373
+ */
374
+ readonly themes: IEditorTheme[];
375
+ }
package/lib/token.js ADDED
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { Token } from '@lumino/coreutils';
6
+ /**
7
+ * Editor language token.
8
+ */
9
+ export const IEditorExtensionRegistry = new Token('@jupyterlab/codemirror:IEditorExtensionRegistry');
10
+ /**
11
+ * Editor language token.
12
+ */
13
+ export const IEditorLanguageRegistry = new Token('@jupyterlab/codemirror:IEditorLanguageRegistry');
14
+ /**
15
+ * Editor theme token.
16
+ */
17
+ export const IEditorThemeRegistry = new Token('@jupyterlab/codemirror:IEditorThemeRegistry');
18
+ //# sourceMappingURL=token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../src/token.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAsB,KAAK,EAAE,MAAM,mBAAmB,CAAC;AA4B9D;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,KAAK,CAC/C,iDAAiD,CAClD,CAAC;AAsMF;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,KAAK,CAC9C,gDAAgD,CACjD,CAAC;AAmIF;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,KAAK,CAC3C,6CAA6C,CAC9C,CAAC"}