This commit is contained in:
Rainer Simon 2022-07-24 11:01:02 +02:00
parent e7d7cd1948
commit 9657769e42
4 changed files with 83 additions and 59 deletions

View File

@ -11,6 +11,7 @@ export default class Selection {
constructor(target, body) {
this.underlying = {
'@context': 'http://www.w3.org/ns/anno.jsonld',
type: 'Selection',
body: body || [],
target
@ -29,6 +30,10 @@ export default class Selection {
return cloned;
}
get context() {
return this.underlying['@context'];
}
get type() {
return this.underlying.type;
}
@ -87,7 +92,6 @@ export default class Selection {
toAnnotation = () => {
const a = Object.assign({}, this.underlying, {
'@context': 'http://www.w3.org/ns/anno.jsonld',
'type': 'Annotation',
'id': `#${uuid()}`
});

View File

@ -51,6 +51,10 @@ export default class WebAnnotation {
return this.underlying.id;
}
get context() {
return this.underlying['@context'];
}
get type() {
return this.underlying.type;
}

View File

@ -260,6 +260,20 @@ export default class Editor extends Component {
}
}
/**
* Adds a URI to the context field
*/
onAddContext = uri => {
const { currentAnnotation } = this.state;
const context = Array.isArray(currentAnnotation.context) ?
currentAnnotation.context : [ currentAnnotation.context ];
if (context.indexOf(uri) < 0) {
context.push(uri);
this.updateCurrentAnnotation({ '@context': context });
}
}
onCancel = () =>
this.props.onCancel(this.props.annotation);
@ -335,6 +349,7 @@ export default class Editor extends Component {
onUpsertBody: this.onUpsertBody,
onBatchModify: this.onBatchModify,
onSetProperty: this.onSetProperty,
onAddContext: this.onAddContext,
onSaveAndClose: this.onOk
})
)}

View File

@ -19,6 +19,7 @@ export default class WrappedWidget extends Component {
onRemoveBody: (body, saveImmediately) => props.onRemoveBody(body, saveImmediately),
onBatchModify: (diffs, saveImmediately) => props.onBatchModify(diffs, saveImmediately),
onSetProperty: (property, value) => props.onSetProperty(property, value),
onAddContext: uri => props.onAddContext(uri),
onSaveAndClose: () => props.onSaveAndClose()
});