From ad280c36afc00fd06dbad81351f8523986ff4901 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Wed, 19 Apr 2017 12:39:48 +0300 Subject: [PATCH] notes importer/exporter expiremental --- .../SimpleEditor/elements/comment/CommentComponent.js | 2 +- .../elements/isolatedNote/IsolatedNoteHTMLConverter.js | 2 +- .../elements/track_change/TrackChangeComponent.js | 10 +--------- app/components/SimpleEditor/panes/Notes/Notes.js | 10 ++++++++-- .../SimpleEditor/panes/Notes/NotesProvider.js | 7 ++++--- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/components/SimpleEditor/elements/comment/CommentComponent.js b/app/components/SimpleEditor/elements/comment/CommentComponent.js index ebae78e..93a16e0 100644 --- a/app/components/SimpleEditor/elements/comment/CommentComponent.js +++ b/app/components/SimpleEditor/elements/comment/CommentComponent.js @@ -10,7 +10,7 @@ class CommentComponent extends AnnotationComponent { const { node } = this.props const active = node.active - var el = $$('comment') + var el = $$('span') .attr('data-id', this.props.node.id) .addClass(this.getClassNames()) diff --git a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js index 3f09358..590f37d 100644 --- a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js +++ b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js @@ -3,7 +3,7 @@ export default { tagName: 'isolated-note', import: function (el, node, converter) { + console.log('imported nodes', node) 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 1305384..4ec60e7 100644 --- a/app/components/SimpleEditor/elements/track_change/TrackChangeComponent.js +++ b/app/components/SimpleEditor/elements/track_change/TrackChangeComponent.js @@ -33,17 +33,9 @@ class TrackChangeComponent extends AnnotationComponent { container.addClass('sc-accept-reject-container-hide') } - // 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') + let el = $$('span') .attr('data-id', id) .attr('title', user.username) - .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/panes/Notes/Notes.js b/app/components/SimpleEditor/panes/Notes/Notes.js index 2bd2fc5..829a4f6 100644 --- a/app/components/SimpleEditor/panes/Notes/Notes.js +++ b/app/components/SimpleEditor/panes/Notes/Notes.js @@ -3,6 +3,7 @@ import { Component, EditorSession, import MiniEditor from '../../miniEditor/miniEditor' import config from '../../miniEditor/config' import Importer from '../../miniEditor/MiniEditorImporter' +import SimpleExporter from '../../SimpleEditorExporter' import {forEach} from 'lodash' class Notes extends Component { @@ -67,7 +68,6 @@ class Notes extends Component { _initMiniEditor () { const configurator = new Configurator().import(config) configurator.addImporter('html', Importer) - const importer = configurator.createImporter('html') const provider = this.getProvider() @@ -97,13 +97,19 @@ class Notes extends Component { // so we rerender the Surface surface.rerender() const notes = provider.computeEntries() + const configurator = new Configurator().import(config) + const exporter = new SimpleExporter(configurator.config) forEach(notes.main, function (mainNote) { forEach(notes.mini, function (miniNote) { if (miniNote.parentNoteId === mainNote.id) { + console.log(exporter.createElement(miniNote)) + // console.log(exportedNode) + // const exportedNode = exporter.convertNode(miniNote) + // console.log('sdlkfjslfkjsfdlkj', exporter.annotatedText(exportedNode.getTextPath())) this.context.editorSession.transaction(function (tx, args) { const path = [mainNote.id, 'note-content'] - tx.set(path, miniNote.content) + tx.set(path, 'exportedNode.outerHTML') }) } }.bind(this)) diff --git a/app/components/SimpleEditor/panes/Notes/NotesProvider.js b/app/components/SimpleEditor/panes/Notes/NotesProvider.js index 5cb58df..7f04639 100644 --- a/app/components/SimpleEditor/panes/Notes/NotesProvider.js +++ b/app/components/SimpleEditor/panes/Notes/NotesProvider.js @@ -69,14 +69,15 @@ class NotesProvider extends TOCProvider { let rootEl = this.config.miniEditorContext.editor.el notes = _.map(notes, function (note) { + console.log('noteeee', 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>' + // 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>' return { id: note.id, - content: noteContent, + content: element.innerHTML, parentNoteId: note.parentNoteId } }) -- GitLab