diff --git a/wax-prosemirror-components/src/components/findAndReplace/helpers.js b/wax-prosemirror-components/src/components/findAndReplace/helpers.js index 2100e93dd9de31c1405c8d212b5f4e9725d60809..5aee17bcde206c7f092b7115ce79b85c6d5dd19e 100644 --- a/wax-prosemirror-components/src/components/findAndReplace/helpers.js +++ b/wax-prosemirror-components/src/components/findAndReplace/helpers.js @@ -32,14 +32,24 @@ const getAllResultsByView = (view, searchValue, matchCaseSearch) => { const getNotesIds = main => { const notesIds = []; - const notes = DocumentHelpers.findChildrenByType( - main.state.doc, - main.state.schema.nodes.footnote, - true, - ); - notes.forEach(note => { - notesIds.push(note.node.attrs.id); + const schemaNotes = []; + each(main.state.schema.nodes, node => { + if (node.groups.includes('notes')) schemaNotes.push(node); }); + + if (schemaNotes.length > 0) { + schemaNotes.forEach(schemaNote => { + const notes = DocumentHelpers.findChildrenByType( + main.state.doc, + main.state.schema.nodes[schemaNote.name], + true, + ); + notes.forEach(note => { + notesIds.push(note.node.attrs.id); + }); + }); + } + return notesIds; }; diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index fb4449b8c5e66da6a27c8a044c1b311b6b2babbb..09f5faf635f4d3239ebcd446b34e2fd95ea5848e 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -1,7 +1,7 @@ /* eslint react/prop-types: 0 */ import React, { useEffect, useState } from 'react'; import debounce from 'lodash/debounce'; - +import { each } from 'lodash'; import { DOMSerializer } from 'prosemirror-model'; import WaxProvider from './WaxContext'; @@ -56,13 +56,21 @@ const Wax = props => { content => { /* HACK alter toDOM of footnote, because of how PM treats inline nodes with content */ - if (schema.nodes.footnote) { - const old = schema.nodes.footnote.spec.toDOM; - schema.nodes.footnote.spec.toDOM = node => { - // eslint-disable-next-line prefer-rest-params - old.apply(this); - if (node) return ['footnote', node.attrs, 0]; - }; + + 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') { @@ -71,13 +79,16 @@ const Wax = props => { const serialize = serializer(schema); WaxOnchange(serialize(content)); } - if (schema.nodes.footnote) { - const old = schema.nodes.footnote.spec.toDOM; - schema.nodes.footnote.spec.toDOM = node => { - // eslint-disable-next-line prefer-rest-params - old.apply(this); - if (node) return ['footnote', node.attrs]; - }; + + 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, diff --git a/wax-prosemirror-core/src/helpers/TransformPasted.js b/wax-prosemirror-core/src/helpers/TransformPasted.js index d8e3ea42581e503cb4dd771e97fe289ca1e617f1..9a4ce541f0ae0911fedf9761b523e70031fa4dee 100644 --- a/wax-prosemirror-core/src/helpers/TransformPasted.js +++ b/wax-prosemirror-core/src/helpers/TransformPasted.js @@ -1,6 +1,6 @@ /* eslint-disable array-callback-return */ /* eslint-disable no-param-reassign */ -import { forEach } from 'lodash'; +import { forEach, each } from 'lodash'; import { v4 as uuidv4 } from 'uuid'; import { DocumentHelpers } from 'wax-prosemirror-utilities'; @@ -36,15 +36,22 @@ const transformPasted = (slice, view) => { }); } - if (view.state.schema.nodes.footnote) { - const notes = DocumentHelpers.findChildrenByType( - content, - view.state.schema.nodes.footnote, - true, - ); - - notes.forEach(note => { - note.node.attrs.id = uuidv4(); + const schemaNotes = []; + each(view.state.schema.nodes, node => { + if (node.groups.includes('notes')) schemaNotes.push(node); + }); + + if (schemaNotes.length > 0) { + schemaNotes.forEach(schemaNote => { + const notes = DocumentHelpers.findChildrenByType( + content, + view.state.schema.nodes[schemaNote.name], + true, + ); + + notes.forEach(note => { + note.node.attrs.id = uuidv4(); + }); }); } diff --git a/wax-prosemirror-schema/src/nodes/footNoteNode.js b/wax-prosemirror-schema/src/nodes/footNoteNode.js index 38b81a21152e0da673594aed101e39f5805db182..ab89aa79a54f3080f52944c39e286df3c4a637d3 100644 --- a/wax-prosemirror-schema/src/nodes/footNoteNode.js +++ b/wax-prosemirror-schema/src/nodes/footNoteNode.js @@ -1,5 +1,5 @@ const footnote = { - group: 'notes, inline', + group: 'notes inline', content: 'inline*', inline: true, atom: true,