From 251ed7e47918c23bec083a639163aa6ed9d5f64c Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Tue, 26 Jul 2022 12:17:33 +0300 Subject: [PATCH] keep all section headings --- editors/demo/src/OEN/OEN.js | 11 ++++------- .../OENContainersService/PopulateHeadingsComponent.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/editors/demo/src/OEN/OEN.js b/editors/demo/src/OEN/OEN.js index 2a9947765..9066fdf78 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 4968f1eef..0b565f4ec 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; -- GitLab