diff --git a/src/AnnotationCreation.js b/src/AnnotationCreation.js index 52042c62999a8e394004d4396526eea47bfcc22f..471f18f258e9bc764e45d541ee5f0b55ab74d7df 100644 --- a/src/AnnotationCreation.js +++ b/src/AnnotationCreation.js @@ -143,8 +143,14 @@ class AnnotationCreation extends Component { strokeWidth: 3, ...(props.config.annotation.defaults || {}), }; + + const timeState = props.currentTime !== null + ? { tend: Math.floor(props.currentTime) + 10, tstart: Math.floor(props.currentTime) } + : { tend: null, tstart: null }; + this.state = { ...toolState, + ...timeState, textBody: '', activeTool: 'cursor', closedMode: 'closed', @@ -155,9 +161,7 @@ class AnnotationCreation extends Component { popoverAnchorEl: null, popoverLineWeightAnchorEl: null, svg: null, - tend: Math.floor(props.currentTime) + 10, textEditorStateBustingKey: 0, - tstart: Math.floor(props.currentTime), imgConstrain: false, imgHeight: { lastSubmittedValue: '', @@ -477,7 +481,8 @@ class AnnotationCreation extends Component { textBody, image, imgWidth, imgHeight, imgUrl, tags, xywh, svg, imgConstrain, tstart, tend, textEditorStateBustingKey, } = this.state; - const annoBody = { value: !textBody.length ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : textBody }; + const t = (tstart && tend) ? `${tstart},${tend}` : null; + const annoBody = { value: (!textBody.length && t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : textBody }; let imgBody; if (imgWidth.validity === 1 && imgHeight.validity === 1 && imgUrl.validity === 1) { @@ -497,7 +502,7 @@ class AnnotationCreation extends Component { const anno = new WebAnnotation({ body: annoBody, canvasId: canvas.id, - fragsel: { t: `${tstart},${tend}`, xywh }, + fragsel: { t, xywh }, id: (annotation && annotation.id) || `${uuid()}`, image: imgBody, manifestId: canvas.options.resource.id, @@ -519,10 +524,10 @@ class AnnotationCreation extends Component { this.setState({ image: false, svg: null, - tend: 0, + tend: null, textBody: '', textEditorStateBustingKey: textEditorStateBustingKey + 1, - tstart: 0, + tstart: null, xywh: null, }); } @@ -919,7 +924,7 @@ AnnotationCreation.propTypes = { ), }), }).isRequired, - currentTime: PropTypes.number, + currentTime: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(null)]), id: PropTypes.string.isRequired, paused: PropTypes.bool, receiveAnnotation: PropTypes.func.isRequired, @@ -932,7 +937,7 @@ AnnotationCreation.defaultProps = { annotation: null, canvases: [], closeCompanionWindow: () => {}, - currentTime: 0, + currentTime: null, paused: true, setCurrentTime: () => {}, setSeekTo: () => {}, diff --git a/src/WebAnnotation.js b/src/WebAnnotation.js index 948dc8909f09cd42c5aae327bc8c17cc62be7f2a..f43d1f807cd5a13197e91a54e16be1b056a1b551 100644 --- a/src/WebAnnotation.js +++ b/src/WebAnnotation.js @@ -58,9 +58,10 @@ export default class WebAnnotation { return bodies; } - /** */ + /** Fill target object with selectors (if any), else returns target url */ target() { - if (!this.svg && !this.fragsel) { + if (!this.svg + && (!this.fragsel || !Object.values(this.fragsel).find((e) => e !== null))) { return this.canvasId; } const target = { source: this.source() }; diff --git a/src/plugins/annotationCreationCompanionWindow.js b/src/plugins/annotationCreationCompanionWindow.js index afe5bed4c5d67df92ac81225c52159f05344665d..4f8cf0303b228ccdef7e94467eb93e71e459c7a6 100644 --- a/src/plugins/annotationCreationCompanionWindow.js +++ b/src/plugins/annotationCreationCompanionWindow.js @@ -25,7 +25,7 @@ function mapStateToProps(state, { id: companionWindowId, windowId }) { const canvases = getVisibleCanvases(state, { windowId }); const annotation = getPresentAnnotationsOnSelectedCanvases(state, { windowId }) - .flatMap((annoPage) => annoPage.json.items) + .flatMap((annoPage) => annoPage.json.items || []) .find((annot) => annot.id === annotationid); return {