Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jupyterlab/codemirror

Package Overview
Dependencies
Maintainers
9
Versions
378
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jupyterlab/codemirror - npm Package Compare versions

Comparing version 0.16.3 to 0.17.0-0

17

lib/codemirror-ipython.js
"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var CodeMirror = require("codemirror");
const codemirror_1 = __importDefault(require("codemirror"));
require("codemirror/mode/meta");

@@ -13,5 +16,5 @@ require("codemirror/mode/python/python");

*/
CodeMirror.defineMode('ipython', function (config, modeOptions) {
var pythonConf = {};
for (var prop in modeOptions) {
codemirror_1.default.defineMode('ipython', (config, modeOptions) => {
let pythonConf = {};
for (let prop in modeOptions) {
if (modeOptions.hasOwnProperty(prop)) {

@@ -24,6 +27,6 @@ pythonConf[prop] = modeOptions[prop];

pythonConf.identifiers = new RegExp('^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*');
return CodeMirror.getMode(config, pythonConf);
return codemirror_1.default.getMode(config, pythonConf);
}, 'python');
CodeMirror.defineMIME('text/x-ipython', 'ipython');
CodeMirror.modeInfo.push({
codemirror_1.default.defineMIME('text/x-ipython', 'ipython');
codemirror_1.default.modeInfo.push({
ext: [],

@@ -30,0 +33,0 @@ mime: 'text/x-ipython',

"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var CodeMirror = require("codemirror");
const codemirror_1 = __importDefault(require("codemirror"));
require("codemirror/mode/stex/stex");

@@ -18,6 +21,6 @@ require("codemirror/mode/gfm/gfm");

*/
CodeMirror.defineMode('ipythongfm', function (config, modeOptions) {
var gfmMode = CodeMirror.getMode(config, 'gfm');
var texMode = CodeMirror.getMode(config, 'stex');
return CodeMirror.multiplexingMode(gfmMode, {
codemirror_1.default.defineMode('ipythongfm', (config, modeOptions) => {
let gfmMode = codemirror_1.default.getMode(config, 'gfm');
let texMode = codemirror_1.default.getMode(config, { name: 'stex', inMathMode: true });
return codemirror_1.default.multiplexingMode(gfmMode, {
open: '$$', close: '$$',

@@ -42,4 +45,4 @@ mode: texMode,

}, 'gfm');
CodeMirror.defineMIME('text/x-ipythongfm', 'ipythongfm');
CodeMirror.modeInfo.push({
codemirror_1.default.defineMIME('text/x-ipythongfm', 'ipythongfm');
codemirror_1.default.modeInfo.push({
ext: [],

@@ -46,0 +49,0 @@ mime: 'text/x-ipythongfm',

@@ -1,2 +0,2 @@

import * as CodeMirror from 'codemirror';
import CodeMirror from 'codemirror';
import { IDisposable } from '@phosphor/disposable';

@@ -200,55 +200,55 @@ import { Signal } from '@phosphor/signaling';

*/
private _toCodeMirrorSelections(selections);
private _toCodeMirrorSelections;
/**
* Handles a mime type change.
*/
private _onMimeTypeChanged();
private _onMimeTypeChanged;
/**
* Handles a selections change.
*/
private _onSelectionsChanged(selections, args);
private _onSelectionsChanged;
/**
* Clean selections for the given uuid.
*/
private _cleanSelections(uuid);
private _cleanSelections;
/**
* Marks selections.
*/
private _markSelections(uuid, selections);
private _markSelections;
/**
* Handles a cursor activity event.
*/
private _onCursorActivity();
private _onCursorActivity;
/**
* Converts a code mirror selection to an editor selection.
*/
private _toSelection(selection);
private _toSelection;
/**
* Converts the selection style to a text marker options.
*/
private _toTextMarkerOptions(style);
private _toTextMarkerOptions;
/**
* Converts an editor selection to a code mirror selection.
*/
private _toCodeMirrorSelection(selection);
private _toCodeMirrorSelection;
/**
* Converts an editor selection to a code mirror selection.
*/
private _toCodeMirrorRange(range);
private _toCodeMirrorRange;
/**
* Convert a code mirror position to an editor position.
*/
private _toPosition(position);
private _toPosition;
/**
* Convert an editor position to a code mirror position.
*/
private _toCodeMirrorPosition(position);
private _toCodeMirrorPosition;
/**
* Handle model value changes.
*/
private _onValueChanged(value, args);
private _onValueChanged;
/**
* Handles document changes.
*/
private _beforeDocChanged(doc, change);
private _beforeDocChanged;
/**

@@ -268,11 +268,11 @@ * Handle the DOM events for the editor.

*/
private _evtFocus(event);
private _evtFocus;
/**
* Handle `blur` events for the editor.
*/
private _evtBlur(event);
private _evtBlur;
/**
* Handle `scroll` events for the editor.
*/
private _evtScroll();
private _evtScroll;
/**

@@ -283,3 +283,3 @@ * Clear the hover for a caret, due to things like

*/
private _clearHover();
private _clearHover;
/**

@@ -289,7 +289,7 @@ * Construct a caret element representing the position

*/
private _getCaret(collaborator);
private _getCaret;
/**
* Check for an out of sync editor.
*/
private _checkSync();
private _checkSync;
private _model;

@@ -301,2 +301,3 @@ private _editor;

private _caretHover;
private readonly _config;
private _hoverTimeout;

@@ -373,3 +374,3 @@ private _hoverId;

*/
gutters?: ReadonlyArray<string>;
gutters?: string[];
/**

@@ -376,0 +377,0 @@ * Determines whether the gutter scrolls along with the content

"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var CodeMirror = require("codemirror");
var coreutils_1 = require("@phosphor/coreutils");
var algorithm_1 = require("@phosphor/algorithm");
var disposable_1 = require("@phosphor/disposable");
var signaling_1 = require("@phosphor/signaling");
var apputils_1 = require("@jupyterlab/apputils");
var codeeditor_1 = require("@jupyterlab/codeeditor");
var coreutils_2 = require("@jupyterlab/coreutils");
var mode_1 = require("./mode");
const codemirror_1 = __importDefault(require("codemirror"));
const coreutils_1 = require("@phosphor/coreutils");
const algorithm_1 = require("@phosphor/algorithm");
const disposable_1 = require("@phosphor/disposable");
const signaling_1 = require("@phosphor/signaling");
const apputils_1 = require("@jupyterlab/apputils");
const codeeditor_1 = require("@jupyterlab/codeeditor");
const coreutils_2 = require("@jupyterlab/coreutils");
const mode_1 = require("./mode");
require("codemirror/addon/comment/comment.js");

@@ -34,36 +38,35 @@ require("codemirror/addon/edit/matchbrackets.js");

*/
var EDITOR_CLASS = 'jp-CodeMirrorEditor';
const EDITOR_CLASS = 'jp-CodeMirrorEditor';
/**
* The class name added to read only cell editor widgets.
*/
var READ_ONLY_CLASS = 'jp-mod-readOnly';
const READ_ONLY_CLASS = 'jp-mod-readOnly';
/**
* The class name for the hover box for collaborator cursors.
*/
var COLLABORATOR_CURSOR_CLASS = 'jp-CollaboratorCursor';
const COLLABORATOR_CURSOR_CLASS = 'jp-CollaboratorCursor';
/**
* The class name for the hover box for collaborator cursors.
*/
var COLLABORATOR_HOVER_CLASS = 'jp-CollaboratorCursor-hover';
const COLLABORATOR_HOVER_CLASS = 'jp-CollaboratorCursor-hover';
/**
* The key code for the up arrow key.
*/
var UP_ARROW = 38;
const UP_ARROW = 38;
/**
* The key code for the down arrow key.
*/
var DOWN_ARROW = 40;
const DOWN_ARROW = 40;
/**
* The time that a collaborator name hover persists.
*/
var HOVER_TIMEOUT = 1000;
const HOVER_TIMEOUT = 1000;
/**
* CodeMirror editor.
*/
var CodeMirrorEditor = /** @class */ (function () {
class CodeMirrorEditor {
/**
* Construct a CodeMirror editor.
*/
function CodeMirrorEditor(options) {
var _this = this;
constructor(options) {
/**

@@ -81,3 +84,3 @@ * A signal emitted when either the top or bottom edge is requested.

this._timer = -1;
var host = this.host = options.host;
let host = this.host = options.host;
host.classList.add(EDITOR_CLASS);

@@ -90,13 +93,15 @@ host.classList.add('jp-Editor');

// Handle selection style.
var style = options.selectionStyle || {};
this._selectionStyle = __assign({}, codeeditor_1.CodeEditor.defaultSelectionStyle, style);
var model = this._model = options.model;
var editor = this._editor = CodeMirror(host, {});
Private.handleConfig(editor, options.config || {});
var doc = editor.getDoc();
let style = options.selectionStyle || {};
this._selectionStyle = Object.assign({}, codeeditor_1.CodeEditor.defaultSelectionStyle, style);
let model = this._model = options.model;
let config = options.config || {};
let fullConfig = this._config = Object.assign({}, CodeMirrorEditor.defaultConfig, config);
let editor = this._editor = Private.createEditor(host, fullConfig);
let doc = editor.getDoc();
// Handle initial values for text, mimetype, and selections.
doc.setValue(model.value.text);
this.clearHistory();
this._onMimeTypeChanged();
this._onCursorActivity();
this._timer = window.setInterval(function () { _this._checkSync(); }, 3000);
this._timer = window.setInterval(() => { this._checkSync(); }, 3000);
// Connect to changes.

@@ -106,5 +111,5 @@ model.value.changed.connect(this._onValueChanged, this);

model.selections.changed.connect(this._onSelectionsChanged, this);
CodeMirror.on(editor, 'keydown', function (editor, event) {
var index = algorithm_1.ArrayExt.findFirstIndex(_this._keydownHandlers, function (handler) {
if (handler(_this, event) === true) {
codemirror_1.default.on(editor, 'keydown', (editor, event) => {
let index = algorithm_1.ArrayExt.findFirstIndex(this._keydownHandlers, handler => {
if (handler(this, event) === true) {
event.preventDefault();

@@ -116,123 +121,87 @@ return true;

if (index === -1) {
_this.onKeydown(event);
this.onKeydown(event);
}
});
CodeMirror.on(editor, 'cursorActivity', function () { return _this._onCursorActivity(); });
CodeMirror.on(editor.getDoc(), 'beforeChange', function (instance, change) {
_this._beforeDocChanged(instance, change);
codemirror_1.default.on(editor, 'cursorActivity', () => this._onCursorActivity());
codemirror_1.default.on(editor.getDoc(), 'beforeChange', (instance, change) => {
this._beforeDocChanged(instance, change);
});
CodeMirror.on(editor.getDoc(), 'change', function (instance, change) {
codemirror_1.default.on(editor.getDoc(), 'change', (instance, change) => {
// Manually refresh after setValue to make sure editor is properly sized.
if (change.origin === 'setValue' && _this.hasFocus()) {
_this.refresh();
if (change.origin === 'setValue' && this.hasFocus()) {
this.refresh();
}
_this._lastChange = change;
this._lastChange = change;
});
// Manually refresh on paste to make sure editor is properly sized.
editor.getWrapperElement().addEventListener('paste', function () {
if (_this.hasFocus()) {
_this.refresh();
editor.getWrapperElement().addEventListener('paste', () => {
if (this.hasFocus()) {
this.refresh();
}
});
}
Object.defineProperty(CodeMirrorEditor.prototype, "uuid", {
/**
* The uuid of this editor;
*/
get: function () {
return this._uuid;
},
set: function (value) {
this._uuid = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CodeMirrorEditor.prototype, "selectionStyle", {
/**
* The selection style of this editor.
*/
get: function () {
return this._selectionStyle;
},
set: function (value) {
this._selectionStyle = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CodeMirrorEditor.prototype, "editor", {
/**
* Get the codemirror editor wrapped by the editor.
*/
get: function () {
return this._editor;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CodeMirrorEditor.prototype, "doc", {
/**
* Get the codemirror doc wrapped by the widget.
*/
get: function () {
return this._editor.getDoc();
},
enumerable: true,
configurable: true
});
Object.defineProperty(CodeMirrorEditor.prototype, "lineCount", {
/**
* Get the number of lines in the editor.
*/
get: function () {
return this.doc.lineCount();
},
enumerable: true,
configurable: true
});
Object.defineProperty(CodeMirrorEditor.prototype, "model", {
/**
* Returns a model for this editor.
*/
get: function () {
return this._model;
},
enumerable: true,
configurable: true
});
Object.defineProperty(CodeMirrorEditor.prototype, "lineHeight", {
/**
* The height of a line in the editor in pixels.
*/
get: function () {
return this._editor.defaultTextHeight();
},
enumerable: true,
configurable: true
});
Object.defineProperty(CodeMirrorEditor.prototype, "charWidth", {
/**
* The widget of a character in the editor in pixels.
*/
get: function () {
return this._editor.defaultCharWidth();
},
enumerable: true,
configurable: true
});
Object.defineProperty(CodeMirrorEditor.prototype, "isDisposed", {
/**
* Tests whether the editor is disposed.
*/
get: function () {
return this._isDisposed;
},
enumerable: true,
configurable: true
});
/**
* The uuid of this editor;
*/
get uuid() {
return this._uuid;
}
set uuid(value) {
this._uuid = value;
}
/**
* The selection style of this editor.
*/
get selectionStyle() {
return this._selectionStyle;
}
set selectionStyle(value) {
this._selectionStyle = value;
}
/**
* Get the codemirror editor wrapped by the editor.
*/
get editor() {
return this._editor;
}
/**
* Get the codemirror doc wrapped by the widget.
*/
get doc() {
return this._editor.getDoc();
}
/**
* Get the number of lines in the editor.
*/
get lineCount() {
return this.doc.lineCount();
}
/**
* Returns a model for this editor.
*/
get model() {
return this._model;
}
/**
* The height of a line in the editor in pixels.
*/
get lineHeight() {
return this._editor.defaultTextHeight();
}
/**
* The widget of a character in the editor in pixels.
*/
get charWidth() {
return this._editor.defaultCharWidth();
}
/**
* Tests whether the editor is disposed.
*/
get isDisposed() {
return this._isDisposed;
}
/**
* Dispose of the resources held by the widget.
*/
CodeMirrorEditor.prototype.dispose = function () {
dispose() {
if (this.isDisposed) {

@@ -248,25 +217,29 @@ return;

signaling_1.Signal.clearData(this);
};
}
/**
* Get a config option for the editor.
*/
CodeMirrorEditor.prototype.getOption = function (option) {
return Private.getOption(this.editor, option);
};
getOption(option) {
return this._config[option];
}
/**
* Set a config option for the editor.
*/
CodeMirrorEditor.prototype.setOption = function (option, value) {
Private.setOption(this.editor, option, value);
};
setOption(option, value) {
// Don't bother setting the option if it is already the same.
if (this._config[option] !== value) {
this._config[option] = value;
Private.setOption(this.editor, option, value);
}
}
/**
* Returns the content for the given line number.
*/
CodeMirrorEditor.prototype.getLine = function (line) {
getLine(line) {
return this.doc.getLine(line);
};
}
/**
* Find an offset for the given position.
*/
CodeMirrorEditor.prototype.getOffsetAt = function (position) {
getOffsetAt(position) {
return this.doc.indexFromPos({

@@ -276,53 +249,53 @@ ch: position.column,

});
};
}
/**
* Find a position fot the given offset.
*/
CodeMirrorEditor.prototype.getPositionAt = function (offset) {
var _a = this.doc.posFromIndex(offset), ch = _a.ch, line = _a.line;
return { line: line, column: ch };
};
getPositionAt(offset) {
const { ch, line } = this.doc.posFromIndex(offset);
return { line, column: ch };
}
/**
* Undo one edit (if any undo events are stored).
*/
CodeMirrorEditor.prototype.undo = function () {
undo() {
this.doc.undo();
};
}
/**
* Redo one undone edit.
*/
CodeMirrorEditor.prototype.redo = function () {
redo() {
this.doc.redo();
};
}
/**
* Clear the undo history.
*/
CodeMirrorEditor.prototype.clearHistory = function () {
clearHistory() {
this.doc.clearHistory();
};
}
/**
* Brings browser focus to this editor text.
*/
CodeMirrorEditor.prototype.focus = function () {
focus() {
this._editor.focus();
};
}
/**
* Test whether the editor has keyboard focus.
*/
CodeMirrorEditor.prototype.hasFocus = function () {
hasFocus() {
return this._editor.getWrapperElement().contains(document.activeElement);
};
}
/**
* Explicitly blur the editor.
*/
CodeMirrorEditor.prototype.blur = function () {
blur() {
this._editor.getInputField().blur();
};
}
/**
* Repaint editor.
*/
CodeMirrorEditor.prototype.refresh = function () {
refresh() {
this._editor.refresh();
this._needsRefresh = false;
};
}
/**

@@ -332,3 +305,3 @@ * Refresh the editor if it is focused;

*/
CodeMirrorEditor.prototype.resizeToFit = function () {
resizeToFit() {
if (this.hasFocus()) {

@@ -341,3 +314,3 @@ this.refresh();

this._clearHover();
};
}
/**

@@ -350,13 +323,12 @@ * Add a keydown handler to the editor.

*/
CodeMirrorEditor.prototype.addKeydownHandler = function (handler) {
var _this = this;
addKeydownHandler(handler) {
this._keydownHandlers.push(handler);
return new disposable_1.DisposableDelegate(function () {
algorithm_1.ArrayExt.removeAllWhere(_this._keydownHandlers, function (val) { return val === handler; });
return new disposable_1.DisposableDelegate(() => {
algorithm_1.ArrayExt.removeAllWhere(this._keydownHandlers, val => val === handler);
});
};
}
/**
* Set the size of the editor in pixels.
*/
CodeMirrorEditor.prototype.setSize = function (dimension) {
setSize(dimension) {
if (dimension) {

@@ -369,25 +341,25 @@ this._editor.setSize(dimension.width, dimension.height);

this._needsRefresh = false;
};
}
/**
* Reveal the given position in the editor.
*/
CodeMirrorEditor.prototype.revealPosition = function (position) {
var cmPosition = this._toCodeMirrorPosition(position);
revealPosition(position) {
const cmPosition = this._toCodeMirrorPosition(position);
this._editor.scrollIntoView(cmPosition);
};
}
/**
* Reveal the given selection in the editor.
*/
CodeMirrorEditor.prototype.revealSelection = function (selection) {
var range = this._toCodeMirrorRange(selection);
revealSelection(selection) {
const range = this._toCodeMirrorRange(selection);
this._editor.scrollIntoView(range);
};
}
/**
* Get the window coordinates given a cursor position.
*/
CodeMirrorEditor.prototype.getCoordinateForPosition = function (position) {
var pos = this._toCodeMirrorPosition(position);
var rect = this.editor.charCoords(pos, 'page');
getCoordinateForPosition(position) {
const pos = this._toCodeMirrorPosition(position);
const rect = this.editor.charCoords(pos, 'page');
return rect;
};
}
/**

@@ -401,12 +373,12 @@ * Get the cursor position given window coordinates.

*/
CodeMirrorEditor.prototype.getPositionForCoordinate = function (coordinate) {
getPositionForCoordinate(coordinate) {
return this._toPosition(this.editor.coordsChar(coordinate)) || null;
};
}
/**
* Returns the primary position of the cursor, never `null`.
*/
CodeMirrorEditor.prototype.getCursorPosition = function () {
var cursor = this.doc.getCursor();
getCursorPosition() {
const cursor = this.doc.getCursor();
return this._toPosition(cursor);
};
}
/**

@@ -418,4 +390,4 @@ * Set the primary position of the cursor.

*/
CodeMirrorEditor.prototype.setCursorPosition = function (position) {
var cursor = this._toCodeMirrorPosition(position);
setCursorPosition(position) {
const cursor = this._toCodeMirrorPosition(position);
this.doc.setCursor(cursor);

@@ -428,28 +400,27 @@ // If the editor does not have focus, this cursor change

}
};
}
/**
* Returns the primary selection, never `null`.
*/
CodeMirrorEditor.prototype.getSelection = function () {
getSelection() {
return this.getSelections()[0];
};
}
/**
* Set the primary selection. This will remove any secondary cursors.
*/
CodeMirrorEditor.prototype.setSelection = function (selection) {
setSelection(selection) {
this.setSelections([selection]);
};
}
/**
* Gets the selections for all the cursors, never `null` or empty.
*/
CodeMirrorEditor.prototype.getSelections = function () {
var _this = this;
var selections = this.doc.listSelections();
getSelections() {
const selections = this.doc.listSelections();
if (selections.length > 0) {
return selections.map(function (selection) { return _this._toSelection(selection); });
return selections.map(selection => this._toSelection(selection));
}
var cursor = this.doc.getCursor();
var selection = this._toSelection({ anchor: cursor, head: cursor });
const cursor = this.doc.getCursor();
const selection = this._toSelection({ anchor: cursor, head: cursor });
return [selection];
};
}
/**

@@ -460,9 +431,9 @@ * Sets the selections for all the cursors, should not be empty.

*/
CodeMirrorEditor.prototype.setSelections = function (selections) {
var cmSelections = this._toCodeMirrorSelections(selections);
setSelections(selections) {
const cmSelections = this._toCodeMirrorSelections(selections);
this.doc.setSelections(cmSelections, 0);
};
CodeMirrorEditor.prototype.newIndentedLine = function () {
}
newIndentedLine() {
this.execCommand('newlineAndIndent');
};
}
/**

@@ -473,11 +444,11 @@ * Execute a codemirror command on the editor.

*/
CodeMirrorEditor.prototype.execCommand = function (command) {
execCommand(command) {
this._editor.execCommand(command);
};
}
/**
* Handle keydown events from the editor.
*/
CodeMirrorEditor.prototype.onKeydown = function (event) {
var position = this.getCursorPosition();
var line = position.line, column = position.column;
onKeydown(event) {
let position = this.getCursorPosition();
let { line, column } = position;
if (line === 0 && column === 0 && event.keyCode === UP_ARROW) {

@@ -489,4 +460,4 @@ if (!event.shiftKey) {

}
var lastLine = this.lineCount - 1;
var lastCh = this.getLine(lastLine).length;
let lastLine = this.lineCount - 1;
let lastCh = this.getLine(lastLine).length;
if (line === lastLine && column === lastCh

@@ -500,25 +471,24 @@ && event.keyCode === DOWN_ARROW) {

return false;
};
}
/**
* Converts selections to code mirror selections.
*/
CodeMirrorEditor.prototype._toCodeMirrorSelections = function (selections) {
var _this = this;
_toCodeMirrorSelections(selections) {
if (selections.length > 0) {
return selections.map(function (selection) { return _this._toCodeMirrorSelection(selection); });
return selections.map(selection => this._toCodeMirrorSelection(selection));
}
var position = { line: 0, ch: 0 };
const position = { line: 0, ch: 0 };
return [{ anchor: position, head: position }];
};
}
/**
* Handles a mime type change.
*/
CodeMirrorEditor.prototype._onMimeTypeChanged = function () {
var mime = this._model.mimeType;
var editor = this._editor;
mode_1.Mode.ensure(mime).then(function (spec) {
_onMimeTypeChanged() {
const mime = this._model.mimeType;
let editor = this._editor;
mode_1.Mode.ensure(mime).then(spec => {
editor.setOption('mode', spec.mime);
});
var extraKeys = editor.getOption('extraKeys') || {};
var isCode = (mime !== 'text/plain') && (mime !== 'text/x-ipythongfm');
let extraKeys = editor.getOption('extraKeys') || {};
const isCode = (mime !== 'text/plain') && (mime !== 'text/x-ipythongfm');
if (isCode) {

@@ -531,8 +501,8 @@ extraKeys['Backspace'] = 'delSpaceToPrevTabStop';

editor.setOption('extraKeys', extraKeys);
};
}
/**
* Handles a selections change.
*/
CodeMirrorEditor.prototype._onSelectionsChanged = function (selections, args) {
var uuid = args.key;
_onSelectionsChanged(selections, args) {
const uuid = args.key;
if (uuid !== this.uuid) {

@@ -544,19 +514,18 @@ this._cleanSelections(uuid);

}
};
}
/**
* Clean selections for the given uuid.
*/
CodeMirrorEditor.prototype._cleanSelections = function (uuid) {
var markers = this.selectionMarkers[uuid];
_cleanSelections(uuid) {
const markers = this.selectionMarkers[uuid];
if (markers) {
markers.forEach(function (marker) { marker.clear(); });
markers.forEach(marker => { marker.clear(); });
}
delete this.selectionMarkers[uuid];
};
}
/**
* Marks selections.
*/
CodeMirrorEditor.prototype._markSelections = function (uuid, selections) {
var _this = this;
var markers = [];
_markSelections(uuid, selections) {
const markers = [];
// If we are marking selections corresponding to an active hover,

@@ -569,3 +538,3 @@ // remove it.

// use that information.
var collaborator;
let collaborator;
if (this._model.modelDB.collaborators) {

@@ -575,38 +544,38 @@ collaborator = this._model.modelDB.collaborators.get(uuid);

// Style each selection for the uuid.
selections.forEach(function (selection) {
selections.forEach(selection => {
// Only render selections if the start is not equal to the end.
// In that case, we don't need to render the cursor.
if (!coreutils_1.JSONExt.deepEqual(selection.start, selection.end)) {
var _a = _this._toCodeMirrorSelection(selection), anchor = _a.anchor, head = _a.head;
var markerOptions = void 0;
const { anchor, head } = this._toCodeMirrorSelection(selection);
let markerOptions;
if (collaborator) {
markerOptions = _this._toTextMarkerOptions(__assign({}, selection.style, { color: collaborator.color }));
markerOptions = this._toTextMarkerOptions(Object.assign({}, selection.style, { color: collaborator.color }));
}
else {
markerOptions = _this._toTextMarkerOptions(selection.style);
markerOptions = this._toTextMarkerOptions(selection.style);
}
markers.push(_this.doc.markText(anchor, head, markerOptions));
markers.push(this.doc.markText(anchor, head, markerOptions));
}
else if (collaborator) {
var caret = _this._getCaret(collaborator);
markers.push(_this.doc.setBookmark(_this._toCodeMirrorPosition(selection.end), { widget: caret }));
let caret = this._getCaret(collaborator);
markers.push(this.doc.setBookmark(this._toCodeMirrorPosition(selection.end), { widget: caret }));
}
});
this.selectionMarkers[uuid] = markers;
};
}
/**
* Handles a cursor activity event.
*/
CodeMirrorEditor.prototype._onCursorActivity = function () {
_onCursorActivity() {
// Only add selections if the editor has focus. This avoids unwanted
// triggering of cursor activity due to collaborator actions.
if (this._editor.hasFocus()) {
var selections = this.getSelections();
const selections = this.getSelections();
this.model.selections.set(this.uuid, selections);
}
};
}
/**
* Converts a code mirror selection to an editor selection.
*/
CodeMirrorEditor.prototype._toSelection = function (selection) {
_toSelection(selection) {
return {

@@ -618,29 +587,29 @@ uuid: this.uuid,

};
};
}
/**
* Converts the selection style to a text marker options.
*/
CodeMirrorEditor.prototype._toTextMarkerOptions = function (style) {
var r = parseInt(style.color.slice(1, 3), 16);
var g = parseInt(style.color.slice(3, 5), 16);
var b = parseInt(style.color.slice(5, 7), 16);
var css = "background-color: rgba( " + r + ", " + g + ", " + b + ", 0.15)";
_toTextMarkerOptions(style) {
let r = parseInt(style.color.slice(1, 3), 16);
let g = parseInt(style.color.slice(3, 5), 16);
let b = parseInt(style.color.slice(5, 7), 16);
let css = `background-color: rgba( ${r}, ${g}, ${b}, 0.15)`;
return {
className: style.className,
title: style.displayName,
css: css
css
};
};
}
/**
* Converts an editor selection to a code mirror selection.
*/
CodeMirrorEditor.prototype._toCodeMirrorSelection = function (selection) {
_toCodeMirrorSelection(selection) {
// Selections only appear to render correctly if the anchor
// is before the head in the document. That is, reverse selections
// do not appear as intended.
var forward = (selection.start.line < selection.end.line) ||
let forward = (selection.start.line < selection.end.line) ||
(selection.start.line === selection.end.line &&
selection.start.column <= selection.end.column);
var anchor = forward ? selection.start : selection.end;
var head = forward ? selection.end : selection.start;
let anchor = forward ? selection.start : selection.end;
let head = forward ? selection.end : selection.start;
return {

@@ -650,7 +619,7 @@ anchor: this._toCodeMirrorPosition(anchor),

};
};
}
/**
* Converts an editor selection to a code mirror selection.
*/
CodeMirrorEditor.prototype._toCodeMirrorRange = function (range) {
_toCodeMirrorRange(range) {
return {

@@ -660,7 +629,7 @@ from: this._toCodeMirrorPosition(range.start),

};
};
}
/**
* Convert a code mirror position to an editor position.
*/
CodeMirrorEditor.prototype._toPosition = function (position) {
_toPosition(position) {
return {

@@ -670,7 +639,7 @@ line: position.line,

};
};
}
/**
* Convert an editor position to a code mirror position.
*/
CodeMirrorEditor.prototype._toCodeMirrorPosition = function (position) {
_toCodeMirrorPosition(position) {
return {

@@ -680,7 +649,7 @@ line: position.line,

};
};
}
/**
* Handle model value changes.
*/
CodeMirrorEditor.prototype._onValueChanged = function (value, args) {
_onValueChanged(value, args) {
if (this._changeGuard) {

@@ -690,11 +659,11 @@ return;

this._changeGuard = true;
var doc = this.doc;
let doc = this.doc;
switch (args.type) {
case 'insert':
var pos = doc.posFromIndex(args.start);
let pos = doc.posFromIndex(args.start);
doc.replaceRange(args.value, pos, pos);
break;
case 'remove':
var from = doc.posFromIndex(args.start);
var to = doc.posFromIndex(args.end);
let from = doc.posFromIndex(args.start);
let to = doc.posFromIndex(args.end);
doc.replaceRange('', from, to);

@@ -709,7 +678,7 @@ break;

this._changeGuard = false;
};
}
/**
* Handles document changes.
*/
CodeMirrorEditor.prototype._beforeDocChanged = function (doc, change) {
_beforeDocChanged(doc, change) {
if (this._changeGuard) {

@@ -719,6 +688,6 @@ return;

this._changeGuard = true;
var value = this._model.value;
var start = doc.indexFromPos(change.from);
var end = doc.indexFromPos(change.to);
var inserted = change.text.join('\n');
let value = this._model.value;
let start = doc.indexFromPos(change.from);
let end = doc.indexFromPos(change.to);
let inserted = change.text.join('\n');
if (end !== start) {

@@ -731,3 +700,3 @@ value.remove(start, end);

this._changeGuard = false;
};
}
/**

@@ -743,3 +712,3 @@ * Handle the DOM events for the editor.

*/
CodeMirrorEditor.prototype.handleEvent = function (event) {
handleEvent(event) {
switch (event.type) {

@@ -758,7 +727,7 @@ case 'focus':

}
};
}
/**
* Handle `focus` events for the editor.
*/
CodeMirrorEditor.prototype._evtFocus = function (event) {
_evtFocus(event) {
if (this._needsRefresh) {

@@ -768,16 +737,16 @@ this.refresh();

this.host.classList.add('jp-mod-focused');
};
}
/**
* Handle `blur` events for the editor.
*/
CodeMirrorEditor.prototype._evtBlur = function (event) {
_evtBlur(event) {
this.host.classList.remove('jp-mod-focused');
};
}
/**
* Handle `scroll` events for the editor.
*/
CodeMirrorEditor.prototype._evtScroll = function () {
_evtScroll() {
// Remove any active hover.
this._clearHover();
};
}
/**

@@ -788,3 +757,3 @@ * Clear the hover for a caret, due to things like

*/
CodeMirrorEditor.prototype._clearHover = function () {
_clearHover() {
if (this._caretHover) {

@@ -795,3 +764,3 @@ window.clearTimeout(this._hoverTimeout);

}
};
}
/**

@@ -801,15 +770,14 @@ * Construct a caret element representing the position

*/
CodeMirrorEditor.prototype._getCaret = function (collaborator) {
var _this = this;
var name = collaborator ? collaborator.displayName : 'Anonymous';
var color = collaborator ? collaborator.color : this._selectionStyle.color;
var caret = document.createElement('span');
_getCaret(collaborator) {
let name = collaborator ? collaborator.displayName : 'Anonymous';
let color = collaborator ? collaborator.color : this._selectionStyle.color;
let caret = document.createElement('span');
caret.className = COLLABORATOR_CURSOR_CLASS;
caret.style.borderBottomColor = color;
caret.onmouseenter = function () {
_this._clearHover();
_this._hoverId = collaborator.sessionId;
var rect = caret.getBoundingClientRect();
caret.onmouseenter = () => {
this._clearHover();
this._hoverId = collaborator.sessionId;
let rect = caret.getBoundingClientRect();
// Construct and place the hover box.
var hover = document.createElement('div');
let hover = document.createElement('div');
hover.className = COLLABORATOR_HOVER_CLASS;

@@ -821,25 +789,25 @@ hover.style.left = String(rect.left) + 'px';

// If the user mouses over the hover, take over the timer.
hover.onmouseenter = function () {
window.clearTimeout(_this._hoverTimeout);
hover.onmouseenter = () => {
window.clearTimeout(this._hoverTimeout);
};
hover.onmouseleave = function () {
_this._hoverTimeout = window.setTimeout(function () {
_this._clearHover();
hover.onmouseleave = () => {
this._hoverTimeout = window.setTimeout(() => {
this._clearHover();
}, HOVER_TIMEOUT);
};
_this._caretHover = hover;
this._caretHover = hover;
document.body.appendChild(hover);
};
caret.onmouseleave = function () {
_this._hoverTimeout = window.setTimeout(function () {
_this._clearHover();
caret.onmouseleave = () => {
this._hoverTimeout = window.setTimeout(() => {
this._clearHover();
}, HOVER_TIMEOUT);
};
return caret;
};
}
/**
* Check for an out of sync editor.
*/
CodeMirrorEditor.prototype._checkSync = function () {
var change = this._lastChange;
_checkSync() {
let change = this._lastChange;
if (!change) {

@@ -849,4 +817,4 @@ return;

this._lastChange = null;
var editor = this._editor;
var doc = editor.getDoc();
let editor = this._editor;
let doc = editor.getDoc();
if (doc.getValue() === this._model.value.text) {

@@ -867,7 +835,6 @@ return;

mode: editor.getOption('mode'),
change: change
change
}));
};
return CodeMirrorEditor;
}());
}
}
exports.CodeMirrorEditor = CodeMirrorEditor;

@@ -881,3 +848,3 @@ /**

*/
CodeMirrorEditor.defaultConfig = __assign({}, codeeditor_1.CodeEditor.defaultConfig, { mode: 'null', theme: 'jupyter', smartIndent: true, electricChars: true, keyMap: 'default', extraKeys: null, gutters: Object.freeze([]), fixedGutter: true, showCursorWhenSelecting: false, coverGutterNextToScrollbar: false, dragDrop: true, lineSeparator: null, scrollbarStyle: 'native', lineWiseCopyCut: true, scrollPastEnd: false });
CodeMirrorEditor.defaultConfig = Object.assign({}, codeeditor_1.CodeEditor.defaultConfig, { mode: 'null', theme: 'jupyter', smartIndent: true, electricChars: true, keyMap: 'default', extraKeys: null, gutters: [], fixedGutter: true, showCursorWhenSelecting: false, coverGutterNextToScrollbar: false, dragDrop: true, lineSeparator: null, scrollbarStyle: 'native', lineWiseCopyCut: true, scrollPastEnd: false });
/**

@@ -891,7 +858,6 @@ * Add a command to CodeMirror.

function addCommand(name, command) {
CodeMirror.commands[name] = command;
codemirror_1.default.commands[name] = command;
}
CodeMirrorEditor.addCommand = addCommand;
})(CodeMirrorEditor = exports.CodeMirrorEditor || (exports.CodeMirrorEditor = {}));
exports.CodeMirrorEditor = CodeMirrorEditor;
/**

@@ -902,13 +868,22 @@ * The namespace for module private data.

(function (Private) {
/**
* Handle the codemirror configuration options.
*/
function handleConfig(editor, config) {
var fullConfig = __assign({}, CodeMirrorEditor.defaultConfig, config);
var key;
for (key in fullConfig) {
Private.setOption(editor, key, fullConfig[key]);
}
function createEditor(host, config) {
let { autoClosingBrackets, fontFamily, fontSize, insertSpaces, lineHeight, lineWrap, tabSize, readOnly } = config, otherOptions = __rest(config, ["autoClosingBrackets", "fontFamily", "fontSize", "insertSpaces", "lineHeight", "lineWrap", "tabSize", "readOnly"]);
let bareConfig = Object.assign({ autoCloseBrackets: autoClosingBrackets, indentUnit: tabSize, indentWithTabs: !insertSpaces, lineWrapping: lineWrap, readOnly }, otherOptions);
return codemirror_1.default(el => {
if (fontFamily) {
el.style.fontFamily = fontFamily;
}
if (fontSize) {
el.style.fontSize = fontSize + 'px';
}
if (lineHeight) {
el.style.lineHeight = lineHeight.toString();
}
if (readOnly) {
el.classList.add(READ_ONLY_CLASS);
}
host.appendChild(el);
}, bareConfig);
}
Private.handleConfig = handleConfig;
Private.createEditor = createEditor;
/**

@@ -918,18 +893,18 @@ * Indent or insert a tab as appropriate.

function indentMoreOrinsertTab(cm) {
var doc = cm.getDoc();
var from = doc.getCursor('from');
var to = doc.getCursor('to');
var sel = !posEq(from, to);
let doc = cm.getDoc();
let from = doc.getCursor('from');
let to = doc.getCursor('to');
let sel = !posEq(from, to);
if (sel) {
CodeMirror.commands['indentMore'](cm);
codemirror_1.default.commands['indentMore'](cm);
return;
}
// Check for start of line.
var line = doc.getLine(from.line);
var before = line.slice(0, from.ch);
let line = doc.getLine(from.line);
let before = line.slice(0, from.ch);
if (/^\s*$/.test(before)) {
CodeMirror.commands['indentMore'](cm);
codemirror_1.default.commands['indentMore'](cm);
}
else {
CodeMirror.commands['insertSoftTab'](cm);
codemirror_1.default.commands['insertSoftTab'](cm);
}

@@ -942,20 +917,20 @@ }

function delSpaceToPrevTabStop(cm) {
var doc = cm.getDoc();
var from = doc.getCursor('from');
var to = doc.getCursor('to');
var sel = !posEq(from, to);
let doc = cm.getDoc();
let from = doc.getCursor('from');
let to = doc.getCursor('to');
let sel = !posEq(from, to);
if (sel) {
var ranges = doc.listSelections();
for (var i = ranges.length - 1; i >= 0; i--) {
var head = ranges[i].head;
var anchor = ranges[i].anchor;
doc.replaceRange('', CodeMirror.Pos(head.line, head.ch), CodeMirror.Pos(anchor.line, anchor.ch));
let ranges = doc.listSelections();
for (let i = ranges.length - 1; i >= 0; i--) {
let head = ranges[i].head;
let anchor = ranges[i].anchor;
doc.replaceRange('', codemirror_1.default.Pos(head.line, head.ch), codemirror_1.default.Pos(anchor.line, anchor.ch));
}
return;
}
var cur = doc.getCursor();
var tabsize = cm.getOption('tabSize');
var chToPrevTabStop = cur.ch - (Math.ceil(cur.ch / tabsize) - 1) * tabsize;
let cur = doc.getCursor();
let tabsize = cm.getOption('tabSize');
let chToPrevTabStop = cur.ch - (Math.ceil(cur.ch / tabsize) - 1) * tabsize;
from = { ch: cur.ch - chToPrevTabStop, line: cur.line };
var select = doc.getRange(from, cur);
let select = doc.getRange(from, cur);
if (select.match(/^\ +$/) !== null) {

@@ -965,3 +940,3 @@ doc.replaceRange('', from, cur);

else {
CodeMirror.commands['delCharBefore'](cm);
codemirror_1.default.commands['delCharBefore'](cm);
}

@@ -978,28 +953,6 @@ }

/**
* Get a config option for the editor.
*/
function getOption(editor, option) {
switch (option) {
case 'lineWrap':
return editor.getOption('lineWrapping');
case 'insertSpaces':
return !editor.getOption('indentWithTabs');
case 'tabSize':
return editor.getOption('indentUnit');
case 'autoClosingBrackets':
return editor.getOption('autoCloseBrackets');
default:
return editor.getOption(option);
}
}
Private.getOption = getOption;
/**
* Set a config option for the editor.
*/
function setOption(editor, option, value) {
// Don't bother setting the option if it is already the same.
var oldValue = getOption(editor, option);
if (oldValue === value) {
return;
}
let el = editor.getWrapperElement();
switch (option) {

@@ -1019,6 +972,14 @@ case 'lineWrap':

case 'readOnly':
var el = editor.getWrapperElement();
el.classList.toggle(READ_ONLY_CLASS, value);
editor.setOption(option, value);
break;
case 'fontFamily':
el.style.fontFamily = value;
break;
case 'fontSize':
el.style.fontSize = value ? value + 'px' : null;
break;
case 'lineHeight':
el.style.lineHeight = value ? value.toString() : null;
break;
default:

@@ -1025,0 +986,0 @@ editor.setOption(option, value);

"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var editor_1 = require("./editor");
const editor_1 = require("./editor");
/**
* CodeMirror editor factory.
*/
var CodeMirrorEditorFactory = /** @class */ (function () {
class CodeMirrorEditorFactory {
/**
* Construct an IEditorFactoryService for CodeMirrorEditors.
*/
function CodeMirrorEditorFactory(defaults) {
if (defaults === void 0) { defaults = {}; }
var _this = this;
constructor(defaults = {}) {
/**
* Create a new editor for inline code.
*/
this.newInlineEditor = function (options) {
this.newInlineEditor = (options) => {
options.host.dataset.type = 'inline';
return new editor_1.CodeMirrorEditor(__assign({}, options, { config: __assign({}, _this.inlineCodeMirrorConfig, options.config || {}) }));
return new editor_1.CodeMirrorEditor(Object.assign({}, options, { config: Object.assign({}, this.inlineCodeMirrorConfig, options.config || {}) }));
};

@@ -34,7 +24,7 @@ /**

*/
this.newDocumentEditor = function (options) {
this.newDocumentEditor = (options) => {
options.host.dataset.type = 'document';
return new editor_1.CodeMirrorEditor(__assign({}, options, { config: __assign({}, _this.documentCodeMirrorConfig, options.config || {}) }));
return new editor_1.CodeMirrorEditor(Object.assign({}, options, { config: Object.assign({}, this.documentCodeMirrorConfig, options.config || {}) }));
};
this.inlineCodeMirrorConfig = __assign({}, editor_1.CodeMirrorEditor.defaultConfig, { extraKeys: {
this.inlineCodeMirrorConfig = Object.assign({}, editor_1.CodeMirrorEditor.defaultConfig, { extraKeys: {
'Cmd-Right': 'goLineRight',

@@ -48,10 +38,9 @@ 'End': 'goLineRight',

} }, defaults);
this.documentCodeMirrorConfig = __assign({}, editor_1.CodeMirrorEditor.defaultConfig, { extraKeys: {
this.documentCodeMirrorConfig = Object.assign({}, editor_1.CodeMirrorEditor.defaultConfig, { extraKeys: {
'Tab': 'indentMoreOrinsertTab',
'Shift-Tab': 'indentLess',
'Shift-Enter': function () { }
'Shift-Enter': () => { }
}, lineNumbers: true, scrollPastEnd: true }, defaults);
}
return CodeMirrorEditorFactory;
}());
}
exports.CodeMirrorEditorFactory = CodeMirrorEditorFactory;

@@ -8,4 +8,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var factory_1 = require("./factory");
var mimetype_1 = require("./mimetype");
const factory_1 = require("./factory");
const mimetype_1 = require("./mimetype");
require("../style/index.css");

@@ -12,0 +12,0 @@ __export(require("./mode"));

@@ -5,10 +5,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var coreutils_1 = require("@jupyterlab/coreutils");
var mode_1 = require("./mode");
const coreutils_1 = require("@jupyterlab/coreutils");
const mode_1 = require("./mode");
/**
* The mime type service for CodeMirror.
*/
var CodeMirrorMimeTypeService = /** @class */ (function () {
function CodeMirrorMimeTypeService() {
}
class CodeMirrorMimeTypeService {
/**

@@ -20,4 +18,4 @@ * Returns a mime type for the given language info.

*/
CodeMirrorMimeTypeService.prototype.getMimeTypeByLanguage = function (info) {
var ext = info.file_extension || '';
getMimeTypeByLanguage(info) {
let ext = info.file_extension || '';
return mode_1.Mode.findBest(info.codemirror_mode || {

@@ -28,3 +26,3 @@ mimetype: info.mimetype,

}).mime;
};
}
/**

@@ -36,4 +34,4 @@ * Returns a mime type for the given file path.

*/
CodeMirrorMimeTypeService.prototype.getMimeTypeByFilePath = function (path) {
var ext = coreutils_1.PathExt.extname(path);
getMimeTypeByFilePath(path) {
const ext = coreutils_1.PathExt.extname(path);
if (ext === '.ipy') {

@@ -45,7 +43,6 @@ return 'text/x-python';

}
var mode = mode_1.Mode.findByFileName(path) || mode_1.Mode.findBest('');
let mode = mode_1.Mode.findByFileName(path) || mode_1.Mode.findBest('');
return mode.mime;
};
return CodeMirrorMimeTypeService;
}());
}
}
exports.CodeMirrorMimeTypeService = CodeMirrorMimeTypeService;
"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var codeeditor_1 = require("@jupyterlab/codeeditor");
var CodeMirror = require("codemirror");
const codeeditor_1 = require("@jupyterlab/codeeditor");
const codemirror_1 = __importDefault(require("codemirror"));
require("codemirror/mode/meta");

@@ -20,3 +23,3 @@ require("codemirror/addon/runmode/runmode");

require("codemirror/mode/sql/sql");
var coreutils_1 = require("@jupyterlab/coreutils");
const coreutils_1 = require("@jupyterlab/coreutils");
/**

@@ -31,3 +34,3 @@ * The namespace for CodeMirror Mode functionality.

function getModeInfo() {
return CodeMirror.modeInfo;
return codemirror_1.default.modeInfo;
}

@@ -39,3 +42,3 @@ Mode.getModeInfo = getModeInfo;

function run(code, mode, el) {
CodeMirror.runMode(code, mode, el);
codemirror_1.default.runMode(code, mode, el);
}

@@ -52,10 +55,12 @@ Mode.run = run;

function ensure(mode) {
var spec = findBest(mode);
let spec = findBest(mode);
// Simplest, cheapest check by mode name.
if (CodeMirror.modes.hasOwnProperty(spec.mode)) {
if (codemirror_1.default.modes.hasOwnProperty(spec.mode)) {
return Promise.resolve(spec);
}
// Fetch the mode asynchronously.
return new Promise(function (resolve, reject) {
require(["codemirror/mode/" + spec.mode + "/" + spec.mode + ".js"], function () {
return new Promise((resolve, reject) => {
// An arrow function below seems to miscompile in our current webpack to
// invalid js.
require([`codemirror/mode/${spec.mode}/${spec.mode}.js`], function () {
resolve(spec);

@@ -70,11 +75,11 @@ });

function findBest(mode) {
var modename = (typeof mode === 'string') ? mode :
let modename = (typeof mode === 'string') ? mode :
mode.mode || mode.name;
var mimetype = (typeof mode !== 'string') ? mode.mime : modename;
var ext = (typeof mode !== 'string') ? mode.ext : [];
return (CodeMirror.findModeByName(modename || '') ||
CodeMirror.findModeByMIME(mimetype || '') ||
let mimetype = (typeof mode !== 'string') ? mode.mime : modename;
let ext = (typeof mode !== 'string') ? mode.ext : [];
return (codemirror_1.default.findModeByName(modename || '') ||
codemirror_1.default.findModeByMIME(mimetype || '') ||
findByExtension(ext) ||
CodeMirror.findModeByMIME(codeeditor_1.IEditorMimeTypeService.defaultMimeType) ||
CodeMirror.findModeByMIME('text/plain'));
codemirror_1.default.findModeByMIME(codeeditor_1.IEditorMimeTypeService.defaultMimeType) ||
codemirror_1.default.findModeByMIME('text/plain'));
}

@@ -86,3 +91,3 @@ Mode.findBest = findBest;

function findByMIME(mime) {
return CodeMirror.findModeByMIME(mime);
return codemirror_1.default.findModeByMIME(mime);
}

@@ -94,3 +99,3 @@ Mode.findByMIME = findByMIME;

function findByName(name) {
return CodeMirror.findModeByName(name);
return codemirror_1.default.findModeByName(name);
}

@@ -102,4 +107,4 @@ Mode.findByName = findByName;

function findByFileName(name) {
var basename = coreutils_1.PathExt.basename(name);
return CodeMirror.findModeByFileName(basename);
let basename = coreutils_1.PathExt.basename(name);
return codemirror_1.default.findModeByFileName(basename);
}

@@ -112,6 +117,6 @@ Mode.findByFileName = findByFileName;

if (typeof ext === 'string') {
return CodeMirror.findModeByExtension(name);
return codemirror_1.default.findModeByExtension(name);
}
for (var i = 0; i < ext.length; i++) {
var mode = CodeMirror.findModeByExtension(ext[i]);
for (let i = 0; i < ext.length; i++) {
let mode = codemirror_1.default.findModeByExtension(ext[i]);
if (mode) {

@@ -118,0 +123,0 @@ return mode;

{
"name": "@jupyterlab/codemirror",
"version": "0.16.3",
"version": "0.17.0-0",
"description": "JupyterLab - CodeMirror Editor Provider",

@@ -30,9 +30,9 @@ "homepage": "https://github.com/jupyterlab/jupyterlab",

"prepublishOnly": "npm run build",
"watch": "tsc -w"
"watch": "tsc -w --listEmittedFiles"
},
"dependencies": {
"@jupyterlab/apputils": "^0.16.4",
"@jupyterlab/codeeditor": "^0.16.2",
"@jupyterlab/coreutils": "^1.1.3",
"@jupyterlab/observables": "^1.0.10",
"@jupyterlab/apputils": "^0.17.0-0",
"@jupyterlab/codeeditor": "^0.17.0-0",
"@jupyterlab/coreutils": "^2.0.0-0",
"@jupyterlab/observables": "^2.0.0-0",
"@phosphor/algorithm": "^1.1.2",

@@ -42,3 +42,3 @@ "@phosphor/coreutils": "^1.3.0",

"@phosphor/signaling": "^1.2.2",
"codemirror": "~5.35.0"
"codemirror": "~5.39.0"
},

@@ -48,4 +48,4 @@ "devDependencies": {

"rimraf": "~2.6.2",
"typescript": "~2.6.2"
"typescript": "~2.9.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc