@jupyterlab/codemirror 4.0.0-alpha.19 → 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 +0 -1
  2. package/lib/codemirror-ipythongfm.js +0 -8
  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 +29 -68
  8. package/lib/editor.js +66 -212
  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 +45 -37
  27. package/lib/factory.js.map +1 -1
  28. package/lib/index.d.ts +7 -20
  29. package/lib/index.js +7 -24
  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 +9 -4
  36. package/lib/mimetype.js.map +1 -1
  37. package/lib/searchprovider.d.ts +90 -80
  38. package/lib/searchprovider.js +221 -352
  39. package/lib/searchprovider.js.map +1 -1
  40. package/lib/theme.d.ts +57 -0
  41. package/lib/{editortheme.js → theme.js} +57 -30
  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 +28 -36
  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/index.css +0 -3
  64. package/style/index.js +0 -3
  65. package/lib/codemirror-ipython.d.ts +0 -1
  66. package/lib/codemirror-ipython.js +0 -12
  67. package/lib/codemirror-ipython.js.map +0 -1
  68. package/lib/editorconfiguration.d.ts +0 -149
  69. package/lib/editorconfiguration.js +0 -289
  70. package/lib/editorconfiguration.js.map +0 -1
  71. package/lib/editortheme.d.ts +0 -41
  72. package/lib/editortheme.js.map +0 -1
  73. package/lib/mode.d.ts +0 -88
  74. package/lib/mode.js +0 -1518
  75. package/lib/mode.js.map +0 -1
  76. package/lib/syntaxstatus.d.ts +0 -67
  77. package/lib/syntaxstatus.js +0 -146
  78. package/lib/syntaxstatus.js.map +0 -1
@@ -1,4 +1,3 @@
1
- export {};
2
1
  /**
3
2
  * Define an IPython GFM (GitHub Flavored Markdown) mode.
4
3
  *
@@ -1,13 +1,5 @@
1
1
  // Copyright (c) Jupyter Development Team.
2
2
  // Distributed under the terms of the Modified BSD License.
3
- import { Mode } from './mode';
4
- Mode.registerModeInfo({
5
- name: 'ipythongfm',
6
- mime: 'text/x-ipythongfm',
7
- load: () => {
8
- return import('@codemirror/lang-markdown').then(m => m.markdown({ codeLanguages: Mode.getModeInfo() }));
9
- }
10
- });
11
3
  // TODO: add support for LaTeX
12
4
  // This should be coded as an extension for https://github.com/lezer-parser/markdown
13
5
  // see https://github.com/lezer-parser/markdown/blob/main/src/extension.ts for examples
@@ -1 +1 @@
1
- {"version":3,"file":"codemirror-ipythongfm.js","sourceRoot":"","sources":["../src/codemirror-ipythongfm.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,IAAI,CAAC,gBAAgB,CAAC;IACpB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE,GAAG,EAAE;QACT,OAAO,MAAM,CAAC,2BAA2B,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAClD,CAAC,CAAC,QAAQ,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,WAAW,EAAS,EAAE,CAAC,CACzD,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,8BAA8B;AAC9B,oFAAoF;AACpF,uFAAuF;AACvF,oEAAoE;AACpE,EAAE;AACF,gBAAgB;AAChB,2FAA2F;AAC3F,IAAI;AAEJ;;;;EAIE;AACF;;;;;;;;GAQG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkFK"}
1
+ {"version":3,"file":"codemirror-ipythongfm.js","sourceRoot":"","sources":["../src/codemirror-ipythongfm.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,8BAA8B;AAC9B,oFAAoF;AACpF,uFAAuF;AACvF,oEAAoE;AACpE,EAAE;AACF,gBAAgB;AAChB,2FAA2F;AAC3F,IAAI;AAEJ;;;;EAIE;AACF;;;;;;;;GAQG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAkFK"}
@@ -0,0 +1,13 @@
1
+ import { EditorState, Transaction } from '@codemirror/state';
2
+ /**
3
+ * CodeMirror commands namespace
4
+ */
5
+ export declare namespace StateCommands {
6
+ /**
7
+ * Indent or insert a tab as appropriate.
8
+ */
9
+ function indentMoreOrInsertTab(target: {
10
+ state: EditorState;
11
+ dispatch: (transaction: Transaction) => void;
12
+ }): boolean;
13
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) Jupyter Development Team.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { indentMore, insertTab } from '@codemirror/commands';
6
+ /**
7
+ * CodeMirror commands namespace
8
+ */
9
+ export var StateCommands;
10
+ (function (StateCommands) {
11
+ /**
12
+ * Indent or insert a tab as appropriate.
13
+ */
14
+ function indentMoreOrInsertTab(target) {
15
+ const arg = { state: target.state, dispatch: target.dispatch };
16
+ const from = target.state.selection.main.from;
17
+ const to = target.state.selection.main.to;
18
+ if (from != to) {
19
+ return indentMore(arg);
20
+ }
21
+ const line = target.state.doc.lineAt(from);
22
+ const before = target.state.doc.slice(line.from, from).toString();
23
+ if (/^\s*$/.test(before)) {
24
+ return indentMore(arg);
25
+ }
26
+ else {
27
+ return insertTab(arg);
28
+ }
29
+ }
30
+ StateCommands.indentMoreOrInsertTab = indentMoreOrInsertTab;
31
+ })(StateCommands || (StateCommands = {}));
32
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAG7D;;GAEG;AACH,MAAM,KAAW,aAAa,CAsB7B;AAtBD,WAAiB,aAAa;IAC5B;;OAEG;IACH,SAAgB,qBAAqB,CAAC,MAGrC;QACC,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;QAC9C,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1C,IAAI,IAAI,IAAI,EAAE,EAAE;YACd,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;SACxB;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;QAClE,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YACxB,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;SACxB;aAAM;YACL,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;SACvB;IACH,CAAC;IAjBe,mCAAqB,wBAiBpC,CAAA;AACH,CAAC,EAtBgB,aAAa,KAAb,aAAa,QAsB7B"}
package/lib/editor.d.ts CHANGED
@@ -1,12 +1,9 @@
1
+ import { EditorState, Extension, StateCommand, Text } from '@codemirror/state';
2
+ import { Command, EditorView } from '@codemirror/view';
1
3
  import { CodeEditor } from '@jupyterlab/codeeditor';
2
- import { ITranslator } from '@jupyterlab/translation';
3
- import { IDisposable } from '@lumino/disposable';
4
4
  import { Signal } from '@lumino/signaling';
5
- import { EditorState, Extension, StateCommand, Text, Transaction } from '@codemirror/state';
6
- import { Command, EditorView } from '@codemirror/view';
7
- import './codemirror-ipython';
8
5
  import './codemirror-ipythongfm';
9
- import { Configuration } from './editorconfiguration';
6
+ import { IEditorExtensionRegistry, IEditorLanguageRegistry, IExtensionsHandler } from './token';
10
7
  /**
11
8
  * CodeMirror editor.
12
9
  */
@@ -15,11 +12,6 @@ export declare class CodeMirrorEditor implements CodeEditor.IEditor {
15
12
  * Construct a CodeMirror editor.
16
13
  */
17
14
  constructor(options: CodeMirrorEditor.IOptions);
18
- /**
19
- * Initialize the editor binding.
20
- */
21
- private _initializeEditorBinding;
22
- save: () => void;
23
15
  /**
24
16
  * A signal emitted when either the top or bottom edge is requested.
25
17
  */
@@ -68,11 +60,15 @@ export declare class CodeMirrorEditor implements CodeEditor.IEditor {
68
60
  /**
69
61
  * Get a config option for the editor.
70
62
  */
71
- getOption<K extends keyof CodeMirrorEditor.IConfig>(option: K): CodeMirrorEditor.IConfig[K];
63
+ getOption(option: string): unknown;
64
+ /**
65
+ * Whether the option exists or not.
66
+ */
67
+ hasOption(option: string): boolean;
72
68
  /**
73
69
  * Set a config option for the editor.
74
70
  */
75
- setOption<K extends keyof CodeMirrorEditor.IConfig>(option: K, value: CodeMirrorEditor.IConfig[K]): void;
71
+ setOption(option: string, value: unknown): void;
76
72
  /**
77
73
  * Set config options for the editor.
78
74
  *
@@ -81,7 +77,14 @@ export declare class CodeMirrorEditor implements CodeEditor.IEditor {
81
77
  * the costly update at the end, and not after every option
82
78
  * is set.
83
79
  */
84
- setOptions(options: Partial<CodeMirrorEditor.IConfig>): void;
80
+ setOptions(options: Record<string, any>): void;
81
+ /**
82
+ * Inject an extension into the editor
83
+ *
84
+ * @alpha
85
+ * @experimental
86
+ * @param ext CodeMirror 6 extension
87
+ */
85
88
  injectExtension(ext: Extension): void;
86
89
  /**
87
90
  * Returns the content for the given line number.
@@ -119,11 +122,6 @@ export declare class CodeMirrorEditor implements CodeEditor.IEditor {
119
122
  * Explicitly blur the editor.
120
123
  */
121
124
  blur(): void;
122
- /**
123
- * Refresh the editor if it is focused;
124
- * otherwise postpone refreshing till focusing.
125
- */
126
- resizeToFit(): void;
127
125
  get state(): EditorState;
128
126
  firstLine(): number;
129
127
  lastLine(): number;
@@ -139,14 +137,6 @@ export declare class CodeMirrorEditor implements CodeEditor.IEditor {
139
137
  line: number;
140
138
  ch: number;
141
139
  }, separator?: string): string;
142
- /**
143
- * Add a keydown handler to the editor.
144
- *
145
- * @param handler - A keydown handler.
146
- *
147
- * @returns A disposable that can be used to remove the handler.
148
- */
149
- addKeydownHandler(handler: CodeEditor.KeydownHandler): IDisposable;
150
140
  /**
151
141
  * Reveal the given position in the editor.
152
142
  */
@@ -231,6 +221,7 @@ export declare class CodeMirrorEditor implements CodeEditor.IEditor {
231
221
  * @param command - The name of the command to execute.
232
222
  */
233
223
  execCommand(command: Command | StateCommand): void;
224
+ protected onConfigChanged(configurator: IExtensionsHandler, changes: Record<string, any>): void;
234
225
  /**
235
226
  * Handle keydown events from the editor.
236
227
  */
@@ -278,59 +269,29 @@ export declare class CodeMirrorEditor implements CodeEditor.IEditor {
278
269
  * Handle `blur` events for the editor.
279
270
  */
280
271
  private _evtBlur;
281
- /**
282
- * Handle `scroll` events for the editor.
283
- */
284
- private _evtScroll;
285
- /**
286
- * Clear the hover for a caret, due to things like
287
- * scrolling, resizing, deactivation, etc, where
288
- * the position is no longer valid.
289
- */
290
- private _clearHover;
291
- protected translator: ITranslator;
292
- private _trans;
293
- private _model;
272
+ private _configurator;
294
273
  private _editor;
295
- private _caretHover;
296
- private _config;
297
- private _hoverTimeout;
298
- private _keydownHandlers;
299
- private _uuid;
300
274
  private _isDisposed;
301
- private _yeditorBinding;
302
- private _editorConfig;
275
+ private _language;
276
+ private _languages;
277
+ private _model;
278
+ private _uuid;
303
279
  }
304
280
  /**
305
281
  * The namespace for `CodeMirrorEditor` statics.
306
282
  */
307
283
  export declare namespace CodeMirrorEditor {
308
- interface IConfig extends Configuration.IConfig {
309
- }
310
284
  /**
311
285
  * The options used to initialize a code mirror editor.
312
286
  */
313
287
  interface IOptions extends CodeEditor.IOptions {
314
288
  /**
315
- * The configuration options for the editor.
289
+ * CodeMirror extensions registry
316
290
  */
317
- config?: Partial<IConfig>;
318
- }
319
- /**
320
- * The options used to set several options at once with reconfigure.
321
- */
322
- interface IConfigOptions<K extends keyof IConfig> {
323
- K: IConfig[K];
291
+ extensionsRegistry?: IEditorExtensionRegistry;
292
+ /**
293
+ * CodeMirror languages registry
294
+ */
295
+ languages?: IEditorLanguageRegistry;
324
296
  }
325
- /**
326
- * The default configuration options for an editor.
327
- */
328
- const defaultConfig: Required<IConfig>;
329
- /**
330
- * Indent or insert a tab as appropriate.
331
- */
332
- function indentMoreOrInsertTab(target: {
333
- state: EditorState;
334
- dispatch: (transaction: Transaction) => void;
335
- }): boolean;
336
297
  }
package/lib/editor.js CHANGED
@@ -1,31 +1,19 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
2
  // Copyright (c) Jupyter Development Team.
3
3
  // Distributed under the terms of the Modified BSD License.
4
- // / <reference types="codemirror"/>
5
- // / <reference types="codemirror/searchcursor"/>
6
- import { CodeEditor } from '@jupyterlab/codeeditor';
7
- import { nullTranslator } from '@jupyterlab/translation';
8
- import { ArrayExt } from '@lumino/algorithm';
9
- import { UUID } from '@lumino/coreutils';
10
- import { DisposableDelegate } from '@lumino/disposable';
11
- import { Signal } from '@lumino/signaling';
12
- import { indentMore, insertNewlineAndIndent, insertTab } from '@codemirror/commands';
4
+ import { insertNewlineAndIndent } from '@codemirror/commands';
13
5
  import { ensureSyntaxTree } from '@codemirror/language';
14
- import { EditorSelection, EditorState, Prec } from '@codemirror/state';
6
+ import { Compartment, EditorSelection, EditorState, Prec } from '@codemirror/state';
15
7
  import { EditorView } from '@codemirror/view';
16
- import { yCollab } from 'y-codemirror.next';
17
- import './codemirror-ipython';
8
+ import { UUID } from '@lumino/coreutils';
9
+ import { Signal } from '@lumino/signaling';
18
10
  import './codemirror-ipythongfm';
19
- import { Configuration } from './editorconfiguration';
20
- import { Mode } from './mode';
11
+ import { ExtensionsHandler } from './extension';
12
+ import { EditorLanguageRegistry } from './language';
21
13
  /**
22
14
  * The class name added to CodeMirrorWidget instances.
23
15
  */
24
16
  const EDITOR_CLASS = 'jp-CodeMirrorEditor';
25
- /**
26
- * The class name added to read only cell editor widgets.
27
- */
28
- const READ_ONLY_CLASS = 'jp-mod-readOnly';
29
17
  /**
30
18
  * The key code for the up arrow key.
31
19
  */
@@ -42,101 +30,51 @@ export class CodeMirrorEditor {
42
30
  * Construct a CodeMirror editor.
43
31
  */
44
32
  constructor(options) {
33
+ var _a, _b, _c, _d, _e, _f;
45
34
  /**
46
35
  * A signal emitted when either the top or bottom edge is requested.
47
36
  */
48
37
  this.edgeRequested = new Signal(this);
49
- this._keydownHandlers = new Array();
50
- this._uuid = '';
51
38
  this._isDisposed = false;
52
- this._editorConfig = new Configuration.EditorConfiguration();
39
+ this._language = new Compartment();
40
+ this._uuid = '';
41
+ this._languages = (_a = options.languages) !== null && _a !== void 0 ? _a : new EditorLanguageRegistry();
42
+ this._configurator =
43
+ (_d = (_b = options.extensionsRegistry) === null || _b === void 0 ? void 0 : _b.createNew({
44
+ ...options,
45
+ inline: (_c = options.inline) !== null && _c !== void 0 ? _c : false
46
+ })) !== null && _d !== void 0 ? _d : new ExtensionsHandler();
53
47
  const host = (this.host = options.host);
54
- this.translator = options.translator || nullTranslator;
55
- this._trans = this.translator.load('jupyterlab');
56
48
  host.classList.add(EDITOR_CLASS);
57
49
  host.classList.add('jp-Editor');
58
50
  host.addEventListener('focus', this, true);
59
51
  host.addEventListener('blur', this, true);
60
52
  host.addEventListener('scroll', this, true);
61
- this._uuid = options.uuid || UUID.uuid4();
53
+ this._uuid = (_e = options.uuid) !== null && _e !== void 0 ? _e : UUID.uuid4();
62
54
  const model = (this._model = options.model);
63
- const config = options.config || {};
64
- const fullConfig = (this._config = {
65
- ...CodeMirrorEditor.defaultConfig,
66
- ...config
67
- });
68
- this._initializeEditorBinding();
69
- // Extension for handling DOM events
70
- const domEventHandlers = EditorView.domEventHandlers({
55
+ // Default keydown handler - it will have low priority
56
+ const onKeyDown = EditorView.domEventHandlers({
71
57
  keydown: (event, view) => {
72
- const index = ArrayExt.findFirstIndex(this._keydownHandlers, handler => {
73
- if (handler(this, event) === true) {
74
- event.preventDefault();
75
- return true;
76
- }
77
- return false;
78
- });
79
- if (index === -1) {
80
- return this.onKeydown(event);
81
- }
82
- return false;
58
+ return this.onKeydown(event);
83
59
  }
84
60
  });
85
61
  const updateListener = EditorView.updateListener.of((update) => {
86
62
  this._onDocChanged(update);
87
63
  });
88
- // The list of internal strings is available at https://codemirror.net/examples/translate/
89
- const translation = EditorState.phrases.of({
90
- // @codemirror/view
91
- 'Control character': this._trans.__('Control character'),
92
- // @codemirror/commands
93
- 'Selection deleted': this._trans.__('Selection deleted'),
94
- // @codemirror/language
95
- 'Folded lines': this._trans.__('Folded lines'),
96
- 'Unfolded lines': this._trans.__('Unfolded lines'),
97
- to: this._trans.__('to'),
98
- 'folded code': this._trans.__('folded code'),
99
- unfold: this._trans.__('unfold'),
100
- 'Fold line': this._trans.__('Fold line'),
101
- 'Unfold line': this._trans.__('Unfold line'),
102
- // @codemirror/search
103
- 'Go to line': this._trans.__('Go to line'),
104
- go: this._trans.__('go'),
105
- Find: this._trans.__('Find'),
106
- Replace: this._trans.__('Replace'),
107
- next: this._trans.__('next'),
108
- previous: this._trans.__('previous'),
109
- all: this._trans.__('all'),
110
- 'match case': this._trans.__('match case'),
111
- replace: this._trans.__('replace'),
112
- 'replace all': this._trans.__('replace all'),
113
- close: this._trans.__('close'),
114
- 'current match': this._trans.__('current match'),
115
- 'replaced $ matches': this._trans.__('replaced $ matches'),
116
- 'replaced match on line $': this._trans.__('replaced match on line $'),
117
- 'on line': this._trans.__('on line'),
118
- // @codemirror/autocomplete
119
- Completions: this._trans.__('Completions'),
120
- // @codemirror/lint
121
- Diagnostics: this._trans.__('Diagnostics'),
122
- 'No diagnostics': this._trans.__('No diagnostics')
123
- });
124
- this._editor = Private.createEditor(host, fullConfig, this._yeditorBinding, this._editorConfig, [Prec.high(domEventHandlers), updateListener, translation]);
64
+ this._editor = Private.createEditor(host, this._configurator, [
65
+ // We need to set the order to high, otherwise the keybinding for ArrowUp/ArrowDown
66
+ // will process the event shunting our edge detection code.
67
+ Prec.high(onKeyDown),
68
+ updateListener,
69
+ // Initialize with empty extension
70
+ this._language.of([]),
71
+ ...((_f = options.extensions) !== null && _f !== void 0 ? _f : [])
72
+ ], model.sharedModel.source);
125
73
  this._onMimeTypeChanged();
126
74
  this._onCursorActivity();
75
+ this._configurator.configChanged.connect(this.onConfigChanged, this);
127
76
  model.mimeTypeChanged.connect(this._onMimeTypeChanged, this);
128
77
  }
129
- /**
130
- * Initialize the editor binding.
131
- */
132
- _initializeEditorBinding() {
133
- const sharedModel = this.model.sharedModel;
134
- this._yeditorBinding = {
135
- text: sharedModel.ysource,
136
- awareness: sharedModel.awareness,
137
- undoManager: sharedModel.undoManager
138
- };
139
- }
140
78
  /**
141
79
  * The uuid of this editor;
142
80
  */
@@ -199,7 +137,7 @@ export class CodeMirrorEditor {
199
137
  this.host.removeEventListener('focus', this, true);
200
138
  this.host.removeEventListener('blur', this, true);
201
139
  this.host.removeEventListener('scroll', this, true);
202
- this._keydownHandlers.length = 0;
140
+ this._configurator.dispose();
203
141
  Signal.clearData(this);
204
142
  this.editor.destroy();
205
143
  }
@@ -207,17 +145,19 @@ export class CodeMirrorEditor {
207
145
  * Get a config option for the editor.
208
146
  */
209
147
  getOption(option) {
210
- return this._config[option];
148
+ return this._configurator.getOption(option);
149
+ }
150
+ /**
151
+ * Whether the option exists or not.
152
+ */
153
+ hasOption(option) {
154
+ return this._configurator.hasOption(option);
211
155
  }
212
156
  /**
213
157
  * Set a config option for the editor.
214
158
  */
215
159
  setOption(option, value) {
216
- // Don't bother setting the option if it is already the same.
217
- if (this._config[option] !== value) {
218
- this._config[option] = value;
219
- this._editorConfig.reconfigureExtension(this._editor, option, value);
220
- }
160
+ this._configurator.setOption(option, value);
221
161
  }
222
162
  /**
223
163
  * Set config options for the editor.
@@ -228,11 +168,17 @@ export class CodeMirrorEditor {
228
168
  * is set.
229
169
  */
230
170
  setOptions(options) {
231
- this._config = { ...this._config, ...options };
232
- this._editorConfig.reconfigureExtensions(this._editor, options);
171
+ this._configurator.setOptions(options);
233
172
  }
173
+ /**
174
+ * Inject an extension into the editor
175
+ *
176
+ * @alpha
177
+ * @experimental
178
+ * @param ext CodeMirror 6 extension
179
+ */
234
180
  injectExtension(ext) {
235
- this._editorConfig.injectExtension(this._editor, ext);
181
+ this._configurator.injectExtension(this._editor, ext);
236
182
  }
237
183
  /**
238
184
  * Returns the content for the given line number.
@@ -273,8 +219,7 @@ export class CodeMirrorEditor {
273
219
  * Clear the undo history.
274
220
  */
275
221
  clearHistory() {
276
- var _a, _b;
277
- (_b = (_a = this._yeditorBinding) === null || _a === void 0 ? void 0 : _a.undoManager) === null || _b === void 0 ? void 0 : _b.clear();
222
+ this.model.sharedModel.clearUndoHistory();
278
223
  }
279
224
  /**
280
225
  * Brings browser focus to this editor text.
@@ -294,13 +239,6 @@ export class CodeMirrorEditor {
294
239
  blur() {
295
240
  this._editor.contentDOM.blur();
296
241
  }
297
- /**
298
- * Refresh the editor if it is focused;
299
- * otherwise postpone refreshing till focusing.
300
- */
301
- resizeToFit() {
302
- this._clearHover();
303
- }
304
242
  get state() {
305
243
  return this._editor.state;
306
244
  }
@@ -322,19 +260,6 @@ export class CodeMirrorEditor {
322
260
  const toOffset = this.getOffsetAt(this._toPosition(to));
323
261
  return this.state.sliceDoc(fromOffset, toOffset);
324
262
  }
325
- /**
326
- * Add a keydown handler to the editor.
327
- *
328
- * @param handler - A keydown handler.
329
- *
330
- * @returns A disposable that can be used to remove the handler.
331
- */
332
- addKeydownHandler(handler) {
333
- this._keydownHandlers.push(handler);
334
- return new DisposableDelegate(() => {
335
- ArrayExt.removeAllWhere(this._keydownHandlers, val => val === handler);
336
- });
337
- }
338
263
  /**
339
264
  * Reveal the given position in the editor.
340
265
  */
@@ -538,6 +463,9 @@ export class CodeMirrorEditor {
538
463
  execCommand(command) {
539
464
  command(this.editor);
540
465
  }
466
+ onConfigChanged(configurator, changes) {
467
+ configurator.reconfigureExtensions(this._editor, changes);
468
+ }
541
469
  /**
542
470
  * Handle keydown events from the editor.
543
471
  */
@@ -569,12 +497,20 @@ export class CodeMirrorEditor {
569
497
  * Handles a mime type change.
570
498
  */
571
499
  _onMimeTypeChanged() {
572
- const mime = this._model.mimeType;
573
500
  // TODO: should we provide a hook for when the mode is done being set?
574
- void Mode.ensure(mime).then(spec => {
575
- if (spec) {
576
- this._editorConfig.reconfigureExtension(this._editor, 'language', spec.support);
577
- }
501
+ this._languages
502
+ .getLanguage(this._model.mimeType)
503
+ .then(language => {
504
+ var _a;
505
+ this._editor.dispatch({
506
+ effects: this._language.reconfigure((_a = language === null || language === void 0 ? void 0 : language.support) !== null && _a !== void 0 ? _a : [])
507
+ });
508
+ })
509
+ .catch(reason => {
510
+ console.log(`Failed to load language for '${this._model.mimeType}'.`, reason);
511
+ this._editor.dispatch({
512
+ effects: this._language.reconfigure([])
513
+ });
578
514
  });
579
515
  }
580
516
  /**
@@ -642,9 +578,6 @@ export class CodeMirrorEditor {
642
578
  case 'blur':
643
579
  this._evtBlur(event);
644
580
  break;
645
- case 'scroll':
646
- this._evtScroll();
647
- break;
648
581
  default:
649
582
  break;
650
583
  }
@@ -665,91 +598,15 @@ export class CodeMirrorEditor {
665
598
  _evtBlur(event) {
666
599
  this.host.classList.remove('jp-mod-focused');
667
600
  }
668
- /**
669
- * Handle `scroll` events for the editor.
670
- */
671
- _evtScroll() {
672
- // Remove any active hover.
673
- this._clearHover();
674
- }
675
- /**
676
- * Clear the hover for a caret, due to things like
677
- * scrolling, resizing, deactivation, etc, where
678
- * the position is no longer valid.
679
- */
680
- _clearHover() {
681
- if (this._caretHover) {
682
- window.clearTimeout(this._hoverTimeout);
683
- document.body.removeChild(this._caretHover);
684
- this._caretHover = null;
685
- }
686
- }
687
601
  }
688
- /**
689
- * The namespace for `CodeMirrorEditor` statics.
690
- */
691
- (function (CodeMirrorEditor) {
692
- /**
693
- * The default configuration options for an editor.
694
- */
695
- CodeMirrorEditor.defaultConfig = {
696
- ...CodeEditor.defaultConfig,
697
- mode: 'null',
698
- theme: 'jupyter',
699
- smartIndent: true,
700
- electricChars: true,
701
- keyMap: 'default',
702
- extraKeys: null,
703
- gutters: [],
704
- fixedGutter: true,
705
- showCursorWhenSelecting: false,
706
- coverGutterNextToScrollbar: false,
707
- dragDrop: true,
708
- lineSeparator: null,
709
- scrollbarStyle: 'native',
710
- lineWiseCopyCut: true,
711
- scrollPastEnd: false,
712
- styleActiveLine: false,
713
- styleSelectedText: true,
714
- selectionPointer: false,
715
- handlePaste: true
716
- };
717
- /**
718
- * Indent or insert a tab as appropriate.
719
- */
720
- function indentMoreOrInsertTab(target) {
721
- const arg = { state: target.state, dispatch: target.dispatch };
722
- const from = target.state.selection.main.from;
723
- const to = target.state.selection.main.to;
724
- if (from != to) {
725
- return indentMore(arg);
726
- }
727
- const line = target.state.doc.lineAt(from);
728
- const before = target.state.doc.slice(line.from, from).toString();
729
- if (/^\s*$/.test(before)) {
730
- return indentMore(arg);
731
- }
732
- else {
733
- return insertTab(arg);
734
- }
735
- }
736
- CodeMirrorEditor.indentMoreOrInsertTab = indentMoreOrInsertTab;
737
- })(CodeMirrorEditor || (CodeMirrorEditor = {}));
738
602
  /**
739
603
  * The namespace for module private data.
740
604
  */
741
605
  var Private;
742
606
  (function (Private) {
743
- function createEditor(host, config, ybinding, editorConfig, additionalExtensions) {
744
- var _a;
745
- const extensions = editorConfig.getInitialExtensions(config);
746
- if (ybinding) {
747
- extensions.push(yCollab(ybinding.text, ybinding.awareness, {
748
- undoManager: (_a = ybinding.undoManager) !== null && _a !== void 0 ? _a : false
749
- }));
750
- }
607
+ function createEditor(host, editorConfig, additionalExtensions, doc) {
608
+ const extensions = editorConfig.getInitialExtensions();
751
609
  extensions.push(...additionalExtensions);
752
- const doc = ybinding === null || ybinding === void 0 ? void 0 : ybinding.text.toString();
753
610
  const view = new EditorView({
754
611
  state: EditorState.create({
755
612
  doc,
@@ -757,9 +614,6 @@ var Private;
757
614
  }),
758
615
  parent: host
759
616
  });
760
- if (config.readOnly) {
761
- view.dom.classList.add(READ_ONLY_CLASS);
762
- }
763
617
  return view;
764
618
  }
765
619
  Private.createEditor = createEditor;