refactor(joyent-manifest-editor): react-codemirror as peer-dep

BREAKING CHANGE
This commit is contained in:
Sérgio Ramos 2017-06-09 05:22:49 +01:00 committed by Judit Greskovits
parent 75eded4b06
commit 14ffdb9636
3 changed files with 100 additions and 881 deletions

View File

@ -6,9 +6,9 @@
"description": "", "description": "",
"keywords": [], "keywords": [],
"repository": "github:yldio/joyent-portal", "repository": "github:yldio/joyent-portal",
"main": "dist/manifest-editor.umd.js", "main": "dist/joyent-manifest-editor.umd.js",
"jsnext:main": "dist/manifest-editor.es.js", "jsnext:main": "dist/joyent-manifest-editor.es.js",
"module": "dist/manifest-editor.es.js", "module": "dist/joyent-manifest-editor.es.js",
"entry": "src/index.js", "entry": "src/index.js",
"scripts": { "scripts": {
"lint:css": "echo 0", "lint:css": "echo 0",
@ -23,13 +23,11 @@
"prepublish": "redrun build" "prepublish": "redrun build"
}, },
"dependencies": { "dependencies": {
"prop-types": "^15.5.10", "prop-types": "^15.5.10"
"react-codemirror": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"babel-preset-react-app": "^3.0.0", "babel-preset-react-app": "^3.0.0",
"bup": "^1.0.9", "bup": "^1.0.9",
"codemirror": "^5.26.0",
"eslint": "^3.19.0", "eslint": "^3.19.0",
"eslint-config-joyent-portal": "1.0.3", "eslint-config-joyent-portal": "1.0.3",
"jest": "^20.0.4", "jest": "^20.0.4",
@ -39,8 +37,7 @@
}, },
"peerDependencies": { "peerDependencies": {
"react": "*", "react": "*",
"codemirror": "*", "react-codemirror": "*"
"react-dom": "*"
}, },
"jest": { "jest": {
"testEnvironment": "jsdom", "testEnvironment": "jsdom",

View File

@ -2,35 +2,13 @@ import React, { Component } from 'react';
import ReactCodeMirror from 'react-codemirror'; import ReactCodeMirror from 'react-codemirror';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
class ManifestEditor extends Component { const options = {
constructor({ value, defaultValue }) { theme: 'eclipse',
super();
this._refs = {};
}
ref(name) {
return ref => {
this._refs[name] = ref;
};
}
options({ mode, theme, keyMap }) {
const modes = {
json: {
name: 'javascript',
json: true
},
yaml: 'yaml'
};
return {
mode: modes[mode.toLowerCase()],
theme,
indentUnit: 2, indentUnit: 2,
smartIndent: true, smartIndent: true,
tabSize: 2, tabSize: 2,
indentWithTabs: false, indentWithTabs: false,
electricChars: true, electricChars: true,
keyMap,
lineNumbers: true, lineNumbers: true,
inputStyle: 'contenteditable', inputStyle: 'contenteditable',
readOnly: false, readOnly: false,
@ -44,10 +22,34 @@ class ManifestEditor extends Component {
viewportMargin: Infinity, viewportMargin: Infinity,
gutters: [ gutters: [
'CodeMirror-lint-markers', 'CodeMirror-lint-markers',
'CodeMirror-linenumbers', 'CodeMirror-foldgutter',
'CodeMirror-foldgutter' 'CodeMirror-linenumbers'
] ]
}; };
class ManifestEditor extends Component {
constructor() {
super();
this._refs = {};
}
ref(name) {
return ref => {
this._refs[name] = ref;
};
}
options({ mode }) {
const modes = {
json: {
name: 'javascript',
json: true
},
yaml: 'yaml'
};
return Object.assign({}, options, {
mode: modes[mode.toLowerCase()]
});
} }
render() { render() {
return ( return (
@ -66,73 +68,20 @@ class ManifestEditor extends Component {
ManifestEditor.defaultProps = { ManifestEditor.defaultProps = {
mode: 'json', mode: 'json',
theme: 'eclipse',
defaultValue: '', defaultValue: '',
onChange: () => null, onChange: () => null,
onFocusChange: () => null, onFocusChange: () => null,
autoSave: true, autoSave: true,
preserveScrollPosition: true, preserveScrollPosition: true
keyMap: 'sublime'
}; };
ManifestEditor.propTypes = { ManifestEditor.propTypes = {
mode: PropTypes.oneOf(['json', 'yaml']), mode: PropTypes.oneOf(['json', 'yaml']),
theme: PropTypes.oneOf([
'3024-day',
'3024-night',
'abcdef',
'ambiance-mobile',
'ambiance',
'base16-dark',
'base16-light',
'bespin',
'blackboard',
'cobalt',
'colorforth',
'dracula',
'duotone-dark',
'duotone-light',
'eclipse',
'elegant',
'erlang-dark',
'hopscotch',
'icecoder',
'isotope',
'lesser-dark',
'liquibyte',
'material',
'mbo',
'mdn-like',
'midnight',
'monokai',
'neat',
'neo',
'night',
'panda-syntax',
'paraiso-dark',
'paraiso-light',
'pastel-on-dark',
'railscasts',
'rubyblue',
'seti',
'solarized',
'the-matrix',
'tomorrow-night-bright',
'tomorrow-night-eighties',
'ttcn',
'twilight',
'vibrant-ink',
'xq-dark',
'xq-light',
'yeti',
'zenburn'
]),
value: PropTypes.string, value: PropTypes.string,
onChange: PropTypes.func, onChange: PropTypes.func,
onFocusChange: PropTypes.func, onFocusChange: PropTypes.func,
autoSave: PropTypes.bool, autoSave: PropTypes.bool,
preserveScrollPosition: PropTypes.bool, preserveScrollPosition: PropTypes.bool
keyMap: PropTypes.oneOf(['sublime', 'vim', 'emacs'])
}; };
export default ManifestEditor; export default ManifestEditor;

File diff suppressed because it is too large Load Diff