@difizen/libro-codemirror 0.0.2-alpha.0 → 0.1.1

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.
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-parameter-properties */
2
- /* eslint-disable @typescript-eslint/parameter-properties */
3
1
  import type { Transaction } from '@codemirror/state';
4
2
  import type {
5
3
  EditorView,
@@ -53,12 +51,16 @@ export function moveCompletionSelection(
53
51
  );
54
52
  }
55
53
  const { length } = cState.open.options;
56
- let selected =
57
- cState.open.selected > -1
58
- ? cState.open.selected + step * (forward ? 1 : -1)
59
- : forward
60
- ? 0
61
- : length - 1;
54
+ let selected;
55
+ if (cState.open.selected > -1) {
56
+ selected = cState.open.selected + step * (forward ? 1 : -1);
57
+ } else {
58
+ if (forward) {
59
+ selected = 0;
60
+ } else {
61
+ selected = length - 1;
62
+ }
63
+ }
62
64
  if (selected < 0) {
63
65
  selected = by === 'page' ? 0 : length - 1;
64
66
  } else if (selected >= length) {
package/src/editor.ts CHANGED
@@ -140,7 +140,7 @@ export class CodeMirrorEditor implements IEditor {
140
140
  */
141
141
  constructor(options: IOptions) {
142
142
  this._editorConfig = new EditorConfiguration(options);
143
- const host = (this.host = options.host);
143
+ const host = (this.host = options['host']);
144
144
 
145
145
  host.classList.add(EDITOR_CLASS);
146
146
  host.classList.add('jp-Editor');
@@ -148,7 +148,7 @@ export class CodeMirrorEditor implements IEditor {
148
148
  host.addEventListener('blur', this, true);
149
149
  host.addEventListener('scroll', this, true);
150
150
 
151
- this._uuid = options.uuid || v4();
151
+ this._uuid = options['uuid'] || v4();
152
152
 
153
153
  // State and effects for handling the selection marks
154
154
  this._addMark = StateEffect.define<ICollabSelectionText>();
@@ -187,19 +187,19 @@ export class CodeMirrorEditor implements IEditor {
187
187
  });
188
188
 
189
189
  // Handle selection style.
190
- const style = options.selectionStyle || {};
190
+ const style = options['selectionStyle'] || {};
191
191
  this._selectionStyle = {
192
192
  ...defaultSelectionStyle,
193
193
  ...(style as IEditorSelectionStyle),
194
194
  };
195
195
 
196
- const model = (this._model = options.model);
196
+ const model = (this._model = options['model']);
197
197
 
198
198
  const config = options.config || {};
199
199
  const fullConfig = (this._config = {
200
200
  ...codeMirrorDefaultConfig,
201
201
  ...config,
202
- mimetype: options.model.mimeType,
202
+ mimetype: options['model'].mimeType,
203
203
  });
204
204
 
205
205
  // this._initializeEditorBinding();
@@ -207,13 +207,16 @@ export class CodeMirrorEditor implements IEditor {
207
207
  // Extension for handling DOM events
208
208
  const domEventHandlers = EditorView.domEventHandlers({
209
209
  keydown: (event: KeyboardEvent) => {
210
- const index = findFirstArrayIndex(this._keydownHandlers, (handler) => {
211
- if (handler(this, event) === true) {
212
- event.preventDefault();
213
- return true;
214
- }
215
- return false;
216
- });
210
+ const index = findFirstArrayIndex(
211
+ this._keydownHandlers,
212
+ (handler: KeydownHandler) => {
213
+ if (handler(this, event) === true) {
214
+ event.preventDefault();
215
+ return true;
216
+ }
217
+ return false;
218
+ },
219
+ );
217
220
  if (index === -1) {
218
221
  return this.onKeydown(event);
219
222
  }
@@ -391,7 +394,7 @@ export class CodeMirrorEditor implements IEditor {
391
394
  // Don't bother setting the option if it is already the same.
392
395
  if (this._config[option] !== value) {
393
396
  this._config[option] = value;
394
- this._editorConfig.reconfigureExtension(this._editor, option, value);
397
+ this._editorConfig.reconfigureExtension(this._editor, option as string, value);
395
398
  }
396
399
 
397
400
  if (option === 'readOnly') {
@@ -544,7 +547,10 @@ export class CodeMirrorEditor implements IEditor {
544
547
  addKeydownHandler(handler: KeydownHandler): Disposable {
545
548
  this._keydownHandlers.push(handler);
546
549
  return Disposable.create(() => {
547
- removeAllWhereFromArray(this._keydownHandlers, (val) => val === handler);
550
+ removeAllWhereFromArray(
551
+ this._keydownHandlers,
552
+ (val: KeydownHandler) => val === handler,
553
+ );
548
554
  });
549
555
  }
550
556
 
@@ -0,0 +1,11 @@
1
+ import 'reflect-metadata';
2
+ import assert from 'assert';
3
+
4
+ import { CodeMirrorEditor, codeMirrorEditorFactory } from './index.js';
5
+
6
+ describe('libro-codemirror', () => {
7
+ it('#import', () => {
8
+ assert(CodeMirrorEditor);
9
+ assert(codeMirrorEditorFactory);
10
+ });
11
+ });
package/src/mode.ts CHANGED
@@ -1,12 +1,7 @@
1
1
  import { markdown } from '@codemirror/lang-markdown';
2
- import type { LanguageSupport } from '@codemirror/language';
3
2
  import { LanguageDescription } from '@codemirror/language';
3
+ import type { LanguageSupport } from '@codemirror/language';
4
4
  import { defaultMimeType } from '@difizen/libro-code-editor';
5
-
6
- // This ensures the language spec for python will be loaded when
7
- // we instantiate a new editor instance, which is required since
8
- // python is the default language and we don't want to split
9
- // the editor constructor because of asynchronous loading.
10
5
  import { PathExt } from '@difizen/libro-common';
11
6
  import { highlightTree } from '@lezer/highlight';
12
7