// adapter.mjs — the saver's view of the editor (saver.mjs): the text // now, the text to send (the structure check, §6.4 step 5), and a body // applied from the server. What is applied is its own undo step, so // undo after a merge brings back the person's own text (§6.5), and is // marked remote, so it is not taken for typing. import { closeHistory } from 'prosemirror-history' import { serialise, applyBody, prepareSave } from './fidelity.mjs' export function editorAdapter (holder, fidelity) { const editor = { remote: false } const view = () => holder.view const remote = run => { const was = editor.remote editor.remote = true try { return run() } finally { editor.remote = was } } editor.current = () => serialise(view().state.doc, fidelity) editor.prepare = () => remote(() => prepareSave(view(), fidelity).body) editor.apply = body => remote(() => { view().dispatch(closeHistory(view().state.tr)) const result = applyBody(view(), fidelity, body) view().dispatch(closeHistory(view().state.tr)) return result }) return editor }