diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index 5f955b45325c998e531aeebbf2e10d2aad8367a7..a4cc8235eb9f4b5624e6953492f36bdfde20f7ac 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -52,14 +52,7 @@ const Wax = forwardRef((props, ref) => { const finalOnChange = content => { if (!onChange) return; const { schema } = application.schema; - helpers.alterNotesSchema(schema); - if (targetFormat === 'JSON') { - onChange(content); - } else { - const serialize = serializer(schema); - onChange(serialize(content)); - } - helpers.revertNotesSchema(schema); + helpers.saveContent(content, onChange, schema, serializer, targetFormat); }; const Layout = application.container.get('Layout'); diff --git a/wax-prosemirror-core/src/helpers/helpers.js b/wax-prosemirror-core/src/helpers/helpers.js index 0041106f99c5be244e4df1397e46fddb0802c80a..ab26271ef901d7f300c1f968990c224e60e48340 100644 --- a/wax-prosemirror-core/src/helpers/helpers.js +++ b/wax-prosemirror-core/src/helpers/helpers.js @@ -1,6 +1,36 @@ /* eslint-disable no-param-reassign */ import { each } from 'lodash'; +// const alterNotesSchema = schema => { +// const notes = []; +// each(schema.nodes, node => { +// if (node.groups.includes('notes')) notes.push(node); +// }); +// if (notes.length > 0) { +// notes.forEach(note => { +// schema.nodes[note.name].spec.toDOM = node => { +// if (node) return [note.name, node.attrs, 0]; +// return true; +// }; +// }); +// } +// }; + +// const revertNotesSchema = schema => { +// const notes = []; +// each(schema.nodes, node => { +// if (node.groups.includes('notes')) notes.push(node); +// }); +// if (notes.length > 0) { +// notes.forEach(note => { +// schema.nodes[note.name].spec.toDOM = node => { +// if (node) return [note.name, node.attrs]; +// return true; +// }; +// }); +// } +// }; + const alterNotesSchema = schema => { const notes = []; each(schema.nodes, node => { @@ -45,8 +75,18 @@ const getDocContent = (schema, serializer, targetFormat, context) => { return content; }; +const saveContent = (content, onChange, schema, serializer, targetFormat) => { + alterNotesSchema(schema); + if (targetFormat === 'JSON') { + onChange(content); + } else { + const serialize = serializer(schema); + onChange(serialize(content)); + } + revertNotesSchema(schema); +}; + export default { - alterNotesSchema, getDocContent, - revertNotesSchema, + saveContent, };