New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-codemirror2

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-codemirror2 - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

package-lock.json

77

index.js

@@ -6,8 +6,61 @@ import React from 'react';

constructor(props) {
super(props);
this.initHydration = false;
}
componentWillMount() {
if (this.props.editorWillMount) {
this.props.editorWillMount(codemirror);
}
}
componentDidMount() {
this.editor = codemirror(this.ref);
this.editor.on('change', () => this.props.onChange(this.editor.getValue()));
this.editor.on('change', () => {
if (this.props.onChange && this.initHydration) {
this.props.onChange(this.editor.getValue());
}
});
if (this.props.onCursorActivity) {
this.editor.on('cursorActivity', this.props.onCursorActivity);
}
if (this.props.onViewportChange) {
this.editor.on('viewportChange', (cm, start, end) => {
this.props.onViewportChange(cm, start, end);
});
}
if (this.props.onGutterClick) {
this.editor.on('gutterClick', (cm, lineNumber, event) => {
this.props.onGutterClick(cm, lineNumber, event);
});
}
if (this.props.onFocus) {
this.editor.on('focus', this.props.onFocus);
}
if (this.props.onBlur) {
this.editor.on('blur', this.props.onBlur);
}
if (this.props.onScroll) {
this.editor.on('scroll', this.props.onScroll);
}
if (this.props.onUpdate) {
this.editor.on('update', this.props.onUpdate);
}
this.hydrate(this.props);
if (this.props.editorDidMount) {
this.props.editorDidMount(codemirror);
}
}

@@ -20,6 +73,26 @@

componentWillUnmount() {
if (this.props.editorWillUnmount) {
this.props.editorWillUnmount(codemirror);
}
}
hydrate(props) {
Object.keys(props.options || {}).forEach(key => this.editor.setOption(key, props.options[key]));
this.editor.setValue(props.value || '');
if (this.props.editorDidConfigure) {
this.props.editorDidConfigure(codemirror);
}
if (this.props.defaultValue && !this.initHydration) {
this.editor.setValue(props.defaultValue);
if (this.props.onSetDefaultValue) {
this.props.onSetDefaultValue(this.editor.getValue());
}
}
this.initHydration = true;
}

@@ -26,0 +99,0 @@

2

package.json
{
"name": "react-codemirror2",
"version": "0.0.2",
"version": "0.0.3",
"description": "a tiny react codemirror component wrapper",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -0,1 +1,3 @@

[![NPM Version](https://img.shields.io/npm/v/react-codemirror2.svg?style=flat-square)](https://www.npmjs.com/package/react-codemirror2)
### react-codemirror2

@@ -7,9 +9,33 @@

<CodeMirror
value='foo'
options={{theme: 'material'}}
onChange={(value) => {
console.log(value);
}} />
defaultValue='react-codemirror2'
options={{theme: 'material', lineNumbers: true}}
editorWillMount={(cm) => {
}}
editorDidMount={(cm) => {
}}
editorDidConfigure={(cm) => {
}}
editorWillUnmount={(cm) => {
}}
onSetDefaultValue={(defaultValue) => {
}}
onChange={(internalValue) => {
}}
onCursorActivity={() => {
}}
onViewportChange={(cm, viewportStart, viewportEnd) => {
}}
onGutterClick={(cm, lineNumber, event) => {
}}
onFocus={() => {
}}
onBlur={() => {
}}
onScroll={() => {
}}
onUpdate={() => {
}}
/>
```
// TODO
// better docs coming soon. all props are optional...

@@ -6,8 +6,61 @@ import React from 'react';

constructor(props) {
super(props);
this.initHydration = false;
}
componentWillMount() {
if (this.props.editorWillMount) {
this.props.editorWillMount(codemirror);
}
}
componentDidMount() {
this.editor = codemirror(this.ref);
this.editor.on('change', () => this.props.onChange(this.editor.getValue()));
this.editor.on('change', () => {
if (this.props.onChange && this.initHydration) {
this.props.onChange(this.editor.getValue());
}
});
if(this.props.onCursorActivity) {
this.editor.on('cursorActivity', this.props.onCursorActivity);
}
if(this.props.onViewportChange) {
this.editor.on('viewportChange', (cm, start, end) => {
this.props.onViewportChange(cm, start, end);
});
}
if(this.props.onGutterClick) {
this.editor.on('gutterClick', (cm, lineNumber, event) => {
this.props.onGutterClick(cm, lineNumber, event);
});
}
if(this.props.onFocus) {
this.editor.on('focus', this.props.onFocus);
}
if(this.props.onBlur) {
this.editor.on('blur', this.props.onBlur);
}
if(this.props.onScroll) {
this.editor.on('scroll', this.props.onScroll);
}
if(this.props.onUpdate) {
this.editor.on('update', this.props.onUpdate);
}
this.hydrate(this.props);
if (this.props.editorDidMount) {
this.props.editorDidMount(codemirror);
}
}

@@ -20,6 +73,26 @@

componentWillUnmount() {
if (this.props.editorWillUnmount) {
this.props.editorWillUnmount(codemirror);
}
}
hydrate(props) {
Object.keys(props.options || {}).forEach(key => this.editor.setOption(key, props.options[key]));
this.editor.setValue(props.value || '');
if (this.props.editorDidConfigure) {
this.props.editorDidConfigure(codemirror);
}
if (this.props.defaultValue && !this.initHydration) {
this.editor.setValue(props.defaultValue);
if (this.props.onSetDefaultValue) {
this.props.onSetDefaultValue(this.editor.getValue());
}
}
this.initHydration = true;
}

@@ -26,0 +99,0 @@

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