Skip to content

Commit

Permalink
Split Editor Component
Browse files Browse the repository at this point in the history
- Adds support for the split editor component.
- Allows for the export of multiple child components in addition to ReactAce being default
  • Loading branch information
securingsincity committed May 27, 2017
1 parent 4db1900 commit b390c19
Show file tree
Hide file tree
Showing 11 changed files with 1,194 additions and 38 deletions.
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ <h1>React-Ace</h1>
<div id="example"></div>
</div>
</div>
<script src="./static/bundle.js"></script>
<script src="./static/index.js"></script>
</body>
</html>
22 changes: 18 additions & 4 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React, { Component } from 'react';
import { render } from 'react-dom';
import AceEditor from '../src/ace.jsx';
import brace from 'brace';


import 'brace/mode/jsx';


const languages = [
'javascript',
'java',
Expand Down Expand Up @@ -223,6 +219,24 @@ class App extends Component {
showPrintMargin={this.state.showPrintMargin}
showGutter={this.state.showGutter}
highlightActiveLine={this.state.highlightActiveLine}
commands={[
{
name: 'myReactAceTest',
bindKey: {win: 'Ctrl-M', mac: 'Command-M'},
exec: () => {
console.log("this coammdb or whatever")
},
readOnly: true
},
{
name: 'myTestCommand',
bindKey: {win: 'Ctrl-W', mac: 'Command-W'},
exec: () => {
console.log("this coammdb or whatever")
},
readOnly: true
}
]}
value={this.state.value}
setOptions={{
enableBasicAutocompletion: this.state.enableBasicAutocompletion,
Expand Down
17 changes: 17 additions & 0 deletions example/split.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Split Editor</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.1/css/bulma.min.css"></link>
</head>
<body>
<div class="container">
<div class="content">
<h1>React-Ace: Split Editor Example</h1>
<div id="example"></div>
</div>
</div>
<script src="./static/split.js"></script>
</body>
</html>
286 changes: 286 additions & 0 deletions example/split.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
import React, { Component } from 'react';
import { render } from 'react-dom';
import SplitAceEditor from '../src/split.jsx';

import 'brace/mode/jsx';


const languages = [
'javascript',
'java',
'python',
'xml',
'ruby',
'sass',
'markdown',
'mysql',
'json',
'html',
'handlebars',
'golang',
'csharp',
'elixir',
'typescript',
'css'
]

const themes = [
'monokai',
'github',
'tomorrow',
'kuroir',
'twilight',
'xcode',
'textmate',
'solarized_dark',
'solarized_light',
'terminal',
]

languages.forEach((lang) => {
require(`brace/mode/${lang}`)
})

themes.forEach((theme) => {
require(`brace/theme/${theme}`)
})
/*eslint-disable no-alert, no-console */
import 'brace/ext/language_tools';


const defaultValue = [
`function onLoad(editor) {
console.log(\"i\'ve loaded\");
}`,
'const secondInput = "me i am the second input";'
];
class App extends Component {
onLoad() {
console.log('i\'ve loaded');
}
onChange(newValue) {
console.log('change', newValue);
this.setState({
value: newValue
})
}

onSelectionChange(newValue, event) {
console.log('select-change', newValue);
console.log('select-change-event', event);
}
setTheme(e) {
this.setState({
theme: e.target.value
})
}
setMode(e) {
this.setState({
mode: e.target.value
})
}
setBoolean(name, value) {
this.setState({
[name]: value
})
}
setFontSize(e) {
this.setState({
fontSize: parseInt(e.target.value,10)
})
}
setSplits(e) {
this.setState({
splits: parseInt(e.target.value,10)
})
}
setOrientation(e) {
this.setState({
orientation: e.target.value
})
}
constructor(props) {
super(props);
this.state = {
splits: 2,
orientation: 'beside',
value: defaultValue,
theme: 'github',
mode: 'javascript',
enableBasicAutocompletion: false,
enableLiveAutocompletion: false,
fontSize: 14,
showGutter: true,
showPrintMargin: true,
highlightActiveLine: true,
enableSnippets: false,
showLineNumbers: true,
};
this.setTheme = this.setTheme.bind(this);
this.setMode = this.setMode.bind(this);
this.onChange = this.onChange.bind(this);
this.setFontSize = this.setFontSize.bind(this);
this.setBoolean = this.setBoolean.bind(this);
this.setSplits = this.setSplits.bind(this);
this.setOrientation = this.setOrientation.bind(this);
}
render() {
return (
<div className="columns">
<div className="column">
<div className="field">
<label>
Mode:
</label>
<p className="control">
<span className="select">
<select name="mode" onChange={this.setMode} value={this.state.mode}>
{languages.map((lang) => <option key={lang} value={lang}>{lang}</option>)}
</select>
</span>
</p>
</div>

<div className="field">
<label>
Theme:
</label>
<p className="control">
<span className="select">
<select name="Theme" onChange={this.setTheme} value={this.state.theme}>
{themes.map((lang) => <option key={lang} value={lang}>{lang}</option>)}
</select></span>
</p>
</div>

<div className="field">
<label>
Font Size:
</label>
<p className="control">
<span className="select">
<select name="Font Size" onChange={this.setFontSize} value={this.state.fontSize}>
{[10,12,14,16,18,20,24,28,32,40].map((lang) => <option key={lang} value={lang}>{lang}</option>)}
</select></span>
</p>
</div>

<div className="field">
<label>
Number of Splits:
</label>
<p className="control">
<span className="select">
<select name="splits" onChange={this.setSplits} value={this.state.splits}>
{[1,2,3,4].map((lang) => <option key={lang} value={lang}>{lang}</option>)}
</select></span>
</p>
</div>

<div className="field">
<label>
Orientation:
</label>
<p className="control">
<span className="select">
<select name="orientation" onChange={this.setOrientation} value={this.state.orientation}>
{['beside', 'below'].map((lang) => <option key={lang} value={lang}>{lang}</option>)}
</select></span>
</p>
</div>
<div className="field">
<p className="control">
<label className="checkbox">
<input type="checkbox" checked={this.state.enableBasicAutocompletion} onChange={(e) => this.setBoolean('enableBasicAutocompletion', e.target.checked)} />
Enable Basic Autocomplete
</label>
</p>
</div>
<div className="field">
<p className="control">
<label className="checkbox">
<input type="checkbox" checked={this.state.enableLiveAutocompletion} onChange={(e) => this.setBoolean('enableLiveAutocompletion', e.target.checked)} />
Enable Live Autocomplete
</label>
</p>
</div>
<div className="field">
<p className="control">
<label className="checkbox">
<input type="checkbox" checked={this.state.showGutter} onChange={(e) => this.setBoolean('showGutter', e.target.checked)} />
Show Gutter
</label>
</p>
</div>
<div className="field">
<p className="control">
<label className="checkbox">
<input type="checkbox" checked={this.state.showPrintMargin} onChange={(e) => this.setBoolean('showPrintMargin', e.target.checked)} />
Show Print Margin
</label>
</p>
</div>
<div className="field">
<p className="control">
<label className="checkbox">
<input type="checkbox" checked={this.state.highlightActiveLine} onChange={(e) => this.setBoolean('highlightActiveLine', e.target.checked)} />
Highlight Active Line
</label>
</p>
</div>
<div className="field">
<p className="control">
<label className="checkbox">
<input type="checkbox" checked={this.state.enableSnippets} onChange={(e) => this.setBoolean('enableSnippets', e.target.checked)} />
Enable Snippets
</label>
</p>
</div>
<div className="field">
<p className="control">
<label className="checkbox">
<input type="checkbox" checked={this.state.showLineNumbers} onChange={(e) => this.setBoolean('showLineNumbers', e.target.checked)} />
Show Line Numbers
</label>
</p>
</div>


</div>
<div className="examples column">
<h2>Editor</h2>
<SplitAceEditor
mode={this.state.mode}
orientation={this.state.orientation}
splits={this.state.splits}
theme={this.state.theme}
name="blah2"
onLoad={this.onLoad}
onChange={this.onChange}
onSelectionChange={this.onSelectionChange}
fontSize={this.state.fontSize}
height="1000px"
width="1000px"
showPrintMargin={this.state.showPrintMargin}
showGutter={this.state.showGutter}
highlightActiveLine={this.state.highlightActiveLine}
value={this.state.value}
setOptions={{
displayIndentGuides: false,
enableBasicAutocompletion: this.state.enableBasicAutocompletion,
enableLiveAutocompletion: this.state.enableLiveAutocompletion,
enableSnippets: this.state.enableSnippets,
showLineNumbers: this.state.showLineNumbers,
tabSize: 2,
}}/>
</div>
</div>
);
}
}


render(
<App />,
document.getElementById('example')
);
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
"name": "react-ace",
"version": "4.4.0",
"description": "A react component for Ace Editor",
"main": "lib/ace.js",
"main": "lib/index.js",
"types": "types.d.ts",
"scripts": {
"clean": "rimraf lib dist",
"lint": "node_modules/.bin/eslint src/ace.jsx",
"lint": "node_modules/.bin/eslint src/*",
"build:lib": "babel src --out-dir lib",
"build:umd": "webpack src/ace.jsx dist/react-ace.js --config webpack.config.development.js",
"build:umd:min": "webpack src/ace.jsx dist/react-ace.min.js --config webpack.config.production.js",
"build:umd": "webpack src/index.js dist/react-ace.js --config webpack.config.development.js",
"build:umd:min": "webpack src/index.js dist/react-ace.min.js --config webpack.config.production.js",
"example": "webpack-dev-server --config webpack.config.example.js",
"build:example": "webpack --config webpack.config.example.js",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
Expand All @@ -25,7 +25,8 @@
"babel": {
"presets": [
"es2015",
"react"
"react",
"stage-2"
],
"plugins": [
"transform-object-rest-spread"
Expand All @@ -41,6 +42,7 @@
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"chai": "^3.5.0",
"coveralls": "^2.13.1",
"enzyme": "^2.4.1",
Expand All @@ -66,6 +68,7 @@
],
"dependencies": {
"brace": "^0.10.0",
"lodash.get": "^4.4.2",
"lodash.isequal": "^4.1.1",
"opencollective": "^1.0.3",
"prop-types": "^15.5.8"
Expand Down
Loading

0 comments on commit b390c19

Please sign in to comment.