diff --git a/app/components/SimpleEditor/ContainerEditor.js b/app/components/SimpleEditor/ContainerEditor.js index ae552f573c469ee70ef8b54c5f7d1ba0ae4b4504..c9e603ae38ee06fe57abf08fe0ba79fd9a4ae91c 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 c29dfbf1eee5ce91099dd6b494aeb23800f44d0e..cbcb44fb2ab13a5dad2832f8017cef18b885d396 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 9db582758811096a8458837ab1a6d37ac05ab48d..222a72ef9bda7c2cbfcc9b40b4df6d767fe49b7b 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 48989fed7a30ab5fa518221d4e3308e34a9b70eb..619326770e805f19b7c9f45e88495e75109cbdf9 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 541e9c6868416b130c0ed09b354c3108c7845b4d..4fb031f4fd189f3627065bfc8493647d207a1c85 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 7bf40267d672ebcf078f5835e449ac6c9be2fe11..9c7211c0a0f3ba419992c234ac9c5a576f5304b2 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']