diff --git a/app/components/SimpleEditor/elements/note/NoteHTMLConverter.js b/app/components/SimpleEditor/elements/note/NoteHTMLConverter.js index 2ce72eab5137194ebf425db8035f10fe59f465df..0beb642ac79e573231c5f03102f22049919a5733 100644 --- a/app/components/SimpleEditor/elements/note/NoteHTMLConverter.js +++ b/app/components/SimpleEditor/elements/note/NoteHTMLConverter.js @@ -3,7 +3,9 @@ export default { tagName: 'note', import: function (element, node, converter) { + // node['note-content'] = converter.annotatedText(element.attr('note-content')) node['note-content'] = element.attr('note-content') + // console.log('converter', converter.annotatedText(element, [node.id, node['note-content']])) }, export: function (node, element, converter) { diff --git a/app/components/SimpleEditor/miniEditor/miniEditor.js b/app/components/SimpleEditor/miniEditor/miniEditor.js index 619326770e805f19b7c9f45e88495e75109cbdf9..383f08650a0d234ea615e26a0347348d20cfe5b0 100644 --- a/app/components/SimpleEditor/miniEditor/miniEditor.js +++ b/app/components/SimpleEditor/miniEditor/miniEditor.js @@ -7,6 +7,7 @@ import ContainerEditor from '../ContainerEditor' import Comments from '../panes/Comments/CommentBoxList' import CommentsProvider from '../panes/Comments/CommentsProvider' import TrackChangesProvider from '../elements/track_change/TrackChangesProvider' +import SimpleExporter from '../SimpleEditorExporter' import {forEach, values} from 'lodash' class MiniEditor extends ProseEditor { @@ -14,6 +15,7 @@ class MiniEditor extends ProseEditor { const provider = this.getProvider() provider.config.miniEditorContext = this.getChildContext() provider.config.miniEditorSession = this.editorSession + this.editorSession.onUpdate('document', this.saveNote, this) this.on('noteSelected', this.scrollTo, this) this.on('notes:updated', this.createNotes, this) } @@ -70,6 +72,7 @@ class MiniEditor extends ProseEditor { book: this.props.book, comments: this.props.comments, containerId: this.props.containerId, + configurator: this.props.configurator, editorSession: this.editorSession, disabled: this.props.disabled, history: this.props.history, @@ -87,7 +90,7 @@ class MiniEditor extends ProseEditor { createNodeData (note, index) { return { 'type': 'isolated-note', - 'content': '', + 'content': note['note-content'], 'parentNoteId': note.id, index: index } @@ -127,6 +130,21 @@ class MiniEditor extends ProseEditor { }.bind(this)) } + saveNote () { + const selection = this.editorSession.getSelection() + if (!selection.end) return + const isolatedNoteId = selection.end.path[0] + const isolatedNote = this.editorSession.document.get(isolatedNoteId) + const exporter = new SimpleExporter(this.props.configurator.config) + const convertedNode = exporter.convertNode(isolatedNote) + + this.context.editorSession.transaction(function (tx, args) { + const path = [isolatedNote.parentNoteId, 'note-content'] + tx.set(path, convertedNode.innerHTML) + }) + // console.log(isolatedNote) + } + getProvider () { return this.context.notesProvider } diff --git a/app/components/SimpleEditor/panes/Notes/Notes.js b/app/components/SimpleEditor/panes/Notes/Notes.js index 4fb031f4fd189f3627065bfc8493647d207a1c85..dbd6045156d69c93a2f06b4a50265839f95a4d30 100644 --- a/app/components/SimpleEditor/panes/Notes/Notes.js +++ b/app/components/SimpleEditor/panes/Notes/Notes.js @@ -39,7 +39,7 @@ class Notes extends Component { } render ($$) { - const miniEditorSession = this._initMiniEditor() + const miniSessionConf = this._initMiniEditor() const resizer = $$('div').addClass('resize-area') const el = $$('div') @@ -49,8 +49,9 @@ class Notes extends Component { el.append($$(MiniEditor, { book: miniEditorProps.book, - editorSession: miniEditorSession, + editorSession: miniSessionConf.editorSession, comments: miniEditorProps.comments, + configurator: miniSessionConf.configurator, containerId: 'mini', history: miniEditorProps.history, disabled: miniEditorProps.disabled, @@ -76,18 +77,21 @@ class Notes extends Component { // let noteContent = '' // // for (var i = 0; i < notes.length; i++) { - // noteContent = '' + // noteContent += notes[i]['note-content'] // } - + // + // const doc = importer.importDocument(noteContent) const doc = importer.importDocument() - const editorSession = new EditorSession(doc, { configurator: configurator }) editorSession.setSaveHandler({ saveDocument: this.saveNotes }) - return editorSession + return { + editorSession: editorSession, + configurator: configurator + } } saveNotes (source) { @@ -142,8 +146,6 @@ class Notes extends Component { return value.type === 'note' }) - console.log('isEmpty(isNoteCreated)', isEmpty(isNoteDeleted)) - if (isEmpty(isNoteCreated) && isEmpty(isNoteDeleted)) return const miniEditor = this.getMiniEditor()