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

cleanup note tool

parent 8863ce30
No related branches found
No related tags found
No related merge requests found
import { each, includes, keys } from 'lodash' import { each, includes, keys } from 'lodash'
import { import {
documentHelpers, documentHelpers,
EditorSession,
ProseEditorConfigurator as Configurator,
Tool Tool
} from 'substance' } from 'substance'
import MiniEditor from '../../miniEditor/miniEditor'
import config from '../../miniEditor/config'
import Importer from '../../SimpleEditorImporter'
import SimpleExporter from '../../SimpleEditorExporter'
class EditNoteTool extends Tool { class EditNoteTool extends Tool {
constructor (props) {
super(props)
this.saveNote = this.saveNote.bind(this)
}
render ($$) { render ($$) {
const miniEditorSession = this._initMiniEditor()
const selected = this.getSelection() const selected = this.getSelection()
const provider = this.getProvider() const provider = this.getProvider()
...@@ -26,9 +14,6 @@ class EditNoteTool extends Tool { ...@@ -26,9 +14,6 @@ class EditNoteTool extends Tool {
if (!selected.node) return el if (!selected.node) return el
el.append($$(MiniEditor, {
editorSession: miniEditorSession
}))
provider.config.miniEditorContext.editor.emit('noteSelected', 'paragraph-71bf75436a5f9b56700064c6ee2116ab') provider.config.miniEditorContext.editor.emit('noteSelected', 'paragraph-71bf75436a5f9b56700064c6ee2116ab')
return el return el
} }
...@@ -37,27 +22,6 @@ class EditNoteTool extends Tool { ...@@ -37,27 +22,6 @@ class EditNoteTool extends Tool {
this.context.editorSession.onUpdate('', this.disableTools, this) this.context.editorSession.onUpdate('', this.disableTools, this)
} }
_initMiniEditor () {
const selected = this.getSelection()
if (!selected.node) return
const configurator = new Configurator().import(config)
configurator.addImporter('html', Importer)
const importer = configurator.createImporter('html')
const doc = importer.importDocument(selected.node['note-content'])
const editorSession = new EditorSession(doc, {
configurator: configurator
})
editorSession.setSaveHandler({
saveDocument: this.saveNote
})
return editorSession
}
disableTools () { disableTools () {
const selected = this.getSelection() const selected = this.getSelection()
if (!selected.node) return if (!selected.node) return
...@@ -69,24 +33,6 @@ class EditNoteTool extends Tool { ...@@ -69,24 +33,6 @@ class EditNoteTool extends Tool {
this.rerender() this.rerender()
} }
saveNote (source) {
const selected = this.getSelection()
const config = this.context.editorSession.configurator.config
const exporter = new SimpleExporter(config)
const convertedSource = exporter.exportDocument(source)
const editorSession = this.context.editorSession
editorSession.transaction(function (tx, args) {
const path = [selected.node.id, 'note-content']
tx.set(path, convertedSource)
})
// Return dummy Promise needed in saveDocument
return new Promise(function (resolve, reject) {
resolve()
})
}
getSelection () { getSelection () {
// TODO -- write cleaner // TODO -- write cleaner
const surface = this.context.surfaceManager.getFocusedSurface() const surface = this.context.surfaceManager.getFocusedSurface()
......
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