diff --git a/editors/demo/src/OEN/OEN.js b/editors/demo/src/OEN/OEN.js index 2a994776548e693ea31c79172ba6b82d0d095b32..9066fdf7877b1b104409df6eb2a381b9b20bf8fa 100644 --- a/editors/demo/src/OEN/OEN.js +++ b/editors/demo/src/OEN/OEN.js @@ -25,10 +25,7 @@ const user = { username: 'admin', }; -const val = `<h3>33333</h3><section class="section"><div class="introduction" data-type="content_structure_element"><p>Intro</p></div> - <div class="outline" data-type="content_structure_element"><h1>heading when i click note</h1><p>some text when i click note</p></div></section> - <section class="section"><div class="introduction" data-type="content_structure_element"><p>Intro</p></div> - <div class="outline" data-type="content_structure_element"><p>outline</p></div></section>`; +const val = `<p>first paragraph</p><section class=\"whatever\"><h2>Section 1 heading 2</h2><p class=\"paragraph\">normal text</p></section><section class=\"whatever\"><h2>Section 2 heading 2</h2><p class=\"paragraph\">normal text</p></section><section class=\"whatever\"><p class=\"paragraph\">dfsfsdfs</p><p class=\"paragraph\">normal text</p></section><section class=\"whatever\"><h2>Section 4 heading 2</h2><p class=\"paragraph\">normal text</p></section><p class=\"paragraph\">some text</p><div class=\"outline\" data-type=\"content_structure_element\"><p class=\"paragraph\"></p></div>`; const Oen = () => { const editorRef = useRef(); @@ -43,9 +40,9 @@ const Oen = () => { value={val} // readonly layout={OenLayout} - // onChange={debounce(source => { - // console.log(JSON.stringify(source)); - // }, 200)} + onChange={debounce(source => { + console.log(JSON.stringify(source)); + }, 200)} user={user} /> ); diff --git a/wax-prosemirror-services/src/OENContainersService/PopulateHeadingsComponent.js b/wax-prosemirror-services/src/OENContainersService/PopulateHeadingsComponent.js index 4968f1eefe54a95457d3cbd80aa7d273d82ab809..0b565f4ec116196470b2b9d9e1fbc9c45ae65761 100644 --- a/wax-prosemirror-services/src/OENContainersService/PopulateHeadingsComponent.js +++ b/wax-prosemirror-services/src/OENContainersService/PopulateHeadingsComponent.js @@ -80,6 +80,7 @@ export default ({ setPosition, position }) => { } = main.state; const allSectionNodes = []; + const sectionHeadings = {}; doc.descendants((editorNode, index) => { if (editorNode.type.name === 'oen_section') { @@ -87,6 +88,16 @@ export default ({ setPosition, position }) => { } }); + allSectionNodes.forEach((node, index) => { + node.content.content.forEach(contentNode => { + if (contentNode.type.name === 'heading2') { + sectionHeadings[index] = [contentNode.textContent]; + } else if (!sectionHeadings[index]) { + sectionHeadings[index] = ['untitled']; + } + }); + }); + let sectionNode; let sectionNodePosition;