react-codemirror2
Advanced tools
Comparing version 5.1.0 to 6.0.0
@@ -5,2 +5,3 @@ 5.1.0 | ||
5.0.3 | ||
@@ -13,2 +14,3 @@ ================== | ||
5.0.1 | ||
@@ -15,0 +17,0 @@ ================== |
@@ -1,3 +0,1 @@ | ||
/// <reference types="codemirror" /> | ||
/// <reference types="react" /> | ||
import * as React from 'react'; | ||
@@ -17,16 +15,4 @@ import * as codemirror from 'codemirror'; | ||
} | ||
export interface IGetSelectionOptions { | ||
ranges: Array<ISetSelectionOptions>; | ||
origin: string; | ||
update: (ranges: Array<ISetSelectionOptions>) => void; | ||
} | ||
export interface IDoc extends codemirror.Doc { | ||
setCursor: (pos: codemirror.Position, ch?: number, options?: {}) => void; | ||
setSelections: (ranges: Array<ISetSelectionOptions>) => void; | ||
} | ||
export interface IInstance extends codemirror.Editor, IDoc { | ||
options: codemirror.EditorConfiguration; | ||
} | ||
export interface DomEvent { | ||
(editor: IInstance, event: Event): void; | ||
(editor: codemirror.Editor, event: Event): void; | ||
} | ||
@@ -39,13 +25,12 @@ export interface ICodeMirror { | ||
defineMode?: IDefineModeOptions; | ||
editorDidConfigure?: (editor: IInstance) => void; | ||
editorDidMount?: (editor: IInstance, value: string, cb: () => void) => void; | ||
editorWillMount?: () => void; | ||
editorDidConfigure?: (editor: codemirror.Editor) => void; | ||
editorDidMount?: (editor: codemirror.Editor, value: string, cb: () => void) => void; | ||
editorWillUnmount?: (lib: any) => void; | ||
onBlur?: DomEvent; | ||
onChange?: (editor: IInstance, data: codemirror.EditorChange, value: string) => void; | ||
onChange?: (editor: codemirror.Editor, data: codemirror.EditorChange, value: string) => void; | ||
onContextMenu?: DomEvent; | ||
onCopy?: DomEvent; | ||
onCursor?: (editor: IInstance, data: codemirror.Position) => void; | ||
onCursor?: (editor: codemirror.Editor, data: codemirror.Position) => void; | ||
onCut?: DomEvent; | ||
onCursorActivity?: (editor: IInstance) => void; | ||
onCursorActivity?: (editor: codemirror.Editor) => void; | ||
onDblClick?: DomEvent; | ||
@@ -58,3 +43,3 @@ onDragEnter?: DomEvent; | ||
onFocus?: DomEvent; | ||
onGutterClick?: (editor: IInstance, lineNumber: number, gutter: string, event: Event) => void; | ||
onGutterClick?: (editor: codemirror.Editor, lineNumber: number, gutter: string, event: Event) => void; | ||
onKeyDown?: DomEvent; | ||
@@ -65,8 +50,8 @@ onKeyPress?: DomEvent; | ||
onPaste?: DomEvent; | ||
onRenderLine?: (editor: IInstance, line: codemirror.LineHandle, element: HTMLElement) => void; | ||
onScroll?: (editor: IInstance, data: codemirror.ScrollInfo) => void; | ||
onSelection?: (editor: IInstance, data: IGetSelectionOptions) => void; | ||
onRenderLine?: (editor: codemirror.Editor, line: codemirror.LineHandle, element: HTMLElement) => void; | ||
onScroll?: (editor: codemirror.Editor, data: codemirror.ScrollInfo) => void; | ||
onSelection?: (editor: codemirror.Editor, data: any) => void; | ||
onTouchStart?: DomEvent; | ||
onUpdate?: (editor: IInstance) => void; | ||
onViewportChange?: (editor: IInstance, start: number, end: number) => void; | ||
onUpdate?: (editor: codemirror.Editor) => void; | ||
onViewportChange?: (editor: codemirror.Editor, start: number, end: number) => void; | ||
options?: codemirror.EditorConfiguration; | ||
@@ -80,3 +65,3 @@ selection?: { | ||
export interface IControlledCodeMirror extends ICodeMirror { | ||
onBeforeChange: (editor: IInstance, data: codemirror.EditorChange, value: string) => void; | ||
onBeforeChange: (editor: codemirror.Editor, data: codemirror.EditorChange, value: string) => void; | ||
value: string; | ||
@@ -86,5 +71,5 @@ } | ||
detach?: boolean; | ||
editorDidAttach?: (editor: IInstance) => void; | ||
editorDidDetach?: (editor: IInstance) => void; | ||
onBeforeChange?: (editor: IInstance, data: codemirror.EditorChange, value: string, next: () => void) => void; | ||
editorDidAttach?: (editor: codemirror.Editor) => void; | ||
editorDidDetach?: (editor: codemirror.Editor) => void; | ||
onBeforeChange?: (editor: codemirror.Editor, data: codemirror.EditorChange, value: string, next: () => void) => void; | ||
value?: string; | ||
@@ -91,0 +76,0 @@ } |
283
index.js
'use strict'; | ||
var _extends = Object.assign || function(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function _typeof(obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function _typeof(obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return target; | ||
}; | ||
return _typeof(obj); | ||
} | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) { | ||
return typeof obj; | ||
} : function(obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var __extends = void 0 && (void 0).__extends || function() { | ||
var _extendStatics = function extendStatics(d, b) { | ||
_extendStatics = Object.setPrototypeOf || { | ||
__proto__: [] | ||
} | ||
instanceof Array && function(d, b) { | ||
d.__proto__ = b; | ||
} || function(d, b) { | ||
for (var p in b) { | ||
if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
} | ||
}; | ||
var __extends = undefined && undefined.__extends || function() { | ||
var extendStatics = Object.setPrototypeOf || { | ||
__proto__: [] | ||
} | ||
instanceof Array && function(d, b) { | ||
d.__proto__ = b; | ||
} || function(d, b) { | ||
for (var p in b) { | ||
if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
} | ||
return _extendStatics(d, b); | ||
}; | ||
return function(d, b) { | ||
extendStatics(d, b); | ||
_extendStatics(d, b); | ||
@@ -38,21 +53,30 @@ function __() { | ||
} | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
}(); | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
var React = require('react'); | ||
var SERVER_RENDERED = typeof navigator === 'undefined' || global['PREVENT_CODEMIRROR_RENDER'] === true; | ||
var cm; | ||
if (!SERVER_RENDERED) { | ||
cm = require('codemirror'); | ||
} | ||
var Helper = function() { | ||
function Helper() {} | ||
Helper.equals = function(x, y) { | ||
var _this = this; | ||
var ok = Object.keys, | ||
tx = typeof x === 'undefined' ? 'undefined' : _typeof(x), | ||
ty = typeof y === 'undefined' ? 'undefined' : _typeof(y); | ||
tx = _typeof(x), | ||
ty = _typeof(y); | ||
return x && y && tx === 'object' && tx === ty ? ok(x).length === ok(y).length && ok(x).every(function(key) { | ||
@@ -62,4 +86,6 @@ return _this.equals(x[key], y[key]); | ||
}; | ||
return Helper; | ||
}(); | ||
var Shared = function() { | ||
@@ -70,7 +96,10 @@ function Shared(editor, props) { | ||
} | ||
Shared.prototype.delegateCursor = function(position, scroll, focus) { | ||
var doc = this.editor.getDoc(); | ||
if (focus) { | ||
this.editor.focus(); | ||
} | ||
scroll ? doc.setCursor(position) : doc.setCursor(position, null, { | ||
@@ -80,7 +109,11 @@ scroll: false | ||
}; | ||
Shared.prototype.delegateScroll = function(coordinates) { | ||
this.editor.scrollTo(coordinates.x, coordinates.y); | ||
}; | ||
Shared.prototype.delegateSelection = function(ranges, focus) { | ||
this.editor.setSelections(ranges); | ||
var doc = this.editor.getDoc(); | ||
doc.setSelections(ranges); | ||
if (focus) { | ||
@@ -90,2 +123,3 @@ this.editor.focus(); | ||
}; | ||
Shared.prototype.apply = function(props) { | ||
@@ -95,5 +129,7 @@ if (props && props.selection && props.selection.ranges) { | ||
} | ||
if (props && props.cursor) { | ||
this.delegateCursor(props.cursor, props.autoScroll || false, this.editor.getOption('autofocus') || false); | ||
} | ||
if (props && props.scroll) { | ||
@@ -103,2 +139,3 @@ this.delegateScroll(props.scroll); | ||
}; | ||
Shared.prototype.applyNext = function(props, next, preserved) { | ||
@@ -110,2 +147,3 @@ if (props && props.selection && props.selection.ranges) { | ||
} | ||
if (props && props.cursor) { | ||
@@ -116,2 +154,3 @@ if (next && next.cursor && !Helper.equals(props.cursor, next.cursor)) { | ||
} | ||
if (props && props.scroll) { | ||
@@ -123,2 +162,3 @@ if (next && next.scroll && !Helper.equals(props.scroll, next.scroll)) { | ||
}; | ||
Shared.prototype.applyUserDefined = function(props, preserved) { | ||
@@ -129,6 +169,8 @@ if (preserved && preserved.cursor) { | ||
}; | ||
Shared.prototype.wire = function(props) { | ||
var _this = this; | ||
Object.keys(props || {}).filter(function(p) { | ||
return (/^on/.test(p)); | ||
return /^on/.test(p); | ||
}).forEach(function(prop) { | ||
@@ -143,2 +185,3 @@ switch (prop) { | ||
break; | ||
case 'onContextMenu': | ||
@@ -149,4 +192,6 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onCopy': | ||
@@ -157,11 +202,14 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onCursor': | ||
{ | ||
_this.editor.on('cursorActivity', function(cm) { | ||
_this.props.onCursor(_this.editor, _this.editor.getCursor()); | ||
_this.props.onCursor(_this.editor, _this.editor.getDoc().getCursor()); | ||
}); | ||
} | ||
break; | ||
case 'onCursorActivity': | ||
@@ -174,2 +222,3 @@ { | ||
break; | ||
case 'onCut': | ||
@@ -180,4 +229,6 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onDblClick': | ||
@@ -188,4 +239,6 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onDragEnter': | ||
@@ -198,2 +251,3 @@ { | ||
break; | ||
case 'onDragLeave': | ||
@@ -204,4 +258,6 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onDragOver': | ||
@@ -214,2 +270,3 @@ { | ||
break; | ||
case 'onDragStart': | ||
@@ -220,4 +277,6 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onDrop': | ||
@@ -230,2 +289,3 @@ { | ||
break; | ||
case 'onFocus': | ||
@@ -238,2 +298,3 @@ { | ||
break; | ||
case 'onGutterClick': | ||
@@ -246,2 +307,3 @@ { | ||
break; | ||
case 'onKeyDown': | ||
@@ -254,2 +316,3 @@ { | ||
break; | ||
case 'onKeyPress': | ||
@@ -262,2 +325,3 @@ { | ||
break; | ||
case 'onKeyUp': | ||
@@ -270,2 +334,3 @@ { | ||
break; | ||
case 'onMouseDown': | ||
@@ -276,4 +341,6 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onPaste': | ||
@@ -284,4 +351,6 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onRenderLine': | ||
@@ -292,4 +361,6 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onScroll': | ||
@@ -302,2 +373,3 @@ { | ||
break; | ||
case 'onSelection': | ||
@@ -310,2 +382,3 @@ { | ||
break; | ||
case 'onTouchStart': | ||
@@ -316,4 +389,6 @@ { | ||
}); | ||
break; | ||
} | ||
case 'onUpdate': | ||
@@ -326,2 +401,3 @@ { | ||
break; | ||
case 'onViewportChange': | ||
@@ -337,4 +413,6 @@ { | ||
}; | ||
return Shared; | ||
}(); | ||
var Controlled = function(_super) { | ||
@@ -345,2 +423,3 @@ __extends(Controlled, _super); | ||
var _this = _super.call(this, props) || this; | ||
if (SERVER_RENDERED) return _this; | ||
@@ -353,2 +432,3 @@ _this.applied = false; | ||
_this.hydrated = false; | ||
_this.initCb = function() { | ||
@@ -359,16 +439,24 @@ if (_this.props.editorDidConfigure) { | ||
}; | ||
_this.mounted = false; | ||
return _this; | ||
} | ||
Controlled.prototype.hydrate = function(props) { | ||
var _this = this; | ||
var userDefinedOptions = _extends({}, cm.defaults, this.editor.options, props.options || {}); | ||
var _options = props && props.options ? props.options : {}; | ||
var userDefinedOptions = _extends({}, cm.defaults, this.editor.options, _options); | ||
var optionDelta = Object.keys(userDefinedOptions).some(function(key) { | ||
return _this.editor.getOption(key) !== userDefinedOptions[key]; | ||
}); | ||
if (optionDelta) { | ||
Object.keys(userDefinedOptions).forEach(function(key) { | ||
if (props.options.hasOwnProperty(key)) { | ||
if (_options.hasOwnProperty(key)) { | ||
if (_this.editor.getOption(key) !== userDefinedOptions[key]) { | ||
_this.editor.setOption(key, userDefinedOptions[key]); | ||
_this.mirror.setOption(key, userDefinedOptions[key]); | ||
@@ -379,20 +467,16 @@ } | ||
} | ||
if (!this.hydrated) { | ||
if (!this.mounted) { | ||
this.initChange(props.value || ''); | ||
} else { | ||
if (this.deferred) { | ||
this.resolveChange(); | ||
} else { | ||
this.initChange(props.value || ''); | ||
} | ||
} | ||
this.deferred ? this.resolveChange() : this.initChange(props.value || ''); | ||
} | ||
this.hydrated = true; | ||
}; | ||
Controlled.prototype.initChange = function(value) { | ||
this.emulating = true; | ||
var lastLine = this.editor.lastLine(); | ||
var lastChar = this.editor.getLine(this.editor.lastLine()).length; | ||
this.editor.replaceRange(value || '', { | ||
var doc = this.editor.getDoc(); | ||
var lastLine = doc.lastLine(); | ||
var lastChar = doc.getLine(doc.lastLine()).length; | ||
doc.replaceRange(value || '', { | ||
line: 0, | ||
@@ -405,24 +489,31 @@ ch: 0 | ||
this.mirror.setValue(value); | ||
this.editor.clearHistory(); | ||
doc.clearHistory(); | ||
this.mirror.clearHistory(); | ||
this.emulating = false; | ||
}; | ||
Controlled.prototype.resolveChange = function() { | ||
this.emulating = true; | ||
var doc = this.editor.getDoc(); | ||
if (this.deferred.origin === 'undo') { | ||
this.editor.undo(); | ||
doc.undo(); | ||
} else if (this.deferred.origin === 'redo') { | ||
this.editor.redo(); | ||
doc.redo(); | ||
} else { | ||
this.editor.replaceRange(this.deferred.text, this.deferred.from, this.deferred.to, this.deferred.origin); | ||
doc.replaceRange(this.deferred.text, this.deferred.from, this.deferred.to, this.deferred.origin); | ||
} | ||
this.emulating = false; | ||
this.deferred = null; | ||
}; | ||
Controlled.prototype.mirrorChange = function(deferred) { | ||
var doc = this.editor.getDoc(); | ||
if (deferred.origin === 'undo') { | ||
this.editor.setHistory(this.mirror.getHistory()); | ||
doc.setHistory(this.mirror.getHistory()); | ||
this.mirror.undo(); | ||
} else if (deferred.origin === 'redo') { | ||
this.editor.setHistory(this.mirror.getHistory()); | ||
doc.setHistory(this.mirror.getHistory()); | ||
this.mirror.redo(); | ||
@@ -432,13 +523,11 @@ } else { | ||
} | ||
return this.mirror.getValue(); | ||
}; | ||
Controlled.prototype.componentWillMount = function() { | ||
if (SERVER_RENDERED) return; | ||
if (this.props.editorWillMount) { | ||
this.props.editorWillMount(); | ||
} | ||
}; | ||
Controlled.prototype.componentDidMount = function() { | ||
var _this = this; | ||
if (SERVER_RENDERED) return; | ||
if (this.props.defineMode) { | ||
@@ -449,2 +538,3 @@ if (this.props.defineMode.name && this.props.defineMode.fn) { | ||
} | ||
this.editor = cm(this.ref); | ||
@@ -454,6 +544,6 @@ this.shared = new Shared(this.editor, this.props); | ||
this.editor.on('electricInput', function() { | ||
_this.mirror.setHistory(_this.editor.getHistory()); | ||
_this.mirror.setHistory(_this.editor.getDoc().getHistory()); | ||
}); | ||
this.editor.on('cursorActivity', function() { | ||
_this.mirror.setCursor(_this.editor.getCursor()); | ||
_this.mirror.setCursor(_this.editor.getDoc().getCursor()); | ||
}); | ||
@@ -464,5 +554,8 @@ this.editor.on('beforeChange', function(cm, data) { | ||
} | ||
data.cancel(); | ||
_this.deferred = data; | ||
var phantomChange = _this.mirrorChange(_this.deferred); | ||
if (_this.props.onBeforeChange) _this.props.onBeforeChange(_this.editor, _this.deferred, phantomChange); | ||
@@ -474,2 +567,3 @@ }); | ||
} | ||
if (_this.props.onChange) { | ||
@@ -484,5 +578,7 @@ _this.props.onChange(_this.editor, data, _this.editor.getValue()); | ||
this.shared.wire(this.props); | ||
if (this.editor.getOption('autofocus')) { | ||
this.editor.focus(); | ||
} | ||
if (this.props.editorDidMount) { | ||
@@ -492,2 +588,3 @@ this.props.editorDidMount(this.editor, this.editor.getValue(), this.initCb); | ||
}; | ||
Controlled.prototype.componentWillReceiveProps = function(nextProps) { | ||
@@ -498,9 +595,13 @@ if (SERVER_RENDERED) return; | ||
}; | ||
if (nextProps.value !== this.props.value) { | ||
this.hydrated = false; | ||
} | ||
if (!this.props.autoCursor && this.props.autoCursor !== undefined) { | ||
preserved.cursor = this.editor.getCursor(); | ||
preserved.cursor = this.editor.getDoc().getCursor(); | ||
} | ||
this.hydrate(nextProps); | ||
if (!this.appliedNext) { | ||
@@ -510,7 +611,10 @@ this.shared.applyNext(this.props, nextProps, preserved); | ||
} | ||
this.shared.applyUserDefined(this.props, preserved); | ||
this.appliedUserDefined = true; | ||
}; | ||
Controlled.prototype.componentWillUnmount = function() { | ||
if (SERVER_RENDERED) return; | ||
if (this.props.editorWillUnmount) { | ||
@@ -520,7 +624,10 @@ this.props.editorWillUnmount(cm); | ||
}; | ||
Controlled.prototype.shouldComponentUpdate = function(nextProps, nextState) { | ||
return !SERVER_RENDERED; | ||
}; | ||
Controlled.prototype.render = function() { | ||
var _this = this; | ||
if (SERVER_RENDERED) return null; | ||
@@ -535,5 +642,8 @@ var className = this.props.className ? 'react-codemirror2 ' + this.props.className : 'react-codemirror2'; | ||
}; | ||
return Controlled; | ||
}(React.Component); | ||
exports.Controlled = Controlled; | ||
var UnControlled = function(_super) { | ||
@@ -544,2 +654,3 @@ __extends(UnControlled, _super); | ||
var _this = _super.call(this, props) || this; | ||
if (SERVER_RENDERED) return _this; | ||
@@ -551,2 +662,3 @@ _this.applied = false; | ||
_this.hydrated = false; | ||
_this.initCb = function() { | ||
@@ -557,17 +669,26 @@ if (_this.props.editorDidConfigure) { | ||
}; | ||
_this.mounted = false; | ||
_this.onBeforeChangeCb = function() { | ||
_this.continueChange = true; | ||
}; | ||
return _this; | ||
} | ||
UnControlled.prototype.hydrate = function(props) { | ||
var _this = this; | ||
var userDefinedOptions = _extends({}, cm.defaults, this.editor.options, props.options || {}); | ||
var _options = props && props.options ? props.options : {}; | ||
var userDefinedOptions = _extends({}, cm.defaults, this.editor.options, _options); | ||
var optionDelta = Object.keys(userDefinedOptions).some(function(key) { | ||
return _this.editor.getOption(key) !== userDefinedOptions[key]; | ||
}); | ||
if (optionDelta) { | ||
Object.keys(userDefinedOptions).forEach(function(key) { | ||
if (props.options.hasOwnProperty(key)) { | ||
if (_options.hasOwnProperty(key)) { | ||
if (_this.editor.getOption(key) !== userDefinedOptions[key]) { | ||
@@ -579,6 +700,8 @@ _this.editor.setOption(key, userDefinedOptions[key]); | ||
} | ||
if (!this.hydrated) { | ||
var lastLine = this.editor.lastLine(); | ||
var lastChar = this.editor.getLine(this.editor.lastLine()).length; | ||
this.editor.replaceRange(props.value || '', { | ||
var doc = this.editor.getDoc(); | ||
var lastLine = doc.lastLine(); | ||
var lastChar = doc.getLine(doc.lastLine()).length; | ||
doc.replaceRange(props.value || '', { | ||
line: 0, | ||
@@ -591,14 +714,12 @@ ch: 0 | ||
} | ||
this.hydrated = true; | ||
}; | ||
UnControlled.prototype.componentWillMount = function() { | ||
if (SERVER_RENDERED) return; | ||
if (this.props.editorWillMount) { | ||
this.props.editorWillMount(); | ||
} | ||
}; | ||
UnControlled.prototype.componentDidMount = function() { | ||
var _this = this; | ||
if (SERVER_RENDERED) return; | ||
this.detached = this.props.detach === true; | ||
if (this.props.defineMode) { | ||
@@ -609,2 +730,3 @@ if (this.props.defineMode.name && this.props.defineMode.fn) { | ||
} | ||
this.editor = cm(this.ref); | ||
@@ -621,2 +743,3 @@ this.shared = new Shared(this.editor, this.props); | ||
} | ||
if (_this.props.onBeforeChange) { | ||
@@ -635,3 +758,4 @@ if (_this.continueChange) { | ||
this.shared.wire(this.props); | ||
this.editor.clearHistory(); | ||
this.editor.getDoc().clearHistory(); | ||
if (this.props.editorDidMount) { | ||
@@ -641,5 +765,7 @@ this.props.editorDidMount(this.editor, this.editor.getValue(), this.initCb); | ||
}; | ||
UnControlled.prototype.componentWillReceiveProps = function(nextProps) { | ||
if (this.detached && nextProps.detach === false) { | ||
this.detached = false; | ||
if (this.props.editorDidAttach) { | ||
@@ -649,4 +775,6 @@ this.props.editorDidAttach(this.editor); | ||
} | ||
if (!this.detached && nextProps.detach === true) { | ||
this.detached = true; | ||
if (this.props.editorDidDetach) { | ||
@@ -656,2 +784,3 @@ this.props.editorDidDetach(this.editor); | ||
} | ||
if (SERVER_RENDERED || this.detached) return; | ||
@@ -661,2 +790,3 @@ var preserved = { | ||
}; | ||
if (nextProps.value !== this.props.value) { | ||
@@ -667,6 +797,9 @@ this.hydrated = false; | ||
} | ||
if (!this.props.autoCursor && this.props.autoCursor !== undefined) { | ||
preserved.cursor = this.editor.getCursor(); | ||
preserved.cursor = this.editor.getDoc().getCursor(); | ||
} | ||
this.hydrate(nextProps); | ||
if (!this.applied) { | ||
@@ -676,2 +809,3 @@ this.shared.apply(this.props); | ||
} | ||
if (!this.appliedUserDefined) { | ||
@@ -682,4 +816,6 @@ this.shared.applyUserDefined(this.props, preserved); | ||
}; | ||
UnControlled.prototype.componentWillUnmount = function() { | ||
if (SERVER_RENDERED) return; | ||
if (this.props.editorWillUnmount) { | ||
@@ -689,2 +825,3 @@ this.props.editorWillUnmount(cm); | ||
}; | ||
UnControlled.prototype.shouldComponentUpdate = function(nextProps, nextState) { | ||
@@ -696,4 +833,6 @@ var update = true; | ||
}; | ||
UnControlled.prototype.render = function() { | ||
var _this = this; | ||
if (SERVER_RENDERED) return null; | ||
@@ -708,4 +847,6 @@ var className = this.props.className ? 'react-codemirror2 ' + this.props.className : 'react-codemirror2'; | ||
}; | ||
return UnControlled; | ||
}(React.Component); | ||
exports.UnControlled = UnControlled; |
{ | ||
"name": "react-codemirror2", | ||
"version": "5.1.0", | ||
"version": "6.0.0", | ||
"description": "a tiny react codemirror component wrapper", | ||
@@ -28,3 +28,3 @@ "main": "index.js", | ||
"transform": { | ||
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js" | ||
".(ts|tsx)": "ts-jest" | ||
}, | ||
@@ -61,8 +61,10 @@ "moduleFileExtensions": [ | ||
"devDependencies": { | ||
"@babel/preset-env": "7.4.4", | ||
"@babel/preset-react": "7.0.0", | ||
"@nteract/mockument": "1.0.4", | ||
"@types/codemirror": "0.0.56", | ||
"@types/jest": "22.2.3", | ||
"@types/react": "16.3.14", | ||
"@types/codemirror": "0.0.74", | ||
"@types/jest": "24.0.11", | ||
"@types/react": "16.8.14", | ||
"babel-core": "6.26.3", | ||
"babel-loader": "7.1.4", | ||
"babel-loader": "8.0.5", | ||
"babel-plugin-transform-object-assign": "6.22.0", | ||
@@ -72,31 +74,31 @@ "babel-preset-env": "1.7.0", | ||
"babel-preset-react": "6.24.1", | ||
"codemirror": "5.38.0", | ||
"coveralls": "3.0.1", | ||
"css-loader": "0.28.11", | ||
"enzyme": "3.3.0", | ||
"enzyme-adapter-react-16": "1.1.1", | ||
"express": "4.16.3", | ||
"gulp": "3.9.1", | ||
"gulp-babel": "7.0.1", | ||
"gulp-beautify": "2.0.1", | ||
"codemirror": "5.46.0", | ||
"coveralls": "3.0.3", | ||
"css-loader": "2.1.1", | ||
"enzyme": "3.9.0", | ||
"enzyme-adapter-react-16": "1.12.1", | ||
"express": "4.16.4", | ||
"gulp": "4.0.1", | ||
"gulp-babel": "8.0.0", | ||
"gulp-beautify": "3.0.0", | ||
"gulp-replace": "1.0.0", | ||
"jest": "22.4.4", | ||
"node-sass": "4.9.0", | ||
"prismjs": "1.14.0", | ||
"raf": "3.4.0", | ||
"react": "16.3.2", | ||
"react-dom": "16.3.2", | ||
"react-redux": "5.0.7", | ||
"react-test-renderer": "16.3.2", | ||
"redux": "4.0.0", | ||
"rimraf": "2.6.2", | ||
"sass-loader": "7.0.1", | ||
"sinon": "5.0.7", | ||
"style-loader": "0.21.0", | ||
"ts-jest": "22.4.6", | ||
"typescript": "2.8.3", | ||
"typescript-formatter": "7.2.0", | ||
"webpack": "4.8.3", | ||
"webpack-cli": "2.1.3" | ||
"jest": "24.7.1", | ||
"node-sass": "4.12.0", | ||
"prismjs": "1.16.0", | ||
"raf": "3.4.1", | ||
"react": "16.8.6", | ||
"react-dom": "16.8.6", | ||
"react-redux": "7.0.3", | ||
"react-test-renderer": "16.8.6", | ||
"redux": "4.0.1", | ||
"rimraf": "2.6.3", | ||
"sass-loader": "7.1.0", | ||
"sinon": "7.3.2", | ||
"style-loader": "0.23.1", | ||
"ts-jest": "24.0.2", | ||
"typescript": "3.4.5", | ||
"typescript-formatter": "7.2.2", | ||
"webpack": "4.30.0", | ||
"webpack-cli": "3.3.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
68003
9
1355
40