From a2f4e1468443422e2dad5363a5ef01a31ca768c2 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Sun, 16 Apr 2017 02:31:58 +0300 Subject: [PATCH] preserve parent id when reloading editor plus fixes --- .../isolatedNote/IsolatedNoteHTMLConverter.js | 1 + .../track_change/TrackChangeComponent.js | 7 ++++--- .../SimpleEditor/miniEditor/miniEditor.js | 6 ++---- .../SimpleEditor/panes/Notes/NotesProvider.js | 20 ++++++++++++++----- .../SimpleEditor/panes/Notes/notes.scss | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js index 3aaf57f..3f09358 100644 --- a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js +++ b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js @@ -4,5 +4,6 @@ export default { import: function (el, node, converter) { node.content = converter.annotatedText(el, [node.id, 'content']) + node.parentNoteId = el.attr('parent-id') } } diff --git a/app/components/SimpleEditor/elements/track_change/TrackChangeComponent.js b/app/components/SimpleEditor/elements/track_change/TrackChangeComponent.js index f6fbfdf..f68e107 100644 --- a/app/components/SimpleEditor/elements/track_change/TrackChangeComponent.js +++ b/app/components/SimpleEditor/elements/track_change/TrackChangeComponent.js @@ -33,16 +33,17 @@ class TrackChangeComponent extends AnnotationComponent { container.addClass('sc-accept-reject-container-hide') } - // .attr('status', status and .attr('roles', user.roles[0]) Only Exist because + // roles, status,username,user-id only exist because // on the second editor we do not have an exporter but everything is pushed to // the note-content property of the callout. So cause we use olny the importer // those attr did not exist - let el = $$('track-change') .attr('data-id', id) .attr('title', user.username) - .attr('status', status) .attr('roles', user.roles[0]) + .attr('status', status) + .attr('username', user.username) + .attr('user-id', user.id) .addClass(this.getClassNames()) .append(this.props.children) diff --git a/app/components/SimpleEditor/miniEditor/miniEditor.js b/app/components/SimpleEditor/miniEditor/miniEditor.js index 14629db..5a1e972 100644 --- a/app/components/SimpleEditor/miniEditor/miniEditor.js +++ b/app/components/SimpleEditor/miniEditor/miniEditor.js @@ -11,14 +11,12 @@ class MiniEditor extends ProseEditor { didMount () { this.context.notesProvider.config.miniEditorContext = this.getChildContext() - this.editorSession.onUpdate('document', this.setEditorSession, this) + this.editorSession.onUpdate('document', this.reComputeEntries, this) this.context.notesProvider.config.miniEditorSession = this.editorSession this.on('noteSelected', this.scrollTo, this) } - setEditorSession () { - this.context.notesProvider.config.miniEditorContext = this.getChildContext() - this.context.notesProvider.config.miniEditorSession = this.editorSession + reComputeEntries () { this.context.notesProvider.computeEntries() } diff --git a/app/components/SimpleEditor/panes/Notes/NotesProvider.js b/app/components/SimpleEditor/panes/Notes/NotesProvider.js index 613dced..7bd4764 100644 --- a/app/components/SimpleEditor/panes/Notes/NotesProvider.js +++ b/app/components/SimpleEditor/panes/Notes/NotesProvider.js @@ -1,6 +1,6 @@ import _ from 'lodash' -import { TOCProvider } from 'substance' +import { TOCProvider, Component } from 'substance' class NotesProvider extends TOCProvider { computeEntries () { @@ -59,19 +59,29 @@ class NotesProvider extends TOCProvider { } sortNodesMini (nodes) { - let notes = _.clone(nodes) if (this.config.miniEditorSession === '') return + let notes = _.clone(nodes) + let rootEl = this.config.miniEditorContext.editor.el + let i = 0 notes = _.map(notes, function (note) { - const element = document.querySelector('p[data-path="' + note.id + '.content"]') - const noteContent = '<isolated-note data-id="' + note.id + '" data-type="isolated-note">' + element.innerHTML + '</isolated-note>' + const element = Component.unwrap(rootEl.find('p[data-path="' + note.id + '.content"]')) + // removes a <br> insterted at the end by inline node + const text = element.innerHTML.slice(0, -4) + let noteContent = '<isolated-note data-id="' + note.id + '" parent-id="' + note.parentNoteId + '" data-type="isolated-note">' + text + '</isolated-note>' + + // TODO For some reason the first character is not in the annotation so it is not getting saved. For that + // miniEditor has a reComputeEntries and in here we rerender Surface only the first time to get the character. + if (i === 0) this.config.miniEditorContext.surfaceManager.getSurface('mini').rerender() + i++ return { id: note.id, content: noteContent, parentNoteId: note.parentNoteId } - }) + }.bind(this)) + return notes } diff --git a/app/components/SimpleEditor/panes/Notes/notes.scss b/app/components/SimpleEditor/panes/Notes/notes.scss index 8ccc0a4..e8c3324 100644 --- a/app/components/SimpleEditor/panes/Notes/notes.scss +++ b/app/components/SimpleEditor/panes/Notes/notes.scss @@ -14,7 +14,6 @@ $light-blue: #e4f0ff; z-index: 0; .resize-area { - padding-top: 40px; background-color: red; cursor: row-resize; height: 5px; @@ -27,6 +26,7 @@ $light-blue: #e4f0ff; .sc-isolated-node.sm-default-style.sm-co-selected { border: 4px solid $light-blue ; outline: none; + padding: 0 0 8px 5px; } .sc-isolated-node .sc-text-property::before { -- GitLab