diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..20af2f68a65875723ab04e6607c5f965cfa01de1 --- /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 d56e33c1ce35c4048a9ad4cff41918f4a4603b82..0a41d0f678d3be6394802c7d0cd5858f08a3e57e 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 0c835b1fbe413f0f053899392f5a50d927b08deb..96fe06442115c27241a0999b90da4e4a033b234b 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 2332bb8c5a2d9617cf047d15df84df8be14c05e6..b0e4efba18c9f88eb53fe1e944d8acc03f5d4d1a 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 c286907f23ee7412004f6e80310e92b4bd29a94b..b5cb018a631cc32f8768bbc11e6002e77c2227c1 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 e64f68163aa1cb52b9e273e2e43213a228944f33..6f3fefb0ab6d08bef4bf55ec83d982f94a111682 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 03cd57060f7012a6574ffa9ad8c489b930ce2f46..3d7bd528e82261b787ed1e816360921624fdf7c2 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 cbcb44fb2ab13a5dad2832f8017cef18b885d396..9ec89c1ed380b8a395dbf36c4d759a91bc61f074 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 cd061b4421f931ada6dc09cbbfff56bad3ff4402..fef234eff61fc0426b193692fe5c596f60c50bc9 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 2ce72eab5137194ebf425db8035f10fe59f465df..6f78450c6bb25354048738e574cf1dee8deb2aaf 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 d2c12d0089cfa03ad9d9cd5bea4a8c6c18955c32..d8653cdb1a1b3e01b204f237db46fbe6a62e261b 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 } }