diff --git a/app/components/SimpleEditor/SimpleEditorExporter.js b/app/components/SimpleEditor/SimpleEditorExporter.js index 34afcfb3a24b5b3d23d50857248db85792d5b434..7fa1ad70940f1982e1c1dc100c3724ab77d81373 100644 --- a/app/components/SimpleEditor/SimpleEditorExporter.js +++ b/app/components/SimpleEditor/SimpleEditorExporter.js @@ -37,7 +37,7 @@ class SimpleExporter extends HTMLExporter { var doc = container.editorSession.getDocument() this.state.doc = doc var elements = [] - console.log(container) + container.editorSession.document.data.nodes.body.nodes.forEach(function (id) { var node = doc.get(id) var nodeEl = this.convertNode(node) diff --git a/app/components/SimpleEditor/elements/comment/CommentComponent.js b/app/components/SimpleEditor/elements/comment/CommentComponent.js index c6e899853c7bc18f0a813e691762d60a718da267..1ab7c4df564ba78d53901b619631e8175cb00a12 100644 --- a/app/components/SimpleEditor/elements/comment/CommentComponent.js +++ b/app/components/SimpleEditor/elements/comment/CommentComponent.js @@ -41,7 +41,7 @@ class CommentComponent extends AnnotationComponent { // put here all conditions for the node to change hasNodeChanged () { const { node } = this.props - console.log(node) + if (this.active !== node.active) return true return false } diff --git a/app/components/SimpleEditor/elements/images/ImageComponent.js b/app/components/SimpleEditor/elements/images/ImageComponent.js index 11e6f89c8a2552a9eac8e3b7a2586725148b744c..65bc57d2133c1f2cadc52ddd0716376f0423d8b4 100644 --- a/app/components/SimpleEditor/elements/images/ImageComponent.js +++ b/app/components/SimpleEditor/elements/images/ImageComponent.js @@ -4,69 +4,39 @@ class ImageComponent extends BlockNodeComponent { didMount () { super.didMount.call(this) - const { node } = this.props - - node.on('upload:started', this.onUploadStarted, this) - node.on('upload:finished', this.onUploadFinished, this) - node.on('upload:failed', this.onUploadFailed, this) + this.context.editorSession.onRender('document', this._onDocumentChange, this) } dispose () { super.dispose.call(this) - const { node } = this.props - node.off(this) + this.context.editorSession.off(this) + } + + _onDocumentChange (change) { + if (change.isAffected(this.props.node.id) || + change.isAffected(this.props.node.imageFile)) { + this.rerender() + } } render ($$) { - let el = super.render.call(this, $$) + let el = super.render($$) el.addClass('sc-image') - el.removeClass('') // An empty class is added for some reason so remove it - el.append( $$('img').attr({ - src: this.props.node.src + src: this.props.node.getUrl() }).ref('image') ) - if (this.state.uploading) { - let progressBar = $$('div') - .addClass('se-progress-bar') - .ref('progressBar') - .append('Uploading ...') - el.append(progressBar) - } - - return el - } - - // TODO -- extend state - onUploadStarted () { - this.setState({ uploading: true }) - } - - onUploadFinished () { - this.setState({}) - const editor = this.getEditor() editor.emit('ui:updated') - } - getEditor () { - return this.context.controller + return el } - onUploadFailed () { - const surface = this.context.surface - let nodeId = this.props.node.id - - const transformation = (tx, args) => { - args.nodeId = nodeId - deleteNode(tx, args) - } - - surface.transaction(transformation) + getEditor () { + return this.context.editor } - } export default ImageComponent diff --git a/app/components/SimpleEditor/elements/images/ImageFileProxy.js b/app/components/SimpleEditor/elements/images/ImageFileProxy.js index 72a3736b456bc070555439d3ca3ff1d0935283cd..99a9dba7eca12575a5eb841b087f4c583910baa6 100644 --- a/app/components/SimpleEditor/elements/images/ImageFileProxy.js +++ b/app/components/SimpleEditor/elements/images/ImageFileProxy.js @@ -4,11 +4,8 @@ class ImageFileProxy extends FileProxy { constructor (fileNode, context) { super(fileNode, context) - console.log('imageFileProxy', this) - console.log('imageFileProxy Node', fileNode) - console.log('imageFileProxy Context', context) - // used locally e.g. after drop or file dialog - this.file = fileNode.data + this.file = fileNode.sourceFile + if (this.file) { this._fileUrl = URL.createObjectURL(this.file) } @@ -29,19 +26,16 @@ class ImageFileProxy extends FileProxy { } sync () { - console.log('sync', this) if (!this.url) { - console.info('Simulating file upload. Creating blob url instead.', this._fileUrl) - console.log('file in sync', this.file) - // this.context.editorSession.saveHandler.uploadFile() - this.url = this._fileUrl + this.context.editorSession.saveHandler.uploadFile(this.file).then((res) => { + this.url = res.file + FileProxy.prototype.triggerUpdate.call(this) + }) } - return Promise.resolve() } } ImageFileProxy.match = function(fileNode, context) { // eslint-disable-line - console.log('imageFileProxy match', fileNode) return fileNode.fileType === 'image' } diff --git a/app/components/SimpleEditor/elements/images/InsertImageCommand.js b/app/components/SimpleEditor/elements/images/InsertImageCommand.js index 33d4bf9fce2f1d0c0a20611ea723c1cab53f7ec3..b23cde7c8cf510eda990a4b318f41c9da9f8f34a 100644 --- a/app/components/SimpleEditor/elements/images/InsertImageCommand.js +++ b/app/components/SimpleEditor/elements/images/InsertImageCommand.js @@ -21,7 +21,7 @@ class ImageCommand extends Command { execute (params) { let editorSession = params.editorSession - console.log('onExecution', params) + editorSession.transaction((tx) => { params.files.forEach((file) => { this._insertImage(tx, file) @@ -32,16 +32,13 @@ class ImageCommand extends Command { } _insertImage (tx, file) { - console.log('file', file) - console.log('insert', this) let imageFile = tx.create({ type: 'file', fileType: 'image', - mimeType: file.type + mimeType: file.type, + sourceFile: file }) - console.log(' After imageFile', imageFile) - // Inserts image at current cursor pos tx.insertBlockNode({ type: 'image', imageFile: imageFile.id diff --git a/app/components/SimpleEditor/panes/Comments/CommentBoxList.js b/app/components/SimpleEditor/panes/Comments/CommentBoxList.js index 8d2962c26bc68f375e5217fc57e31a49158c75f5..61736afdcebdbee1b412bce7b2ab943a7dfd5324 100644 --- a/app/components/SimpleEditor/panes/Comments/CommentBoxList.js +++ b/app/components/SimpleEditor/panes/Comments/CommentBoxList.js @@ -117,7 +117,6 @@ class CommentBoxList extends Component { // if active, move as many boxes above as needed to bring it to the annotation's height if (isActive) { - console.log('isActive', isActive) entry.endHeight = annotationTop + boxHeight + 2 result[pos] = annotationTop diff --git a/app/components/SimpleEditor/panes/Comments/CommentsProvider.js b/app/components/SimpleEditor/panes/Comments/CommentsProvider.js index b6fc77c37ae6b5aace3e4a63244bc40c1e7d7486..ca2e84afac1d095bca2c5efb2a802433087c2ba6 100644 --- a/app/components/SimpleEditor/panes/Comments/CommentsProvider.js +++ b/app/components/SimpleEditor/panes/Comments/CommentsProvider.js @@ -11,11 +11,12 @@ class CommentsProvider extends TocProvider { editorSession.onUpdate('', this.updateActiveEntry, this) editorSession.onRender('document', this.update, this) + const editor = props.controller + editor.on('ui:updated', this.onUiUpdate, this) + // TODO is this needed anymore? // const doc = editorSession.getDocument() // doc.on('document:changed', this.update, this) - // const editor = props.controller - // editor.on('ui:updated', this.onUiUpdate, this) } // @@ -34,7 +35,7 @@ class CommentsProvider extends TocProvider { // TODO -- this will probably not be needed if we stop moving the line height for track changes // offset by the time it takes the animation to change the line height onUiUpdate () { - setTimeout(() => { this.update() }, 300) + setTimeout(() => { this.update() }, 100) } reComputeEntries () {