@vite-hub/comments 0.1.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/README.md +79 -31
- package/dist/anchor.d.ts +7 -4
- package/dist/anchor.js +10 -5
- package/dist/client-diagnostics-CcFpkbAk.js +40 -0
- package/dist/client.d.ts +78 -3
- package/dist/client.js +198 -13
- package/dist/{console-BIz9t2cO.d.ts → console-h4KlhIik.d.ts} +97 -8
- package/dist/context-BqIsmYP1.js +61 -0
- package/dist/database/postgres.d.ts +738 -347
- package/dist/database/postgres.js +28 -7
- package/dist/{database-Cb2xjC1V.d.ts → database-CA1aHKN7.d.ts} +675 -276
- package/dist/database.d.ts +6 -98
- package/dist/database.js +2 -3
- 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-3qtVC4rF.js → identity-CBOzgxSf.js} +7 -2
- package/dist/index-DNhy69Wt.d.ts +83 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +196 -5
- 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-0B0QTVWX.d.ts → operations-D4A1Fcgf.d.ts} +37 -15
- package/dist/operations-DMMIfYPW.js +1159 -0
- package/dist/operations-GLeOqgMt.d.ts +257 -0
- package/dist/operations.d.ts +3 -7
- package/dist/operations.js +3 -2
- 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 +183 -177
- package/dist/page/loader.js +138 -18
- package/dist/{page-BuroSMXO.js → page-B41ozN63.js} +8 -6
- package/dist/{page-BtXADR6d.d.ts → page-DtbMOEMd.d.ts} +6 -5
- 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 +6 -12
- package/dist/realtime.js +23 -24
- package/dist/rpc-HBcWtg0T.d.ts +17 -0
- package/dist/rpc-RKPAusHp.js +153 -0
- package/dist/rpc.d.ts +2 -29
- package/dist/rpc.js +2 -75
- package/dist/runtime/auth.d.ts +5 -3
- package/dist/runtime/auth.js +8 -5
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +26 -21
- package/dist/runtime/index.d.ts +108 -60
- package/dist/runtime/index.js +684 -236
- package/dist/{server-BomGg3Gb.js → server-D8k-0GXe.js} +16 -7
- package/dist/server.d.ts +14 -88
- package/dist/server.js +7 -326
- 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 +1 -1
- package/dist/testing.js +14 -2
- 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 +91 -87
- package/dist/vite.js +535 -796
- package/package.json +24 -27
- package/dist/database-BSnVrwHn.js +0 -60
- package/dist/database-C-ktS9Do.js +0 -95
- package/dist/define-BzW2Ychn.d.ts +0 -46
- package/dist/define-Cbhl6QVJ.js +0 -32
- package/dist/errors-BAQYcy3_.d.ts +0 -89
- package/dist/errors-DeD6wTCl.js +0 -77
- package/dist/h3-v1-request-DDGXJ9E7.js +0 -166
- package/dist/index-DklG2Etf.d.ts +0 -111
- package/dist/operations-NZG5dB8y.js +0 -732
- package/dist/page-tools-shared-D-amu6sx.js +0 -53
- package/dist/plugin-QElKQYkA.js +0 -725
- package/dist/request-DVc3M_AG.js +0 -14
- package/dist/src-CRTwnaEG.js +0 -1362
- package/dist/types-Cj8K7Vx7.d.ts +0 -176
- package/dist/types-Un2dcJWD.d.ts +0 -288
package/dist/client.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { i as commentsUnansweredError, r as commentsClientDiagnostics, t as commentsAnswerError } from "./client-diagnostics-CcFpkbAk.js";
|
|
2
|
+
import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
|
|
3
|
+
import { t as foldName } from "./fold-name-B7Zb3-MF.js";
|
|
4
|
+
import { i as commentsRoute } from "./page-B41ozN63.js";
|
|
5
|
+
import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
|
|
2
6
|
//#region src/client-anchor.ts
|
|
3
7
|
const defaultContext = 32;
|
|
4
8
|
const clamp = (value) => Math.min(1e3, Math.max(0, value));
|
|
@@ -122,9 +126,9 @@ function textAnchor(target, options) {
|
|
|
122
126
|
const range = rangeOf(target);
|
|
123
127
|
const exact = range?.toString() ?? "";
|
|
124
128
|
const container = range && elementOfNode(range.commonAncestorContainer);
|
|
125
|
-
if (!range || !container || exact === "") throw
|
|
129
|
+
if (!range || !container || exact === "") throw commentsClientDiagnostics.COMMENTS_R0001({ target: "an empty selection" });
|
|
126
130
|
const element = ignoreUp(container, options) ?? container;
|
|
127
|
-
if (options.root && (!options.root.contains(range.startContainer) || !options.root.contains(range.endContainer) || !options.root.contains(element))) throw
|
|
131
|
+
if (options.root && (!options.root.contains(range.startContainer) || !options.root.contains(range.endContainer) || !options.root.contains(element))) throw commentsClientDiagnostics.COMMENTS_R0001({ target: "a selection outside the configured root" });
|
|
128
132
|
const start = textOffset(element, range.startContainer, range.startOffset);
|
|
129
133
|
const text = textNodes(element).map((node) => node.data).join("");
|
|
130
134
|
const context = options.context ?? defaultContext;
|
|
@@ -145,7 +149,7 @@ function isImage(element) {
|
|
|
145
149
|
return element.localName === "img";
|
|
146
150
|
}
|
|
147
151
|
function boxAnchor(element, options, point) {
|
|
148
|
-
if (options.root && !options.root.contains(element)) throw
|
|
152
|
+
if (options.root && !options.root.contains(element)) throw commentsClientDiagnostics.COMMENTS_R0001({ target: "an element outside the configured root" });
|
|
149
153
|
const box = boxOf(element);
|
|
150
154
|
const selector = selectorFor(element, options.root ?? defaultRoot(element));
|
|
151
155
|
const kind = isImage(element) ? "image" : void 0;
|
|
@@ -191,7 +195,7 @@ function createAnchor(target, options = {}) {
|
|
|
191
195
|
if ("nodeType" in target) return boxAnchor(target, options, options.point);
|
|
192
196
|
if ("rangeCount" in target || "startContainer" in target) return textAnchor(target, options);
|
|
193
197
|
const element = pointTarget(target, options);
|
|
194
|
-
if (!element) throw
|
|
198
|
+
if (!element) throw commentsClientDiagnostics.COMMENTS_R0001({ target: `the point ${Math.round(target.x)}, ${Math.round(target.y)}` });
|
|
195
199
|
return boxAnchor(element, options, target);
|
|
196
200
|
}
|
|
197
201
|
const minimumContext = 4;
|
|
@@ -238,6 +242,19 @@ function boundary(nodes, offset, end) {
|
|
|
238
242
|
function visible(rect) {
|
|
239
243
|
return rect.width > 0 || rect.height > 0;
|
|
240
244
|
}
|
|
245
|
+
/** The nearest block around an element, such as the paragraph around a `<strong>`: its right edge is the pin's gutter. */
|
|
246
|
+
function blockOf(element) {
|
|
247
|
+
const view = ownerDocument(element)?.defaultView;
|
|
248
|
+
for (let node = element; node; node = node.parentElement) {
|
|
249
|
+
const display = view?.getComputedStyle(node).display ?? "block";
|
|
250
|
+
if (!display.startsWith("inline") && display !== "contents") return node;
|
|
251
|
+
}
|
|
252
|
+
return element;
|
|
253
|
+
}
|
|
254
|
+
/** The space between a text block and its 28px pin, as in Drop. */
|
|
255
|
+
const PIN_GUTTER = 8;
|
|
256
|
+
/** The room that a pin takes right of its spot at the screen's edge: the pin and 2px. */
|
|
257
|
+
const PIN_ROOM = 30;
|
|
241
258
|
function resolveText(anchor, element) {
|
|
242
259
|
const nodes = textNodes(element);
|
|
243
260
|
const match = findQuote(nodes.map((node) => node.data).join(""), anchor);
|
|
@@ -247,7 +264,7 @@ function resolveText(anchor, element) {
|
|
|
247
264
|
const to = boundary(nodes, start + anchor.exact.length, true);
|
|
248
265
|
const own = boxOf(element);
|
|
249
266
|
let rect = own;
|
|
250
|
-
let
|
|
267
|
+
let last = own;
|
|
251
268
|
if (from && to) {
|
|
252
269
|
const range = (ownerDocument(element) ?? document).createRange();
|
|
253
270
|
range.setStart(from.node, from.offset);
|
|
@@ -266,8 +283,8 @@ function resolveText(anchor, element) {
|
|
|
266
283
|
height
|
|
267
284
|
};
|
|
268
285
|
}
|
|
269
|
-
const line = typeof range.getClientRects === "function" ? range.getClientRects()
|
|
270
|
-
|
|
286
|
+
const line = (typeof range.getClientRects === "function" ? [...range.getClientRects()].filter(visible) : []).at(-1);
|
|
287
|
+
last = line ? {
|
|
271
288
|
left: line.left,
|
|
272
289
|
top: line.top,
|
|
273
290
|
width: line.width,
|
|
@@ -275,11 +292,13 @@ function resolveText(anchor, element) {
|
|
|
275
292
|
} : rect;
|
|
276
293
|
}
|
|
277
294
|
if (!visible(rect)) return void 0;
|
|
278
|
-
const
|
|
279
|
-
const
|
|
295
|
+
const view = ownerDocument(element)?.defaultView;
|
|
296
|
+
const block = boxOf(blockOf(element));
|
|
297
|
+
const x = Math.min(Math.max(block.left + block.width, last.left + last.width) + PIN_GUTTER, (view?.innerWidth ?? Infinity) - PIN_ROOM);
|
|
298
|
+
const y = last.top + last.height / 2;
|
|
280
299
|
return {
|
|
281
300
|
position: {
|
|
282
|
-
clipped: isClipped(element,
|
|
301
|
+
clipped: isClipped(element, last.left + Math.max(0, last.width - 1), y),
|
|
283
302
|
detached: false,
|
|
284
303
|
kind: "text",
|
|
285
304
|
x,
|
|
@@ -314,6 +333,34 @@ function isClipped(element, x, y) {
|
|
|
314
333
|
return false;
|
|
315
334
|
}
|
|
316
335
|
/**
|
|
336
|
+
* The range of the quote of a text anchor on the page, for a highlight. It finds the quote as `resolveAnchor()` does,
|
|
337
|
+
* and returns `undefined` when that would detach the anchor.
|
|
338
|
+
*/
|
|
339
|
+
function anchorRange(anchor, root = document) {
|
|
340
|
+
let best;
|
|
341
|
+
for (const element of lookup(root, anchor.selector)) {
|
|
342
|
+
const nodes = textNodes(element);
|
|
343
|
+
const match = findQuote(nodes.map((node) => node.data).join(""), anchor);
|
|
344
|
+
const from = match && boundary(nodes, match.start, false);
|
|
345
|
+
const to = match && boundary(nodes, match.start + anchor.exact.length, true);
|
|
346
|
+
if (!match || !from || !to) continue;
|
|
347
|
+
if (best && match.score === best.score) {
|
|
348
|
+
best.ambiguous = true;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (best && match.score < best.score) continue;
|
|
352
|
+
const range = (ownerDocument(element) ?? document).createRange();
|
|
353
|
+
range.setStart(from.node, from.offset);
|
|
354
|
+
range.setEnd(to.node, to.offset);
|
|
355
|
+
best = {
|
|
356
|
+
range,
|
|
357
|
+
score: match.score,
|
|
358
|
+
ambiguous: match.ambiguous
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
return best && !best.ambiguous ? best.range : void 0;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
317
364
|
* Finds an anchor on the page again. It returns the pin position in client coordinates, or `{ detached: true }`
|
|
318
365
|
* when the element is gone, hidden, ambiguous, or no longer holds the quote. A selector that names more than one
|
|
319
366
|
* element is ambiguous, so a pin never lands on the wrong one. A text anchor tries every match and takes the one
|
|
@@ -359,6 +406,142 @@ function resolveAnchor(anchor, root = document) {
|
|
|
359
406
|
};
|
|
360
407
|
}
|
|
361
408
|
//#endregion
|
|
409
|
+
//#region src/rest-transport.ts
|
|
410
|
+
/** The URL of an attachment key below the Comments API, such as `/api/_vitehub/comments/attachments/comments/<id>/shot.png`. */
|
|
411
|
+
function commentAttachmentUrl(key, base = "") {
|
|
412
|
+
return `${base.replace(/\/+$/, "")}${commentsRoute}/attachments/${key.split("/").map((part) => encodeURIComponent(part)).join("/")}`;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Requests to the Comments API at `<base>/api/_vitehub/comments`, with the guest headers and the session cookie. A
|
|
416
|
+
* failure throws a diagnostic with the `code`, `why`, and `fix` of the error object of the answer, and its `status`.
|
|
417
|
+
*/
|
|
418
|
+
function createCommentsRestRequest(options = {}) {
|
|
419
|
+
const route = options.route ?? `${(options.base ?? "").replace(/\/+$/, "")}/api/_vitehub/comments`;
|
|
420
|
+
return async (path, init = {}) => {
|
|
421
|
+
const send = options.fetch ?? globalThis.fetch;
|
|
422
|
+
const headers = new Headers(typeof options.headers === "function" ? await options.headers() : options.headers);
|
|
423
|
+
for (const [name, value] of new Headers(init.headers)) headers.set(name, value);
|
|
424
|
+
if (init.body !== void 0 && !headers.has("content-type")) headers.set("content-type", "application/json");
|
|
425
|
+
const guest = typeof options.guest === "function" ? options.guest() : options.guest;
|
|
426
|
+
if (guest) {
|
|
427
|
+
headers.set("x-vitehub-comments-guest-id", guest.id);
|
|
428
|
+
headers.set("x-vitehub-comments-guest-name", encodeURIComponent(guest.name));
|
|
429
|
+
}
|
|
430
|
+
let response;
|
|
431
|
+
try {
|
|
432
|
+
response = await send(`${route}${path}`, {
|
|
433
|
+
...init,
|
|
434
|
+
headers,
|
|
435
|
+
credentials: options.credentials ?? "same-origin",
|
|
436
|
+
cache: "no-store"
|
|
437
|
+
});
|
|
438
|
+
} catch (cause) {
|
|
439
|
+
throw commentsUnansweredError(0, cause);
|
|
440
|
+
}
|
|
441
|
+
const value = await response.json().catch(() => void 0);
|
|
442
|
+
if (isRecordOrFunction(value) && isRecordOrFunction(value.error)) {
|
|
443
|
+
const { code, why, fix } = value.error;
|
|
444
|
+
if (typeof code !== "string" || typeof why !== "string") throw commentsUnansweredError(response.status);
|
|
445
|
+
throw commentsAnswerError({
|
|
446
|
+
code,
|
|
447
|
+
why,
|
|
448
|
+
...typeof fix === "string" ? { fix } : {},
|
|
449
|
+
status: response.status
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
if (isRecordOrFunction(value) && "data" in value) {
|
|
453
|
+
const answer = {
|
|
454
|
+
data: value.data,
|
|
455
|
+
people: Array.isArray(value.people) ? value.people : [],
|
|
456
|
+
...isRecordOrFunction(value.thread) ? { thread: value.thread } : {}
|
|
457
|
+
};
|
|
458
|
+
options.onAnswer?.(answer);
|
|
459
|
+
return answer;
|
|
460
|
+
}
|
|
461
|
+
throw commentsUnansweredError(response.status);
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function listSearch(query) {
|
|
465
|
+
const params = new URLSearchParams();
|
|
466
|
+
if (query.page !== void 0) params.set("page", query.page);
|
|
467
|
+
if (query.subject) {
|
|
468
|
+
params.set("subjectKind", query.subject.kind);
|
|
469
|
+
params.set("subjectId", query.subject.id);
|
|
470
|
+
} else if (query.subjectKind) params.set("subjectKind", query.subjectKind);
|
|
471
|
+
if (query.status) params.set("status", query.status);
|
|
472
|
+
if (query.mine !== void 0) params.set("mine", String(query.mine));
|
|
473
|
+
if (query.mentions !== void 0) params.set("mentions", String(query.mentions));
|
|
474
|
+
if (query.revision) params.set("revision", String(query.revision.lte));
|
|
475
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
476
|
+
if (query.before) {
|
|
477
|
+
params.set("beforeId", query.before.id);
|
|
478
|
+
params.set("beforeUpdatedAt", String(query.before.updatedAt));
|
|
479
|
+
}
|
|
480
|
+
return params;
|
|
481
|
+
}
|
|
482
|
+
const thread = (id) => `/threads/${encodeURIComponent(id)}`;
|
|
483
|
+
const post = (body) => ({
|
|
484
|
+
method: "POST",
|
|
485
|
+
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
486
|
+
});
|
|
487
|
+
/**
|
|
488
|
+
* A transport over the Comments API at `<base>/api/_vitehub/comments`: the routes that the overlay uses. The server
|
|
489
|
+
* runs the `authorize` policy of `server/comments.ts` for the user of the request: the app session, or a guest that
|
|
490
|
+
* `guest` names. Guests and share-link readers can use it. It has no
|
|
491
|
+
* `subscribe`: the client refreshes when the window gets focus.
|
|
492
|
+
*/
|
|
493
|
+
function createRestTransport(options = {}) {
|
|
494
|
+
const request = createCommentsRestRequest(options);
|
|
495
|
+
const base = (options.base ?? "").replace(/\/+$/, "");
|
|
496
|
+
return {
|
|
497
|
+
async list(query) {
|
|
498
|
+
return (await request(`/threads?${listSearch(query)}`)).data;
|
|
499
|
+
},
|
|
500
|
+
async get(input) {
|
|
501
|
+
const path = "id" in input ? thread(input.id) : `/scopes/${encodeURIComponent(input.scope)}/threads/${input.n}`;
|
|
502
|
+
return (await request(path)).data;
|
|
503
|
+
},
|
|
504
|
+
async create(input) {
|
|
505
|
+
return (await request("/threads", post(input))).data;
|
|
506
|
+
},
|
|
507
|
+
async reply({ threadId, ...input }) {
|
|
508
|
+
const answer = await request(`${thread(threadId)}/comments`, post(input));
|
|
509
|
+
if (!answer.thread) throw commentsUnansweredError(200);
|
|
510
|
+
return answer.thread;
|
|
511
|
+
},
|
|
512
|
+
async edit({ threadId, messageId, ...input }) {
|
|
513
|
+
return (await request(`${thread(threadId)}/comments/${encodeURIComponent(messageId)}`, {
|
|
514
|
+
method: "PATCH",
|
|
515
|
+
body: JSON.stringify(input)
|
|
516
|
+
})).data;
|
|
517
|
+
},
|
|
518
|
+
async delete({ threadId, messageId }) {
|
|
519
|
+
const path = messageId === void 0 ? thread(threadId) : `${thread(threadId)}/comments/${encodeURIComponent(messageId)}`;
|
|
520
|
+
return (await request(path, { method: "DELETE" })).data;
|
|
521
|
+
},
|
|
522
|
+
async resolve({ threadId }) {
|
|
523
|
+
return (await request(`${thread(threadId)}/resolve`, post())).data;
|
|
524
|
+
},
|
|
525
|
+
async reopen({ threadId }) {
|
|
526
|
+
return (await request(`${thread(threadId)}/reopen`, post())).data;
|
|
527
|
+
},
|
|
528
|
+
async users({ query, limit, threadId, subject }) {
|
|
529
|
+
const params = new URLSearchParams({ q: query });
|
|
530
|
+
if (limit !== void 0) params.set("limit", String(limit));
|
|
531
|
+
if (threadId !== void 0) params.set("thread", threadId);
|
|
532
|
+
else if (subject) {
|
|
533
|
+
params.set("subjectKind", subject.kind);
|
|
534
|
+
params.set("subjectId", subject.id);
|
|
535
|
+
}
|
|
536
|
+
return (await request(`/people?${params}`)).data;
|
|
537
|
+
},
|
|
538
|
+
async upload(input) {
|
|
539
|
+
return (await request("/attachments", post(input))).data;
|
|
540
|
+
},
|
|
541
|
+
attachmentUrl: (key) => commentAttachmentUrl(key, base)
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
//#endregion
|
|
362
545
|
//#region src/client.ts
|
|
363
546
|
/** A cache and a change signal over a transport. It has no framework in it. */
|
|
364
547
|
function createCommentsClient(options) {
|
|
@@ -380,7 +563,9 @@ function createCommentsClient(options) {
|
|
|
380
563
|
const matchesQuery = (thread) => {
|
|
381
564
|
const user = options.user;
|
|
382
565
|
if (query.subject && (thread.subject.kind !== query.subject.kind || thread.subject.id !== query.subject.id)) return false;
|
|
566
|
+
if (query.subjectKind !== void 0 && thread.subject.kind !== query.subjectKind) return false;
|
|
383
567
|
if (query.page !== void 0 && (thread.subject.kind !== "page" || thread.subject.id !== query.page)) return false;
|
|
568
|
+
if (query.revision && (thread.revision === void 0 || thread.revision > query.revision.lte)) return false;
|
|
384
569
|
if (query.status && thread.status !== query.status) return false;
|
|
385
570
|
if (user && query.mine && thread.author.id !== user.id) return false;
|
|
386
571
|
if (user && query.mentions && !thread.messages.some((message) => message.mentions.includes(user.id))) return false;
|
|
@@ -453,7 +638,7 @@ function createCommentsClient(options) {
|
|
|
453
638
|
if (requested.limit !== void 0 || pages === 1 && previousSnapshot === void 0) break;
|
|
454
639
|
const snapshot = JSON.stringify(list);
|
|
455
640
|
if (snapshot === previousSnapshot) break;
|
|
456
|
-
if (scan === 2) throw
|
|
641
|
+
if (scan === 2) throw commentsClientDiagnostics.COMMENTS_R0015();
|
|
457
642
|
previousSnapshot = snapshot;
|
|
458
643
|
}
|
|
459
644
|
if (current !== generation) return threads;
|
|
@@ -550,4 +735,4 @@ function createCommentsClient(options) {
|
|
|
550
735
|
};
|
|
551
736
|
}
|
|
552
737
|
//#endregion
|
|
553
|
-
export { commentsErrorDiagnostics, createAnchor, createCommentsClient, resolveAnchor, selectorFor };
|
|
738
|
+
export { anchorRange, commentAttachmentUrl, commentsErrorDiagnostics, createAnchor, createCommentsClient, createCommentsRestRequest, createRestTransport, foldName, resolveAnchor, selectorFor };
|
|
@@ -24,9 +24,35 @@ interface ViteHubProviderOutputEntry {
|
|
|
24
24
|
/** Absolute path. */
|
|
25
25
|
path: string;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Where an inspected resource id came from. `name` means the host binds the resource by its name and needs no id.
|
|
29
|
+
* The CLI sets `provider-output` when only a generated Wrangler config names the id.
|
|
30
|
+
*/
|
|
31
|
+
type ViteHubResourceIdSource = "config" | "env" | "name" | "provider-output" | "provision-state";
|
|
32
|
+
/** One host resource that a Definition or store maps to. Owner packages read only local config and Provision State. */
|
|
33
|
+
interface ViteHubResourceSummary {
|
|
34
|
+
/** Cloudflare binding name, so the CLI can find the id in generated Wrangler config. */
|
|
35
|
+
binding?: string;
|
|
36
|
+
/** Definition or store name. */
|
|
37
|
+
definition: string;
|
|
38
|
+
/** Env variable that supplied the id when `source` is `env`. */
|
|
39
|
+
env?: string;
|
|
40
|
+
host: "cloudflare" | "vercel";
|
|
41
|
+
id?: string;
|
|
42
|
+
/** Same resource kind names as Provision actions, for example `cloudflare-d1`. */
|
|
43
|
+
kind: string;
|
|
44
|
+
/** Resource name on the host, when the config names it. */
|
|
45
|
+
name?: string;
|
|
46
|
+
/** Explains how the host finds the resource when no id or name is known locally. */
|
|
47
|
+
note?: string;
|
|
48
|
+
owner: string;
|
|
49
|
+
/** Absent when no id is known yet. */
|
|
50
|
+
source?: ViteHubResourceIdSource;
|
|
51
|
+
}
|
|
27
52
|
interface ViteHubInspectionContributor {
|
|
28
53
|
definitions?: readonly ViteHubDefinitionInspector[];
|
|
29
54
|
providerOutput?: readonly ViteHubProviderOutputEntry[];
|
|
55
|
+
resources?: () => readonly ViteHubResourceSummary[] | Promise<readonly ViteHubResourceSummary[]>;
|
|
30
56
|
}
|
|
31
57
|
type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
|
|
32
58
|
interface ViteHubInspectionPluginMetadata {
|
|
@@ -41,7 +67,15 @@ interface ViteHubConsoleDefinitionCatalogView {
|
|
|
41
67
|
/** States which runtime data this catalog does not include. */
|
|
42
68
|
notice: string;
|
|
43
69
|
}
|
|
70
|
+
/** Lists Workspace Definitions like a catalog, and browses the refs, revisions, and files of the selected one. */
|
|
71
|
+
interface ViteHubConsoleWorkspaceBrowserView {
|
|
72
|
+
kind: "workspace-browser";
|
|
73
|
+
/** States which runtime data the browser does not include. */
|
|
74
|
+
notice: string;
|
|
75
|
+
}
|
|
44
76
|
interface ViteHubConsoleRecordColumn {
|
|
77
|
+
/** Set it for a column with few values, such as a status. The Console then filters the table by its values. */
|
|
78
|
+
filter?: boolean;
|
|
45
79
|
/** Key in `ViteHubConsoleRecord.cells`. */
|
|
46
80
|
key: string;
|
|
47
81
|
label: string;
|
|
@@ -66,8 +100,42 @@ interface ViteHubConsoleOperationColumn {
|
|
|
66
100
|
/** Dot path into each item of the result, such as `author.name` or `messages.0.body`. */
|
|
67
101
|
key: string;
|
|
68
102
|
label: string;
|
|
69
|
-
/**
|
|
70
|
-
|
|
103
|
+
/**
|
|
104
|
+
* `datetime` shows a time in milliseconds since the epoch as a relative date, such as `5m ago`. `excerpt` cuts a long
|
|
105
|
+
* text. `status` shows the value as a status with a colored dot, such as `Open`. `tones` picks the color of each value.
|
|
106
|
+
* `switch` shows a boolean as a switch that calls the `switch` operation.
|
|
107
|
+
*/
|
|
108
|
+
format?: "datetime" | "excerpt" | "status" | "switch";
|
|
109
|
+
/** The color of each value of a `status` column, such as `{ open: "info", resolved: "success" }`. Other values are neutral. */
|
|
110
|
+
tones?: Readonly<Record<string, "error" | "info" | "neutral" | "success" | "warning">>;
|
|
111
|
+
/**
|
|
112
|
+
* What a `switch` column calls when the user flips it: `operation` with an input that maps each key of `input` to a
|
|
113
|
+
* dot path of the item, and the column `key` to the new value. `{ operation: "skills.set", input: { name: "name" } }`
|
|
114
|
+
* on the column `enabled` calls `skills.set` with `{ name, enabled }`, then loads the list again. A user who may only
|
|
115
|
+
* read the section sees the switch disabled.
|
|
116
|
+
*/
|
|
117
|
+
switch?: {
|
|
118
|
+
operation: string;
|
|
119
|
+
input: Readonly<Record<string, string>>;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A button on each row that calls `operation` with the Console user, then loads the list again. `input` maps each input
|
|
124
|
+
* key to a dot path of the item, as a `switch` column does.
|
|
125
|
+
*/
|
|
126
|
+
interface ViteHubConsoleOperationAction {
|
|
127
|
+
label: string;
|
|
128
|
+
operation: string;
|
|
129
|
+
input: Readonly<Record<string, string>>;
|
|
130
|
+
/**
|
|
131
|
+
* The result is `{ url }`, such as a one-time link or a provider sign-in: the Console opens it in a new tab, and loads
|
|
132
|
+
* the list again when the person comes back. The URL must be `https:`, or `http:` on a loopback host.
|
|
133
|
+
*/
|
|
134
|
+
tab?: true;
|
|
135
|
+
/** Show the button only on rows where each dot path holds one of the listed values. */
|
|
136
|
+
when?: Readonly<Record<string, readonly string[]>>;
|
|
137
|
+
/** Ask this question before the call. `{path}` takes a value from the item. */
|
|
138
|
+
confirm?: string;
|
|
71
139
|
}
|
|
72
140
|
/** A chip above the list. Choosing it merges `input` into the operation input. The first chip is the default. */
|
|
73
141
|
interface ViteHubConsoleOperationFilter {
|
|
@@ -81,13 +149,24 @@ interface ViteHubConsoleOperationFilter {
|
|
|
81
149
|
* array of objects with an `id`. A failure of the operation, with its `fix`, shows where the list would be.
|
|
82
150
|
*/
|
|
83
151
|
interface ViteHubConsoleOperationView {
|
|
152
|
+
/** Buttons on each row. A user who may only read the section does not see them. */
|
|
153
|
+
actions?: readonly ViteHubConsoleOperationAction[];
|
|
84
154
|
columns: readonly ViteHubConsoleOperationColumn[];
|
|
155
|
+
/**
|
|
156
|
+
* Opens the item of a row in a side panel. `comment-thread` shows an item of `comments.list` as a comment thread
|
|
157
|
+
* where the user reads, replies, resolves, reopens, and mentions people. The panel calls the `comments.*` operations
|
|
158
|
+
* with the Console user, and `?thread=<id>` in the URL opens it.
|
|
159
|
+
*/
|
|
160
|
+
detail?: {
|
|
161
|
+
kind: "comment-thread";
|
|
162
|
+
};
|
|
85
163
|
filters?: readonly ViteHubConsoleOperationFilter[];
|
|
86
164
|
kind: "operation-view";
|
|
87
165
|
/**
|
|
88
166
|
* Makes each row a link: `{path}` placeholders take values from the item and are URL-encoded, and `{path:path}` takes an
|
|
89
|
-
* app path and encodes each segment (a value that is not an app path, such as `//evil.com/x`, gives no link).
|
|
90
|
-
* `
|
|
167
|
+
* app path and encodes each segment (a value that is not an app path, such as `//evil.com/x`, gives no link).
|
|
168
|
+
* `{path:href}` takes an app URL that is already encoded, with its query, as it is. Rows where `when.path` is not
|
|
169
|
+
* `when.equals` get none.
|
|
91
170
|
*/
|
|
92
171
|
link?: {
|
|
93
172
|
label?: string;
|
|
@@ -110,7 +189,16 @@ interface ViteHubConsoleAuthView {
|
|
|
110
189
|
kind: "auth-management";
|
|
111
190
|
notice: string;
|
|
112
191
|
}
|
|
113
|
-
|
|
192
|
+
/**
|
|
193
|
+
* The webhooks of the app, their pending debounce timers, and their delivery log. The Console calls the `webhooks.*`
|
|
194
|
+
* operations of `@vite-hub/webhooks` with the Console user to list them, send a test, send a pending delivery now,
|
|
195
|
+
* cancel it, and redeliver. It has no build-time data.
|
|
196
|
+
*/
|
|
197
|
+
interface ViteHubConsoleWebhooksView {
|
|
198
|
+
kind: "webhooks";
|
|
199
|
+
notice: string;
|
|
200
|
+
}
|
|
201
|
+
type ViteHubConsoleSectionView = ViteHubConsoleOperationView | ViteHubConsoleAuthView | ViteHubConsoleWebhooksView | ViteHubConsoleDefinitionCatalogView | ViteHubConsoleRecordTableView | ViteHubConsoleDocumentEditorView | ViteHubConsoleWorkspaceBrowserView;
|
|
114
202
|
/**
|
|
115
203
|
* The overview of a document editor section: document counts by state, the changes that wait for a publish, recent
|
|
116
204
|
* activity, and a New button per collection. It reads the owner `overview` action.
|
|
@@ -212,8 +300,8 @@ interface ViteHubConsoleServerExport {
|
|
|
212
300
|
/** Named export of `module`. */
|
|
213
301
|
export: string;
|
|
214
302
|
/**
|
|
215
|
-
*
|
|
216
|
-
* path that the application can import.
|
|
303
|
+
* Absolute path of the owner module, such as `ownModule(import.meta.url, "runtime/console")`, or an owner package
|
|
304
|
+
* specifier that the host maps to a module path that the application can import.
|
|
217
305
|
*/
|
|
218
306
|
module: string;
|
|
219
307
|
}
|
|
@@ -224,7 +312,8 @@ interface ViteHubConsoleServerExport {
|
|
|
224
312
|
interface ViteHubConsoleRuntimeReader extends ViteHubConsoleServerExport {}
|
|
225
313
|
/**
|
|
226
314
|
* A record table that also reads records at request time. The Console shows the build-time records of `read` first,
|
|
227
|
-
* then the records of the `runtime` reader. A runtime record
|
|
315
|
+
* then the records of the `runtime` reader. A runtime record updates the build-time record with the same id: its cells
|
|
316
|
+
* and fields replace the build-time ones with the same key or label.
|
|
228
317
|
*/
|
|
229
318
|
interface ViteHubConsoleRuntimeRecordTableSection<TOptions = void> extends ViteHubConsoleSectionDescriptor<ViteHubConsoleRecordTableView> {
|
|
230
319
|
/** Reads build-time records on the server. When omitted, the section has only runtime records. */
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//#region src/context.ts
|
|
2
|
+
/**
|
|
3
|
+
* The context of a thread as label and value pairs, in the order a person reads them: page, element, components,
|
|
4
|
+
* browser, build. The Console and Agent tools show these.
|
|
5
|
+
*/
|
|
6
|
+
function describeCommentContext(context) {
|
|
7
|
+
if (!context) return [];
|
|
8
|
+
const fields = [{
|
|
9
|
+
label: "URL",
|
|
10
|
+
value: context.url
|
|
11
|
+
}];
|
|
12
|
+
if (context.title) fields.push({
|
|
13
|
+
label: "Title",
|
|
14
|
+
value: context.title
|
|
15
|
+
});
|
|
16
|
+
if (context.route) fields.push({
|
|
17
|
+
label: "Route",
|
|
18
|
+
value: context.route
|
|
19
|
+
});
|
|
20
|
+
const element = context.element;
|
|
21
|
+
if (element) {
|
|
22
|
+
const tag = `<${element.tag}${element.id ? ` id="${element.id}"` : ""}${element.testId ? ` data-testid="${element.testId}"` : ""}>`;
|
|
23
|
+
fields.push({
|
|
24
|
+
label: "Element",
|
|
25
|
+
value: [
|
|
26
|
+
tag,
|
|
27
|
+
element.role && `role ${element.role}`,
|
|
28
|
+
element.name && `"${element.name}"`
|
|
29
|
+
].filter(Boolean).join(" ")
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (context.components?.length) {
|
|
33
|
+
fields.push({
|
|
34
|
+
label: "Components",
|
|
35
|
+
value: context.components.map((component) => component.name).join(" › ")
|
|
36
|
+
});
|
|
37
|
+
const files = [...new Set(context.components.flatMap((component) => component.files ?? []))];
|
|
38
|
+
if (files.length) fields.push({
|
|
39
|
+
label: "Files",
|
|
40
|
+
value: files.join(", ")
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const environment = context.environment;
|
|
44
|
+
if (environment) {
|
|
45
|
+
fields.push({
|
|
46
|
+
label: "Viewport",
|
|
47
|
+
value: `${environment.viewport.width}×${environment.viewport.height} at ${environment.devicePixelRatio}x${environment.colorScheme ? `, ${environment.colorScheme}` : ""}`
|
|
48
|
+
});
|
|
49
|
+
fields.push({
|
|
50
|
+
label: "Browser",
|
|
51
|
+
value: environment.userAgent
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (context.build?.commit || context.build?.branch) fields.push({
|
|
55
|
+
label: "Build",
|
|
56
|
+
value: [context.build.branch, context.build.commit?.slice(0, 12)].filter(Boolean).join(" @ ")
|
|
57
|
+
});
|
|
58
|
+
return fields;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { describeCommentContext as t };
|