This commit is contained in:
Jori Lallo
2017-09-10 16:32:01 -04:00
parent 2140a0698a
commit c3d918e165
4 changed files with 2 additions and 81 deletions

View File

@ -32,6 +32,7 @@ const Anchor = styled.a`
} }
`; `;
// $FlowIssue I don't know
const titleStyles = component => styled(component)` const titleStyles = component => styled(component)`
position: relative; position: relative;

View File

@ -1,77 +0,0 @@
// @flow
import React from 'react';
import { State, Document, Editor } from 'slate';
import MarkdownSerializer from '../Editor/serializer';
import type { State as StateType } from '../Editor/types';
import schema from '../Editor/schema';
import styles from '../Editor/Editor.scss';
type Props = {
text: string,
className: string,
limit: number,
};
function filterDocumentState({ state, characterLimit, nodeLimit }) {
const { document } = state;
if (document.text.length <= characterLimit) {
return state;
}
let totalCharacters = 0;
let totalNodes = 0;
const nodes = document.nodes.filter(childNode => {
if (childNode.text.length + totalCharacters <= characterLimit) {
totalCharacters += childNode.text.length;
if (totalNodes++ <= nodeLimit) {
return true;
}
}
return false;
});
return State.create({
document: Document.create({
...document,
nodes: nodes,
}),
});
}
class Markdown extends React.Component {
props: Props;
state: {
state: StateType,
};
constructor(props: Props) {
super(props);
const state = MarkdownSerializer.deserialize(props.text);
const options = {
state,
characterLimit: props.limit,
nodeLimit: 5,
};
this.state = {
state: filterDocumentState(options),
};
}
render() {
return (
<span className={this.props.className}>
<Editor
className={styles.editor}
schema={schema}
state={this.state.state}
readOnly
/>
</span>
);
}
}
export default Markdown;

View File

@ -1,3 +0,0 @@
// @flow
import Markdown from './Markdown';
export default Markdown;

View File

@ -7,7 +7,7 @@ import { color } from 'styles/constants';
type Props = { type Props = {
id: string, id: string,
name: string, name: ?string,
secret: string, secret: string,
onDelete: Function, onDelete: Function,
}; };