Skip to content
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
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ browser. The author's dashboard hands out this tag and the invite links:
|---|---|
| `data-api` | The backend origin. Without it the page stays local-only, exactly as above. |
| `data-review-id` | The review this page belongs to. |
| `data-credentials` | `omit` (default), `same-origin` or `include`. Whether backend and `data-post-url` requests carry cookies. Use `same-origin` when the backend shares the page's origin behind a cookie sign-in (an identity-aware proxy, for example). A cross-origin backend needs CORS with `Access-Control-Allow-Credentials` for `include`. |

Reviewers arrive through a personal link, `https://your-site/page?an_invite=…`.
The token is stored for that review in the reviewer's browser and removed from
Expand All @@ -167,6 +168,27 @@ site addresses registered on the review may use it.
- In a synced review there is nothing to submit: the footer reads "Sent to the
review" as soon as a comment is posted.

#### Your own sign-in (`auth`)

When the backend sits behind your site's own sign-in, skip invite links and
hand Annotate the session yourself (programmatic config only):

```js
Annotate.init({
api: "/review-api", // same origin, behind your proxy
reviewId: "rvw_…",
credentials: "same-origin", // send the proxy's session cookie
auth: {
getToken: () => mySession.token, // bearer token, or null when signed out
getReviewer: () => ({ id: me.id, name: me.name, role: me.isOwner ? "author" : "reviewer" }),
onUnauthorized: () => mySession.signIn(),
},
});
```

`getReviewer` is optional. Without it the viewer is unnamed and never gets
the review author's controls.

## Framework integration

For a bundler, install `@reviewjs/annotate`, call `init()` after mount, and
Expand Down Expand Up @@ -299,6 +321,11 @@ Sharing is an explicit action:
4. You open the same page, click **Import** (⬆), pick the file — every comment
reappears anchored in place.

Reviewing a whole site? When other pages have comments too, the footer offers
**All pages** under the buttons: one file with every page's comments. Import it
on any page of the site and each comment goes back to the page it was made on
(the project name may differ between the two browsers).

To paste feedback directly into another tool, click **Copy** to copy the same
complete, import-compatible JSON payload to the clipboard.

Expand Down Expand Up @@ -362,7 +389,8 @@ Annotate.disable(); // collapse to the launcher
Annotate.setTool("highlight");// show the layer, then choose cursor | highlight | rect | circle | pen | pin
Annotate.comments(); // → array of comment objects for this page
Annotate.focus(id); // scroll to & highlight a comment
Annotate.export(); // trigger the JSON download
Annotate.export(); // trigger the JSON download for this page
Annotate.export({ scope: "site" }); // one file with every page's comments
Annotate.import(); // open the file picker
await Annotate.submit(); // POST the JSON export to postUrl
Annotate.refresh(); // manually re-read the current page when spa is off
Expand Down
23 changes: 22 additions & 1 deletion annotate.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ export interface AnnotateConfig {
inviteParam?: string;
/** Poll interval in milliseconds for remote reads. Default 20000, minimum 500. */
pollInterval?: number;
/**
* Fetch credentials mode for backend (api) and postUrl requests. Default
* "omit". Use "same-origin" for a same-origin backend behind a cookie
* sign-in, or "include" for a cross-origin one that allows credentials.
*/
credentials?: 'omit' | 'same-origin' | 'include';
/** Integrator-managed auth. Replaces the built-in invite-link exchange. */
auth?: AnnotateAuth;
}
Expand All @@ -33,6 +39,17 @@ export interface AnnotateAuth {
getToken(): Promise<string | null> | string | null;
/** Called when the backend refuses the token after one refresh. */
onUnauthorized?(): void;
/**
* Optional: who the signed-in viewer is. Without it the viewer is unnamed
* and never a review author (no owner controls).
*/
getReviewer?(): Promise<AnnotateReviewer | null> | AnnotateReviewer | null;
}

export interface AnnotateReviewer {
id: string;
name: string;
role: 'author' | 'reviewer';
}

export interface ResolvedAnnotateConfig {
Expand All @@ -51,6 +68,7 @@ export interface ResolvedAnnotateConfig {
reviewId: string;
inviteParam: string;
pollInterval: number;
credentials: 'omit' | 'same-origin' | 'include';
}

export type AnnotateStatus = 'open' | 'in_progress' | 'resolved' | 'wont_fix';
Expand Down Expand Up @@ -116,6 +134,8 @@ export interface FeedbackExport {
url: string;
project: string;
exportedViewport: { vw: number; vh: number; dpr: number };
/** "site" when the file holds every page of the project; absent for a page export. */
scope?: 'site';
comments: AnnotateComment[];
}

Expand All @@ -134,7 +154,8 @@ export interface AnnotateAPI {
comments(): AnnotateComment[];
focus(id: string): void;
toast(message: string, options?: { kind?: 'info' | 'error' | 'success'; duration?: number }): void;
export(): void;
/** Download this page's comments, or every page's with { scope: 'site' } (local mode). */
export(options?: { scope?: 'page' | 'site' }): void;
import(): void;
/**
* Local mode: sends the current page's export JSON to postUrl; rejects on failure.
Expand Down
23 changes: 22 additions & 1 deletion annotate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export interface AnnotateConfig {
inviteParam?: string;
/** Poll interval in milliseconds for remote reads. Default 20000, minimum 500. */
pollInterval?: number;
/**
* Fetch credentials mode for backend (api) and postUrl requests. Default
* "omit". Use "same-origin" for a same-origin backend behind a cookie
* sign-in, or "include" for a cross-origin one that allows credentials.
*/
credentials?: 'omit' | 'same-origin' | 'include';
/** Integrator-managed auth. Replaces the built-in invite-link exchange. */
auth?: AnnotateAuth;
}
Expand All @@ -32,6 +38,17 @@ export interface AnnotateAuth {
getToken(): Promise<string | null> | string | null;
/** Called when the backend refuses the token after one refresh. */
onUnauthorized?(): void;
/**
* Optional: who the signed-in viewer is. Without it the viewer is unnamed
* and never a review author (no owner controls).
*/
getReviewer?(): Promise<AnnotateReviewer | null> | AnnotateReviewer | null;
}

export interface AnnotateReviewer {
id: string;
name: string;
role: 'author' | 'reviewer';
}

export interface ResolvedAnnotateConfig {
Expand All @@ -50,6 +67,7 @@ export interface ResolvedAnnotateConfig {
reviewId: string;
inviteParam: string;
pollInterval: number;
credentials: 'omit' | 'same-origin' | 'include';
}

export type AnnotateStatus = 'open' | 'in_progress' | 'resolved' | 'wont_fix';
Expand Down Expand Up @@ -115,6 +133,8 @@ export interface FeedbackExport {
url: string;
project: string;
exportedViewport: { vw: number; vh: number; dpr: number };
/** "site" when the file holds every page of the project; absent for a page export. */
scope?: 'site';
comments: AnnotateComment[];
}

Expand All @@ -133,7 +153,8 @@ export interface AnnotateAPI {
comments(): AnnotateComment[];
focus(id: string): void;
toast(message: string, options?: { kind?: 'info' | 'error' | 'success'; duration?: number }): void;
export(): void;
/** Download this page's comments, or every page's with { scope: 'site' } (local mode). */
export(options?: { scope?: 'page' | 'site' }): void;
import(): void;
/**
* Local mode: sends the current page's export JSON to postUrl; rejects on failure.
Expand Down
Loading
Loading