Skip to content

Commit

Permalink
Initial rebuild and prettify.
Browse files Browse the repository at this point in the history
  • Loading branch information
cssquirrel committed Feb 20, 2018
1 parent f7ec6a4 commit b238c8f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 73 deletions.
43 changes: 22 additions & 21 deletions build/assets/js/components/logic/ErnestLogic/ErnestLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
RichUtils,
SelectionState
} from 'draft-js';
import {stateToHTML} from 'draft-js-export-html';
import { stateToHTML } from 'draft-js-export-html';

// utils
import Constants from '../../../utils/Constants';
Expand All @@ -29,10 +29,11 @@ class ErnestLogic extends React.Component {
super(props);

const value = props.value;
const contentState = value && value.raw && value.raw !== '' ? convertFromRaw(value.raw) : false;
const editorState = contentState
? EditorState.createWithContent(contentState)
: EditorState.createEmpty();
const contentState =
value && value.raw && value.raw !== '' ? convertFromRaw(value.raw) : false;
const editorState = contentState
? EditorState.createWithContent(contentState)
: EditorState.createEmpty();

this.state = {
editor: editorState
Expand Down Expand Up @@ -141,7 +142,7 @@ class ErnestLogic extends React.Component {
* @param {RawDraftContentState} newProps.value
* @returns {boolean}
*/
isContentFromPropsNew = (newProps: { value: {raw: RawDraftContentState }}) => {
isContentFromPropsNew = (newProps: { value: { raw: RawDraftContentState } }) => {
const editorState = this.state.editor;
const currentRaw = JSON.stringify(convertToRaw(editorState.getCurrentContent()));
const nextRaw = JSON.stringify(newProps.value.raw);
Expand All @@ -155,7 +156,7 @@ class ErnestLogic extends React.Component {
*/
updateEditorStateFromValue = (value: RawDraftContentState) => {
if (value && value !== '') {
const editorState = this.state.editor;
const editorState = this.state.editor;
const contentState = convertFromRaw(value);
const newEditorState = EditorState.push(editorState, contentState);
this.updateState({ editor: newEditorState });
Expand Down Expand Up @@ -186,15 +187,15 @@ class ErnestLogic extends React.Component {
console.groupEnd('===ErnestLogic===');
}
return this.state;
};
updateValue = (editor: EditorState) => {
const value = {
raw: this.convertEditorStateToValue(this.state.editor),
html: this.convertEditorStateToHtml(this.state.editor)
};
this.props.onValueChange(value);
}
};

updateValue = (editor: EditorState) => {
const value = {
raw: this.convertEditorStateToValue(this.state.editor),
html: this.convertEditorStateToHtml(this.state.editor)
};
this.props.onValueChange(value);
};

// Event Handlers //////////////////////////////////////////////////////////

Expand All @@ -212,10 +213,10 @@ class ErnestLogic extends React.Component {
const newEditorState = StyleHelpers.toggleBlockType(this.state.editor, buttonType);

this.updateState({ editor: newEditorState }, () => {
this.updateValue(this.state.editor);
this.updateValue(this.state.editor);
});
};
};

/**
* @method onInlineClick
* @param {Event} e
Expand All @@ -237,7 +238,7 @@ class ErnestLogic extends React.Component {
const newEditorState = StyleHelpers.toggleInlineStyle(this.state.editor, options);

this.updateState({ editor: newEditorState }, () => {
this.updateValue(this.state.editor);
this.updateValue(this.state.editor);
});
};

Expand All @@ -261,7 +262,7 @@ class ErnestLogic extends React.Component {
this.updateState({ editor: cleaned }, () => {
const highlighted = this.highlightSuggestions(this.state.editor);
this.updateState({ editor: highlighted }, () => {
this.updateValue(this.state.editor);
this.updateValue(this.state.editor);
});
});
};
Expand Down
80 changes: 40 additions & 40 deletions build/assets/js/components/views/Ernest/Ernest.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,53 +39,53 @@ const styleMap = {
* @returns {JSX.Element}
*/
class Ernest extends React.Component {
constructor (props) {
super(props);
}
constructor(props) {
super(props);
}

// React Lifecycle Methods /////////////////////////////////////////////////

// Helper Functions ////////////////////////////////////////////////////////

// React Lifecycle Methods /////////////////////////////////////////////////

// Helper Functions ////////////////////////////////////////////////////////

// Event Handlers //////////////////////////////////////////////////////////

/**
* @method onFocusClick - If the user clicks on the container outside of the
* actual editor, focus on the editor.
* @param {Event} e
* @returns {void}
*/
onFocusClick = (e) => {
if (e) {
e.preventDefault();
}
this.refs.editor.focus();
}
/**
* @method onFocusClick - If the user clicks on the container outside of the
* actual editor, focus on the editor.
* @param {Event} e
* @returns {void}
*/
onFocusClick = (e) => {
if (e) {
e.preventDefault();
}
this.refs.editor.focus();
};

// Render Assisting Methods ////////////////////////////////////////////////

// Render //////////////////////////////////////////////////////////////////
// Render //////////////////////////////////////////////////////////////////

render = () => {
const events = this.props.events;
const editor = this.props.editor;
const value = editor ? editor : EditorState.createEmpty();
render = () => {
const events = this.props.events;
const editor = this.props.editor;
const value = editor ? editor : EditorState.createEmpty();

return (
<div className="ernest-container">
<Toolbar events={events} />
<div className="text-editor-wrapper" onClick={this.onFocusClick}>
<Editor
customStyleMap={styleMap}
editorState={value}
onChange={events.onValueChange}
ref="editor"
/>
</div>
<Suggestions suggestions={this.props.suggestions} />
</div>
);
}
};
return (
<div className="ernest-container">
<Toolbar events={events} />
<div className="text-editor-wrapper" onClick={this.onFocusClick}>
<Editor
customStyleMap={styleMap}
editorState={value}
onChange={events.onValueChange}
ref="editor"
/>
</div>
<Suggestions suggestions={this.props.suggestions} />
</div>
);
};
}

module.exports = Ernest;
2 changes: 1 addition & 1 deletion build/assets/js/controllers/AngularWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const AngularWrapper = function($scope, $element) {
* the Angular controller's state.
*/
$scope.updateAngular = function(value) {
$scope.model.value = value;
$scope.model.value = value;
$scope.$apply();
};

Expand Down
20 changes: 10 additions & 10 deletions build/assets/js/utils/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const Constants = {
UNORDERED_LIST: 'unordered-list-item',
ORDERED_LIST: 'ordered-list-item'
},
DEFAULT_REASON_KEYS: 'passive,illusion,so,thereIs,weasel,adverb,tooWordy,cliches',
HIGHLIGHT_COLORS: {
LIGHT_GREEN: 'lightgreen',
ADVERB: '#c4e3f3',
PASSIVE: '#c4ed9d',
TOOWORDY: '#e4b9b9',
SOTHEREISWEASEL: '#e3b7e8',
CLICHETOBEILLUSION: '#f7ecb5'
},
DEFAULT_REASON_KEYS: 'passive,illusion,so,thereIs,weasel,adverb,tooWordy,cliches',
HIGHLIGHT_COLORS: {
LIGHT_GREEN: 'lightgreen',
ADVERB: '#c4e3f3',
PASSIVE: '#c4ed9d',
TOOWORDY: '#e4b9b9',
SOTHEREISWEASEL: '#e3b7e8',
CLICHETOBEILLUSION: '#f7ecb5'
},
StyleKeys: {
BOLD: 'BOLD',
HIGHLIGHT: 'HIGHLIGHT',
Expand All @@ -29,7 +29,7 @@ const Constants = {
HIGHLIGHT_SOTHEREISWEASEL: 'HIGHLIGHT_SOTHEREISWEASEL',
HIGHLIGHT_CLICHETOBEILLUSION: 'HIGHLIGHT_CLICHETOBEILLUSION',
ITALIC: 'ITALIC'
}
}
};

module.exports = Constants;
2 changes: 1 addition & 1 deletion build/dist/App_Plugins/Ernest/js/bundle.js

Large diffs are not rendered by default.

0 comments on commit b238c8f

Please sign in to comment.