@vite-hub/comments 0.0.0 → 0.3.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/LICENSE +201 -0
- package/README.md +291 -0
- package/dist/anchor.d.ts +43 -0
- package/dist/anchor.js +133 -0
- package/dist/client-diagnostics-CcFpkbAk.js +40 -0
- package/dist/client.d.ts +176 -0
- package/dist/client.js +738 -0
- package/dist/console-h4KlhIik.d.ts +332 -0
- package/dist/context-BqIsmYP1.js +61 -0
- package/dist/database/postgres.d.ts +1402 -0
- package/dist/database/postgres.js +81 -0
- package/dist/database-CA1aHKN7.d.ts +1495 -0
- package/dist/database.d.ts +12 -0
- package/dist/database.js +2 -0
- package/dist/define-43mMR39K.js +89 -0
- package/dist/define-B3TF9zzn.d.ts +204 -0
- package/dist/errors-4gelGVmK.js +57 -0
- package/dist/errors-C6qptPoG.js +135 -0
- package/dist/errors-CyQyKAvy.d.ts +185 -0
- package/dist/fold-name-B7Zb3-MF.js +7 -0
- package/dist/identity-CBOzgxSf.js +39 -0
- package/dist/index-DNhy69Wt.d.ts +83 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +196 -0
- package/dist/install-BcMPgPk_.js +1154 -0
- package/dist/install-W9ghhGoh.d.ts +36 -0
- package/dist/installed-B-PfERBU.js +30 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/migrate-B0k_0swk.d.ts +54 -0
- package/dist/migrate-BDQ8xqUs.js +289 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operations-D4A1Fcgf.d.ts +160 -0
- package/dist/operations-DMMIfYPW.js +1159 -0
- package/dist/operations-GLeOqgMt.d.ts +257 -0
- package/dist/operations.d.ts +3 -0
- package/dist/operations.js +3 -0
- package/dist/overlay/client-DmsSMOzi.js +4 -0
- package/dist/overlay/dist-BoHMOFax.js +14 -0
- package/dist/overlay/dist-yIZmvSaU.js +1 -0
- package/dist/overlay/overlay.js +201 -0
- package/dist/page/loader.js +142 -0
- package/dist/page-B41ozN63.js +40 -0
- package/dist/page-DtbMOEMd.d.ts +22 -0
- package/dist/page-tools-shared-NHUjKI8E.js +117 -0
- package/dist/path--zk6PEMz.js +18 -0
- package/dist/plugin-PS8PMYus.js +74 -0
- package/dist/realtime.d.ts +12 -0
- package/dist/realtime.js +47 -0
- package/dist/rpc-HBcWtg0T.d.ts +17 -0
- package/dist/rpc-RKPAusHp.js +153 -0
- package/dist/rpc.d.ts +2 -0
- package/dist/rpc.js +2 -0
- package/dist/runtime/auth.d.ts +8 -0
- package/dist/runtime/auth.js +18 -0
- package/dist/runtime/connect/node.d.ts +1 -0
- package/dist/runtime/connect/node.js +2 -0
- package/dist/runtime/connect.d.ts +1 -0
- package/dist/runtime/connect.js +2 -0
- package/dist/runtime/console.d.ts +5 -0
- package/dist/runtime/console.js +64 -0
- package/dist/runtime/index.d.ts +270 -0
- package/dist/runtime/index.js +1113 -0
- package/dist/server-D8k-0GXe.js +72 -0
- package/dist/server.d.ts +20 -0
- package/dist/server.js +7 -0
- package/dist/service-CFVm23k7.d.ts +158 -0
- package/dist/service-GHhhyQj4.js +609 -0
- package/dist/session-DVx-1Tym.d.ts +14 -0
- package/dist/session-EkudzUmm.js +503 -0
- package/dist/testing.d.ts +30 -0
- package/dist/testing.js +187 -0
- package/dist/tokens-DSbwkVSy.js +58 -0
- package/dist/types-BIS0hCEl.d.ts +124 -0
- package/dist/types-CZujrMFd.d.ts +322 -0
- package/dist/vite.d.ts +308 -0
- package/dist/vite.js +1660 -0
- package/package.json +153 -4
package/dist/anchor.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
//#region src/anchor.ts
|
|
2
|
+
/** The attribute that Content's `contentField()` writes on an element that renders a field. */
|
|
3
|
+
const fieldAttribute = "data-content-field";
|
|
4
|
+
const maxDepth = 10;
|
|
5
|
+
function cssEscape(value) {
|
|
6
|
+
return typeof CSS !== "undefined" && CSS.escape ? CSS.escape(value) : value.replace(/[^\w-]/g, (character) => `\\${character}`);
|
|
7
|
+
}
|
|
8
|
+
function attributeSelector(name, value) {
|
|
9
|
+
return `[${name}="${value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"]`;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* CSS path of an element: tag and `:nth-of-type` per level, at most 10 levels, from the closest ancestor with an id or
|
|
13
|
+
* a Content field. Positional only, so `label` checks that it still finds the same element.
|
|
14
|
+
*/
|
|
15
|
+
function selectorOf(element) {
|
|
16
|
+
const parts = [];
|
|
17
|
+
let current = element;
|
|
18
|
+
while (current && current !== document.documentElement && parts.length < maxDepth) {
|
|
19
|
+
if (current.id) {
|
|
20
|
+
parts.unshift(`#${cssEscape(current.id)}`);
|
|
21
|
+
return parts.join(" > ");
|
|
22
|
+
}
|
|
23
|
+
const field = current.getAttribute(fieldAttribute);
|
|
24
|
+
if (field) {
|
|
25
|
+
parts.unshift(attributeSelector(fieldAttribute, field));
|
|
26
|
+
return parts.join(" > ");
|
|
27
|
+
}
|
|
28
|
+
const tag = current.tagName.toLowerCase();
|
|
29
|
+
const parent = current.parentElement;
|
|
30
|
+
if (!parent) {
|
|
31
|
+
parts.unshift(tag);
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
const sameTag = [...parent.children].filter((child) => child.tagName === current.tagName);
|
|
35
|
+
parts.unshift(sameTag.length > 1 ? `${tag}:nth-of-type(${sameTag.indexOf(current) + 1})` : tag);
|
|
36
|
+
current = parent;
|
|
37
|
+
}
|
|
38
|
+
return parts.join(" > ");
|
|
39
|
+
}
|
|
40
|
+
/** Tag and the first 40 characters of the element text. */
|
|
41
|
+
function labelOf(element) {
|
|
42
|
+
const text = (element.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 40);
|
|
43
|
+
const tag = element.tagName.toLowerCase();
|
|
44
|
+
return text ? `${tag} ${text}` : tag;
|
|
45
|
+
}
|
|
46
|
+
function thousandths(value, size) {
|
|
47
|
+
if (!size) return 0;
|
|
48
|
+
return Math.min(1e3, Math.max(0, Math.round(value / size * 1e3)));
|
|
49
|
+
}
|
|
50
|
+
function documentWidth() {
|
|
51
|
+
return Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth, 1);
|
|
52
|
+
}
|
|
53
|
+
/** The closest element with a Content field, from the element itself up. */
|
|
54
|
+
function fieldElementOf(element) {
|
|
55
|
+
return element.closest(`[data-content-field]`) ?? void 0;
|
|
56
|
+
}
|
|
57
|
+
/** The anchor of a point on an element, in client coordinates. */
|
|
58
|
+
function createAnchor(element, clientX, clientY) {
|
|
59
|
+
const box = element.getBoundingClientRect();
|
|
60
|
+
const field = fieldElementOf(element)?.getAttribute("data-content-field") ?? void 0;
|
|
61
|
+
return {
|
|
62
|
+
kind: "element",
|
|
63
|
+
...field ? { field } : {},
|
|
64
|
+
selector: selectorOf(element),
|
|
65
|
+
label: labelOf(element),
|
|
66
|
+
x: thousandths(clientX - box.left, box.width),
|
|
67
|
+
y: thousandths(clientY - box.top, box.height),
|
|
68
|
+
page: {
|
|
69
|
+
x: thousandths(clientX + window.scrollX, documentWidth()),
|
|
70
|
+
y: Math.max(0, Math.round(clientY + window.scrollY))
|
|
71
|
+
},
|
|
72
|
+
viewport: { width: window.innerWidth }
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function query(selector) {
|
|
76
|
+
try {
|
|
77
|
+
return document.querySelector(selector) ?? void 0;
|
|
78
|
+
} catch {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function sameLabel(element, label) {
|
|
83
|
+
return labelOf(element) === label;
|
|
84
|
+
}
|
|
85
|
+
/** An element of the same tag whose label matches, for anchors whose CSS path moved. */
|
|
86
|
+
function findByLabel(label) {
|
|
87
|
+
const tag = label.split(" ", 1)[0];
|
|
88
|
+
if (!tag || tag === label) return;
|
|
89
|
+
try {
|
|
90
|
+
for (const candidate of document.querySelectorAll(tag)) if (sameLabel(candidate, label)) return candidate;
|
|
91
|
+
} catch {}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Where an anchor is now, in client coordinates: the Content field, then the CSS path if its label still matches,
|
|
95
|
+
* then any element of that tag with the same label, then the page point. An anchor without a label trusts the path.
|
|
96
|
+
*/
|
|
97
|
+
function placeAnchor(anchor) {
|
|
98
|
+
let element;
|
|
99
|
+
if (anchor.field) {
|
|
100
|
+
element = query(attributeSelector(fieldAttribute, anchor.field));
|
|
101
|
+
const byPath = query(anchor.selector);
|
|
102
|
+
if (element && byPath && fieldElementOf(byPath)?.getAttribute("data-content-field") === anchor.field) element = byPath;
|
|
103
|
+
}
|
|
104
|
+
if (!element) {
|
|
105
|
+
const byPath = query(anchor.selector);
|
|
106
|
+
if (byPath && (anchor.label === void 0 || sameLabel(byPath, anchor.label))) element = byPath;
|
|
107
|
+
}
|
|
108
|
+
if (anchor.label !== void 0) element ??= findByLabel(anchor.label);
|
|
109
|
+
if (element) {
|
|
110
|
+
const box = element.getBoundingClientRect();
|
|
111
|
+
if (!box.width && !box.height) return {
|
|
112
|
+
state: "hidden",
|
|
113
|
+
element
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
state: "exact",
|
|
117
|
+
element,
|
|
118
|
+
x: box.left + anchor.x / 1e3 * box.width,
|
|
119
|
+
y: box.top + anchor.y / 1e3 * box.height
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const page = anchor.page ?? {
|
|
123
|
+
x: 0,
|
|
124
|
+
y: 0
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
state: "moved",
|
|
128
|
+
x: page.x / 1e3 * documentWidth() - window.scrollX,
|
|
129
|
+
y: page.y - window.scrollY
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
export { createAnchor, fieldAttribute, fieldElementOf, labelOf, placeAnchor, selectorOf };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Diagnostic, defineDiagnostics } from "nostics";
|
|
2
|
+
//#region src/client-diagnostics.ts
|
|
3
|
+
const commentsClientCodes = {
|
|
4
|
+
COMMENTS_R0001: {
|
|
5
|
+
why: ({ target }) => `createAnchor() found nothing to anchor to for ${target}.`,
|
|
6
|
+
fix: "Pass an element, a non-empty selection, or a point that is over an element of the page."
|
|
7
|
+
},
|
|
8
|
+
COMMENTS_R0013: {
|
|
9
|
+
why: "The comments request did not get an answer from the server.",
|
|
10
|
+
fix: "Check the connection and the app URL, then try again."
|
|
11
|
+
},
|
|
12
|
+
COMMENTS_R0015: {
|
|
13
|
+
why: "The comment list kept changing while its pages were loading.",
|
|
14
|
+
fix: "Refresh again. The previous cache is kept until two complete scans agree."
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const commentsClientDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
18
|
+
docsBase: "https://vitehub.dev/docs/comments/diagnostics",
|
|
19
|
+
codes: commentsClientCodes
|
|
20
|
+
});
|
|
21
|
+
/** A failure that the server answered: a diagnostic with its code, why, and fix, and the HTTP status of the answer. */
|
|
22
|
+
function commentsAnswerError(failure) {
|
|
23
|
+
const { code, details, fix, status, why } = failure;
|
|
24
|
+
const docs = code.startsWith("COMMENTS_") ? `https://vitehub.dev/docs/comments/diagnostics/${code.toLowerCase()}` : void 0;
|
|
25
|
+
return Object.assign(new Diagnostic({
|
|
26
|
+
code,
|
|
27
|
+
why,
|
|
28
|
+
...fix ? { fix } : {},
|
|
29
|
+
...docs ? { docs } : {}
|
|
30
|
+
}), {
|
|
31
|
+
status,
|
|
32
|
+
...details ? { details } : {}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** `COMMENTS_R0013`: the request got no usable answer. `status` is 0 when it got no answer at all. */
|
|
36
|
+
function commentsUnansweredError(status, cause) {
|
|
37
|
+
return Object.assign(commentsClientDiagnostics.COMMENTS_R0013(cause === void 0 ? {} : { cause }), { status });
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { commentsUnansweredError as i, commentsClientCodes as n, commentsClientDiagnostics as r, commentsAnswerError as t };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { A as TextAnchor, C as CommentUploadInput, D as ElementAnchor, E as CommentsTransport, O as ImageAnchor, S as CommentThread, T as CommentUsersInput, _ as CommentMetadata, a as CommentBuild, b as CommentStatusInput, c as CommentCreateInput, d as CommentEvent, f as CommentForgeLink, g as CommentMessage, h as CommentListQuery, i as CommentAttachment, k as PageAnchor, l as CommentDeleteInput, m as CommentListCursor, n as CommentActor, o as CommentComponent, p as CommentGetInput, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentEditInput, v as CommentReplyInput, w as CommentUser, x as CommentSubject, y as CommentStatus } from "./types-CZujrMFd.js";
|
|
2
|
+
import { t as commentsErrorDiagnostics } from "./errors-CyQyKAvy.js";
|
|
3
|
+
//#region src/client-anchor.d.ts
|
|
4
|
+
/** A point in client (viewport) coordinates, such as `event.clientX` and `event.clientY`. */
|
|
5
|
+
interface AnchorPoint {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}
|
|
9
|
+
interface AnchorRect {
|
|
10
|
+
left: number;
|
|
11
|
+
top: number;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
type AnchorTarget = Element | Range | Selection | AnchorPoint | "page";
|
|
16
|
+
interface CreateAnchorOptions {
|
|
17
|
+
/** Where selectors are looked up. Defaults to the document of the target. */
|
|
18
|
+
root?: ParentNode;
|
|
19
|
+
/** For an element target: where the click landed, in client coordinates. Defaults to the middle. */
|
|
20
|
+
point?: AnchorPoint;
|
|
21
|
+
/** For an element target: a rectangle in client coordinates. It makes an `area` anchor, or an `image` area on an image. */
|
|
22
|
+
area?: AnchorRect;
|
|
23
|
+
/** Skip elements that are not the page, such as the comment layer. */
|
|
24
|
+
ignore?: (element: Element) => boolean;
|
|
25
|
+
/** How many characters of text to keep before and after a quote. Default 32. */
|
|
26
|
+
context?: number;
|
|
27
|
+
}
|
|
28
|
+
interface ResolvedAnchor {
|
|
29
|
+
detached: false;
|
|
30
|
+
/** A scroll container or an `overflow: hidden` ancestor cuts the spot off. Hide the pin. */
|
|
31
|
+
clipped: boolean;
|
|
32
|
+
kind: CommentAnchor["kind"];
|
|
33
|
+
/** The pin position in client coordinates. For a `page` anchor it is `0, 0`. */
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
/** The size of an area or a quote in pixels. `0` for a point. */
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
/** Missing for a `page` anchor. */
|
|
40
|
+
element?: Element;
|
|
41
|
+
}
|
|
42
|
+
interface DetachedAnchor {
|
|
43
|
+
detached: true;
|
|
44
|
+
}
|
|
45
|
+
type AnchorPosition = ResolvedAnchor | DetachedAnchor;
|
|
46
|
+
/**
|
|
47
|
+
* The shortest selector that names the element: a stable attribute, else a path from the nearest stable
|
|
48
|
+
* ancestor or from the top of the page, cut as soon as it is unique.
|
|
49
|
+
*/
|
|
50
|
+
export declare function selectorFor(element: Element, root?: ParentNode): string;
|
|
51
|
+
/**
|
|
52
|
+
* Describes a spot of the page so it can be found again: an element with an offset, a text quote, an area,
|
|
53
|
+
* a point on an image, or the whole page. Selectors and offsets survive layout changes, because offsets are
|
|
54
|
+
* thousandths of the element box.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createAnchor(target: AnchorTarget, options?: CreateAnchorOptions): CommentAnchor;
|
|
57
|
+
/**
|
|
58
|
+
* The range of the quote of a text anchor on the page, for a highlight. It finds the quote as `resolveAnchor()` does,
|
|
59
|
+
* and returns `undefined` when that would detach the anchor.
|
|
60
|
+
*/
|
|
61
|
+
export declare function anchorRange(anchor: TextAnchor, root?: ParentNode): Range | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Finds an anchor on the page again. It returns the pin position in client coordinates, or `{ detached: true }`
|
|
64
|
+
* when the element is gone, hidden, ambiguous, or no longer holds the quote. A selector that names more than one
|
|
65
|
+
* element is ambiguous, so a pin never lands on the wrong one. A text anchor tries every match and takes the one
|
|
66
|
+
* that holds the quote best.
|
|
67
|
+
*/
|
|
68
|
+
export declare function resolveAnchor(anchor: CommentAnchor, root?: ParentNode): AnchorPosition;
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/fold-name.d.ts
|
|
71
|
+
/** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
|
|
72
|
+
export declare function foldName(text: string): string;
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/rest-transport.d.ts
|
|
75
|
+
/** A guest that named itself in the browser. The server keeps the name as display data only. */
|
|
76
|
+
interface CommentsGuest {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
}
|
|
80
|
+
interface RestTransportOptions {
|
|
81
|
+
/**
|
|
82
|
+
* The app origin and mount, such as `https://app.example.com` or `/portal`. The routes are
|
|
83
|
+
* `<base>/api/_vitehub/comments/**`. Default: the page origin.
|
|
84
|
+
*/
|
|
85
|
+
base?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Headers for each request, such as a share-link token that `identify` reads. A function runs before each request,
|
|
88
|
+
* so it can read a token that changes.
|
|
89
|
+
*/
|
|
90
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
91
|
+
/** The guest that writes when nobody is signed in, and the policy lets guests write. A function runs before each request. */
|
|
92
|
+
guest?: CommentsGuest | (() => CommentsGuest | undefined);
|
|
93
|
+
/** Default `same-origin`, so the browser sends the session cookie to the app's own origin. */
|
|
94
|
+
credentials?: RequestCredentials;
|
|
95
|
+
/** Replaces `fetch`, for tests or a server. */
|
|
96
|
+
fetch?: typeof fetch;
|
|
97
|
+
/** Runs after each answer that has data, such as to learn the names of the people that it mentions. */
|
|
98
|
+
onAnswer?: (answer: CommentsRestAnswer<unknown>) => void;
|
|
99
|
+
}
|
|
100
|
+
/** A thread as the API answers it: with what the reader may do with it. */
|
|
101
|
+
type RestCommentThread = CommentThread & {
|
|
102
|
+
can?: {
|
|
103
|
+
comment: boolean;
|
|
104
|
+
resolve: boolean;
|
|
105
|
+
delete?: boolean;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
/** The answer of a route: its data, and the people that its threads mention, so a UI shows their names. */
|
|
109
|
+
interface CommentsRestAnswer<T> {
|
|
110
|
+
data: T;
|
|
111
|
+
people: CommentUser[];
|
|
112
|
+
/** The thread after a reply. */
|
|
113
|
+
thread?: RestCommentThread;
|
|
114
|
+
}
|
|
115
|
+
/** The request function of the Comments API that the overlay and `createRestTransport()` share. */
|
|
116
|
+
type CommentsRestRequest = <T>(path: string, init?: RequestInit) => Promise<CommentsRestAnswer<T>>;
|
|
117
|
+
/** The URL of an attachment key below the Comments API, such as `/api/_vitehub/comments/attachments/comments/<id>/shot.png`. */
|
|
118
|
+
export declare function commentAttachmentUrl(key: string, base?: string): string;
|
|
119
|
+
/**
|
|
120
|
+
* Requests to the Comments API at `<base>/api/_vitehub/comments`, with the guest headers and the session cookie. A
|
|
121
|
+
* failure throws a diagnostic with the `code`, `why`, and `fix` of the error object of the answer, and its `status`.
|
|
122
|
+
*/
|
|
123
|
+
export declare function createCommentsRestRequest(options?: RestTransportOptions & {
|
|
124
|
+
route?: string;
|
|
125
|
+
}): CommentsRestRequest;
|
|
126
|
+
/** A `CommentsTransport` over the Comments API, with `upload` and the URL of each attachment. */
|
|
127
|
+
interface RestTransport extends CommentsTransport {
|
|
128
|
+
upload: (input: CommentUploadInput) => Promise<CommentAttachment>;
|
|
129
|
+
/** The URL that serves the file of an attachment key to people who may read its thread, such as for a thumbnail. */
|
|
130
|
+
attachmentUrl: (key: string) => string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A transport over the Comments API at `<base>/api/_vitehub/comments`: the routes that the overlay uses. The server
|
|
134
|
+
* runs the `authorize` policy of `server/comments.ts` for the user of the request: the app session, or a guest that
|
|
135
|
+
* `guest` names. Guests and share-link readers can use it. It has no
|
|
136
|
+
* `subscribe`: the client refreshes when the window gets focus.
|
|
137
|
+
*/
|
|
138
|
+
export declare function createRestTransport(options?: RestTransportOptions): RestTransport;
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/client.d.ts
|
|
141
|
+
export type CommentsClientStatus = "idle" | "loading" | "ready" | "error";
|
|
142
|
+
export interface CommentsClientOptions {
|
|
143
|
+
transport: CommentsTransport;
|
|
144
|
+
/** The signed-in user. The UI uses it for the "mine" filter and to know which messages the user may edit. */
|
|
145
|
+
user?: CommentUser;
|
|
146
|
+
/** What `refresh()` lists. For example `{ page: "/pricing" }`. Without an explicit limit, loads all pages. */
|
|
147
|
+
query?: CommentListQuery;
|
|
148
|
+
/** Refresh when the window gets focus and the transport cannot push updates. Default `true`. */
|
|
149
|
+
refreshOnFocus?: boolean;
|
|
150
|
+
}
|
|
151
|
+
export interface CommentsClient {
|
|
152
|
+
readonly transport: CommentsTransport;
|
|
153
|
+
readonly user: CommentUser | undefined;
|
|
154
|
+
/** The threads that the last `refresh()` and every change since then produced, ordered by `n`. A new array after each change. */
|
|
155
|
+
readonly threads: readonly CommentThread[];
|
|
156
|
+
readonly status: CommentsClientStatus;
|
|
157
|
+
readonly error: unknown;
|
|
158
|
+
query: CommentListQuery;
|
|
159
|
+
refresh: () => Promise<readonly CommentThread[]>;
|
|
160
|
+
get: (input: CommentGetInput) => Promise<CommentThread | null>;
|
|
161
|
+
create: (input: CommentCreateInput) => Promise<CommentThread>;
|
|
162
|
+
reply: (input: CommentReplyInput) => Promise<CommentThread>;
|
|
163
|
+
edit: (input: CommentEditInput) => Promise<CommentThread>;
|
|
164
|
+
delete: (input: CommentDeleteInput) => Promise<CommentThread | null>;
|
|
165
|
+
resolve: (input: CommentStatusInput) => Promise<CommentThread>;
|
|
166
|
+
reopen: (input: CommentStatusInput) => Promise<CommentThread>;
|
|
167
|
+
users: (input: CommentUsersInput) => Promise<CommentUser[]>;
|
|
168
|
+
/** Calls `listener` after every change of `threads`, `status`, or `error`. Returns a function that stops it. */
|
|
169
|
+
onChange: (listener: () => void) => () => void;
|
|
170
|
+
/** Loads the threads, then keeps them fresh: pushed events when the transport has `subscribe`, else a refresh on window focus. Returns a function that stops it. */
|
|
171
|
+
start: () => () => void;
|
|
172
|
+
}
|
|
173
|
+
/** A cache and a change signal over a transport. It has no framework in it. */
|
|
174
|
+
export declare function createCommentsClient(options: CommentsClientOptions): CommentsClient;
|
|
175
|
+
//#endregion
|
|
176
|
+
export { type AnchorPoint, type AnchorPosition, type AnchorRect, type AnchorTarget, type AreaAnchor, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentEditInput, type CommentEvent, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMessage, type CommentMetadata, type CommentReplyInput, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, type CommentsGuest, type CommentsRestAnswer, type CommentsRestRequest, type CommentsTransport, type CreateAnchorOptions, type DetachedAnchor, type ElementAnchor, type ImageAnchor, type PageAnchor, type ResolvedAnchor, type RestCommentThread, type RestTransport, type RestTransportOptions, type TextAnchor, commentsErrorDiagnostics };
|