8000 Allows to change the readOnly property of the editor. by lauxley · Pull Request #54 · recogito/recogito-js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allows to change the readOnly property of the editor. #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/TextAnnotator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export default class TextAnnotator extends Component {
selectedAnnotation: null,
selectedDOMElement: null,
selectedRelation: null,


// ReadOnly mode
readOnly: this.props.config.readOnly,

// Headless mode
editorDisabled: this.props.config.disableEditor,
}
Expand All @@ -42,7 +45,6 @@ export default class TextAnnotator extends Component {
this.selectionHandler.on('select', this.handleSelect);

this.relationsLayer = new RelationsLayer(this.props.contentEl);
this.relationsLayer.readOnly = true; // Deactivate by default

this.relationsLayer.on('createRelation', this.onEditRelation);
this.relationsLayer.on('selectRelation', this.onEditRelation);
Expand All @@ -64,7 +66,7 @@ export default class TextAnnotator extends Componen 8000 t {
this.state.editorDisabled ?
this.onHeadlessSelect(evt) : this.onNormalSelect(evt);
}

=> {
const { selection, element } = evt;
if (selection) {
Expand All @@ -82,7 +84,7 @@ export default class TextAnnotator extends Component {
this.clearState();
}
}

=> {
const { selection, element } = evt;
if (selection) {
Expand All @@ -99,7 +101,7 @@ export default class TextAnnotator extends Component {
this.props.onAnnotationSelected(selection.clone(), element);
} else {
// Notify backend text selection to create a new annotation
const undraft = annotation =>
const undraft = annotation =>
annotation.clone({
body : annotation.bodies.map(({ draft, ...rest }) => rest)
});
Expand Down Expand Up @@ -262,7 +264,7 @@ export default class TextAnnotator extends Component {
setAnnotations = annotations => {
this.highlighter.clear();
this.relationsLayer.clear();

const clones = annotations.map(a => a.clone());
this.highlighter.init(clones).then(() =>
this.relationsLayer.init(clones));
Expand Down Expand Up @@ -292,10 +294,20 @@ export default class TextAnnotator extends Component {
}
}

get readOnly() {
return this.state.readOnly;
}

set readOnly(readOnly) {
this.selectionHandler.readOnly = readOnly;
// Note: relationsHandler.readOnly should be set by setMode.
this.setState({ readOnly });
}

render() {
// The editor should open under normal conditions - annotation was selected, no headless mode
const open = (this.state.selectedAnnotation || this.state.selectedRelation) && !this.state.editorDisabled;
const open = (this.state.selectedAnnotation || this.state.selectedRelation) && !this.state.editorDisabled;

const readOnly = this.props.config.readOnly || this.state.selectedAnnotation?.readOnly

return (open && (
Expand Down
12 changes: 10 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react';
import ReactDOM from 'react-dom';
import Emitter from 'tiny-emitter';
import {
WebAnnotation,
WebAnnotation,
createEnvironment,
setLocale
setLocale
} from '@recogito/recogito-client-core';
import TextAnnotator from './TextAnnotator';
import { deflateHTML } from './utils';
Expand Down Expand Up @@ -145,6 +145,14 @@ export class Recogito {
setServerTime = timestamp =>
this._environment.setServerTime(timestamp);

get readOnly() {
return this._app.current.readOnly;
}

set readOnly(readOnly) {
this._app.current.readOnly = readOnly;
}

}

export const init = config => new Recogito(config);
14 changes: 8 additions & 6 deletions src/relations/RelationsLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default class RelationsLayer extends EventEmitter {
this.svg.setAttribute('class', 'r6o-relations-layer');
this.contentEl.appendChild(this.svg);

this.readOnly = true; // deactivate by default

this.drawingTool = new DrawingTool(contentEl, this.svg);

// Forward events
Expand Down Expand Up @@ -152,16 +154,16 @@ export default class RelationsLayer extends EventEmitter {

resetDrawing = () =>
this.drawingTool.reset();

get readOnly() {
this.svg.classList.contains('readonly');
}
/*
* get readOnly() {
* this.svg.classList.contains('readonly');
* } */

set readOnly(readOnly) {
if (readOnly)
this.svg.setAttribute('class', 'r6o-relations-layer readonly');
this.svg.classList.add('readonly');
else
this.svg.setAttribute('class', 'r6o-relations-layer');
this.svg.classList.remove('readonly');
}

}
0