Skip to content

Commit f2eadc2

Browse files
authored
Merge pull request #23 from hbogdanov/hristo
feat: Undo/Redo Buttons and draft callback for ctrl+z, ctrl+y
2 parents 8b919a3 + 7a243e7 commit f2eadc2

10 files changed

Lines changed: 198 additions & 145 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './annotation-layer';
1+
export * from "./annotation-layer"
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { CSSProperties, MouseEvent, TouchEvent } from 'react';
2-
import { Rect } from '@embedpdf/models';
1+
import { CSSProperties, MouseEvent, TouchEvent } from "react"
2+
import { Rect } from "@embedpdf/models"
33

44
type HighlightProps = {
5-
color?: string;
6-
opacity?: number;
7-
segmentRects: Rect[];
8-
rect?: Rect;
9-
scale: number;
10-
onClick?: (e: MouseEvent<HTMLDivElement> | TouchEvent<HTMLDivElement>) => void;
11-
style?: CSSProperties;
12-
};
5+
color?: string
6+
opacity?: number
7+
segmentRects: Rect[]
8+
rect?: Rect
9+
scale: number
10+
onClick?: (e: MouseEvent<HTMLDivElement> | TouchEvent<HTMLDivElement>) => void
11+
style?: CSSProperties
12+
}
1313

1414
export function Highlight({
15-
color = '#FFFF00',
15+
color = "#FFFF00",
1616
opacity = 0.5,
1717
segmentRects,
1818
rect,
@@ -28,20 +28,20 @@ export function Highlight({
2828
onPointerDown={onClick}
2929
onTouchStart={onClick}
3030
style={{
31-
position: 'absolute',
31+
position: "absolute",
3232
left: (rect ? b.origin.x - rect.origin.x : b.origin.x) * scale,
3333
top: (rect ? b.origin.y - rect.origin.y : b.origin.y) * scale,
3434
width: b.size.width * scale,
3535
height: b.size.height * scale,
3636
background: color,
3737
opacity: opacity,
38-
pointerEvents: onClick ? 'auto' : 'none',
39-
cursor: onClick ? 'pointer' : 'default',
38+
pointerEvents: onClick ? "auto" : "none",
39+
cursor: onClick ? "pointer" : "default",
4040
zIndex: onClick ? 1 : undefined,
4141
...style,
4242
}}
4343
/>
4444
))}
4545
</>
46-
);
46+
)
4747
}
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import { CSSProperties, MouseEvent, TouchEvent } from 'react';
2-
import { Rect } from '@embedpdf/models';
1+
import { CSSProperties, MouseEvent, TouchEvent } from "react"
2+
import { Rect } from "@embedpdf/models"
33

44
type SquigglyProps = {
5-
color?: string;
6-
opacity?: number;
7-
segmentRects: Rect[];
8-
rect?: Rect;
9-
scale: number;
10-
onClick?: (e: MouseEvent<HTMLDivElement> | TouchEvent<HTMLDivElement>) => void;
11-
style?: CSSProperties;
12-
};
5+
color?: string
6+
opacity?: number
7+
segmentRects: Rect[]
8+
rect?: Rect
9+
scale: number
10+
onClick?: (e: MouseEvent<HTMLDivElement> | TouchEvent<HTMLDivElement>) => void
11+
style?: CSSProperties
12+
}
1313

1414
export function Squiggly({
15-
color = '#FFFF00',
15+
color = "#FFFF00",
1616
opacity = 0.5,
1717
segmentRects,
1818
rect,
1919
scale,
2020
onClick,
2121
style,
2222
}: SquigglyProps) {
23-
const amplitude = 2 * scale; // wave height
24-
const period = 6 * scale; // wave length
23+
const amplitude = 2 * scale // wave height
24+
const period = 6 * scale // wave length
2525

2626
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${period}" height="${amplitude * 2}" viewBox="0 0 ${period} ${amplitude * 2}">
2727
<path d="M0 ${amplitude} Q ${period / 4} 0 ${period / 2} ${amplitude} T ${period} ${amplitude}"
2828
fill="none" stroke="${color}" stroke-width="${amplitude}" stroke-linecap="round"/>
29-
</svg>`;
29+
</svg>`
3030

3131
// Completely escape the SVG markup
32-
const svgDataUri = `url("data:image/svg+xml;utf8,${encodeURIComponent(svg)}")`;
32+
const svgDataUri = `url("data:image/svg+xml;utf8,${encodeURIComponent(svg)}")`
3333

3434
return (
3535
<>
@@ -39,35 +39,35 @@ export function Squiggly({
3939
onPointerDown={onClick}
4040
onTouchStart={onClick}
4141
style={{
42-
position: 'absolute',
42+
position: "absolute",
4343
left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
4444
top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
4545
width: r.size.width * scale,
4646
height: r.size.height * scale,
47-
background: 'transparent',
48-
pointerEvents: onClick ? 'auto' : 'none',
49-
cursor: onClick ? 'pointer' : 'default',
47+
background: "transparent",
48+
pointerEvents: onClick ? "auto" : "none",
49+
cursor: onClick ? "pointer" : "default",
5050
zIndex: onClick ? 1 : 0,
5151
...style,
5252
}}
5353
>
5454
{/* Visual squiggly line */}
5555
<div
5656
style={{
57-
position: 'absolute',
57+
position: "absolute",
5858
left: 0,
5959
bottom: 0,
60-
width: '100%',
60+
width: "100%",
6161
height: amplitude * 2,
6262
backgroundImage: svgDataUri,
63-
backgroundRepeat: 'repeat-x',
63+
backgroundRepeat: "repeat-x",
6464
backgroundSize: `${period}px ${amplitude * 2}px`,
6565
opacity: opacity,
66-
pointerEvents: 'none',
66+
pointerEvents: "none",
6767
}}
6868
/>
6969
</div>
7070
))}
7171
</>
72-
);
72+
)
7373
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import { CSSProperties, MouseEvent, TouchEvent } from 'react';
2-
import { Rect } from '@embedpdf/models';
1+
import { CSSProperties, MouseEvent, TouchEvent } from "react"
2+
import { Rect } from "@embedpdf/models"
33

44
type StrikeoutProps = {
5-
color?: string;
6-
opacity?: number;
7-
segmentRects: Rect[];
8-
rect?: Rect;
9-
scale: number;
10-
onClick?: (e: MouseEvent<HTMLDivElement> | TouchEvent<HTMLDivElement>) => void;
11-
style?: CSSProperties;
12-
};
5+
color?: string
6+
opacity?: number
7+
segmentRects: Rect[]
8+
rect?: Rect
9+
scale: number
10+
onClick?: (e: MouseEvent<HTMLDivElement> | TouchEvent<HTMLDivElement>) => void
11+
style?: CSSProperties
12+
}
1313

1414
export function Strikeout({
15-
color = '#FFFF00',
15+
color = "#FFFF00",
1616
opacity = 0.5,
1717
segmentRects,
1818
rect,
1919
scale,
2020
onClick,
2121
style,
2222
}: StrikeoutProps) {
23-
const thickness = 2 * scale;
23+
const thickness = 2 * scale
2424

2525
return (
2626
<>
@@ -30,34 +30,34 @@ export function Strikeout({
3030
onPointerDown={onClick}
3131
onTouchStart={onClick}
3232
style={{
33-
position: 'absolute',
33+
position: "absolute",
3434
left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
3535
top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
3636
width: r.size.width * scale,
3737
height: r.size.height * scale,
38-
background: 'transparent',
39-
pointerEvents: onClick ? 'auto' : 'none',
40-
cursor: onClick ? 'pointer' : 'default',
38+
background: "transparent",
39+
pointerEvents: onClick ? "auto" : "none",
40+
cursor: onClick ? "pointer" : "default",
4141
zIndex: onClick ? 1 : 0,
4242
...style,
4343
}}
4444
>
4545
{/* Visual strikeout line */}
4646
<div
4747
style={{
48-
position: 'absolute',
48+
position: "absolute",
4949
left: 0,
50-
top: '50%',
51-
width: '100%',
50+
top: "50%",
51+
width: "100%",
5252
height: thickness,
5353
background: color,
5454
opacity: opacity,
55-
transform: 'translateY(-50%)',
56-
pointerEvents: 'none',
55+
transform: "translateY(-50%)",
56+
pointerEvents: "none",
5757
}}
5858
/>
5959
</div>
6060
))}
6161
</>
62-
);
62+
)
6363
}
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import { CSSProperties, MouseEvent, TouchEvent } from 'react';
2-
import { Rect } from '@embedpdf/models';
1+
import { CSSProperties, MouseEvent, TouchEvent } from "react"
2+
import { Rect } from "@embedpdf/models"
33

44
type UnderlineProps = {
5-
color?: string;
6-
opacity?: number;
7-
segmentRects: Rect[];
8-
rect?: Rect;
9-
scale: number;
10-
onClick?: (e: MouseEvent<HTMLDivElement> | TouchEvent<HTMLDivElement>) => void;
11-
style?: CSSProperties;
12-
};
5+
color?: string
6+
opacity?: number
7+
segmentRects: Rect[]
8+
rect?: Rect
9+
scale: number
10+
onClick?: (e: MouseEvent<HTMLDivElement> | TouchEvent<HTMLDivElement>) => void
11+
style?: CSSProperties
12+
}
1313

1414
export function Underline({
15-
color = '#FFFF00',
15+
color = "#FFFF00",
1616
opacity = 0.5,
1717
segmentRects,
1818
rect,
1919
scale,
2020
onClick,
2121
style,
2222
}: UnderlineProps) {
23-
const thickness = 2 * scale; // 2 CSS px at 100 % zoom
23+
const thickness = 2 * scale // 2 CSS px at 100 % zoom
2424

2525
return (
2626
<>
@@ -30,33 +30,33 @@ export function Underline({
3030
onPointerDown={onClick}
3131
onTouchStart={onClick}
3232
style={{
33-
position: 'absolute',
33+
position: "absolute",
3434
left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
3535
top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
3636
width: r.size.width * scale,
3737
height: r.size.height * scale,
38-
background: 'transparent',
39-
pointerEvents: onClick ? 'auto' : 'none',
40-
cursor: onClick ? 'pointer' : 'default',
38+
background: "transparent",
39+
pointerEvents: onClick ? "auto" : "none",
40+
cursor: onClick ? "pointer" : "default",
4141
zIndex: onClick ? 1 : 0,
4242
...style,
4343
}}
4444
>
4545
{/* Visual underline */}
4646
<div
4747
style={{
48-
position: 'absolute',
48+
position: "absolute",
4949
left: 0,
5050
bottom: 0,
51-
width: '100%',
51+
width: "100%",
5252
height: thickness,
5353
background: color,
5454
opacity: opacity,
55-
pointerEvents: 'none',
55+
pointerEvents: "none",
5656
}}
5757
/>
5858
</div>
5959
))}
6060
</>
61-
);
61+
)
6262
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './use-annotation';
1+
export * from "./use-annotation"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './components';
2-
export * from './hooks';
3-
export * from './lib';
1+
export * from "./components"
2+
export * from "./hooks"
3+
export * from "./lib"

components/pdf-container/plugin-annotation-2/lib/selectors.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ export const getAnnotations = (s: AnnotationState): Record<number, TrackedAnnota
1818

1919
/** The full `TrackedAnnotation` for the current selection. */
2020
export const getSelectedAnnotation = (s: AnnotationState): TrackedAnnotation | null =>
21-
s.selectedUid ? s.byUid[s.selectedUid] ?? null : null
21+
s.selectedUid ? (s.byUid[s.selectedUid] ?? null) : null
2222

23-
export const getSelectedAnnotationByPageIndex = (s: AnnotationState, pageIndex: number): TrackedAnnotation | null => {
23+
export const getSelectedAnnotationByPageIndex = (
24+
s: AnnotationState,
25+
pageIndex: number,
26+
): TrackedAnnotation | null => {
2427
if (!s.selectedUid) return null
2528

2629
const pageUids = s.pages[pageIndex] ?? []

0 commit comments

Comments
 (0)