diff --git a/src/lib/components/forms/EditNote.svelte b/src/lib/components/forms/EditNote.svelte
index 314afe99d..ba3bbc60e 100644
--- a/src/lib/components/forms/EditNote.svelte
+++ b/src/lib/components/forms/EditNote.svelte
@@ -46,13 +46,7 @@ Positioning and generating coordinates should happen outside of this form.
}
-
-
-
diff --git a/src/lib/components/viewer/AnnotationLayer.svelte b/src/lib/components/viewer/AnnotationLayer.svelte
index 58f3206cc..ae8b6412e 100644
--- a/src/lib/components/viewer/AnnotationLayer.svelte
+++ b/src/lib/components/viewer/AnnotationLayer.svelte
@@ -27,6 +27,7 @@ Assumes it's a child of a ViewerContext
getCurrentMode,
getCurrentNote,
getDocument,
+ getNewNote,
isEmbedded,
} from "$lib/components/viewer/ViewerContext.svelte";
import { getNotes, getViewerHref } from "$lib/utils/viewer";
@@ -40,8 +41,8 @@ Assumes it's a child of a ViewerContext
const embed = isEmbedded();
const mode = getCurrentMode();
const currentNote = getCurrentNote();
+ const newNote = getNewNote();
- let newNote: Nullable & BBox> = null;
let drawStart: Nullable<[x: number, y: number]> = null;
let drawing = false;
@@ -49,7 +50,7 @@ Assumes it's a child of a ViewerContext
$: notes =
getNotes(document)[page_number]?.filter((note) => !isPageLevel(note)) ?? [];
$: writing = $mode === "annotating";
- $: activeNote = Boolean($currentNote) || (Boolean(newNote) && !drawing);
+ $: activeNote = Boolean($currentNote) || (Boolean($newNote) && !drawing);
$: edit_page_note =
writing &&
Boolean($currentNote) &&
@@ -70,18 +71,20 @@ Assumes it's a child of a ViewerContext
}
function startDrawingBox(e: PointerEvent) {
- if ($currentNote || newNote) return;
+ closeNote();
drawing = true;
$currentNote = null;
+ $newNote = null;
const [x, y] = getLayerPosition(e);
drawStart = [x, y];
// when starting, the note is a 0px shape
- newNote = {
+ $newNote = {
x1: x,
x2: x,
y1: y,
y2: y,
+ page_number,
};
}
@@ -94,24 +97,25 @@ Assumes it's a child of a ViewerContext
const movingRight = x > startX;
const movingDown = y > startY;
- const x1 = movingRight ? newNote.x1 : x;
- const x2 = movingRight ? x : newNote.x2;
- const y1 = movingDown ? newNote.y1 : y;
- const y2 = movingDown ? y : newNote.y2;
+ const x1 = movingRight ? $newNote.x1 : x;
+ const x2 = movingRight ? x : $newNote.x2;
+ const y1 = movingDown ? $newNote.y1 : y;
+ const y2 = movingDown ? y : $newNote.y2;
- newNote = {
+ $newNote = {
x1,
x2,
y1,
y2,
+ page_number,
};
}
function finishDrawingBox(e: PointerEvent) {
if (!newNote || !drawing) return;
- newNote = {
- ...newNote,
+ $newNote = {
+ ...$newNote,
// now initialize some note values
page_number,
title: "",
@@ -123,17 +127,27 @@ Assumes it's a child of a ViewerContext
drawing = false;
}
+ function positionNote(note: BBox, offset: number) {
+ const isLastPage = page_number + 1 === document.page_count;
+ if (isLastPage && note.y2 > 0.5) {
+ return `bottom: calc(calc(100% - ${note.y1 * 100}%) + ${offset}rem);`;
+ } else {
+ return `top: calc(${note.y2 * 100}% + ${offset}rem);`;
+ }
+ }
+
function openNote(e: MouseEvent, note: NoteType) {
const target = e.target as HTMLAnchorElement;
const href =
target?.href || getViewerHref({ document, note, mode: $mode, embed });
$currentNote = note;
+ $newNote = null;
pushState(href, { note });
}
function closeNote() {
drawing = false;
- newNote = null;
+ $newNote = null;
$currentNote = null;
const href = getViewerHref({ document, mode: $mode, embed });
pushState(href, {});
@@ -192,6 +206,7 @@ Assumes it's a child of a ViewerContext
{note.title}
- {#if note.id === $currentNote?.id}
+ {/each}
+
+ {#if $currentNote && !Boolean($newNote) && $currentNote.page_number === page_number}
+
{#if writing}
-
- onEditNoteSuccess(e, note)}
- />
-
+
onEditNoteSuccess(e, $currentNote)}
+ />
{:else}
-
-
-
+
{/if}
- {/if}
- {/each}
+
+ {/if}
- {#if newNote}
+ {#if $newNote && $newNote.page_number === page_number}
{#if !drawing}