Skip to content
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

feat(highlight): Change cursor when hovering over text #547

Merged
merged 3 commits into from
Jul 30, 2020
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
8 changes: 8 additions & 0 deletions src/document/DocumentAnnotator.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import '../highlight/HighlightCreator';

.bp-doc {
.ba-Layer {
position: absolute;
Expand All @@ -7,4 +9,10 @@
width: 100%;
pointer-events: none;
}

&.ba-is-highlighting {
.textLayer > span {
@include ba-HighlightCreator-cursor;
}
}
}
22 changes: 21 additions & 1 deletion src/document/DocumentAnnotator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import BaseAnnotator from '../common/BaseAnnotator';
import BaseAnnotator, { Options } from '../common/BaseAnnotator';
import BaseManager from '../common/BaseManager';
import { centerRegion, isRegion, RegionManager } from '../region';
import { Event } from '../@types';
import { getAnnotation } from '../store/annotations';
import { HighlightManager } from '../highlight';
import { Mode } from '../store';
import { scrollToLocation } from '../utils/scroll';
import './DocumentAnnotator.scss';

Expand All @@ -11,6 +13,12 @@ export default class DocumentAnnotator extends BaseAnnotator {

managers: Map<number, Set<BaseManager>> = new Map();

constructor(options: Options) {
super(options);

this.addListener(Event.ANNOTATIONS_MODE_CHANGE, this.handleChangeMode);
}

getAnnotatedElement(): HTMLElement | null | undefined {
return this.containerEl?.querySelector('.bp-doc');
}
Expand Down Expand Up @@ -57,6 +65,18 @@ export default class DocumentAnnotator extends BaseAnnotator {
return this.annotatedEl ? Array.from(this.annotatedEl.querySelectorAll('.page')) : [];
}

handleChangeMode = ({ mode }: { mode: Mode }): void => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleModeChange?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually followed the naming convention in BaseAnnotator like handleSetVisible and handleSetActive

if (!this.annotatedEl) {
return;
}

if (mode === Mode.HIGHLIGHT) {
this.annotatedEl.classList.add('ba-is-highlighting');
} else {
this.annotatedEl.classList.remove('ba-is-highlighting');
}
};

render(): void {
this.getPages()
.filter(({ dataset }) => dataset.loaded && dataset.pageNumber)
Expand Down
19 changes: 18 additions & 1 deletion src/document/__tests__/DocumentAnnotator-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BaseManager from '../../common/BaseManager';
import DocumentAnnotator from '../DocumentAnnotator';
import RegionManager from '../../region/RegionManager';
import { Annotation } from '../../@types';
import { Annotation, Event } from '../../@types';
import { annotations as regions } from '../../region/__mocks__/data';
import { fetchAnnotationsAction } from '../../store';
import { scrollToLocation } from '../../utils/scroll';
Expand Down Expand Up @@ -66,6 +66,23 @@ describe('DocumentAnnotator', () => {
}
});

describe('event handlers', () => {
beforeEach(() => {
annotator.annotatedEl = container.querySelector('.bp-doc') as HTMLElement;

jest.spyOn(annotator.annotatedEl.classList, 'add');
jest.spyOn(annotator.annotatedEl.classList, 'remove');
});

test('should add/remove highlight class', () => {
annotator.emit(Event.ANNOTATIONS_MODE_CHANGE, { mode: 'highlight' });
expect(annotator.annotatedEl?.classList.add).toHaveBeenCalledWith('ba-is-highlighting');

annotator.emit(Event.ANNOTATIONS_MODE_CHANGE, { mode: 'region' });
expect(annotator.annotatedEl?.classList.remove).toHaveBeenCalledWith('ba-is-highlighting');
});
});

describe('getPageManagers()', () => {
test('should create new managers given a new page element', () => {
const managers = annotator.getPageManagers(getPage());
Expand Down
2 changes: 1 addition & 1 deletion src/highlight/HighlightAnnotations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
position: absolute;
top: 0;
left: 0;
display: none;
width: 100%;
height: 100%;
pointer-events: auto;
mxiao6 marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion src/highlight/HighlightCreator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $text_cursor_32: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABz
$text_cursor_32_2x: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAQKADAAQAAAABAAAAQAAAAABlmWCKAAADvElEQVR4Ae2ZzUsbQRTA37a1BSkVhNjEg400h2ouQiWpaFIpftGmxP4FQqs9RLykiIj0JD3YIgVvFnvrUYppUq0kSk9Wi0URcrNgtGCKFyW9JKHZvrfNVjTJmt3R3bSdBy+zO/ve7rzfvJnMzgJw4QQ4AU6AE+AEOAFOgBPgBDgBToAT4AQ4AU5AJQFRFGtQw6hJ1JOEbMi2RuVjStc8G9BJgR+/Hi6ViATWhmBkSbzHxVuNjXBwcKB4u4qKClheXSWblCAIlxSNdbp4Tqfn/LuPKTQEbthsImkBKZkhcBoZ8Ai7N4KaKqKbyYZsyackhBkAjuVt1HYa06hKc8qXbMRtWMYKZIZSdQIvLqP2oSo9RxVYZgAqnnYTbS+qsD9uehkrnKivUCMIwXLcQMv5BS1Oan3SqZT4xO8XPi4uQjqdVusu2ZtMJnA4nTA4NCReNZvvYOUbhNCGSSdqumHWSZcMCMzMCOH5ec3BU1v39vbgfSgEXo9H+B6PU9AEoZeusYguAOLxOEsbj/jSWuPF2Jg8BzBPproMgSMR5Dmx1taCr78f6urrwVJdDVtbWzA1OQkf5ubyWAN8XlmR6+3ygdZSlwxQapzL7YZAMAj3vV4wVVWBmMmA3W6HlxMT0NHVldeVhkNWaGJkEsMBrK+twbtAAAZ8PqDldEtTE7ydnpaC6u3rYwquGGfDASQSCXg6MgKR8O/FYT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yZmZnLysqiRwq2vNptWSnRO8I5fnXhAty5ffu5pASfnut3d3XB/sbGbTg0hd3O1LQ02da8fKIi7PgrYAUfRXzc1gYVbjeU79wJLpfLv/oZvHuXVkR+Zp+cOgVVOFds2bo1JMOi59/e+ztkhigTON4Bov1jo6NAqif0GLq/r08vasNvtD8siU8KKwmGfWkqKT2IUWlvNkgqc6NoX5g25yW5KoWVBG3rgHcPHlTS4EBGxaY8bsSLJLQpr/xFLa00UapVR5wktd3vQG/Gxei1FEJAW2eb+7UUqzqCTjkE/z3s/b/oxJn+k22HINNbGp7BAUxGPd8S+FQlu6+C4v7lXEscgMM9fdn4BfUuVP/3YngMR+jlXBLaVRlG7cDeqb/WpFQOFOUOWIc/hGz+f14cGSRyWgNqLdqLq28ErJgDqOdHA192Gdkhe3Ejypeh2GP5M9Ug3cUKB+iu94PUSTdK/ngP5wHl9dathIIfrRiCtNcSxGNjo+14IZ9mz6idTZkehyD+q4JYeh4dwH/WEUsHUNnrTuC/q4m1I7h8JsAEmAATYAJMgAkwASbABJgAE2ACTIAJMAEmwASYABNgAkyACTABJsAEmAATYAJMgAkwASbABCwh8B+n1k4/vWVUjgAAAABJRU5ErkJggg==';

.ba-HighlightCreator {
@mixin ba-HighlightCreator-cursor {
cursor: url($text_cursor_32) 16 16, text; /* Legacy */
cursor: image-set(url($text_cursor_32) 1x, url($text_cursor_32_2x) 2x, url($text_cursor_32_3x) 3x) 16 16, text; /* Webkit */ /* stylelint-disable-line */
}