Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
id: '1',
mimeType: 'image/png',
src: imgSrc,
title: 'My image'
});
const imgEntityKey = contentState.getLastCreatedEntityKey();
// $FlowFixMe DraftEntityType is too restrictive in DraftJS (see https://github.com/facebook/draft-js/issues/868 )
contentState = contentState.createEntity(ENTITY_TYPES.document, ENTITY_MUTABILITY.immutable, {
id: '2',
mimeType: 'application/pdf',
src: fileSrc,
title: 'My document'
});
const docEntityKey = contentState.getLastCreatedEntityKey();
let editorState = EditorState.createWithContent(contentState);
editorState = AtomicBlockUtils.insertAtomicBlock(editorState, imgEntityKey, ' ');
editorState = AtomicBlockUtils.insertAtomicBlock(editorState, docEntityKey, ' ');
return editorState;
},
contentFormat = contentFormat || 'raw';
initialContent = initialContent || '';
if (!initialContent) {
initialEditorState = EditorState.createEmpty(editorDecorators);
} else {
let convertedContent;
if (contentFormat === 'html') {
convertedContent = convertFromHTML(getFromHTMLConfig())(initialContent);
} else if (contentFormat === 'raw') {
convertedContent = convertFromRaw(initialContent);
}
initialEditorState = EditorState.createWithContent(convertedContent, editorDecorators);
}
// $FlowIssue
this.readyForSync = true;
this.state = {
editorState: initialEditorState,
editorProps: {},
};
}
state: State;
{
"key": "7bvko",
"text": "",
"type": "unstyled",
"depth": 0,
"inlineStyleRanges": [],
"entityRanges": [],
"data": {}
}
]
};
/* eslint-enable */
export default class CustomVideoEditor extends Component {
state = {
editorState: EditorState.createWithContent(convertFromRaw(initialState)),
};
onChange = (editorState) => {
this.setState({
editorState,
});
};
focus = () => {
this.editor.focus();
};
render() {
return (
<div>
</div>
const entityRanges = blocks.map(block => block.entityRanges);
const flatEntityRanges = flatten(entityRanges);
const entityMap = {};
flatEntityRanges.forEach((data) => {
entityMap[data.key] = {
type: "WORD",
mutability: "MUTABLE",
data
}
});
const contentState = convertFromRaw({ blocks, entityMap });
const editorState = EditorState.createWithContent(
contentState,
decorator
);
this.setState({ editorState });
}
}
constructor(props) {
super(props);
const { maxlength, input: { value } } = props;
const editorState = value ? EditorState.createWithContent(ContentState.createFromText(value)) : EditorState.createEmpty();
this.state = { editorState };
this.handleReturn = () => {
this.editor.blur();
return true;
};
this.handleReturn = this.handleReturn.bind(this);
this.handleBeforeInput = () => false;
if (maxlength >= 0) {
this.handleBeforeInput = () => {
const plainText = this.state.editorState.getCurrentContent().getPlainText();
return plainText.length >= maxlength;
};
}
async getDetail (id) {
const {code, data} = await api.get('/article/item', {id})
if (code !== 1000) return false
const { title, author, summary, category, tag, content } = data
this.props.form.setFieldsValue({title, author, summary, category, tag})
const contentBlock = htmlToDraft(content)
const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks)
const editorState = EditorState.createWithContent(contentState)
this.setState({ editorState })
}
constructor(props) {
super(props);
this.state = {
editorState: EditorState.createWithContent(ContentState.createFromText(props.initialValue))
}
this.handleChange = this.handleChange.bind(this);
}
export const HTMLToEditor = html =>
EditorState.createWithContent(fromHTML(html))
this.props.getCurrentCaptivePortal((res) => {
let newHtmlBlock = convertFromHTML(res);
let newHtmlContent = ContentState.createFromBlockArray(newHtmlBlock.contentBlocks, newHtmlBlock.entityMap);
this.setState({editorState : EditorState.createWithContent(newHtmlContent)});
})
}