diff --git a/editors/demo/src/Editoria/Editoria.js b/editors/demo/src/Editoria/Editoria.js index 45d5b114ee90370a54a3c881cb138b55390385c8..309694948be6604c1ac01a63a494924211df8680 100644 --- a/editors/demo/src/Editoria/Editoria.js +++ b/editors/demo/src/Editoria/Editoria.js @@ -5,6 +5,7 @@ import { Wax } from 'wax-prosemirror-core'; import { EditoriaLayout, EditoriaMobileLayout } from './layout'; import { config, configMobile } from './config'; import { demo } from './demo'; +import { debounce } from 'lodash'; const renderImage = file => { const reader = new FileReader(); @@ -50,7 +51,9 @@ const Editoria = () => { value={`<p> some text</p><h2>h2</h2><h3>a head</h3><h4>fff</h4><h1>ttt</h1>`} // readonly layout={layout} - // onChange={source => console.log(source)} + onChange={debounce(source => { + console.log(source); + }, 3000)} user={user} /> </> diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index 09f5faf635f4d3239ebcd446b34e2fd95ea5848e..5e5ddf67edff0b8e22db3e77d36dbefa4798ce03 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -51,49 +51,44 @@ const Wax = props => { if (!application) return null; const WaxOnchange = onChange || (v => true); - const finalOnChange = schema => - debounce( - content => { - /* HACK alter toDOM of footnote, because of how PM treats inline nodes + const finalOnChange = schema => content => { + /* HACK alter toDOM of footnote, because of how PM treats inline nodes with content */ - const notes = []; - each(schema.nodes, node => { - if (node.groups.includes('notes')) notes.push(node); - }); - - if (notes.length > 0) { - notes.forEach(note => { - const old = schema.nodes[note.name].spec.toDOM; - schema.nodes[note.name].spec.toDOM = node => { - // eslint-disable-next-line prefer-rest-params - old.apply(this); - if (node) return [note.name, node.attrs, 0]; - }; - }); - } - - if (targetFormat === 'JSON') { - WaxOnchange(content); - } else { - const serialize = serializer(schema); - WaxOnchange(serialize(content)); - } - - if (notes.length > 0) { - notes.forEach(note => { - const old = schema.nodes[note.name].spec.toDOM; - schema.nodes[note.name].spec.toDOM = node => { - // eslint-disable-next-line prefer-rest-params - old.apply(this); - if (node) return [note.name, node.attrs]; - }; - }); - } - }, - 1000, - { maxWait: 5000 }, - ); + const notes = []; + each(schema.nodes, node => { + if (node.groups.includes('notes')) notes.push(node); + }); + + if (notes.length > 0) { + notes.forEach(note => { + const old = schema.nodes[note.name].spec.toDOM; + schema.nodes[note.name].spec.toDOM = node => { + // eslint-disable-next-line prefer-rest-params + old.apply(this); + if (node) return [note.name, node.attrs, 0]; + }; + }); + } + + if (targetFormat === 'JSON') { + WaxOnchange(content); + } else { + const serialize = serializer(schema); + WaxOnchange(serialize(content)); + } + + if (notes.length > 0) { + notes.forEach(note => { + const old = schema.nodes[note.name].spec.toDOM; + schema.nodes[note.name].spec.toDOM = node => { + // eslint-disable-next-line prefer-rest-params + old.apply(this); + if (node) return [note.name, node.attrs]; + }; + }); + } + }; const TrackChange = application.config.get('config.EnableTrackChangeService'); const Layout = application.container.get('Layout');