Make linter happier
This commit is contained in:
parent
f40b75e2e3
commit
3a087e44fa
@ -34,13 +34,6 @@ export default class RawEditor extends React.Component {
|
|||||||
this.element.addEventListener('drop', this.handleDrop, false);
|
this.element.addEventListener('drop', this.handleDrop, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
console.log('unmounting');
|
|
||||||
this.element.removeEventListener('dragenter', preventDefault);
|
|
||||||
this.element.removeEventListener('dragover', preventDefault);
|
|
||||||
this.element.removeEventListener('drop', this.handleDrop);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
if (this.newSelection) {
|
if (this.newSelection) {
|
||||||
this.element.selectionStart = this.newSelection.start;
|
this.element.selectionStart = this.newSelection.start;
|
||||||
@ -49,74 +42,12 @@ export default class RawEditor extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange = (e) => {
|
componentWillUnmount() {
|
||||||
this.props.onChange(e.target.value);
|
this.element.removeEventListener('dragenter', preventDefault);
|
||||||
this.updateHeight();
|
this.element.removeEventListener('dragover', preventDefault);
|
||||||
};
|
this.element.removeEventListener('drop', this.handleDrop);
|
||||||
|
|
||||||
handleDrop = (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
let data;
|
|
||||||
|
|
||||||
if (e.dataTransfer.files && e.dataTransfer.files.length) {
|
|
||||||
data = Array.from(e.dataTransfer.files).map((file) => {
|
|
||||||
const mediaProxy = new MediaProxy(file.name, file);
|
|
||||||
this.props.onAddMedia(mediaProxy);
|
|
||||||
const link = `[${ file.name }](${ mediaProxy.public_path })`;
|
|
||||||
if (file.type.split('/')[0] === 'image') {
|
|
||||||
return `!${ link }`;
|
|
||||||
}
|
|
||||||
return link;
|
|
||||||
}).join('\n\n');
|
|
||||||
} else {
|
|
||||||
data = e.dataTransfer.getData('text/plain');
|
|
||||||
}
|
|
||||||
this.replaceSelection(data);
|
|
||||||
};
|
|
||||||
|
|
||||||
updateHeight() {
|
|
||||||
if (this.element.scrollHeight > this.element.clientHeight) {
|
|
||||||
this.element.style.height = `${ this.element.scrollHeight }px`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRef = (ref) => {
|
|
||||||
this.element = ref;
|
|
||||||
};
|
|
||||||
|
|
||||||
handleToolbarRef = (ref) => {
|
|
||||||
this.toolbar = ref;
|
|
||||||
};
|
|
||||||
|
|
||||||
handleKey = (e) => {
|
|
||||||
if (e.metaKey) {
|
|
||||||
const action = this.shortcuts.meta[e.key];
|
|
||||||
if (action) {
|
|
||||||
e.preventDefault();
|
|
||||||
action();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
handleBold = () => {
|
|
||||||
this.surroundSelection('**');
|
|
||||||
};
|
|
||||||
|
|
||||||
handleItalic = () => {
|
|
||||||
this.surroundSelection('*');
|
|
||||||
};
|
|
||||||
|
|
||||||
handleLink = () => {
|
|
||||||
const url = prompt('URL:');
|
|
||||||
const selection = this.getSelection();
|
|
||||||
this.replaceSelection(`[${ selection.selected }](${ processUrl(url) })`);
|
|
||||||
};
|
|
||||||
|
|
||||||
handleSelection = () => {
|
|
||||||
const selection = this.getSelection();
|
|
||||||
this.setState({ showToolbar: selection.start !== selection.end });
|
|
||||||
};
|
|
||||||
|
|
||||||
getSelection() {
|
getSelection() {
|
||||||
const start = this.element.selectionStart;
|
const start = this.element.selectionStart;
|
||||||
const end = this.element.selectionEnd;
|
const end = this.element.selectionEnd;
|
||||||
@ -164,6 +95,74 @@ export default class RawEditor extends React.Component {
|
|||||||
this.props.onChange(beforeSelection + chars + afterSelection);
|
this.props.onChange(beforeSelection + chars + afterSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateHeight() {
|
||||||
|
if (this.element.scrollHeight > this.element.clientHeight) {
|
||||||
|
this.element.style.height = `${ this.element.scrollHeight }px`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRef = (ref) => {
|
||||||
|
this.element = ref;
|
||||||
|
};
|
||||||
|
|
||||||
|
handleToolbarRef = (ref) => {
|
||||||
|
this.toolbar = ref;
|
||||||
|
};
|
||||||
|
|
||||||
|
handleKey = (e) => {
|
||||||
|
if (e.metaKey) {
|
||||||
|
const action = this.shortcuts.meta[e.key];
|
||||||
|
if (action) {
|
||||||
|
e.preventDefault();
|
||||||
|
action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
handleBold = () => {
|
||||||
|
this.surroundSelection('**');
|
||||||
|
};
|
||||||
|
|
||||||
|
handleItalic = () => {
|
||||||
|
this.surroundSelection('*');
|
||||||
|
};
|
||||||
|
|
||||||
|
handleLink = () => {
|
||||||
|
const url = prompt('URL:');
|
||||||
|
const selection = this.getSelection();
|
||||||
|
this.replaceSelection(`[${ selection.selected }](${ processUrl(url) })`);
|
||||||
|
};
|
||||||
|
|
||||||
|
handleSelection = () => {
|
||||||
|
const selection = this.getSelection();
|
||||||
|
this.setState({ showToolbar: selection.start !== selection.end });
|
||||||
|
};
|
||||||
|
|
||||||
|
handleChange = (e) => {
|
||||||
|
this.props.onChange(e.target.value);
|
||||||
|
this.updateHeight();
|
||||||
|
};
|
||||||
|
|
||||||
|
handleDrop = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
let data;
|
||||||
|
|
||||||
|
if (e.dataTransfer.files && e.dataTransfer.files.length) {
|
||||||
|
data = Array.from(e.dataTransfer.files).map((file) => {
|
||||||
|
const mediaProxy = new MediaProxy(file.name, file);
|
||||||
|
this.props.onAddMedia(mediaProxy);
|
||||||
|
const link = `[${ file.name }](${ mediaProxy.public_path })`;
|
||||||
|
if (file.type.split('/')[0] === 'image') {
|
||||||
|
return `!${ link }`;
|
||||||
|
}
|
||||||
|
return link;
|
||||||
|
}).join('\n\n');
|
||||||
|
} else {
|
||||||
|
data = e.dataTransfer.getData('text/plain');
|
||||||
|
}
|
||||||
|
this.replaceSelection(data);
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { showToolbar } = this.state;
|
const { showToolbar } = this.state;
|
||||||
return (<div>
|
return (<div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user