web-comments 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +188 -6
- package/dist/auth/bearer-token.js +43 -0
- package/dist/auth/cloudflare-access.js +90 -0
- package/dist/auth/dev-user.js +21 -0
- package/dist/auth/session-endpoint.js +47 -0
- package/dist/chunks/chunk-6VWNCJ3A.js +72 -0
- package/dist/chunks/chunk-GHNSLFY2.js +72 -0
- package/dist/chunks/chunk-LBIURYPH.js +192 -0
- package/dist/chunks/chunk-PLAC65HG.js +71 -0
- package/dist/chunks/chunk-WSFCRVEQ.js +9 -0
- package/dist/index.js +44 -0
- package/dist/react.js +19 -0
- package/dist/server.js +501 -0
- package/dist/store/d1.js +16 -0
- package/dist/store/drizzle/mysql.js +13 -0
- package/dist/store/drizzle/pg.js +13 -0
- package/dist/store/drizzle/sqlite.js +13 -0
- package/dist/store/drizzle.js +10 -0
- package/dist/store/memory.js +75 -0
- package/dist/store/r2.js +25 -0
- package/dist/store/s3.js +43 -0
- package/dist/types/auth/bearer-token.d.ts +13 -0
- package/dist/types/auth/cloudflare-access.d.ts +33 -0
- package/dist/types/auth/dev-user.d.ts +6 -0
- package/dist/types/auth/session-endpoint.d.ts +25 -0
- package/dist/types/react.d.ts +8 -0
- package/dist/types/server/auth.d.ts +16 -0
- package/dist/types/server/index.d.ts +71 -0
- package/dist/types/server/store.d.ts +59 -0
- package/dist/types/server/validate.d.ts +20 -0
- package/dist/types/shared/types.d.ts +108 -0
- package/dist/types/store/d1.d.ts +9 -0
- package/dist/types/store/drizzle/index.d.ts +22 -0
- package/dist/types/store/drizzle/mysql.d.ts +506 -0
- package/dist/types/store/drizzle/pg.d.ts +476 -0
- package/dist/types/store/drizzle/sqlite.d.ts +506 -0
- package/dist/types/store/memory.d.ts +10 -0
- package/dist/types/store/r2.d.ts +20 -0
- package/dist/types/store/s3.d.ts +21 -0
- package/dist/types/widget/anchor.d.ts +9 -0
- package/dist/types/widget/api.d.ts +43 -0
- package/dist/types/widget/app.d.ts +29 -0
- package/dist/types/widget/capture.d.ts +33 -0
- package/dist/types/widget/format.d.ts +15 -0
- package/dist/types/widget/index.d.ts +41 -0
- package/dist/types/widget/styles.d.ts +6 -0
- package/dist/types/widget/thread.d.ts +32 -0
- package/dist/types/widget/tracker.d.ts +68 -0
- package/dist/widget.global.js +44 -0
- package/package.json +132 -6
- package/types/widget.global.d.ts +5 -0
- package/index.d.ts +0 -2
- package/index.js +0 -6
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type Settings } from "./app";
|
|
2
|
+
export type * from "../shared/types";
|
|
3
|
+
export interface MountOptions {
|
|
4
|
+
/** Where the comments API is mounted. Default "/__comments". */
|
|
5
|
+
endpoint?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Which page a comment belongs to. Default: the path. Return a route
|
|
8
|
+
* pattern (e.g. "/:org/settings") to share comments across ids.
|
|
9
|
+
*/
|
|
10
|
+
page?: () => string;
|
|
11
|
+
/** Extra request headers, e.g. a bearer token the host app holds. */
|
|
12
|
+
headers?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
13
|
+
/** Default "include", so cookie-based gates such as Cloudflare Access work cross-origin too. */
|
|
14
|
+
credentials?: RequestCredentials;
|
|
15
|
+
/**
|
|
16
|
+
* The toolbar is docked on the right. "push" (default) moves the page over
|
|
17
|
+
* to make room for it; "overlay" draws it on top of the page.
|
|
18
|
+
*/
|
|
19
|
+
dock?: Settings["dock"];
|
|
20
|
+
/** Key that toggles comment mode. Default "c"; false turns it off. */
|
|
21
|
+
shortcut?: string | false;
|
|
22
|
+
theme?: "auto" | "light" | "dark";
|
|
23
|
+
/** Default: just under the largest z-index. */
|
|
24
|
+
zIndex?: number;
|
|
25
|
+
/** How often to look for new comments, in ms. Default 15000. */
|
|
26
|
+
pollInterval?: number;
|
|
27
|
+
/** Query parameter that links to a thread. Default "comment". */
|
|
28
|
+
linkParam?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CommentsHandle {
|
|
31
|
+
/** Opens a thread on this page by id. */
|
|
32
|
+
open(threadId: string): void;
|
|
33
|
+
/** Turns comment mode on or off. */
|
|
34
|
+
setCommentMode(on: boolean): void;
|
|
35
|
+
unmount(): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Puts the comments toolbar on the page for people the API accepts; everyone
|
|
39
|
+
* else sees nothing. Call unmount() to take it off again.
|
|
40
|
+
*/
|
|
41
|
+
export declare function mountComments(options?: MountOptions): CommentsHandle;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Everything that styles the widget, injected into its shadow root. */
|
|
2
|
+
export declare const SHADOW_CSS: string;
|
|
3
|
+
/** @font-face and @property rules, which only work in the document. */
|
|
4
|
+
export declare const DOCUMENT_CSS: string;
|
|
5
|
+
/** The widget's own base rules, and keyframes its styles refer to by name. */
|
|
6
|
+
export declare const BASE_CSS = "\nimg { -webkit-user-drag: none; user-select: none; }\n@keyframes wc-pop-in {\n from { opacity: 0; transform: scale(0.5); animation-timing-function: cubic-bezier(0, 0, 0.4, 1); }\n 60% { opacity: 1; transform: scale(1.12); animation-timing-function: cubic-bezier(0.45, 0, 0.4, 1); }\n to { opacity: 1; transform: scale(1); }\n}\n@keyframes wc-grow-in {\n from { opacity: 0; transform: scale(0.96); }\n to { opacity: 1; transform: scale(1); }\n}\n";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Author, Identity, Thread } from "../shared/types";
|
|
2
|
+
import type { Api } from "./api";
|
|
3
|
+
export declare function PersonAvatar({ person, size, }: {
|
|
4
|
+
person: Pick<Author, "id" | "name" | "avatarUrl">;
|
|
5
|
+
size?: 20 | 24 | 28 | 32;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
7
|
+
interface ComposerProps {
|
|
8
|
+
label: string;
|
|
9
|
+
value: string;
|
|
10
|
+
onChange: (value: string) => void;
|
|
11
|
+
onSubmit: () => Promise<void>;
|
|
12
|
+
/** Escape calls this: drops a draft, or closes the thread. */
|
|
13
|
+
onCancel?: () => void;
|
|
14
|
+
autoFocus?: boolean;
|
|
15
|
+
/** Floats on its own over the page (a new comment) rather than inside a card. */
|
|
16
|
+
floating?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function Composer(props: ComposerProps): import("react").JSX.Element;
|
|
19
|
+
interface ThreadViewProps {
|
|
20
|
+
thread: Thread;
|
|
21
|
+
me: Identity;
|
|
22
|
+
api: Api;
|
|
23
|
+
now: number;
|
|
24
|
+
linkFor: (thread: Thread) => string;
|
|
25
|
+
onChange: (thread: Thread) => void;
|
|
26
|
+
onDeleted: (threadId: string) => void;
|
|
27
|
+
onClose?: () => void;
|
|
28
|
+
/** Shown inside the panel rather than as a card by its pin. */
|
|
29
|
+
inline?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare function ThreadView(props: ThreadViewProps): import("react").JSX.Element;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Anchor } from "../shared/types";
|
|
2
|
+
export interface Box {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
/** The element a comment is on, for cards that sit under it. */
|
|
8
|
+
rect?: {
|
|
9
|
+
left: number;
|
|
10
|
+
top: number;
|
|
11
|
+
right: number;
|
|
12
|
+
bottom: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
type Place = (node: HTMLElement, box: Box) => void;
|
|
16
|
+
interface Item {
|
|
17
|
+
node: HTMLElement;
|
|
18
|
+
box: () => Box | null;
|
|
19
|
+
place: Place;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Moves pins and cards with their elements every frame, through the
|
|
23
|
+
* `translate` property so a hover `scale` grows the pin in place instead of
|
|
24
|
+
* scaling its offset from the corner of the viewport. Positions are written
|
|
25
|
+
* straight to the DOM so scrolling never re-renders the widget.
|
|
26
|
+
*/
|
|
27
|
+
export declare class Tracker {
|
|
28
|
+
private items;
|
|
29
|
+
private ticks;
|
|
30
|
+
private frame;
|
|
31
|
+
set(key: string, item: Item): void;
|
|
32
|
+
delete(key: string): void;
|
|
33
|
+
/** Runs a callback on every frame, for cheap checks such as "did the page change?". */
|
|
34
|
+
onTick(callback: () => void): () => void;
|
|
35
|
+
start(): void;
|
|
36
|
+
stop(): void;
|
|
37
|
+
private place;
|
|
38
|
+
}
|
|
39
|
+
export declare const placePin: Place;
|
|
40
|
+
export declare const placeOutline: Place;
|
|
41
|
+
/**
|
|
42
|
+
* Places a card under the element its comment is on, left edges aligned, or
|
|
43
|
+
* above it when there's no room below. An element too tall for either gets
|
|
44
|
+
* the card beside the pin. Everything stays left of `rightEdge()` (the docked
|
|
45
|
+
* toolbar, and the panel when it's open). The transform origin follows the
|
|
46
|
+
* pin, so an entering card grows out of it.
|
|
47
|
+
*/
|
|
48
|
+
export declare function placeCardNear(rightEdge: () => number): Place;
|
|
49
|
+
/** Remembers which element each thread is on, looking again when the page replaces it. */
|
|
50
|
+
export declare class AnchorCache {
|
|
51
|
+
private entries;
|
|
52
|
+
element(id: string, anchor: Anchor): Element | null;
|
|
53
|
+
/** Where a thread's pin goes right now, or null when its element is gone or hidden. */
|
|
54
|
+
point(id: string, anchor: Anchor): Box | null;
|
|
55
|
+
/** The pin's point plus its element's box, for the thread's card. */
|
|
56
|
+
card(id: string, anchor: Anchor): Box | null;
|
|
57
|
+
/** The box of a thread's element, for an outline around it. */
|
|
58
|
+
outline(id: string, anchor: Anchor): Box | null;
|
|
59
|
+
/** Looks for a thread's element afresh, e.g. after it was moved. */
|
|
60
|
+
forget(id: string): void;
|
|
61
|
+
clear(): void;
|
|
62
|
+
}
|
|
63
|
+
export declare function pointOn(element: Element, anchor: Pick<Anchor, "x" | "y">): Box | null;
|
|
64
|
+
/** An element's box, for an outline drawn around it. */
|
|
65
|
+
export declare function outlineOf(element: Element | null | undefined): Box | null;
|
|
66
|
+
/** Where a comment's card goes: the pin's point, plus the element's box to sit under. */
|
|
67
|
+
export declare function cardBoxOf(element: Element | null | undefined, anchor: Pick<Anchor, "x" | "y">): Box | null;
|
|
68
|
+
export {};
|