Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
documentChangeHandler (_, newEditorState) {
const { data: { repository }, path, uncommittedChangesMutation } = this.props
const { committedEditorState, uncommittedChanges } = this.state
const serializedNewEditorState = Raw.serialize(newEditorState, {terse: true})
const serializedCommittedEditorState = Raw.serialize(committedEditorState, {terse: true})
if (JSON.stringify(serializedNewEditorState) !== JSON.stringify(serializedCommittedEditorState)) {
this.store.set('editorState', serializedNewEditorState)
this.store.set('commit', repository.commit)
if (!uncommittedChanges) {
this.setState({
uncommittedChanges: true
})
uncommittedChangesMutation({
login: repository.owner.login,
repository: repository.name,
path: path.split('/').slice(1).join('/'), // omit branch
action: 'create'
}).catch((error) => {
console.log('uncommittedChangesMutation error')
changeValue = (value) => {
const { onChangeHeadings } = this.props;
this.value = value;
this.forceUpdate();
if (changeValue) {
const rawValue = Raw.serialize(value, { terse });
if (JSON.stringify(this.rawValue) !== JSON.stringify(rawValue)) {
this.rawValue = rawValue;
this.batch(() => {
// Flatten & filter
const flattenNodes = (nodes, level = 0) =>
nodes.reduce((arr, node) => {
const { type, kind, text } = node;
let newArr = [...arr];
const newNode = { ...node };
if (newNode.nodes) {
newArr = arr.concat(flattenNodes(newNode.nodes, level + 1));
delete newNode.nodes;
}
// Filter empty Blocks
if (
onChange (state) {
console.log(Raw.serialize(state, { terse: true }))
this.setState(() => ({
state
}))
}
onChange = async () => {
const { onEditorChange, editorState, onChange, id } = this.props
onEditorChange(editorState)
onChange(Raw.serialize(editorState), id)
}
changeValue = value => {
this.value = value;
this.forceUpdate();
if (changeValue) {
const rawValue = Raw.serialize(value, { terse });
if (JSON.stringify(this.rawValue) !== JSON.stringify(rawValue)) {
this.rawValue = rawValue;
this.batch(() => changeValue(this.props, rawValue));
}
}
}
function serialize(state: State, format: Format = 'raw'): any {
switch (format) {
case 'raw':
return Raw.serialize(state, { terse: true })
case 'html':
return Html.serialize(state)
case 'plain':
return Plain.serialize(state)
default:
throw new Error(`Don't know how to deserialize ${format}`)
}
}