Linting
This commit is contained in:
parent
004d4828f8
commit
89afcfd897
7 changed files with 23 additions and 17 deletions
|
@ -21,14 +21,14 @@ class HistoryItem {
|
||||||
let {message} = this;
|
let {message} = this;
|
||||||
if (format === 'markdown') {
|
if (format === 'markdown') {
|
||||||
if (this.format === 'html') {
|
if (this.format === 'html') {
|
||||||
message = _flow([RichText.HTMLtoContentState, RichText.stateToMarkdown])(message);
|
message = _flow([RichText.htmlToContentState, RichText.stateToMarkdown])(message);
|
||||||
}
|
}
|
||||||
return ContentState.createFromText(message);
|
return ContentState.createFromText(message);
|
||||||
} else {
|
} else {
|
||||||
if (this.format === 'markdown') {
|
if (this.format === 'markdown') {
|
||||||
message = new Markdown(message).toHTML();
|
message = new Markdown(message).toHTML();
|
||||||
}
|
}
|
||||||
return RichText.HTMLtoContentState(message);
|
return RichText.htmlToContentState(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ export const contentStateToHTML = (contentState: ContentState) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export function HTMLtoContentState(html: string): ContentState {
|
export function htmlToContentState(html: string): ContentState {
|
||||||
return ContentState.createFromBlockArray(convertFromHTML(html));
|
return ContentState.createFromBlockArray(convertFromHTML(html));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ const COMMANDS = [
|
||||||
command: '/op',
|
command: '/op',
|
||||||
args: '<userId> [<power level>]',
|
args: '<userId> [<power level>]',
|
||||||
description: 'Define the power level of a user',
|
description: 'Define the power level of a user',
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const COMMAND_RE = /(^\/\w*)/g;
|
const COMMAND_RE = /(^\/\w*)/g;
|
||||||
|
@ -96,7 +96,7 @@ export default class CommandProvider extends AutocompleteProvider {
|
||||||
let completions = [];
|
let completions = [];
|
||||||
const {command, range} = this.getCurrentCommand(query, selection);
|
const {command, range} = this.getCurrentCommand(query, selection);
|
||||||
if (command) {
|
if (command) {
|
||||||
completions = this.matcher.match(command[0]).map(result => {
|
completions = this.matcher.match(command[0]).map((result) => {
|
||||||
return {
|
return {
|
||||||
completion: result.command + ' ',
|
completion: result.command + ' ',
|
||||||
component: (<TextualCompletion
|
component: (<TextualCompletion
|
||||||
|
|
|
@ -19,15 +19,17 @@ const DEFAULT_DISTANCE = 5;
|
||||||
import PrefixMatcher from './QueryMatcher';
|
import PrefixMatcher from './QueryMatcher';
|
||||||
export default PrefixMatcher;
|
export default PrefixMatcher;
|
||||||
|
|
||||||
class FuzzyMatcher {
|
class FuzzyMatcher { // eslint-disable-line no-unused-vars
|
||||||
/**
|
/**
|
||||||
* Given an array of objects and keys, returns a KeyMap
|
* @param {object[]} objects the objects to perform a match on
|
||||||
|
* @param {string[]} keys an array of keys within each object to match on
|
||||||
* Keys can refer to object properties by name and as in JavaScript (for nested properties)
|
* Keys can refer to object properties by name and as in JavaScript (for nested properties)
|
||||||
*
|
*
|
||||||
* To use, simply presort objects by required criteria, run through this function and create a FuzzyMatcher with the
|
* To use, simply presort objects by required criteria, run through this function and create a FuzzyMatcher with the
|
||||||
* resulting KeyMap.
|
* resulting KeyMap.
|
||||||
*
|
*
|
||||||
* TODO: Handle arrays and objects (Fuse did this, RoomProvider uses it)
|
* TODO: Handle arrays and objects (Fuse did this, RoomProvider uses it)
|
||||||
|
* @return {KeyMap}
|
||||||
*/
|
*/
|
||||||
static valuesToKeyMap(objects: Array<Object>, keys: Array<String>): KeyMap {
|
static valuesToKeyMap(objects: Array<Object>, keys: Array<String>): KeyMap {
|
||||||
const keyMap = new KeyMap();
|
const keyMap = new KeyMap();
|
||||||
|
@ -48,7 +50,7 @@ class FuzzyMatcher {
|
||||||
|
|
||||||
keyMap.objectMap = map;
|
keyMap.objectMap = map;
|
||||||
keyMap.priorityMap = priorities;
|
keyMap.priorityMap = priorities;
|
||||||
keyMap.keys = _sortBy(_keys(map), [value => priorities[value]]);
|
keyMap.keys = _sortBy(_keys(map), [(value) => priorities[value]]);
|
||||||
return keyMap;
|
return keyMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,15 +76,15 @@ class FuzzyMatcher {
|
||||||
match(query: String): Array<Object> {
|
match(query: String): Array<Object> {
|
||||||
const candidates = this.matcher.transduce(query, this.options.distance || DEFAULT_DISTANCE);
|
const candidates = this.matcher.transduce(query, this.options.distance || DEFAULT_DISTANCE);
|
||||||
// TODO FIXME This is hideous. Clean up when possible.
|
// TODO FIXME This is hideous. Clean up when possible.
|
||||||
const val = _sortedUniq(_sortBy(_flatMap(candidates, candidate => {
|
const val = _sortedUniq(_sortBy(_flatMap(candidates, (candidate) => {
|
||||||
return this.keyMap.objectMap[candidate[0]].map(value => {
|
return this.keyMap.objectMap[candidate[0]].map((value) => {
|
||||||
return {
|
return {
|
||||||
distance: candidate[1],
|
distance: candidate[1],
|
||||||
...value,
|
...value,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
[candidate => candidate.distance, candidate => this.keyMap.priorityMap[candidate]]));
|
[(candidate) => candidate.distance, (candidate) => this.keyMap.priorityMap[candidate]]));
|
||||||
console.log(val);
|
console.log(val);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,15 @@ class KeyMap {
|
||||||
|
|
||||||
export default class QueryMatcher {
|
export default class QueryMatcher {
|
||||||
/**
|
/**
|
||||||
* Given an array of objects and keys, returns a KeyMap
|
* @param {object[]} objects the objects to perform a match on
|
||||||
|
* @param {string[]} keys an array of keys within each object to match on
|
||||||
* Keys can refer to object properties by name and as in JavaScript (for nested properties)
|
* Keys can refer to object properties by name and as in JavaScript (for nested properties)
|
||||||
*
|
*
|
||||||
* To use, simply presort objects by required criteria, run through this function and create a QueryMatcher with the
|
* To use, simply presort objects by required criteria, run through this function and create a QueryMatcher with the
|
||||||
* resulting KeyMap.
|
* resulting KeyMap.
|
||||||
*
|
*
|
||||||
* TODO: Handle arrays and objects (Fuse did this, RoomProvider uses it)
|
* TODO: Handle arrays and objects (Fuse did this, RoomProvider uses it)
|
||||||
|
* @return {KeyMap}
|
||||||
*/
|
*/
|
||||||
static valuesToKeyMap(objects: Array<Object>, keys: Array<String>): KeyMap {
|
static valuesToKeyMap(objects: Array<Object>, keys: Array<String>): KeyMap {
|
||||||
const keyMap = new KeyMap();
|
const keyMap = new KeyMap();
|
||||||
|
|
|
@ -642,6 +642,10 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_renderUserInterfaceSettings: function() {
|
_renderUserInterfaceSettings: function() {
|
||||||
|
// TODO: this ought to be a separate component so that we don't need
|
||||||
|
// to rebind the onChange each time we render
|
||||||
|
const onChange = (e) =>
|
||||||
|
UserSettingsStore.setLocalSetting('autocompleteDelay', + e.target.value);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h3>{ _t("User Interface") }</h3>
|
<h3>{ _t("User Interface") }</h3>
|
||||||
|
@ -657,9 +661,7 @@ module.exports = React.createClass({
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
defaultValue={UserSettingsStore.getLocalSetting('autocompleteDelay', 200)}
|
defaultValue={UserSettingsStore.getLocalSetting('autocompleteDelay', 200)}
|
||||||
onChange={
|
onChange={onChange}
|
||||||
(e) => UserSettingsStore.setLocalSetting('autocompleteDelay', + e.target.value)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -201,7 +201,7 @@ export default class MessageComposerInput extends React.Component {
|
||||||
let {body, formatted_body} = payload.event.getContent();
|
let {body, formatted_body} = payload.event.getContent();
|
||||||
formatted_body = formatted_body || escape(body);
|
formatted_body = formatted_body || escape(body);
|
||||||
if (formatted_body) {
|
if (formatted_body) {
|
||||||
let content = RichText.HTMLtoContentState(`<blockquote>${formatted_body}</blockquote>`);
|
let content = RichText.htmlToContentState(`<blockquote>${formatted_body}</blockquote>`);
|
||||||
if (!this.state.isRichtextEnabled) {
|
if (!this.state.isRichtextEnabled) {
|
||||||
content = ContentState.createFromText(RichText.stateToMarkdown(content));
|
content = ContentState.createFromText(RichText.stateToMarkdown(content));
|
||||||
}
|
}
|
||||||
|
@ -350,7 +350,7 @@ export default class MessageComposerInput extends React.Component {
|
||||||
let contentState = null;
|
let contentState = null;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
const md = new Markdown(this.state.editorState.getCurrentContent().getPlainText());
|
const md = new Markdown(this.state.editorState.getCurrentContent().getPlainText());
|
||||||
contentState = RichText.HTMLtoContentState(md.toHTML());
|
contentState = RichText.htmlToContentState(md.toHTML());
|
||||||
} else {
|
} else {
|
||||||
let markdown = RichText.stateToMarkdown(this.state.editorState.getCurrentContent());
|
let markdown = RichText.stateToMarkdown(this.state.editorState.getCurrentContent());
|
||||||
if (markdown[markdown.length - 1] === '\n') {
|
if (markdown[markdown.length - 1] === '\n') {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue