Skip to content
Snippets Groups Projects
Commit ea91d2cf authored by chris's avatar chris
Browse files

fix footnotes

parent 2dbf7465
No related branches found
No related tags found
1 merge request!301Question controls
...@@ -53,7 +53,7 @@ const Editoria = () => { ...@@ -53,7 +53,7 @@ const Editoria = () => {
layout={layout} layout={layout}
onChange={debounce(source => { onChange={debounce(source => {
console.log(source); console.log(source);
}, 3000)} }, 200)}
onBlur={source => console.log(source)} onBlur={source => console.log(source)}
user={user} user={user}
/> />
......
...@@ -54,7 +54,7 @@ const Editors = () => { ...@@ -54,7 +54,7 @@ const Editors = () => {
case 'ncbi': case 'ncbi':
break; break;
default: default:
return <HHMI />; return <Editoria />;
} }
}; };
......
/* eslint react/prop-types: 0 */ /* eslint react/prop-types: 0 */
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import debounce from 'lodash/debounce';
import { each } from 'lodash'; import { each } from 'lodash';
import { DOMSerializer } from 'prosemirror-model'; import { DOMSerializer } from 'prosemirror-model';
...@@ -51,10 +50,10 @@ const Wax = props => { ...@@ -51,10 +50,10 @@ const Wax = props => {
if (!application) return null; if (!application) return null;
const WaxOnchange = onChange || (v => true); const WaxOnchange = onChange || (v => true);
const finalOnChange = schema => content => { const finalOnChange = content => {
/* HACK alter toDOM of footnote, because of how PM treats inline nodes /* HACK alter toDOM of footnote, because of how PM treats inline nodes
with content */ with content */
const { schema } = application.schema;
const notes = []; const notes = [];
each(schema.nodes, node => { each(schema.nodes, node => {
if (node.groups.includes('notes')) notes.push(node); if (node.groups.includes('notes')) notes.push(node);
...@@ -62,10 +61,8 @@ const Wax = props => { ...@@ -62,10 +61,8 @@ const Wax = props => {
if (notes.length > 0) { if (notes.length > 0) {
notes.forEach(note => { notes.forEach(note => {
const old = schema.nodes[note.name].spec.toDOM; schema.nodes.footnote.spec.toDOM = node => {
schema.nodes[note.name].spec.toDOM = node => {
// eslint-disable-next-line prefer-rest-params // eslint-disable-next-line prefer-rest-params
old.apply(this);
if (node) return [note.name, node.attrs, 0]; if (node) return [note.name, node.attrs, 0];
}; };
}); });
...@@ -80,10 +77,8 @@ const Wax = props => { ...@@ -80,10 +77,8 @@ const Wax = props => {
if (notes.length > 0) { if (notes.length > 0) {
notes.forEach(note => { notes.forEach(note => {
const old = schema.nodes[note.name].spec.toDOM; schema.nodes.footnote.spec.toDOM = node => {
schema.nodes[note.name].spec.toDOM = node => {
// eslint-disable-next-line prefer-rest-params // eslint-disable-next-line prefer-rest-params
old.apply(this);
if (node) return [note.name, node.attrs]; if (node) return [note.name, node.attrs];
}; };
}); });
......
...@@ -130,11 +130,11 @@ export default props => { ...@@ -130,11 +130,11 @@ export default props => {
} }
if (targetFormat === 'JSON') { if (targetFormat === 'JSON') {
if (view.state.doc !== previousDoc || tr.getMeta('forceUpdate')) if (view.state.doc !== previousDoc || tr.getMeta('forceUpdate'))
props.onChange(schema)(state.doc.toJSON()); props.onChange(state.doc.toJSON());
} else { } else {
// eslint-disable-next-line no-lonely-if // eslint-disable-next-line no-lonely-if
if (view.state.doc !== previousDoc || tr.getMeta('forceUpdate')) if (view.state.doc !== previousDoc || tr.getMeta('forceUpdate'))
props.onChange(schema)(state.doc.content); props.onChange(state.doc.content);
} }
}; };
......
...@@ -7,9 +7,7 @@ const footnote = { ...@@ -7,9 +7,7 @@ const footnote = {
id: { default: '' }, id: { default: '' },
}, },
toDOM: node => { toDOM: node => {
if (node) { return ['footnote', node.attrs];
return ['footnote', node.attrs];
}
}, },
parseDOM: [ parseDOM: [
{ {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment