From dc014d05692aede69dc53c4d8c60a2db1034fcde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFs=20Poujade?= <lois.poujade@tetras-libre.fr> Date: Mon, 21 Nov 2022 08:19:30 +0100 Subject: [PATCH] WIP standard image annotation --- src/AnnotationCreation.js | 14 +++++--------- src/WebAnnotation.js | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/AnnotationCreation.js b/src/AnnotationCreation.js index 15ae285..ad80f17 100644 --- a/src/AnnotationCreation.js +++ b/src/AnnotationCreation.js @@ -86,6 +86,7 @@ class AnnotationCreation extends Component { super(props); const annoState = {}; annoState.image = false; + console.log('edition/creation annotation: ', props.annotation); if (props.annotation) { // @@ -97,14 +98,14 @@ class AnnotationCreation extends Component { annoState.tags.push(body.value); } else if (body.type === 'TextualBody') { annoState.textBody = body.value; - } else if (body.type === 'imgBody') { + } else if (body.type === 'Image') { annoState.textBody = body.value; annoState.image = body.image; } }); } else if (props.annotation.body.type === 'TextualBody') { annoState.textBody = props.annotation.body.value; - } else if (props.annotation.body.type === 'imgBody') { + } else if (props.annotation.body.type === 'Image') { annoState.textBody = props.annotation.body.value; annoState.image = props.annotation.body.image; } @@ -142,7 +143,6 @@ class AnnotationCreation extends Component { }; this.state = { ...toolState, - annoBody: '', textBody: '', activeTool: 'cursor', closedMode: 'closed', @@ -474,7 +474,7 @@ class AnnotationCreation extends Component { }); this.setState({ - annoBody: '', + textBody: '', svg: null, textEditorStateBustingKey: textEditorStateBustingKey + 1, xywh: null, @@ -744,11 +744,7 @@ class AnnotationCreation extends Component { </Grid> <Grid item xs={12}> <TextEditor - key={textEditorStateBustingKey} - annoHtml={annoBody} - updateAnnotationBody={this.updateBody} - /> - <TextEditor + key={textEditorStateBustingKey} annoHtml={textBody} updateAnnotationBody={this.updateTextBody} /> diff --git a/src/WebAnnotation.js b/src/WebAnnotation.js index e023d8c..6c35a91 100644 --- a/src/WebAnnotation.js +++ b/src/WebAnnotation.js @@ -26,7 +26,7 @@ export default class WebAnnotation { return { body: this.createBody(), id: this.id, - motivation: 'commenting', + motivation: 'supplementing', target: this.target(), type: 'Annotation', }; @@ -36,17 +36,21 @@ export default class WebAnnotation { createBody() { let bodies = []; - if (this.body) { - const annoBody = { + if (this.body && this.body.value != '') { + const textBody = { type: 'TextualBody', value: this.body.value, }; + bodies.push(textBody); + } - if (this.image) { - annoBody.type = 'ImageBody'; - Object.assign(annoBody, this.image); - } - bodies.push(annoBody); + if (this.image) { + const imgBody = { + type: 'Image', + id: this.image.url, + format: 'image/jpg', + }; + bodies.push(imgBody); } if (this.tags) { -- GitLab