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

both editors listen throught same provider to compute their nodes (needs to...

both editors listen throught same provider to compute their nodes (needs to write cleaner notesProvider)
parent d5168df8
No related branches found
No related tags found
No related merge requests found
......@@ -259,7 +259,9 @@ class Editor extends ProseEditor {
})
// notes provider
const notesProvider = new NotesProvider(doc)
const notesProvider = new NotesProvider(doc, {
miniEditorSession: ''
})
// comments provider
const commentsProvider = new CommentsProvider(doc, {
......
......@@ -8,6 +8,17 @@ import Comments from '../panes/Comments/CommentBoxList'
import CommentsProvider from '../panes/Comments/CommentsProvider'
class MiniEditor extends ProseEditor {
didMount () {
this.editorSession.onUpdate('document', this.setEditorSession, this)
this.context.notesProvider.config.miniEditorSession = this.editorSession
}
setEditorSession () {
this.context.notesProvider.config.miniEditorSession = this.editorSession
this.context.notesProvider.computeEntries()
}
render ($$) {
const el = $$('div').addClass('sc-mini-editor')
let toolbar = this._renderMiniToolbar($$)
......
......@@ -55,7 +55,7 @@ class Notes extends Component {
configurator.addImporter('html', Importer)
const importer = configurator.createImporter('html')
const doc = importer.importDocument('Hello')
const doc = importer.importDocument('')
const editorSession = new EditorSession(doc, {
configurator: configurator
......@@ -75,6 +75,7 @@ class Notes extends Component {
onNotesUpdated (change) {
const notesProvider = this.getProvider()
notesProvider.handleDocumentChange(change)
this.context.notesProvider.config.miniEditorSession = this._initMiniEditor()
this.rerender()
}
......
......@@ -4,15 +4,24 @@ import { TOCProvider } from 'substance'
class NotesProvider extends TOCProvider {
computeEntries () {
const doc = this.getDocument()
const nodes = doc.getNodes()
const docMain = this.getDocument()
const nodesMain = docMain.getNodes()
const docMini = this.config.miniEditorSession.document
let nodesMini = ''
if (docMini) nodesMini = docMini.getNodes()
// get all notes from the document
const notes = _.pickBy(nodes, function (value, key) {
const notesMain = _.pickBy(nodesMain, function (value, key) {
return value.type === 'note'
})
const notesMini = _.pickBy(nodesMini, function (value, key) {
return value.type === 'note'
})
const entries = this.sortNodes(notes)
const entries = this.sortNodes(notesMain)
const entriesMini = this.sortNodesMini(notesMini)
console.log(entries, entriesMini)
return entries
}
......@@ -41,6 +50,30 @@ class NotesProvider extends TOCProvider {
return _.sortBy(notes, ['blockPosition', 'nodePosition'])
}
sortNodesMini (nodes) {
let notes = _.clone(nodes)
if (this.config.miniEditorSession === '') return
const doc = this.config.miniEditorSession.document
const container = doc.get('mini')
notes = _.map(notes, function (note) {
const blockId = note.path[0]
const blockPosition = container.getPosition(blockId)
const nodePosition = note.start.offset
return {
id: note.id,
content: note['note-content'],
blockPosition: blockPosition,
nodePosition: nodePosition,
node: note
}
})
return _.sortBy(notes, ['blockPosition', 'nodePosition'])
}
}
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