Skip to content
Snippets Groups Projects
Commit 762787c0 authored by chris's avatar chris Committed by john
Browse files

on minieditor init load isolated notes

parent ec0547ff
No related branches found
No related tags found
No related merge requests found
import { each, keys, includes } from 'lodash' import { each, keys, includes, forEach } from 'lodash'
import { import {
ContainerEditor as SubstanceContainerEditor, ContainerEditor as SubstanceContainerEditor,
// deleteCharacter, // deleteCharacter,
...@@ -36,6 +36,7 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -36,6 +36,7 @@ class ContainerEditor extends SubstanceContainerEditor {
super.didMount() super.didMount()
if (this.isEmpty() && this.props.containerId !== 'mini') this.createText() 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 ? // TODO -- why this and not this.focus ?
this.el.focus() this.el.focus()
...@@ -209,6 +210,28 @@ class ContainerEditor extends SubstanceContainerEditor { ...@@ -209,6 +210,28 @@ class ContainerEditor extends SubstanceContainerEditor {
this.editorSession.setSelection(newSel) 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 // only runs if editor is in read-only mode
// disables all tools, apart from comments // disables all tools, apart from comments
disableToolbar () { disableToolbar () {
......
...@@ -13,24 +13,8 @@ class NoteCommand extends InsertInlineNodeCommand { ...@@ -13,24 +13,8 @@ class NoteCommand extends InsertInlineNodeCommand {
editorSession.transaction((tx) => { editorSession.transaction((tx) => {
return tx.insertInlineNode(nodeData) 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) { getNotesProvider (params) {
return params.surface.context.notesProvider return params.surface.context.notesProvider
} }
......
...@@ -19,7 +19,7 @@ let config = { ...@@ -19,7 +19,7 @@ let config = {
config.defineSchema({ config.defineSchema({
name: 'prose-article', name: 'prose-article',
ArticleClass: ProseArticle, ArticleClass: ProseArticle,
defaultTextType: 'paragraph' defaultTextType: 'isolated-note'
}) })
config.import(BasePackage, { config.import(BasePackage, {
......
...@@ -7,7 +7,7 @@ import ContainerEditor from '../ContainerEditor' ...@@ -7,7 +7,7 @@ import ContainerEditor from '../ContainerEditor'
import Comments from '../panes/Comments/CommentBoxList' import Comments from '../panes/Comments/CommentBoxList'
import CommentsProvider from '../panes/Comments/CommentsProvider' import CommentsProvider from '../panes/Comments/CommentsProvider'
import TrackChangesProvider from '../elements/track_change/TrackChangesProvider' import TrackChangesProvider from '../elements/track_change/TrackChangesProvider'
import {forEach, values, reverse} from 'lodash' import {forEach, values} from 'lodash'
class MiniEditor extends ProseEditor { class MiniEditor extends ProseEditor {
didMount () { didMount () {
......
...@@ -70,16 +70,16 @@ class Notes extends Component { ...@@ -70,16 +70,16 @@ class Notes extends Component {
configurator.addImporter('html', Importer) configurator.addImporter('html', Importer)
const importer = configurator.createImporter('html') const importer = configurator.createImporter('html')
const provider = this.getProvider() // const provider = this.getProvider()
//
const notes = provider.computeEntries() // const notes = provider.computeEntries()
let noteContent = '' // let noteContent = ''
//
for (var i = 0; i < notes.length; i++) { // for (var i = 0; i < notes.length; i++) {
noteContent += notes[i]['note-content'] // noteContent = ''
} // }
const doc = importer.importDocument(noteContent) const doc = importer.importDocument()
const editorSession = new EditorSession(doc, { const editorSession = new EditorSession(doc, {
configurator: configurator configurator: configurator
......
...@@ -49,71 +49,6 @@ class NotesProvider extends TOCProvider { ...@@ -49,71 +49,6 @@ class NotesProvider extends TOCProvider {
const miniNote = _.find(notes.mini, ['parentNoteId', note.id]) const miniNote = _.find(notes.mini, ['parentNoteId', note.id])
if (miniNote) this.config.miniEditorContext.editor.emit('noteSelected', miniNote.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'] NotesProvider.tocTypes = ['note']
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment