From cc427e5682504cc26d803abf4013141dbc1cc591 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Wed, 2 Jun 2021 09:19:21 +0300 Subject: [PATCH] remove inner debounce --- editors/demo/src/Editoria/Editoria.js | 5 +- wax-prosemirror-core/src/Wax.js | 77 +++++++++++++-------------- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/editors/demo/src/Editoria/Editoria.js b/editors/demo/src/Editoria/Editoria.js index 45d5b114e..309694948 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 09f5faf63..5e5ddf67e 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'); -- GitLab