Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onChange = (editorState) => {
const {document, name} = this.props
const currentContent = this.state.editorState.getCurrentContent()
const newContent = editorState.getCurrentContent()
if (currentContent !== newContent) {
// Only save to localStorage on every 30th content change
// TODO: Consider debouncing rather than saving every 30th change
// TODO: Consider saving on blur
this.changeCount = this.changeCount + 1;
if (this.changeCount % 30 === 0) {
const rawContent = convertToRaw(newContent);
this.getStorageHandlers().set({state: rawContent, doc: document, name})
}
}
this.setState({editorState: editorState})
return editorState;
}
componentWillUnmount() {
const {editorState, save = () => {}} = this.props;
const blocks = convertToRaw(editorState.getCurrentContent()).blocks;
// it can happen that first block is empty, i.e. there is a carriage return
const rawText = blocks.length === 1 ? convertToRaw(editorState.getCurrentContent()).blocks[0].text : true;
const html = draftToHtml(convertToRaw(editorState.getCurrentContent()));
// when text written inside editor is "" then return EMPTY_CONTENT to manage placeholder outside
save(rawText ? html : EMPTY_CONTENT);
}
}),
handleSave = ({ updateNode }) => () => {
const { editorState } = this.state;
const { node = {} } = this.props;
const markdown = draftToMarkdown(
convertToRaw(editorState.getCurrentContent())
);
this.setState({ source: markdown, originalEditorState: editorState });
updateNode({ variables: { id: node.id, content: markdown } });
console.log('Synced to GraphCMS');
};
render() {
handleAlternate(event) {
var { editorState } = this.state;
var html_body = editorState ? draftToHtml(convertToRaw(editorState.getCurrentContent())) : null;
const section = 'articles'
const articleVars = {
sourceRoute: `public/${section}`,
sourceObject: `${this.state.title}.html`,
destRoute: `${section}`,
delete: false,
};
//console.log(this.state.itemProps)
if (this.state.title === this.state.itemProps.title && this.state.itemProps.body_html === html_body) {
publishArticle(articleVars);
}
else {
alert('Error. Please Save your changes before publishing')
}
event.preventDefault();
}
const submitRawContentState = (data) => {
data.content = convertToRaw(this.state.editorState.getCurrentContent())
return data;
}
this.context.addToSubmitForm(submitRawContentState);
onChange(editorState) {
const shouldFilterPaste =
editorState.getLastChangeType() === 'insert-fragment';
if (
!isEqual(
convertToRaw(editorState.getCurrentContent()),
convertToRaw(this.state.editorState.getCurrentContent()),
)
) {
if (shouldFilterPaste) {
let filteredState = editorState;
filteredState = filterEditorState(
{
blocks: [],
styles: [],
entities: [
{
type: 'LINK',
attributes: ['url'],
},
],
whitespacedCharacters: [],
@action onEditorStateChange=(editorState)=>{
const {
store,
store:{
editingData:data,
setEditingData
}
}=this.props;
const label=draftToHtml(convertToRaw(editorState.getCurrentContent()))
setEditingData(`label`,label);
store.editorState=editorState;
}
render(){
export const convertForSubmit = (editorState) => {
const currentContent = editorState.getCurrentContent();
const messageBody = convertToRaw(currentContent);
return JSON.stringify(messageBody);
};
onClick: () => {
const contentState = this.state.editorState.getCurrentContent();
this.props.consoleLog(JSON.stringify(convertToRaw(contentState), null, 4));
},
text: "Log Raw ContentState",
onChange(editorState) {
if (
!isEqual(
convertToRaw(editorState.getCurrentContent()),
convertToRaw(this.state.editorState.getCurrentContent()),
)
) {
this.props.onChangeBlock(this.props.block, {
...this.props.data,
text: convertToRaw(editorState.getCurrentContent()),
});
}
this.setState({ editorState });
}