Skip to content
Snippets Groups Projects
Commit 2e929dbc authored by Yannis Barlas's avatar Yannis Barlas Committed by john
Browse files

mark todos in new notes implementation

parent b39fbf03
No related branches found
No related tags found
No related merge requests found
Showing
with 84 additions and 35 deletions
// Place your settings in this file to overwrite default and user settings.
{
}
\ No newline at end of file
...@@ -2,18 +2,21 @@ import {DocumentNode} from 'substance' ...@@ -2,18 +2,21 @@ import {DocumentNode} from 'substance'
class IsolatedNote extends DocumentNode {} class IsolatedNote extends DocumentNode {}
// TODO -- rename parentNoteId to calloutId
// TODO -- should we get rid of index?
// TODO -- callout id should not be optional
IsolatedNote.define({ IsolatedNote.define({
'type': 'isolated-note', type: 'isolated-note',
'parentNoteId': { content: 'text',
type: 'string', index: {
optional: true
},
'index': {
type: 'number', type: 'number',
optional: true optional: true
}, },
content: 'text' parentNoteId: {
type: 'string',
optional: true
}
}) })
IsolatedNote.mode = 'focused'
IsolatedNote.unblocked = true
export default IsolatedNote export default IsolatedNote
import { Command } from 'substance' import { Command } from 'substance'
// TODO -- delete this file
class IsolatedNoteCommand extends Command { class IsolatedNoteCommand extends Command {
constructor () { constructor () {
super({ name: 'insert-isolated-note' }) super({ name: 'insert-isolated-note' })
...@@ -23,7 +25,7 @@ class IsolatedNoteCommand extends Command { ...@@ -23,7 +25,7 @@ class IsolatedNoteCommand extends Command {
let editorSession = this._getEditorSession(params) let editorSession = this._getEditorSession(params)
editorSession.transaction((tx) => { editorSession.transaction((tx) => {
let nodeData = this.createNodeData(tx, params) let nodeData = this.createNodeData(tx, params)
console.log('nodeData', nodeData) // console.log('nodeData', nodeData)
tx.insertBlockNode(nodeData) tx.insertBlockNode(nodeData)
}) })
} }
......
...@@ -3,15 +3,26 @@ import TextPropertyEditor from './TextPropertyEditor' ...@@ -3,15 +3,26 @@ import TextPropertyEditor from './TextPropertyEditor'
class IsolatedNoteComponent extends IsolatedNodeComponent { class IsolatedNoteComponent extends IsolatedNodeComponent {
render ($$) { render ($$) {
let el = $$('div').addClass('sc-entity')
el.attr('data-id', this.props.node.id) // TODO
el.append( // why class sc-entity??
$$(TextPropertyEditor, { // rename dataId to calloutId ?? if so, change in provider
path: [this.props.node.id, 'content'], // is there a better way than rendering a text property editor???
disabled: this.props.disabled, // review ref name
tagName: 'p', // do we need a ref ??
multiLine: false
}).ref('noteContentEditor-' + this.props.node.id)) let el = $$('div')
.addClass('sc-entity')
.attr('data-id', this.props.node.id)
.append(
$$(TextPropertyEditor, {
disabled: this.props.disabled,
multiLine: false,
path: [this.props.node.id, 'content'],
tagName: 'p'
}
)
.ref('noteContentEditor-' + this.props.node.id))
return el return el
} }
......
// TODO
// review tag name
// this converter shouldn't exist
export default { export default {
type: 'isolated-note', type: 'isolated-note',
tagName: 'isolated-note', tagName: 'isolated-note',
...@@ -6,10 +10,12 @@ export default { ...@@ -6,10 +10,12 @@ export default {
node.content = converter.annotatedText(el, [node.id, 'content']) node.content = converter.annotatedText(el, [node.id, 'content'])
node.parentNoteId = el.attr('data-parent-id') node.parentNoteId = el.attr('data-parent-id')
}, },
export: function (node, el, converter) { export: function (node, el, converter) {
el.append( el.append(
converter.annotatedText([node.id, 'content']) converter.annotatedText([node.id, 'content'])
) )
el.setAttribute('data-parent-id', node.parentNoteId) el.setAttribute('data-parent-id', node.parentNoteId)
} }
} }
...@@ -4,6 +4,8 @@ import IsolatedNoteHTMLConverter from './IsolatedNoteHTMLConverter' ...@@ -4,6 +4,8 @@ import IsolatedNoteHTMLConverter from './IsolatedNoteHTMLConverter'
import IsolatedNoteCommand from './IsolatedNoteCommand' import IsolatedNoteCommand from './IsolatedNoteCommand'
import IsolatedNoteTool from './IsolatedNoteTool' import IsolatedNoteTool from './IsolatedNoteTool'
// TODO -- should there be anything other than name and configure?
export default { export default {
name: 'isolated-note', name: 'isolated-note',
configure: function (config) { configure: function (config) {
......
import { Tool } from 'substance' import { Tool } from 'substance'
// TOOD -- delete this file
class IsolatedNoteTool extends Tool { class IsolatedNoteTool extends Tool {
getClassNames () { getClassNames () {
return 'sc-insert-isolated-note-tool' return 'sc-insert-isolated-note-tool'
......
...@@ -6,6 +6,7 @@ class NoteCommand extends InsertInlineNodeCommand { ...@@ -6,6 +6,7 @@ class NoteCommand extends InsertInlineNodeCommand {
type: 'note' type: 'note'
} }
} }
execute (params) { execute (params) {
let editorSession = params.editorSession let editorSession = params.editorSession
let nodeData = this.createNodeData() let nodeData = this.createNodeData()
...@@ -14,10 +15,6 @@ class NoteCommand extends InsertInlineNodeCommand { ...@@ -14,10 +15,6 @@ class NoteCommand extends InsertInlineNodeCommand {
return tx.insertInlineNode(nodeData) return tx.insertInlineNode(nodeData)
}) })
} }
getNotesProvider (params) {
return params.surface.context.notesProvider
}
} }
NoteCommand.type = 'note' NoteCommand.type = 'note'
......
/* eslint react/prop-types: 0 */ /* eslint react/prop-types: 0 */
import { each, includes, keys } from 'lodash' import { each, get, includes, keys } from 'lodash'
import { Component, documentHelpers } from 'substance' import { Component, documentHelpers } from 'substance'
class NoteComponent extends Component { class NoteComponent extends Component {
didMount () { didMount () {
this.context.editorSession.onUpdate('', this.showNote, this) // TODO -- this disables the toolbar
// TODO -- unload listener on dispose
// TODO -- this gets registered once for each note -- fix
this.context.editorSession.onUpdate('', this.noteSelected, this)
} }
render ($$) { render ($$) {
const el = $$('note') const noteContent = this.props.node['note-content']
.attr('note-content', this.props.node['note-content'])
.addClass('sc-note').on('click', this.showNote) // TODO -- why note???
// const el = $$('note')
const el = $$('span')
.attr('note-content', noteContent)
.addClass('sc-note')
.on('click', this.noteSelected)
return el return el
} }
showNote () { // TODO -- should this maybe be the provider's job?
noteSelected () {
const selected = this.getSelection() const selected = this.getSelection()
if (!selected.node) return if (get(selected, 'node.type') !== 'note') return
const provider = this.getProvider()
this.disableTools(selected) this.disableTools(selected)
provider.showNote(selected.node)
const provider = this.getProvider()
const noteId = selected.node.id
provider.calloutSelected(noteId)
} }
// TODO -- review
disableTools () { disableTools () {
const commandStates = this.getCommandStates() const commandStates = this.getCommandStates()
each(keys(commandStates), (key) => { each(keys(commandStates), (key) => {
const allowed = ['comment', 'redo', 'save', 'switch-text-type', 'undo', 'note'] const allowed = ['comment', 'redo', 'save', 'switch-text-type', 'undo', 'note']
if (!includes(allowed, key)) commandStates[key].disabled = true if (!includes(allowed, key)) commandStates[key].disabled = true
}) })
this.rerender() this.rerender()
} }
...@@ -68,6 +83,7 @@ class NoteComponent extends Component { ...@@ -68,6 +83,7 @@ class NoteComponent extends Component {
} }
getSurface () { getSurface () {
// TODO -- write with container id
return this.context.surfaceManager.getFocusedSurface() return this.context.surfaceManager.getFocusedSurface()
} }
......
// TODO -- es6 this
export default { export default {
type: 'note', type: 'note',
tagName: 'note', tagName: 'note',
......
...@@ -44,8 +44,13 @@ class NotesProvider extends TOCProvider { ...@@ -44,8 +44,13 @@ class NotesProvider extends TOCProvider {
return _.sortBy(notes, ['blockPosition', 'nodePosition']) return _.sortBy(notes, ['blockPosition', 'nodePosition'])
} }
showNote (note) { calloutSelected (noteId) {
this.config.notesEditorContext.editor.emit('noteSelected', note.id) const notesEditor = this.getNotesEditor()
notesEditor.emit('noteSelected', noteId)
}
getNotesEditor () {
return this.config.notesEditorContext.editor
} }
} }
......
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