From 2e929dbc41884ec3922d59002b3117296abcb1cd Mon Sep 17 00:00:00 2001 From: yannis <yannisbarlas@gmail.com> Date: Wed, 26 Apr 2017 18:10:47 +0300 Subject: [PATCH] mark todos in new notes implementation --- .vscode/settings.json | 3 ++ .../elements/isolatedNote/IsolatedNote.js | 21 ++++++----- .../isolatedNote/IsolatedNoteCommand.js | 4 ++- .../isolatedNote/IsolatedNoteComponent.js | 29 ++++++++++----- .../isolatedNote/IsolatedNoteHTMLConverter.js | 6 ++++ .../isolatedNote/IsolatedNotePackage.js | 2 ++ .../elements/isolatedNote/IsolatedNoteTool.js | 2 ++ .../SimpleEditor/elements/note/NoteCommand.js | 5 +-- .../elements/note/NoteComponent.js | 36 +++++++++++++------ .../elements/note/NoteHTMLConverter.js | 2 ++ .../SimpleEditor/panes/Notes/NotesProvider.js | 9 +++-- 11 files changed, 84 insertions(+), 35 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..20af2f6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +// Place your settings in this file to overwrite default and user settings. +{ +} \ No newline at end of file diff --git a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNote.js b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNote.js index d56e33c..0a41d0f 100644 --- a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNote.js +++ b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNote.js @@ -2,18 +2,21 @@ import {DocumentNode} from 'substance' 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({ - 'type': 'isolated-note', - 'parentNoteId': { - type: 'string', - optional: true - }, - 'index': { + type: 'isolated-note', + content: 'text', + index: { type: 'number', optional: true }, - content: 'text' + parentNoteId: { + type: 'string', + optional: true + } }) -IsolatedNote.mode = 'focused' -IsolatedNote.unblocked = true + export default IsolatedNote diff --git a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteCommand.js b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteCommand.js index 0c835b1..96fe064 100644 --- a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteCommand.js +++ b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteCommand.js @@ -1,5 +1,7 @@ import { Command } from 'substance' +// TODO -- delete this file + class IsolatedNoteCommand extends Command { constructor () { super({ name: 'insert-isolated-note' }) @@ -23,7 +25,7 @@ class IsolatedNoteCommand extends Command { let editorSession = this._getEditorSession(params) editorSession.transaction((tx) => { let nodeData = this.createNodeData(tx, params) - console.log('nodeData', nodeData) + // console.log('nodeData', nodeData) tx.insertBlockNode(nodeData) }) } diff --git a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteComponent.js b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteComponent.js index 2332bb8..b0e4efb 100644 --- a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteComponent.js +++ b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteComponent.js @@ -3,15 +3,26 @@ import TextPropertyEditor from './TextPropertyEditor' class IsolatedNoteComponent extends IsolatedNodeComponent { render ($$) { - let el = $$('div').addClass('sc-entity') - el.attr('data-id', this.props.node.id) - el.append( - $$(TextPropertyEditor, { - path: [this.props.node.id, 'content'], - disabled: this.props.disabled, - tagName: 'p', - multiLine: false - }).ref('noteContentEditor-' + this.props.node.id)) + + // TODO + // why class sc-entity?? + // rename dataId to calloutId ?? if so, change in provider + // is there a better way than rendering a text property editor??? + // review ref name + // do we need a ref ?? + + 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 } diff --git a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js index c286907..b5cb018 100644 --- a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js +++ b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteHTMLConverter.js @@ -1,3 +1,7 @@ +// TODO +// review tag name +// this converter shouldn't exist + export default { type: 'isolated-note', tagName: 'isolated-note', @@ -6,10 +10,12 @@ export default { node.content = converter.annotatedText(el, [node.id, 'content']) node.parentNoteId = el.attr('data-parent-id') }, + export: function (node, el, converter) { el.append( converter.annotatedText([node.id, 'content']) ) + el.setAttribute('data-parent-id', node.parentNoteId) } } diff --git a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNotePackage.js b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNotePackage.js index e64f681..6f3fefb 100644 --- a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNotePackage.js +++ b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNotePackage.js @@ -4,6 +4,8 @@ import IsolatedNoteHTMLConverter from './IsolatedNoteHTMLConverter' import IsolatedNoteCommand from './IsolatedNoteCommand' import IsolatedNoteTool from './IsolatedNoteTool' +// TODO -- should there be anything other than name and configure? + export default { name: 'isolated-note', configure: function (config) { diff --git a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteTool.js b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteTool.js index 03cd570..3d7bd52 100644 --- a/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteTool.js +++ b/app/components/SimpleEditor/elements/isolatedNote/IsolatedNoteTool.js @@ -1,5 +1,7 @@ import { Tool } from 'substance' +// TOOD -- delete this file + class IsolatedNoteTool extends Tool { getClassNames () { return 'sc-insert-isolated-note-tool' diff --git a/app/components/SimpleEditor/elements/note/NoteCommand.js b/app/components/SimpleEditor/elements/note/NoteCommand.js index cbcb44f..9ec89c1 100644 --- a/app/components/SimpleEditor/elements/note/NoteCommand.js +++ b/app/components/SimpleEditor/elements/note/NoteCommand.js @@ -6,6 +6,7 @@ class NoteCommand extends InsertInlineNodeCommand { type: 'note' } } + execute (params) { let editorSession = params.editorSession let nodeData = this.createNodeData() @@ -14,10 +15,6 @@ class NoteCommand extends InsertInlineNodeCommand { return tx.insertInlineNode(nodeData) }) } - - getNotesProvider (params) { - return params.surface.context.notesProvider - } } NoteCommand.type = 'note' diff --git a/app/components/SimpleEditor/elements/note/NoteComponent.js b/app/components/SimpleEditor/elements/note/NoteComponent.js index cd061b4..fef234e 100644 --- a/app/components/SimpleEditor/elements/note/NoteComponent.js +++ b/app/components/SimpleEditor/elements/note/NoteComponent.js @@ -1,36 +1,51 @@ /* eslint react/prop-types: 0 */ -import { each, includes, keys } from 'lodash' +import { each, get, includes, keys } from 'lodash' import { Component, documentHelpers } from 'substance' class NoteComponent extends Component { - 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 ($$) { - const el = $$('note') - .attr('note-content', this.props.node['note-content']) - .addClass('sc-note').on('click', this.showNote) + const noteContent = this.props.node['note-content'] + + // TODO -- why note??? + // const el = $$('note') + const el = $$('span') + .attr('note-content', noteContent) + .addClass('sc-note') + .on('click', this.noteSelected) return el } - showNote () { + // TODO -- should this maybe be the provider's job? + noteSelected () { const selected = this.getSelection() - if (!selected.node) return - const provider = this.getProvider() + if (get(selected, 'node.type') !== 'note') return + this.disableTools(selected) - provider.showNote(selected.node) + + const provider = this.getProvider() + const noteId = selected.node.id + + provider.calloutSelected(noteId) } + // TODO -- review disableTools () { const commandStates = this.getCommandStates() + each(keys(commandStates), (key) => { const allowed = ['comment', 'redo', 'save', 'switch-text-type', 'undo', 'note'] if (!includes(allowed, key)) commandStates[key].disabled = true }) + this.rerender() } @@ -68,6 +83,7 @@ class NoteComponent extends Component { } getSurface () { + // TODO -- write with container id return this.context.surfaceManager.getFocusedSurface() } diff --git a/app/components/SimpleEditor/elements/note/NoteHTMLConverter.js b/app/components/SimpleEditor/elements/note/NoteHTMLConverter.js index 2ce72ea..6f78450 100644 --- a/app/components/SimpleEditor/elements/note/NoteHTMLConverter.js +++ b/app/components/SimpleEditor/elements/note/NoteHTMLConverter.js @@ -1,3 +1,5 @@ +// TODO -- es6 this + export default { type: 'note', tagName: 'note', diff --git a/app/components/SimpleEditor/panes/Notes/NotesProvider.js b/app/components/SimpleEditor/panes/Notes/NotesProvider.js index d2c12d0..d8653cd 100644 --- a/app/components/SimpleEditor/panes/Notes/NotesProvider.js +++ b/app/components/SimpleEditor/panes/Notes/NotesProvider.js @@ -44,8 +44,13 @@ class NotesProvider extends TOCProvider { return _.sortBy(notes, ['blockPosition', 'nodePosition']) } - showNote (note) { - this.config.notesEditorContext.editor.emit('noteSelected', note.id) + calloutSelected (noteId) { + const notesEditor = this.getNotesEditor() + notesEditor.emit('noteSelected', noteId) + } + + getNotesEditor () { + return this.config.notesEditorContext.editor } } -- GitLab