From 762787c0f9fabbda1813f131218c7c09de2db6a0 Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Fri, 21 Apr 2017 16:17:13 +0300 Subject: [PATCH] on minieditor init load isolated notes --- .../SimpleEditor/ContainerEditor.js | 25 ++++++- .../SimpleEditor/elements/note/NoteCommand.js | 16 ----- .../SimpleEditor/miniEditor/config.js | 2 +- .../SimpleEditor/miniEditor/miniEditor.js | 2 +- .../SimpleEditor/panes/Notes/Notes.js | 20 +++--- .../SimpleEditor/panes/Notes/NotesProvider.js | 65 ------------------- 6 files changed, 36 insertions(+), 94 deletions(-) diff --git a/app/components/SimpleEditor/ContainerEditor.js b/app/components/SimpleEditor/ContainerEditor.js index ae552f5..c9e603a 100644 --- a/app/components/SimpleEditor/ContainerEditor.js +++ b/app/components/SimpleEditor/ContainerEditor.js @@ -1,4 +1,4 @@ -import { each, keys, includes } from 'lodash' +import { each, keys, includes, forEach } from 'lodash' import { ContainerEditor as SubstanceContainerEditor, // deleteCharacter, @@ -36,6 +36,7 @@ class ContainerEditor extends SubstanceContainerEditor { super.didMount() if (this.isEmpty() && this.props.containerId !== 'mini') this.createText() + if (this.isEmpty() && this.props.containerId === 'mini') this.createTextMini() // TODO -- why this and not this.focus ? this.el.focus() @@ -209,6 +210,28 @@ class ContainerEditor extends SubstanceContainerEditor { this.editorSession.setSelection(newSel) } + createTextMini () { + const notes = this.context.notesProvider.computeEntries() + + this.editorSession.transaction(function (tx) { + var container = tx.get(this.props.containerId) + var textType = tx.getSchema().getDefaultTextType() + + forEach(notes, function (note, index) { + let node = tx.create({ + 'content': note['note-content'], + 'parentNoteId': note.id, + index: index, + type: textType + }) + container.show(node.id) + }) + }.bind(this)) + + this.rerender() + // this.editorSession.setSelection(newSel) + } + // only runs if editor is in read-only mode // disables all tools, apart from comments disableToolbar () { diff --git a/app/components/SimpleEditor/elements/note/NoteCommand.js b/app/components/SimpleEditor/elements/note/NoteCommand.js index c29dfbf..cbcb44f 100644 --- a/app/components/SimpleEditor/elements/note/NoteCommand.js +++ b/app/components/SimpleEditor/elements/note/NoteCommand.js @@ -13,24 +13,8 @@ class NoteCommand extends InsertInlineNodeCommand { editorSession.transaction((tx) => { return tx.insertInlineNode(nodeData) }) - - // let selection = editorSession.getSelection() - // let selectionBefore = selection._clone() - // selectionBefore.start.offset -= 1 - // let note = this.getCreatedNote(selectionBefore, editorSession) - // const notesProvider = this.getNotesProvider(params) - // notesProvider.createIsolatedNote(note) } - // getCreatedNote (selection, editorSession) { - // const note = documentHelpers.getPropertyAnnotationsForSelection( - // editorSession.getDocument(), - // selection, - // { type: 'note' } - // ) - // return note[0] - // } - getNotesProvider (params) { return params.surface.context.notesProvider } diff --git a/app/components/SimpleEditor/miniEditor/config.js b/app/components/SimpleEditor/miniEditor/config.js index 9db5827..222a72e 100644 --- a/app/components/SimpleEditor/miniEditor/config.js +++ b/app/components/SimpleEditor/miniEditor/config.js @@ -19,7 +19,7 @@ let config = { config.defineSchema({ name: 'prose-article', ArticleClass: ProseArticle, - defaultTextType: 'paragraph' + defaultTextType: 'isolated-note' }) config.import(BasePackage, { diff --git a/app/components/SimpleEditor/miniEditor/miniEditor.js b/app/components/SimpleEditor/miniEditor/miniEditor.js index 48989fe..6193267 100644 --- a/app/components/SimpleEditor/miniEditor/miniEditor.js +++ b/app/components/SimpleEditor/miniEditor/miniEditor.js @@ -7,7 +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 {forEach, values, reverse} from 'lodash' +import {forEach, values} from 'lodash' class MiniEditor extends ProseEditor { didMount () { diff --git a/app/components/SimpleEditor/panes/Notes/Notes.js b/app/components/SimpleEditor/panes/Notes/Notes.js index 541e9c6..4fb031f 100644 --- a/app/components/SimpleEditor/panes/Notes/Notes.js +++ b/app/components/SimpleEditor/panes/Notes/Notes.js @@ -70,16 +70,16 @@ class Notes extends Component { configurator.addImporter('html', Importer) const importer = configurator.createImporter('html') - const provider = this.getProvider() - - const notes = provider.computeEntries() - let noteContent = '' - - for (var i = 0; i < notes.length; i++) { - noteContent += notes[i]['note-content'] - } - - const doc = importer.importDocument(noteContent) + // const provider = this.getProvider() + // + // const notes = provider.computeEntries() + // let noteContent = '' + // + // for (var i = 0; i < notes.length; i++) { + // noteContent = '' + // } + + const doc = importer.importDocument() const editorSession = new EditorSession(doc, { configurator: configurator diff --git a/app/components/SimpleEditor/panes/Notes/NotesProvider.js b/app/components/SimpleEditor/panes/Notes/NotesProvider.js index 7bf4026..9c7211c 100644 --- a/app/components/SimpleEditor/panes/Notes/NotesProvider.js +++ b/app/components/SimpleEditor/panes/Notes/NotesProvider.js @@ -49,71 +49,6 @@ class NotesProvider extends TOCProvider { const miniNote = _.find(notes.mini, ['parentNoteId', note.id]) if (miniNote) this.config.miniEditorContext.editor.emit('noteSelected', miniNote.id) } - - createNodeData (note) { - return { - 'type': 'isolated-note', - 'content': '', - 'parentNoteId': note.id - } - } - - createIsolatedNote (note) { - const notes = this.computeEntries() - - let surface = this.getSurface() - if (notes.mini) { - let container = surface.getContainer() - - let findIndex = _.findIndex(notes.main, ['id', note.id]) - - let nodeData = this.createNodeData(note) - this.config.miniEditorSession.transaction(function (tx) { - if (!tx.get(nodeData.id)) { - let blockNode = tx.create(nodeData) - tx.update(container.getContentPath(), { type: 'insert', pos: findIndex, value: blockNode.id }) - } - }) - } - } - - findDeletedNote (entries) { - let position - let note - if (entries.main.length === 0) { - position = 0 - note = entries.mini[0] - } else { - _.forEach(entries.main, function (mainNote) { - _.forEach(entries.mini, function (miniNote) { - if (miniNote.parentNoteId !== mainNote.id) { - position = _.findIndex(entries.mini, ['id', miniNote.id]) - note = miniNote - } - }) - }) - } - - this.removeIsolatedNote(position, note) - } - - removeIsolatedNote (position, note) { - let surface = this.getSurface() - let container = surface.getContainer() - this.config.miniEditorSession.transaction(function (tx) { - tx.update(container.getContentPath(), { type: 'delete', pos: position }) - tx.delete(note.id) - }) - } - - getMiniContainerId () { - return this.config.miniEditorContext.editor.props.containerId - } - - getSurface () { - const containerId = this.getMiniContainerId() - return this.config.miniEditorContext.surfaceManager.getSurface(containerId) - } } NotesProvider.tocTypes = ['note'] -- GitLab