@jupyterlab/codeeditor 4.0.0-alpha.9 → 4.0.0-beta.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.
- package/lib/editor.d.ts +48 -216
- package/lib/editor.js +26 -140
- package/lib/editor.js.map +1 -1
- package/lib/factory.d.ts +2 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/jsoneditor.d.ts +5 -9
- package/lib/jsoneditor.js +41 -39
- package/lib/jsoneditor.js.map +1 -1
- package/lib/lineCol.js +4 -3
- package/lib/lineCol.js.map +1 -1
- package/lib/tokens.d.ts +1 -1
- package/lib/viewer.d.ts +48 -0
- package/lib/viewer.js +45 -0
- package/lib/viewer.js.map +1 -0
- package/lib/widget.d.ts +5 -31
- package/lib/widget.js +6 -43
- package/lib/widget.js.map +1 -1
- package/package.json +23 -22
- package/src/editor.ts +560 -0
- package/src/factory.ts +19 -0
- package/src/index.ts +15 -0
- package/src/jsoneditor.ts +358 -0
- package/src/lineCol.tsx +381 -0
- package/src/mimetype.ts +43 -0
- package/src/tokens.ts +57 -0
- package/src/viewer.ts +93 -0
- package/src/widget.ts +289 -0
- package/style/linecol.css +5 -0
package/lib/editor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { Extension } from '@codemirror/state';
|
|
2
|
+
import { ISharedText } from '@jupyter/ydoc';
|
|
1
3
|
import { IChangedArgs } from '@jupyterlab/coreutils';
|
|
2
|
-
import
|
|
3
|
-
import { IModelDB, IObservableMap, IObservableString } from '@jupyterlab/observables';
|
|
4
|
-
import * as models from '@jupyterlab/shared-models';
|
|
4
|
+
import { IObservableMap } from '@jupyterlab/observables';
|
|
5
5
|
import { ITranslator } from '@jupyterlab/translation';
|
|
6
6
|
import { JSONObject } from '@lumino/coreutils';
|
|
7
7
|
import { IDisposable } from '@lumino/disposable';
|
|
@@ -67,27 +67,6 @@ export declare namespace CodeEditor {
|
|
|
67
67
|
*/
|
|
68
68
|
readonly end: IPosition;
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
71
|
-
* A selection style.
|
|
72
|
-
*/
|
|
73
|
-
interface ISelectionStyle extends JSONObject {
|
|
74
|
-
/**
|
|
75
|
-
* A class name added to a selection.
|
|
76
|
-
*/
|
|
77
|
-
className: string;
|
|
78
|
-
/**
|
|
79
|
-
* A display name added to a selection.
|
|
80
|
-
*/
|
|
81
|
-
displayName: string;
|
|
82
|
-
/**
|
|
83
|
-
* A color for UI elements.
|
|
84
|
-
*/
|
|
85
|
-
color: string;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* The default selection style.
|
|
89
|
-
*/
|
|
90
|
-
const defaultSelectionStyle: ISelectionStyle;
|
|
91
70
|
/**
|
|
92
71
|
* A text selection.
|
|
93
72
|
*/
|
|
@@ -96,10 +75,6 @@ export declare namespace CodeEditor {
|
|
|
96
75
|
* The uuid of the text selection owner.
|
|
97
76
|
*/
|
|
98
77
|
readonly uuid: string;
|
|
99
|
-
/**
|
|
100
|
-
* The style of this selection.
|
|
101
|
-
*/
|
|
102
|
-
readonly style: ISelectionStyle;
|
|
103
78
|
}
|
|
104
79
|
/**
|
|
105
80
|
* An interface for a text token, such as a word, keyword, or variable.
|
|
@@ -142,14 +117,6 @@ export declare namespace CodeEditor {
|
|
|
142
117
|
* A signal emitted when a property changes.
|
|
143
118
|
*/
|
|
144
119
|
mimeTypeChanged: ISignal<IModel, IChangedArgs<string>>;
|
|
145
|
-
/**
|
|
146
|
-
* A signal emitted when the shared model was switched.
|
|
147
|
-
*/
|
|
148
|
-
sharedModelSwitched: ISignal<IModel, boolean>;
|
|
149
|
-
/**
|
|
150
|
-
* The text stored in the model.
|
|
151
|
-
*/
|
|
152
|
-
readonly value: IObservableString;
|
|
153
120
|
/**
|
|
154
121
|
* A mime type of the model.
|
|
155
122
|
*
|
|
@@ -161,20 +128,10 @@ export declare namespace CodeEditor {
|
|
|
161
128
|
* The currently selected code.
|
|
162
129
|
*/
|
|
163
130
|
readonly selections: IObservableMap<ITextSelection[]>;
|
|
164
|
-
/**
|
|
165
|
-
* The underlying `IModelDB` instance in which model
|
|
166
|
-
* data is stored.
|
|
167
|
-
*/
|
|
168
|
-
readonly modelDB: IModelDB;
|
|
169
131
|
/**
|
|
170
132
|
* The shared model for the cell editor.
|
|
171
133
|
*/
|
|
172
|
-
readonly sharedModel:
|
|
173
|
-
/**
|
|
174
|
-
* When we initialize a cell model, we create a standalone cell model that cannot be shared in a YNotebook.
|
|
175
|
-
* Call this function to re-initialize the local representation based on a fresh shared model (e.g. models.YFile or models.YCodeCell).
|
|
176
|
-
*/
|
|
177
|
-
switchSharedModel(sharedModel: models.ISharedText, reinitialize: boolean): void;
|
|
134
|
+
readonly sharedModel: ISharedText;
|
|
178
135
|
}
|
|
179
136
|
/**
|
|
180
137
|
* The default implementation of the editor model.
|
|
@@ -184,47 +141,14 @@ export declare namespace CodeEditor {
|
|
|
184
141
|
* Construct a new Model.
|
|
185
142
|
*/
|
|
186
143
|
constructor(options?: Model.IOptions);
|
|
187
|
-
/**
|
|
188
|
-
* When we initialize a cell model, we create a standalone model that cannot be shared in a YNotebook.
|
|
189
|
-
* Call this function to re-initialize the local representation based on a fresh shared model (e.g. models.YFile or models.YCodeCell).
|
|
190
|
-
*
|
|
191
|
-
* @param sharedModel
|
|
192
|
-
* @param reinitialize Whether to reinitialize the shared model.
|
|
193
|
-
*/
|
|
194
|
-
switchSharedModel(sharedModel: models.ISharedText, reinitialize?: boolean): void;
|
|
195
|
-
/**
|
|
196
|
-
* We update the modeldb store when the shared model changes.
|
|
197
|
-
* To ensure that we don't run into infinite loops, we wrap this call in a "mutex".
|
|
198
|
-
* The "mutex" ensures that the wrapped code can only be executed by either the sharedModelChanged handler
|
|
199
|
-
* or the modelDB change handler.
|
|
200
|
-
*/
|
|
201
|
-
protected _onSharedModelChanged(sender: models.ISharedBaseCell<any>, change: models.CellChange<nbformat.IBaseCellMetadata>): void;
|
|
202
|
-
/**
|
|
203
|
-
* Handle a change to the modelDB value.
|
|
204
|
-
*/
|
|
205
|
-
private _onModelDBValueChanged;
|
|
206
|
-
get type(): nbformat.CellType;
|
|
207
144
|
/**
|
|
208
145
|
* The shared model for the cell editor.
|
|
209
146
|
*/
|
|
210
|
-
sharedModel:
|
|
211
|
-
/**
|
|
212
|
-
* The underlying `IModelDB` instance in which model
|
|
213
|
-
* data is stored.
|
|
214
|
-
*/
|
|
215
|
-
readonly modelDB: IModelDB;
|
|
147
|
+
readonly sharedModel: ISharedText;
|
|
216
148
|
/**
|
|
217
149
|
* A signal emitted when a mimetype changes.
|
|
218
150
|
*/
|
|
219
151
|
get mimeTypeChanged(): ISignal<this, IChangedArgs<string>>;
|
|
220
|
-
/**
|
|
221
|
-
* A signal emitted when the shared model was switched.
|
|
222
|
-
*/
|
|
223
|
-
get sharedModelSwitched(): ISignal<this, boolean>;
|
|
224
|
-
/**
|
|
225
|
-
* Get the value of the model.
|
|
226
|
-
*/
|
|
227
|
-
get value(): IObservableString;
|
|
228
152
|
/**
|
|
229
153
|
* Get the selections for the model.
|
|
230
154
|
*/
|
|
@@ -242,10 +166,14 @@ export declare namespace CodeEditor {
|
|
|
242
166
|
* Dispose of the resources used by the model.
|
|
243
167
|
*/
|
|
244
168
|
dispose(): void;
|
|
245
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Whether the model should disposed the shared model on disposal or not.
|
|
171
|
+
*/
|
|
172
|
+
protected standaloneModel: boolean;
|
|
246
173
|
private _isDisposed;
|
|
174
|
+
private _selections;
|
|
175
|
+
private _mimeType;
|
|
247
176
|
private _mimeTypeChanged;
|
|
248
|
-
private _sharedModelSwitched;
|
|
249
177
|
}
|
|
250
178
|
/**
|
|
251
179
|
* A selection owner.
|
|
@@ -311,16 +239,15 @@ export declare namespace CodeEditor {
|
|
|
311
239
|
type EdgeLocation = 'top' | 'topLine' | 'bottom';
|
|
312
240
|
/**
|
|
313
241
|
* A widget that provides a code editor.
|
|
242
|
+
*
|
|
243
|
+
* As of JupyterLab 4.0.0, it is not possible to provide an editor
|
|
244
|
+
* that is different of CodeMirror 6.
|
|
314
245
|
*/
|
|
315
246
|
interface IEditor extends ISelectionOwner, IDisposable {
|
|
316
247
|
/**
|
|
317
248
|
* A signal emitted when either the top or bottom edge is requested.
|
|
318
249
|
*/
|
|
319
250
|
readonly edgeRequested: ISignal<IEditor, EdgeLocation>;
|
|
320
|
-
/**
|
|
321
|
-
* The default selection style for the editor.
|
|
322
|
-
*/
|
|
323
|
-
selectionStyle: CodeEditor.ISelectionStyle;
|
|
324
251
|
/**
|
|
325
252
|
* The DOM node that hosts the editor.
|
|
326
253
|
*/
|
|
@@ -344,15 +271,23 @@ export declare namespace CodeEditor {
|
|
|
344
271
|
/**
|
|
345
272
|
* Get a config option for the editor.
|
|
346
273
|
*/
|
|
347
|
-
getOption
|
|
274
|
+
getOption(option: string): unknown;
|
|
348
275
|
/**
|
|
349
276
|
* Set a config option for the editor.
|
|
350
277
|
*/
|
|
351
|
-
setOption
|
|
278
|
+
setOption(option: string, value: unknown): void;
|
|
352
279
|
/**
|
|
353
280
|
* Set config options for the editor.
|
|
354
281
|
*/
|
|
355
|
-
setOptions(options:
|
|
282
|
+
setOptions(options: Record<string, any>): void;
|
|
283
|
+
/**
|
|
284
|
+
* Inject an extension into the editor
|
|
285
|
+
*
|
|
286
|
+
* @alpha
|
|
287
|
+
* @experimental
|
|
288
|
+
* @param ext Editor extension
|
|
289
|
+
*/
|
|
290
|
+
injectExtension(ext: Extension): void;
|
|
356
291
|
/**
|
|
357
292
|
* Returns the content for the given line number.
|
|
358
293
|
*
|
|
@@ -407,34 +342,6 @@ export declare namespace CodeEditor {
|
|
|
407
342
|
* Explicitly blur the editor.
|
|
408
343
|
*/
|
|
409
344
|
blur(): void;
|
|
410
|
-
/**
|
|
411
|
-
* Repaint the editor.
|
|
412
|
-
*
|
|
413
|
-
* #### Notes
|
|
414
|
-
* A repainted editor should fit to its host node.
|
|
415
|
-
*/
|
|
416
|
-
refresh(): void;
|
|
417
|
-
/**
|
|
418
|
-
* Resize the editor to fit its host node.
|
|
419
|
-
*/
|
|
420
|
-
resizeToFit(): void;
|
|
421
|
-
/**
|
|
422
|
-
* Add a keydown handler to the editor.
|
|
423
|
-
*
|
|
424
|
-
* @param handler - A keydown handler.
|
|
425
|
-
*
|
|
426
|
-
* @returns A disposable that can be used to remove the handler.
|
|
427
|
-
*/
|
|
428
|
-
addKeydownHandler(handler: KeydownHandler): IDisposable;
|
|
429
|
-
/**
|
|
430
|
-
* Set the size of the editor.
|
|
431
|
-
*
|
|
432
|
-
* @param size - The desired size.
|
|
433
|
-
*
|
|
434
|
-
* #### Notes
|
|
435
|
-
* Use `null` if the size is unknown.
|
|
436
|
-
*/
|
|
437
|
-
setSize(size: IDimension | null): void;
|
|
438
345
|
/**
|
|
439
346
|
* Reveals the given position in the editor.
|
|
440
347
|
*
|
|
@@ -444,7 +351,7 @@ export declare namespace CodeEditor {
|
|
|
444
351
|
/**
|
|
445
352
|
* Reveals the given selection in the editor.
|
|
446
353
|
*
|
|
447
|
-
* @param
|
|
354
|
+
* @param selection - The desired selection to reveal.
|
|
448
355
|
*/
|
|
449
356
|
revealSelection(selection: IRange): void;
|
|
450
357
|
/**
|
|
@@ -465,17 +372,21 @@ export declare namespace CodeEditor {
|
|
|
465
372
|
*/
|
|
466
373
|
getPositionForCoordinate(coordinate: ICoordinate): IPosition | null;
|
|
467
374
|
/**
|
|
468
|
-
*
|
|
375
|
+
* Get a list of tokens for the current editor text content.
|
|
469
376
|
*/
|
|
470
|
-
|
|
377
|
+
getTokens(): CodeEditor.IToken[];
|
|
471
378
|
/**
|
|
472
|
-
*
|
|
379
|
+
* Get the token at a given editor position.
|
|
473
380
|
*/
|
|
474
|
-
|
|
381
|
+
getTokenAt(offset: number): CodeEditor.IToken;
|
|
475
382
|
/**
|
|
476
|
-
*
|
|
383
|
+
* Get the token a the cursor position.
|
|
384
|
+
*/
|
|
385
|
+
getTokenAtCursor(): CodeEditor.IToken;
|
|
386
|
+
/**
|
|
387
|
+
* Inserts a new line at the cursor position and indents it.
|
|
477
388
|
*/
|
|
478
|
-
|
|
389
|
+
newIndentedLine(): void;
|
|
479
390
|
/**
|
|
480
391
|
* Replaces selection with the given text.
|
|
481
392
|
*/
|
|
@@ -485,85 +396,6 @@ export declare namespace CodeEditor {
|
|
|
485
396
|
* A factory used to create a code editor.
|
|
486
397
|
*/
|
|
487
398
|
type Factory = (options: IOptions) => CodeEditor.IEditor;
|
|
488
|
-
/**
|
|
489
|
-
* The configuration options for an editor.
|
|
490
|
-
*/
|
|
491
|
-
interface IConfig {
|
|
492
|
-
/**
|
|
493
|
-
* Half-period in milliseconds used for cursor blinking.
|
|
494
|
-
* By setting this to zero, blinking can be disabled.
|
|
495
|
-
* A negative value hides the cursor entirely.
|
|
496
|
-
*/
|
|
497
|
-
cursorBlinkRate: number;
|
|
498
|
-
/**
|
|
499
|
-
* User preferred font family for text editors.
|
|
500
|
-
*/
|
|
501
|
-
fontFamily: string | null;
|
|
502
|
-
/**
|
|
503
|
-
* User preferred size in pixel of the font used in text editors.
|
|
504
|
-
*/
|
|
505
|
-
fontSize: number | null;
|
|
506
|
-
/**
|
|
507
|
-
* User preferred text line height, as a multiplier of font size.
|
|
508
|
-
*/
|
|
509
|
-
lineHeight: number | null;
|
|
510
|
-
/**
|
|
511
|
-
* Whether line numbers should be displayed.
|
|
512
|
-
*/
|
|
513
|
-
lineNumbers: boolean;
|
|
514
|
-
/**
|
|
515
|
-
* Control the line wrapping of the editor. Possible values are:
|
|
516
|
-
* - "off", lines will never wrap.
|
|
517
|
-
* - "on", lines will wrap at the viewport border.
|
|
518
|
-
* - "wordWrapColumn", lines will wrap at `wordWrapColumn`.
|
|
519
|
-
* - "bounded", lines will wrap at minimum between viewport width and wordWrapColumn.
|
|
520
|
-
*/
|
|
521
|
-
lineWrap: 'off' | 'on' | 'wordWrapColumn' | 'bounded';
|
|
522
|
-
/**
|
|
523
|
-
* Whether the editor is read-only.
|
|
524
|
-
*/
|
|
525
|
-
readOnly: boolean;
|
|
526
|
-
/**
|
|
527
|
-
* The number of spaces a tab is equal to.
|
|
528
|
-
*/
|
|
529
|
-
tabSize: number;
|
|
530
|
-
/**
|
|
531
|
-
* Whether to insert spaces when pressing Tab.
|
|
532
|
-
*/
|
|
533
|
-
insertSpaces: boolean;
|
|
534
|
-
/**
|
|
535
|
-
* Whether to highlight matching brackets when one of them is selected.
|
|
536
|
-
*/
|
|
537
|
-
matchBrackets: boolean;
|
|
538
|
-
/**
|
|
539
|
-
* Whether to automatically close brackets after opening them.
|
|
540
|
-
*/
|
|
541
|
-
autoClosingBrackets: boolean;
|
|
542
|
-
/**
|
|
543
|
-
* Whether the editor should handle paste events.
|
|
544
|
-
*/
|
|
545
|
-
handlePaste?: boolean;
|
|
546
|
-
/**
|
|
547
|
-
* The column where to break text line.
|
|
548
|
-
*/
|
|
549
|
-
wordWrapColumn: number;
|
|
550
|
-
/**
|
|
551
|
-
* Column index at which rulers should be added.
|
|
552
|
-
*/
|
|
553
|
-
rulers: Array<number>;
|
|
554
|
-
/**
|
|
555
|
-
* Whether to allow code folding
|
|
556
|
-
*/
|
|
557
|
-
codeFolding: boolean;
|
|
558
|
-
/**
|
|
559
|
-
* Whether to highlight trailing whitespace
|
|
560
|
-
*/
|
|
561
|
-
showTrailingSpace: boolean;
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* The default configuration options for an editor.
|
|
565
|
-
*/
|
|
566
|
-
const defaultConfig: IConfig;
|
|
567
399
|
/**
|
|
568
400
|
* The options used to initialize an editor.
|
|
569
401
|
*/
|
|
@@ -577,21 +409,25 @@ export declare namespace CodeEditor {
|
|
|
577
409
|
*/
|
|
578
410
|
model: IModel;
|
|
579
411
|
/**
|
|
580
|
-
* The
|
|
412
|
+
* The configuration options for the editor.
|
|
581
413
|
*/
|
|
582
|
-
|
|
414
|
+
config?: Record<string, any>;
|
|
583
415
|
/**
|
|
584
|
-
*
|
|
416
|
+
* List of editor extensions to be added.
|
|
585
417
|
*/
|
|
586
|
-
|
|
418
|
+
extensions?: Extension[];
|
|
587
419
|
/**
|
|
588
|
-
*
|
|
420
|
+
* Whether the editor will be inline or not.
|
|
589
421
|
*/
|
|
590
|
-
|
|
422
|
+
inline?: boolean;
|
|
591
423
|
/**
|
|
592
424
|
* The configuration options for the editor.
|
|
593
425
|
*/
|
|
594
426
|
translator?: ITranslator;
|
|
427
|
+
/**
|
|
428
|
+
* The desired uuid for the editor.
|
|
429
|
+
*/
|
|
430
|
+
uuid?: string;
|
|
595
431
|
}
|
|
596
432
|
namespace Model {
|
|
597
433
|
interface IOptions {
|
|
@@ -599,18 +435,14 @@ export declare namespace CodeEditor {
|
|
|
599
435
|
* A unique identifier for the model.
|
|
600
436
|
*/
|
|
601
437
|
id?: string;
|
|
602
|
-
/**
|
|
603
|
-
* The initial value of the model.
|
|
604
|
-
*/
|
|
605
|
-
value?: string;
|
|
606
438
|
/**
|
|
607
439
|
* The mimetype of the model.
|
|
608
440
|
*/
|
|
609
441
|
mimeType?: string;
|
|
610
442
|
/**
|
|
611
|
-
*
|
|
443
|
+
* Shared editor text.
|
|
612
444
|
*/
|
|
613
|
-
|
|
445
|
+
sharedModel?: ISharedText;
|
|
614
446
|
}
|
|
615
447
|
}
|
|
616
448
|
}
|
package/lib/editor.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { YFile } from '@jupyter/ydoc';
|
|
4
|
+
import { ObservableMap } from '@jupyterlab/observables';
|
|
5
5
|
import { Signal } from '@lumino/signaling';
|
|
6
|
-
const globalModelDBMutex = models.createMutex();
|
|
7
6
|
/**
|
|
8
7
|
* A namespace for code editors.
|
|
9
8
|
*
|
|
@@ -14,14 +13,6 @@ const globalModelDBMutex = models.createMutex();
|
|
|
14
13
|
*/
|
|
15
14
|
export var CodeEditor;
|
|
16
15
|
(function (CodeEditor) {
|
|
17
|
-
/**
|
|
18
|
-
* The default selection style.
|
|
19
|
-
*/
|
|
20
|
-
CodeEditor.defaultSelectionStyle = {
|
|
21
|
-
className: '',
|
|
22
|
-
displayName: '',
|
|
23
|
-
color: 'black'
|
|
24
|
-
};
|
|
25
16
|
/**
|
|
26
17
|
* The default implementation of the editor model.
|
|
27
18
|
*/
|
|
@@ -29,94 +20,20 @@ export var CodeEditor;
|
|
|
29
20
|
/**
|
|
30
21
|
* Construct a new Model.
|
|
31
22
|
*/
|
|
32
|
-
constructor(options) {
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the model should disposed the shared model on disposal or not.
|
|
27
|
+
*/
|
|
28
|
+
this.standaloneModel = false;
|
|
33
29
|
this._isDisposed = false;
|
|
30
|
+
this._selections = new ObservableMap();
|
|
31
|
+
this._mimeType = 'text/plain';
|
|
34
32
|
this._mimeTypeChanged = new Signal(this);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.modelDB = new ModelDB();
|
|
42
|
-
}
|
|
43
|
-
this.sharedModel = models.createStandaloneCell(this.type, options.id);
|
|
44
|
-
this.sharedModel.changed.connect(this._onSharedModelChanged, this);
|
|
45
|
-
const value = this.modelDB.createString('value');
|
|
46
|
-
value.changed.connect(this._onModelDBValueChanged, this);
|
|
47
|
-
value.text = value.text || options.value || '';
|
|
48
|
-
const mimeType = this.modelDB.createValue('mimeType');
|
|
49
|
-
mimeType.changed.connect(this._onModelDBMimeTypeChanged, this);
|
|
50
|
-
mimeType.set(options.mimeType || 'text/plain');
|
|
51
|
-
this.modelDB.createMap('selections');
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* When we initialize a cell model, we create a standalone model that cannot be shared in a YNotebook.
|
|
55
|
-
* Call this function to re-initialize the local representation based on a fresh shared model (e.g. models.YFile or models.YCodeCell).
|
|
56
|
-
*
|
|
57
|
-
* @param sharedModel
|
|
58
|
-
* @param reinitialize Whether to reinitialize the shared model.
|
|
59
|
-
*/
|
|
60
|
-
switchSharedModel(sharedModel, reinitialize) {
|
|
61
|
-
if (reinitialize) {
|
|
62
|
-
// update local modeldb
|
|
63
|
-
// @todo also change metadata
|
|
64
|
-
this.value.text = sharedModel.getSource();
|
|
65
|
-
}
|
|
66
|
-
this.sharedModel.changed.disconnect(this._onSharedModelChanged, this);
|
|
67
|
-
// clone model retrieve a shared (not standalone) model
|
|
68
|
-
this.sharedModel = sharedModel;
|
|
69
|
-
this.sharedModel.changed.connect(this._onSharedModelChanged, this);
|
|
70
|
-
this._sharedModelSwitched.emit(true);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* We update the modeldb store when the shared model changes.
|
|
74
|
-
* To ensure that we don't run into infinite loops, we wrap this call in a "mutex".
|
|
75
|
-
* The "mutex" ensures that the wrapped code can only be executed by either the sharedModelChanged handler
|
|
76
|
-
* or the modelDB change handler.
|
|
77
|
-
*/
|
|
78
|
-
_onSharedModelChanged(sender, change) {
|
|
79
|
-
globalModelDBMutex(() => {
|
|
80
|
-
if (change.sourceChange) {
|
|
81
|
-
const value = this.modelDB.get('value');
|
|
82
|
-
let currpos = 0;
|
|
83
|
-
change.sourceChange.forEach(delta => {
|
|
84
|
-
if (delta.insert != null) {
|
|
85
|
-
value.insert(currpos, delta.insert);
|
|
86
|
-
currpos += delta.insert.length;
|
|
87
|
-
}
|
|
88
|
-
else if (delta.delete != null) {
|
|
89
|
-
value.remove(currpos, currpos + delta.delete);
|
|
90
|
-
}
|
|
91
|
-
else if (delta.retain != null) {
|
|
92
|
-
currpos += delta.retain;
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Handle a change to the modelDB value.
|
|
100
|
-
*/
|
|
101
|
-
_onModelDBValueChanged(value, event) {
|
|
102
|
-
globalModelDBMutex(() => {
|
|
103
|
-
this.sharedModel.transact(() => {
|
|
104
|
-
switch (event.type) {
|
|
105
|
-
case 'insert':
|
|
106
|
-
this.sharedModel.updateSource(event.start, event.start, event.value);
|
|
107
|
-
break;
|
|
108
|
-
case 'remove':
|
|
109
|
-
this.sharedModel.updateSource(event.start, event.end);
|
|
110
|
-
break;
|
|
111
|
-
default:
|
|
112
|
-
this.sharedModel.setSource(value.text);
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
get type() {
|
|
119
|
-
return 'code';
|
|
33
|
+
// Track if we need to dispose the model or not.
|
|
34
|
+
this.standaloneModel = typeof options.sharedModel === 'undefined';
|
|
35
|
+
this.sharedModel = (_a = options.sharedModel) !== null && _a !== void 0 ? _a : new YFile();
|
|
36
|
+
this._mimeType = (_b = options.mimeType) !== null && _b !== void 0 ? _b : 'text/plain';
|
|
120
37
|
}
|
|
121
38
|
/**
|
|
122
39
|
* A signal emitted when a mimetype changes.
|
|
@@ -124,36 +41,29 @@ export var CodeEditor;
|
|
|
124
41
|
get mimeTypeChanged() {
|
|
125
42
|
return this._mimeTypeChanged;
|
|
126
43
|
}
|
|
127
|
-
/**
|
|
128
|
-
* A signal emitted when the shared model was switched.
|
|
129
|
-
*/
|
|
130
|
-
get sharedModelSwitched() {
|
|
131
|
-
return this._sharedModelSwitched;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Get the value of the model.
|
|
135
|
-
*/
|
|
136
|
-
get value() {
|
|
137
|
-
return this.modelDB.get('value');
|
|
138
|
-
}
|
|
139
44
|
/**
|
|
140
45
|
* Get the selections for the model.
|
|
141
46
|
*/
|
|
142
47
|
get selections() {
|
|
143
|
-
return this.
|
|
48
|
+
return this._selections;
|
|
144
49
|
}
|
|
145
50
|
/**
|
|
146
51
|
* A mime type of the model.
|
|
147
52
|
*/
|
|
148
53
|
get mimeType() {
|
|
149
|
-
return this.
|
|
54
|
+
return this._mimeType;
|
|
150
55
|
}
|
|
151
56
|
set mimeType(newValue) {
|
|
152
57
|
const oldValue = this.mimeType;
|
|
153
58
|
if (oldValue === newValue) {
|
|
154
59
|
return;
|
|
155
60
|
}
|
|
156
|
-
this.
|
|
61
|
+
this._mimeType = newValue;
|
|
62
|
+
this._mimeTypeChanged.emit({
|
|
63
|
+
name: 'mimeType',
|
|
64
|
+
oldValue: oldValue,
|
|
65
|
+
newValue: newValue
|
|
66
|
+
});
|
|
157
67
|
}
|
|
158
68
|
/**
|
|
159
69
|
* Whether the model is disposed.
|
|
@@ -169,37 +79,13 @@ export var CodeEditor;
|
|
|
169
79
|
return;
|
|
170
80
|
}
|
|
171
81
|
this._isDisposed = true;
|
|
82
|
+
this._selections.dispose();
|
|
83
|
+
if (this.standaloneModel) {
|
|
84
|
+
this.sharedModel.dispose();
|
|
85
|
+
}
|
|
172
86
|
Signal.clearData(this);
|
|
173
87
|
}
|
|
174
|
-
_onModelDBMimeTypeChanged(mimeType, args) {
|
|
175
|
-
this._mimeTypeChanged.emit({
|
|
176
|
-
name: 'mimeType',
|
|
177
|
-
oldValue: args.oldValue,
|
|
178
|
-
newValue: args.newValue
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
88
|
}
|
|
182
89
|
CodeEditor.Model = Model;
|
|
183
|
-
/**
|
|
184
|
-
* The default configuration options for an editor.
|
|
185
|
-
*/
|
|
186
|
-
CodeEditor.defaultConfig = {
|
|
187
|
-
autoClosingBrackets: false,
|
|
188
|
-
codeFolding: false,
|
|
189
|
-
cursorBlinkRate: 530,
|
|
190
|
-
fontFamily: null,
|
|
191
|
-
fontSize: null,
|
|
192
|
-
handlePaste: true,
|
|
193
|
-
insertSpaces: true,
|
|
194
|
-
lineHeight: null,
|
|
195
|
-
lineNumbers: false,
|
|
196
|
-
lineWrap: 'on',
|
|
197
|
-
matchBrackets: true,
|
|
198
|
-
readOnly: false,
|
|
199
|
-
tabSize: 4,
|
|
200
|
-
rulers: [],
|
|
201
|
-
showTrailingSpace: false,
|
|
202
|
-
wordWrapColumn: 80
|
|
203
|
-
};
|
|
204
90
|
})(CodeEditor || (CodeEditor = {}));
|
|
205
91
|
//# sourceMappingURL=editor.js.map
|
package/lib/editor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;
|
|
1
|
+
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAG3D,OAAO,EAAe,KAAK,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAkB,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAIxE,OAAO,EAAW,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,KAAW,UAAU,CA2hB1B;AA3hBD,WAAiB,UAAU;IAsIzB;;OAEG;IACH,MAAa,KAAK;QAChB;;WAEG;QACH,YAAY,UAA0B,EAAE;;YAmExC;;eAEG;YACO,oBAAe,GAAG,KAAK,CAAC;YAE1B,gBAAW,GAAG,KAAK,CAAC;YACpB,gBAAW,GAAG,IAAI,aAAa,EAAoB,CAAC;YACpD,cAAS,GAAG,YAAY,CAAC;YACzB,qBAAgB,GAAG,IAAI,MAAM,CAA6B,IAAI,CAAC,CAAC;YA1EtE,gDAAgD;YAChD,IAAI,CAAC,eAAe,GAAG,OAAO,OAAO,CAAC,WAAW,KAAK,WAAW,CAAC;YAClE,IAAI,CAAC,WAAW,GAAG,MAAA,OAAO,CAAC,WAAW,mCAAI,IAAI,KAAK,EAAE,CAAC;YACtD,IAAI,CAAC,SAAS,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,YAAY,CAAC;QACpD,CAAC;QAOD;;WAEG;QACH,IAAI,eAAe;YACjB,OAAO,IAAI,CAAC,gBAAgB,CAAC;QAC/B,CAAC;QAED;;WAEG;QACH,IAAI,UAAU;YACZ,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;QAED;;WAEG;QACH,IAAI,QAAQ;YACV,OAAO,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC;QACD,IAAI,QAAQ,CAAC,QAAgB;YAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;YAC/B,IAAI,QAAQ,KAAK,QAAQ,EAAE;gBACzB,OAAO;aACR;YACD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;YAC1B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACzB,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,QAAQ;gBAClB,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;QACL,CAAC;QAED;;WAEG;QACH,IAAI,UAAU;YACZ,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;QAED;;WAEG;QACH,OAAO;YACL,IAAI,IAAI,CAAC,WAAW,EAAE;gBACpB,OAAO;aACR;YACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;YAC3B,IAAI,IAAI,CAAC,eAAe,EAAE;gBACxB,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;aAC5B;YACD,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACzB,CAAC;KAWF;IAhFY,gBAAK,QAgFjB,CAAA;AAkUH,CAAC,EA3hBgB,UAAU,KAAV,UAAU,QA2hB1B"}
|
package/lib/factory.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ export interface IEditorFactoryService {
|
|
|
6
6
|
/**
|
|
7
7
|
* Create a new editor for inline code.
|
|
8
8
|
*/
|
|
9
|
-
newInlineEditor
|
|
9
|
+
newInlineEditor: CodeEditor.Factory;
|
|
10
10
|
/**
|
|
11
11
|
* Create a new editor for a full document.
|
|
12
12
|
*/
|
|
13
|
-
newDocumentEditor
|
|
13
|
+
newDocumentEditor: CodeEditor.Factory;
|
|
14
14
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
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,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,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,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|