@jupyterlab/codemirror 4.6.0-alpha.2 → 4.6.0-alpha.4

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 (52) hide show
  1. package/lib/commands.d.ts +1 -1
  2. package/lib/editor.d.ts +6 -4
  3. package/lib/editor.js +0 -1
  4. package/lib/editor.js.map +1 -1
  5. package/lib/extension.d.ts +7 -6
  6. package/lib/extension.js.map +1 -1
  7. package/lib/extensions/customStyle.d.ts +1 -1
  8. package/lib/extensions/customStyle.js.map +1 -1
  9. package/lib/extensions/ipython-md.d.ts +2 -2
  10. package/lib/extensions/ipython-md.js.map +1 -1
  11. package/lib/extensions/rulers.d.ts +1 -1
  12. package/lib/extensions/rulers.js +0 -1
  13. package/lib/extensions/rulers.js.map +1 -1
  14. package/lib/extensions/ybinding.d.ts +4 -2
  15. package/lib/extensions/ybinding.js +0 -9
  16. package/lib/extensions/ybinding.js.map +1 -1
  17. package/lib/extensions/yundomanager.d.ts +2 -1
  18. package/lib/extensions/yundomanager.js +0 -16
  19. package/lib/extensions/yundomanager.js.map +1 -1
  20. package/lib/factory.d.ts +3 -3
  21. package/lib/factory.js.map +1 -1
  22. package/lib/language.d.ts +6 -4
  23. package/lib/language.js +28 -6
  24. package/lib/language.js.map +1 -1
  25. package/lib/mimetype.d.ts +2 -2
  26. package/lib/mimetype.js +6 -6
  27. package/lib/mimetype.js.map +1 -1
  28. package/lib/pythonBuiltin.d.ts +4 -3
  29. package/lib/pythonBuiltin.js.map +1 -1
  30. package/lib/searchprovider.d.ts +7 -6
  31. package/lib/searchprovider.js.map +1 -1
  32. package/lib/theme.d.ts +3 -3
  33. package/lib/theme.js.map +1 -1
  34. package/lib/token.d.ts +2 -1
  35. package/lib/token.js.map +1 -1
  36. package/package.json +10 -10
  37. package/src/commands.ts +1 -1
  38. package/src/editor.ts +7 -9
  39. package/src/extension.ts +13 -14
  40. package/src/extensions/customStyle.ts +2 -1
  41. package/src/extensions/ipython-md.ts +3 -2
  42. package/src/extensions/rulers.ts +4 -2
  43. package/src/extensions/ybinding.ts +4 -8
  44. package/src/extensions/yundomanager.ts +4 -7
  45. package/src/factory.ts +4 -3
  46. package/src/language.ts +35 -11
  47. package/src/mimetype.ts +8 -8
  48. package/src/pythonBuiltin.ts +6 -9
  49. package/src/searchprovider.ts +16 -18
  50. package/src/theme.ts +4 -3
  51. package/src/token.ts +2 -1
  52. package/src/typings.d.ts +1 -1
package/src/extension.ts CHANGED
@@ -9,13 +9,9 @@ import {
9
9
  indentOnInput,
10
10
  indentUnit
11
11
  } from '@codemirror/language';
12
- import {
13
- Compartment,
14
- EditorState,
15
- Extension,
16
- Prec,
17
- StateEffect
18
- } from '@codemirror/state';
12
+ import type { Extension } from '@codemirror/state';
13
+ import { Compartment, EditorState, Prec, StateEffect } from '@codemirror/state';
14
+ import type { KeyBinding } from '@codemirror/view';
19
15
  import {
20
16
  crosshairCursor,
21
17
  drawSelection,
@@ -25,20 +21,23 @@ import {
25
21
  highlightSpecialChars,
26
22
  highlightTrailingWhitespace,
27
23
  highlightWhitespace,
28
- KeyBinding,
29
24
  keymap,
30
25
  lineNumbers,
31
26
  rectangularSelection,
32
27
  scrollPastEnd,
33
28
  tooltips
34
29
  } from '@codemirror/view';
35
- import { ITranslator, nullTranslator } from '@jupyterlab/translation';
36
- import { JSONExt, ReadonlyJSONObject } from '@lumino/coreutils';
37
- import { IObservableDisposable } from '@lumino/disposable';
38
- import { ISignal, Signal } from '@lumino/signaling';
30
+ import type { ITranslator } from '@jupyterlab/translation';
31
+ import { nullTranslator } from '@jupyterlab/translation';
32
+ import type { ReadonlyJSONObject } from '@lumino/coreutils';
33
+ import { JSONExt } from '@lumino/coreutils';
34
+ import type { IObservableDisposable } from '@lumino/disposable';
35
+ import type { ISignal } from '@lumino/signaling';
36
+ import { Signal } from '@lumino/signaling';
39
37
  import { StateCommands } from './commands';
40
- import { customTheme, CustomTheme, rulers } from './extensions';
41
- import {
38
+ import type { CustomTheme } from './extensions';
39
+ import { customTheme, rulers } from './extensions';
40
+ import type {
42
41
  IConfigurableExtension,
43
42
  IEditorExtensionFactory,
44
43
  IEditorExtensionRegistry,
@@ -3,7 +3,8 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
 
6
- import { combineConfig, Extension, Facet } from '@codemirror/state';
6
+ import type { Extension } from '@codemirror/state';
7
+ import { combineConfig, Facet } from '@codemirror/state';
7
8
  import { EditorView } from '@codemirror/view';
8
9
 
9
10
  /**
@@ -1,9 +1,10 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
 
4
- import { parseMixed, Parser } from '@lezer/common';
4
+ import type { Parser } from '@lezer/common';
5
+ import { parseMixed } from '@lezer/common';
5
6
  import { tags } from '@lezer/highlight';
6
- import {
7
+ import type {
7
8
  DelimiterType,
8
9
  InlineContext,
9
10
  MarkdownConfig,
@@ -5,8 +5,10 @@
5
5
 
6
6
  // Inspired by https://discuss.codemirror.net/t/how-to-implement-ruler/4616/
7
7
 
8
- import { Extension, Facet } from '@codemirror/state';
9
- import { EditorView, ViewPlugin, ViewUpdate } from '@codemirror/view';
8
+ import type { Extension } from '@codemirror/state';
9
+ import { Facet } from '@codemirror/state';
10
+ import type { ViewUpdate } from '@codemirror/view';
11
+ import { EditorView, ViewPlugin } from '@codemirror/view';
10
12
  import { JSONExt } from '@lumino/coreutils';
11
13
 
12
14
  const RULERS_CLASSNAME = 'cm-rulers';
@@ -7,14 +7,10 @@
7
7
  * It is a simplification of https://github.com/yjs/y-codemirror.next
8
8
  * licensed under MIT License by Kevin Jahns
9
9
  */
10
- import {
11
- Annotation,
12
- EditorSelection,
13
- Extension,
14
- Facet,
15
- SelectionRange
16
- } from '@codemirror/state';
17
- import { EditorView, ViewPlugin, ViewUpdate } from '@codemirror/view';
10
+ import type { Extension, SelectionRange } from '@codemirror/state';
11
+ import { Annotation, EditorSelection, Facet } from '@codemirror/state';
12
+ import type { EditorView, ViewUpdate } from '@codemirror/view';
13
+ import { ViewPlugin } from '@codemirror/view';
18
14
  import {
19
15
  yUndoManager,
20
16
  YUndoManagerConfig,
@@ -14,14 +14,11 @@
14
14
  * - simplified `YUndoManagerConfig` by removing public methods
15
15
  * - moved `_onStackItemAdded`, `_onStackItemPopped` and `_storeSelection` definitions out of constructor
16
16
  */
17
- import {
18
- EditorView,
19
- PluginValue,
20
- ViewPlugin,
21
- ViewUpdate
22
- } from '@codemirror/view';
17
+ import type { PluginValue, ViewUpdate } from '@codemirror/view';
18
+ import { EditorView, ViewPlugin } from '@codemirror/view';
23
19
  import { Facet } from '@codemirror/state';
24
- import { YRange, ySyncAnnotation, YSyncConfig, ySyncFacet } from './ybinding';
20
+ import type { YRange, YSyncConfig } from './ybinding';
21
+ import { ySyncAnnotation, ySyncFacet } from './ybinding';
25
22
  import type { UndoManager } from 'yjs';
26
23
 
27
24
  interface IStackItem {
package/src/factory.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
 
4
- import { CodeEditor, IEditorFactoryService } from '@jupyterlab/codeeditor';
5
- import { ITranslator, nullTranslator } from '@jupyterlab/translation';
4
+ import type { CodeEditor, IEditorFactoryService } from '@jupyterlab/codeeditor';
5
+ import type { ITranslator } from '@jupyterlab/translation';
6
+ import { nullTranslator } from '@jupyterlab/translation';
6
7
  import { EditorExtensionRegistry } from './extension';
7
8
  import { CodeMirrorEditor } from './editor';
8
9
  import { EditorLanguageRegistry } from './language';
9
- import {
10
+ import type {
10
11
  IEditorExtensionFactory,
11
12
  IEditorExtensionRegistry,
12
13
  IEditorFactoryOptions,
package/src/language.ts CHANGED
@@ -1,21 +1,23 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
 
4
+ import type * as SQLModule from '@codemirror/lang-sql';
5
+ import type { StreamParser } from '@codemirror/language';
4
6
  import {
5
7
  LanguageDescription,
6
8
  LanguageSupport,
7
9
  LRLanguage,
8
- StreamLanguage,
9
- StreamParser
10
+ StreamLanguage
10
11
  } from '@codemirror/language';
11
12
  import { IEditorMimeTypeService } from '@jupyterlab/codeeditor';
12
13
  import { PathExt } from '@jupyterlab/coreutils';
13
- import { ITranslator, nullTranslator } from '@jupyterlab/translation';
14
+ import type { ITranslator } from '@jupyterlab/translation';
15
+ import { nullTranslator } from '@jupyterlab/translation';
14
16
  import { buildParser } from '@lezer/generator';
15
17
  import { highlightTree } from '@lezer/highlight';
16
18
 
17
19
  import { jupyterHighlightStyle } from './theme';
18
- import { IEditorLanguage, IEditorLanguageRegistry } from './token';
20
+ import type { IEditorLanguage, IEditorLanguageRegistry } from './token';
19
21
  import { pythonBuiltin } from './pythonBuiltin';
20
22
 
21
23
  /**
@@ -198,7 +200,7 @@ export class EditorLanguageRegistry implements IEditorLanguageRegistry {
198
200
  ): IEditorLanguage | null {
199
201
  const modename = typeof language === 'string' ? language : language.name;
200
202
  const mimetype = typeof language !== 'string' ? language.mime : modename;
201
- const ext = typeof language !== 'string' ? language.extensions ?? [] : [];
203
+ const ext = typeof language !== 'string' ? (language.extensions ?? []) : [];
202
204
 
203
205
  return (
204
206
  (modename ? this.findByName(modename) : null) ??
@@ -247,9 +249,13 @@ export class EditorLanguageRegistry implements IEditorLanguageRegistry {
247
249
  pos = to;
248
250
  });
249
251
 
250
- if (pos < tree.length - 1) {
251
- // No style applied on the trailing text
252
- el.appendChild(document.createTextNode(code.slice(pos, tree.length)));
252
+ if (pos === 0 && code.length > 0) {
253
+ // No tokens were emitted (e.g., single unrecognized character like 'x')
254
+ // Render the entire code as plain text fallback
255
+ el.appendChild(document.createTextNode(code));
256
+ } else if (pos < code.length) {
257
+ // Handle any remaining unstyled content
258
+ el.appendChild(document.createTextNode(code.slice(pos, code.length)));
253
259
  }
254
260
  }
255
261
 
@@ -286,7 +292,7 @@ export namespace EditorLanguageRegistry {
286
292
  * @returns Language object
287
293
  */
288
294
  async function sql(
289
- dialectName: keyof typeof import('@codemirror/lang-sql')
295
+ dialectName: keyof typeof SQLModule
290
296
  ): Promise<LanguageSupport> {
291
297
  const m = await import('@codemirror/lang-sql');
292
298
  return m.sql({ dialect: (m as any)[dialectName] });
@@ -296,10 +302,12 @@ export namespace EditorLanguageRegistry {
296
302
  * Get the default editor languages
297
303
  *
298
304
  * @param translator Application translator
305
+ * @param findLanguage Optional function to find a language by name for markdown code block highlighting
299
306
  * @returns Default CodeMirror 6 languages
300
307
  */
301
308
  export function getDefaultLanguages(
302
- translator?: ITranslator | null
309
+ translator?: ITranslator | null,
310
+ findLanguage?: (info: string) => IEditorLanguage | null
303
311
  ): ReadonlyArray<IEditorLanguage> {
304
312
  const trans = (translator ?? nullTranslator).load('jupyterlab');
305
313
  return [
@@ -416,7 +424,23 @@ export namespace EditorLanguageRegistry {
416
424
  extensions: ['md', 'markdown', 'mkd'],
417
425
  async load() {
418
426
  const m = await import('@codemirror/lang-markdown');
419
- return m.markdown({ codeLanguages: this._modeList as any });
427
+ if (!findLanguage) {
428
+ return m.markdown();
429
+ }
430
+ return m.markdown({
431
+ codeLanguages: (info: string) => {
432
+ const language = findLanguage(info);
433
+ if (!language) {
434
+ return null;
435
+ }
436
+ if (language instanceof LanguageDescription) {
437
+ // Sometimes the IEditorLanguage returned is a
438
+ // LanguageDescription instance, so early return in this case.
439
+ return language;
440
+ }
441
+ return LanguageDescription.of(language);
442
+ }
443
+ });
420
444
  }
421
445
  },
422
446
  {
package/src/mimetype.ts CHANGED
@@ -3,8 +3,8 @@
3
3
 
4
4
  import { IEditorMimeTypeService } from '@jupyterlab/codeeditor';
5
5
  import { PathExt } from '@jupyterlab/coreutils';
6
- import * as nbformat from '@jupyterlab/nbformat';
7
- import { IEditorLanguageRegistry } from './token';
6
+ import type * as nbformat from '@jupyterlab/nbformat';
7
+ import type { IEditorLanguageRegistry } from './token';
8
8
 
9
9
  /**
10
10
  * The mime type service for CodeMirror.
@@ -29,9 +29,9 @@ export class CodeMirrorMimeTypeService implements IEditorMimeTypeService {
29
29
  }
30
30
  );
31
31
  return mode
32
- ? Array.isArray(mode.mime)
33
- ? mode.mime[0] ?? IEditorMimeTypeService.defaultMimeType
34
- : mode.mime
32
+ ? typeof mode.mime === 'string'
33
+ ? mode.mime
34
+ : (mode.mime[0] ?? IEditorMimeTypeService.defaultMimeType)
35
35
  : IEditorMimeTypeService.defaultMimeType;
36
36
  }
37
37
 
@@ -52,9 +52,9 @@ export class CodeMirrorMimeTypeService implements IEditorMimeTypeService {
52
52
  }
53
53
  const mode = this.languages.findByFileName(path);
54
54
  return mode
55
- ? Array.isArray(mode.mime)
56
- ? mode.mime[0] ?? IEditorMimeTypeService.defaultMimeType
57
- : mode.mime
55
+ ? typeof mode.mime === 'string'
56
+ ? mode.mime
57
+ : (mode.mime[0] ?? IEditorMimeTypeService.defaultMimeType)
58
58
  : IEditorMimeTypeService.defaultMimeType;
59
59
  }
60
60
  }
@@ -3,16 +3,13 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
 
6
- import { Language, syntaxTree } from '@codemirror/language';
6
+ import type { Language } from '@codemirror/language';
7
+ import { syntaxTree } from '@codemirror/language';
7
8
  import { RangeSetBuilder } from '@codemirror/state';
8
- import {
9
- Decoration,
10
- DecorationSet,
11
- EditorView,
12
- ViewPlugin,
13
- ViewUpdate
14
- } from '@codemirror/view';
15
- import { NodeProp, SyntaxNodeRef, Tree } from '@lezer/common';
9
+ import type { DecorationSet, EditorView, ViewUpdate } from '@codemirror/view';
10
+ import { Decoration, ViewPlugin } from '@codemirror/view';
11
+ import type { SyntaxNodeRef, Tree } from '@lezer/common';
12
+ import { NodeProp } from '@lezer/common';
16
13
 
17
14
  export class PythonBuiltin {
18
15
  decorations: DecorationSet;
@@ -30,26 +30,25 @@
30
30
  THE SOFTWARE.
31
31
  */
32
32
 
33
- import { ISearchMatch } from '@jupyterlab/documentsearch';
34
- import { CodeMirrorEditor } from './editor';
35
- import {
36
- EditorSelection,
37
- Extension,
38
- StateEffect,
39
- StateEffectType,
40
- StateField
41
- } from '@codemirror/state';
42
- import { Decoration, DecorationSet, EditorView } from '@codemirror/view';
43
- import { CodeEditor } from '@jupyterlab/codeeditor';
44
- import {
45
- GenericSearchProvider,
33
+ import type { ISearchMatch } from '@jupyterlab/documentsearch';
34
+ import type { CodeMirrorEditor } from './editor';
35
+ import type { Extension, StateEffectType } from '@codemirror/state';
36
+ import { EditorSelection, StateEffect, StateField } from '@codemirror/state';
37
+ import type { DecorationSet } from '@codemirror/view';
38
+ import { Decoration, EditorView } from '@codemirror/view';
39
+ import type { CodeEditor } from '@jupyterlab/codeeditor';
40
+ import type {
46
41
  IBaseSearchProvider,
47
42
  IFilters,
48
- IReplaceOptions,
43
+ IReplaceOptions
44
+ } from '@jupyterlab/documentsearch';
45
+ import {
46
+ GenericSearchProvider,
49
47
  TextSearchEngine
50
48
  } from '@jupyterlab/documentsearch';
51
- import { ISignal, Signal } from '@lumino/signaling';
52
- import { ISharedText, SourceChange } from '@jupyter/ydoc';
49
+ import type { ISignal } from '@lumino/signaling';
50
+ import { Signal } from '@lumino/signaling';
51
+ import type { ISharedText, SourceChange } from '@jupyter/ydoc';
53
52
 
54
53
  /**
55
54
  * Defines from which position the search should be executed.
@@ -93,8 +92,7 @@ export interface IHighlightAdjacentMatchOptions extends IHighlightMatchOptions {
93
92
  */
94
93
  export abstract class EditorSearchProvider<
95
94
  T extends CodeEditor.IModel = CodeEditor.IModel
96
- > implements IBaseSearchProvider
97
- {
95
+ > implements IBaseSearchProvider {
98
96
  /**
99
97
  * Constructor
100
98
  */
package/src/theme.ts CHANGED
@@ -6,11 +6,12 @@ import {
6
6
  HighlightStyle,
7
7
  syntaxHighlighting
8
8
  } from '@codemirror/language';
9
- import { Extension } from '@codemirror/state';
9
+ import type { Extension } from '@codemirror/state';
10
10
  import { EditorView } from '@codemirror/view';
11
- import { ITranslator, nullTranslator } from '@jupyterlab/translation';
11
+ import type { ITranslator } from '@jupyterlab/translation';
12
+ import { nullTranslator } from '@jupyterlab/translation';
12
13
  import { tags as t } from '@lezer/highlight';
13
- import { IEditorTheme, IEditorThemeRegistry } from './token';
14
+ import type { IEditorTheme, IEditorThemeRegistry } from './token';
14
15
 
15
16
  export const jupyterEditorTheme = EditorView.theme({
16
17
  /**
package/src/token.ts CHANGED
@@ -8,7 +8,8 @@ import type { Extension, StateEffect } from '@codemirror/state';
8
8
  import type { EditorView } from '@codemirror/view';
9
9
  import type { CodeEditor } from '@jupyterlab/codeeditor';
10
10
  import type { ITranslator } from '@jupyterlab/translation';
11
- import { ReadonlyJSONObject, Token } from '@lumino/coreutils';
11
+ import type { ReadonlyJSONObject } from '@lumino/coreutils';
12
+ import { Token } from '@lumino/coreutils';
12
13
  import type { IDisposable } from '@lumino/disposable';
13
14
  import type { ISignal } from '@lumino/signaling';
14
15
 
package/src/typings.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  declare module '@codemirror/legacy-modes/mode/python' {
7
- import { StreamParser } from '@codemirror/language';
7
+ import type { StreamParser } from '@codemirror/language';
8
8
 
9
9
  export const python: StreamParser<unknown>;
10
10
  export const cython: StreamParser<unknown>;