@tdacorp/hyle-sdk 0.14.1 → 0.21.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 +171 -32
- package/dist/check-routes-bin.js +48 -21
- package/dist/chunk-56Y24XBV.js +840 -0
- package/dist/{chunk-MGSUQBDW.js → chunk-75JFLML4.js} +176 -14
- package/dist/chunk-HJX57NLI.js +1105 -0
- package/dist/chunk-K5VDLROQ.js +145 -0
- package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
- package/dist/chunk-U74B7AUG.js +398 -0
- package/dist/{chunk-6VOHFFA5.js → chunk-X2TLYM7Y.js} +2 -2
- package/dist/client-41fU6OY2.d.cts +201 -0
- package/dist/client-LwzHwqpM.d.ts +201 -0
- package/dist/code-copy.cjs +72 -0
- package/dist/code-copy.d.cts +15 -0
- package/dist/code-copy.d.ts +15 -0
- package/dist/code-copy.js +48 -0
- package/dist/comments.cjs +733 -278
- package/dist/comments.d.cts +66 -3
- package/dist/comments.d.ts +66 -3
- package/dist/comments.js +414 -330
- package/dist/{diagram-viewer-DYX6R63Y.js → diagram-viewer-XY3CG75U.js} +107 -46
- package/dist/{embed-B76zRRPa.d.cts → embed-BUFRQboD.d.ts} +10 -5
- package/dist/{embed-SqOBGI-E.d.ts → embed-CYt-q13P.d.cts} +10 -5
- package/dist/fragment-alias.cjs +51 -0
- package/dist/fragment-alias.d.cts +7 -0
- package/dist/fragment-alias.d.ts +7 -0
- package/dist/fragment-alias.js +27 -0
- package/dist/html.cjs +881 -0
- package/dist/html.d.cts +20 -0
- package/dist/html.d.ts +20 -0
- package/dist/html.js +45 -0
- package/dist/index.cjs +181 -14
- package/dist/index.d.cts +14 -62
- package/dist/index.d.ts +14 -62
- package/dist/index.js +11 -1
- package/dist/labels-CrA-iqTN.d.cts +46 -0
- package/dist/labels-CrA-iqTN.d.ts +46 -0
- package/dist/mermaid-diagram.cjs +453 -148
- package/dist/mermaid-diagram.d.cts +25 -42
- package/dist/mermaid-diagram.d.ts +25 -42
- package/dist/mermaid-diagram.js +205 -50
- package/dist/mermaid-image.cjs +1456 -0
- package/dist/mermaid-image.d.cts +30 -0
- package/dist/mermaid-image.d.ts +30 -0
- package/dist/mermaid-image.js +93 -0
- package/dist/next.cjs +1709 -1134
- package/dist/next.d.cts +67 -14
- package/dist/next.d.ts +67 -14
- package/dist/next.js +950 -794
- package/dist/print-coordinator.cjs +157 -0
- package/dist/print-coordinator.d.cts +27 -0
- package/dist/print-coordinator.d.ts +27 -0
- package/dist/print-coordinator.js +83 -0
- package/dist/react.cjs +677 -264
- package/dist/react.d.cts +161 -31
- package/dist/react.d.ts +161 -31
- package/dist/react.js +23 -3
- package/dist/reactions.cjs +653 -0
- package/dist/reactions.d.cts +27 -0
- package/dist/reactions.d.ts +27 -0
- package/dist/reactions.js +364 -0
- package/dist/{resolve-DC2ccfwA.d.ts → resolve-BjAK0k_Y.d.ts} +2 -2
- package/dist/{resolve-DKLVftk_.d.cts → resolve-eI1muCKL.d.cts} +2 -2
- package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
- package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
- package/dist/sanitize-ijiWjEm9.d.cts +23 -0
- package/dist/sanitize-ijiWjEm9.d.ts +23 -0
- package/dist/styles.css +107 -47
- package/dist/toc-spy.cjs +59 -0
- package/dist/toc-spy.d.cts +15 -0
- package/dist/toc-spy.d.ts +15 -0
- package/dist/toc-spy.js +35 -0
- package/dist/{types-ByodIyEv.d.cts → types-3F0wqD-o.d.cts} +44 -4
- package/dist/{types-ByodIyEv.d.ts → types-3F0wqD-o.d.ts} +44 -4
- package/dist/use-cache.cjs +37 -11
- package/dist/use-cache.d.cts +12 -5
- package/dist/use-cache.d.ts +12 -5
- package/dist/use-cache.js +7 -7
- package/dist/youtube-facade.cjs +50 -0
- package/dist/youtube-facade.d.cts +17 -0
- package/dist/youtube-facade.d.ts +17 -0
- package/dist/youtube-facade.js +26 -0
- package/package.json +16 -3
- package/dist/chunk-4V4VKB3O.js +0 -1471
- package/dist/chunk-R5EMI4HQ.js +0 -61
- package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
- package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
package/dist/comments.cjs
CHANGED
|
@@ -24,12 +24,27 @@ __export(comments_exports, {
|
|
|
24
24
|
Comments: () => Comments
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(comments_exports);
|
|
27
|
-
var
|
|
27
|
+
var import_react6 = require("react");
|
|
28
28
|
|
|
29
29
|
// src/react/comments-api.ts
|
|
30
30
|
var CSRF_HEADER = "x-hyle-engage";
|
|
31
31
|
var TIMEOUT_MS = 15e3;
|
|
32
|
-
|
|
32
|
+
var reading = /* @__PURE__ */ new Map();
|
|
33
|
+
function call(endpoint, method, path, body) {
|
|
34
|
+
if (method !== "GET") {
|
|
35
|
+
reading.clear();
|
|
36
|
+
return send(endpoint, method, path, body).finally(() => reading.clear());
|
|
37
|
+
}
|
|
38
|
+
const key = `${endpoint}${path}`;
|
|
39
|
+
const shared = reading.get(key);
|
|
40
|
+
if (shared) return shared;
|
|
41
|
+
const request = send(endpoint, method, path).finally(() => {
|
|
42
|
+
if (reading.get(key) === request) reading.delete(key);
|
|
43
|
+
});
|
|
44
|
+
reading.set(key, request);
|
|
45
|
+
return request;
|
|
46
|
+
}
|
|
47
|
+
async function send(endpoint, method, path, body) {
|
|
33
48
|
try {
|
|
34
49
|
const res = await fetch(`${endpoint}${path}`, {
|
|
35
50
|
method,
|
|
@@ -50,8 +65,17 @@ async function call(endpoint, method, path, body) {
|
|
|
50
65
|
return { status: 0, data: void 0, retryAfter: void 0 };
|
|
51
66
|
}
|
|
52
67
|
}
|
|
68
|
+
var REACTION_KINDS = ["like", "love", "insightful", "celebrate"];
|
|
69
|
+
var isCursor = (v) => typeof v === "string" && /^[A-Za-z0-9_-]{1,200}$/.test(v);
|
|
53
70
|
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
54
71
|
var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0;
|
|
72
|
+
function parseCounts(v) {
|
|
73
|
+
if (!isObject(v)) return void 0;
|
|
74
|
+
return Object.fromEntries(REACTION_KINDS.map((kind) => [kind, count(v[kind])]).filter(([, n]) => n > 0));
|
|
75
|
+
}
|
|
76
|
+
var toVote = (v) => v === 1 || v === -1 ? v : null;
|
|
77
|
+
var toUnrenderable = (v) => v === true ? { unrenderable: true } : {};
|
|
78
|
+
var toMine = (v) => Array.isArray(v) ? { my_reactions: REACTION_KINDS.filter((kind) => v.includes(kind)) } : {};
|
|
55
79
|
function toComment(raw) {
|
|
56
80
|
if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string") return void 0;
|
|
57
81
|
const depth = typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1;
|
|
@@ -59,6 +83,7 @@ function toComment(raw) {
|
|
|
59
83
|
const name = typeof raw.author_name === "string" ? raw.author_name : author;
|
|
60
84
|
const body = isObject(raw.body) && raw.body.format === "hast" ? { format: "hast", tree: raw.body.tree } : null;
|
|
61
85
|
const removed = raw.removed === true || body === null;
|
|
86
|
+
const reactions = parseCounts(raw.reaction_counts);
|
|
62
87
|
return {
|
|
63
88
|
id: raw.id,
|
|
64
89
|
parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
|
|
@@ -67,11 +92,14 @@ function toComment(raw) {
|
|
|
67
92
|
created_at: raw.created_at,
|
|
68
93
|
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
69
94
|
like_count: count(raw.like_count),
|
|
95
|
+
...Number.isSafeInteger(raw.score) ? { score: raw.score } : {},
|
|
96
|
+
...reactions ? { reaction_counts: reactions } : {},
|
|
70
97
|
removed,
|
|
71
98
|
...removed && (raw.removed_by === "moderator" || raw.removed_by === "author") ? { removed_by: raw.removed_by } : {},
|
|
99
|
+
...removed ? {} : toUnrenderable(raw.unrenderable),
|
|
72
100
|
body,
|
|
73
101
|
// Viewer members exist only on a live comment of a viewer-aware listing; a tombstone never carries them.
|
|
74
|
-
...!removed && typeof raw.mine === "boolean" ? { mine: raw.mine, liked_by_me: raw.liked_by_me === true, can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null } : {}
|
|
102
|
+
...!removed && typeof raw.mine === "boolean" ? { mine: raw.mine, liked_by_me: raw.liked_by_me === true, can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null, ..."my_vote" in raw ? { my_vote: toVote(raw.my_vote) } : {}, ...toMine(raw.my_reactions) } : {}
|
|
75
103
|
};
|
|
76
104
|
}
|
|
77
105
|
function toHeld(raw) {
|
|
@@ -85,20 +113,59 @@ function toHeld(raw) {
|
|
|
85
113
|
created_at: raw.created_at,
|
|
86
114
|
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
87
115
|
can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null,
|
|
116
|
+
...toUnrenderable(raw.unrenderable),
|
|
88
117
|
body: { format: "hast", tree: raw.body.tree }
|
|
89
118
|
};
|
|
90
119
|
}
|
|
91
120
|
function parseListing(data) {
|
|
92
121
|
if (!isObject(data) || data.kind !== "comments" || !Array.isArray(data.comments)) return void 0;
|
|
93
122
|
const comments = data.comments.map(toComment).filter((c) => c !== void 0);
|
|
94
|
-
const viewer = Array.isArray(data.mine_held) ? { liked_by_me: data.liked_by_me === true, mine_held: data.mine_held.slice(0, 5).map(toHeld).filter((h) => h !== void 0) } : {};
|
|
95
|
-
|
|
123
|
+
const viewer = Array.isArray(data.mine_held) ? { liked_by_me: data.liked_by_me === true, ...toMine(data.my_reactions), mine_held: data.mine_held.slice(0, 5).map(toHeld).filter((h) => h !== void 0) } : {};
|
|
124
|
+
const reactions = parseCounts(data.reaction_counts);
|
|
125
|
+
return { cp: 1, kind: "comments", publication_id: String(data.publication_id ?? ""), comment_count: count(data.comment_count), like_count: count(data.like_count), ...reactions ? { reaction_counts: reactions } : {}, truncated: data.truncated === true, next_cursor: isCursor(data.next_cursor) ? data.next_cursor : null, comments, ...viewer };
|
|
126
|
+
}
|
|
127
|
+
async function fetchPage(endpoint, path, sort, cursor) {
|
|
128
|
+
const query = new URLSearchParams({ path, ...cursor ? { cursor } : {}, ...sort ? { sort } : {} });
|
|
129
|
+
const r = await call(endpoint, "GET", `/comments?${query}`);
|
|
130
|
+
let listing = r.status === 200 ? parseListing(r.data) : void 0;
|
|
131
|
+
if (listing?.next_cursor && (listing.comments.length === 0 || listing.next_cursor === cursor)) listing = { ...listing, next_cursor: null };
|
|
132
|
+
return { status: r.status, listing, pages: listing ? 1 : 0, sort };
|
|
133
|
+
}
|
|
134
|
+
async function fetchPages(endpoint, path, order, pages, legacy = false) {
|
|
135
|
+
let out = await fetchPage(endpoint, path, order === "top" ? "top" : legacy ? void 0 : "new");
|
|
136
|
+
if (out.status === 400 && out.sort === "new") out = await fetchPage(endpoint, path, void 0);
|
|
137
|
+
while (out.listing?.next_cursor && out.pages < pages) {
|
|
138
|
+
const next = await fetchPage(endpoint, path, out.sort, out.listing.next_cursor);
|
|
139
|
+
if (!next.listing) return { ...next, status: next.status === 404 ? 502 : next.status, pages: 0 };
|
|
140
|
+
out = { ...next, listing: mergeListings(out.listing, next.listing), pages: out.pages + 1 };
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
async function fetchNext(endpoint, path, order, loaded, legacy = false) {
|
|
145
|
+
const next = await fetchPage(endpoint, path, loaded.sort, loaded.listing.next_cursor ?? void 0);
|
|
146
|
+
if (next.status === 400) return { ...await fetchPages(endpoint, path, order, loaded.pages + 1, legacy), restarted: true };
|
|
147
|
+
return { ...next, ...next.listing ? { listing: mergeListings(loaded.listing, next.listing), pages: loaded.pages + 1 } : {}, restarted: false };
|
|
148
|
+
}
|
|
149
|
+
var viewerOf = ({ mine, liked_by_me, my_reactions, can_edit_until, my_vote }) => mine === void 0 ? {} : { mine, liked_by_me: liked_by_me === true, ...my_reactions ? { my_reactions } : {}, can_edit_until: can_edit_until ?? null, ...my_vote === void 0 ? {} : { my_vote } };
|
|
150
|
+
function mergeListings(earlier, later) {
|
|
151
|
+
const byId = new Map(earlier.comments.map((c) => [c.id, c]));
|
|
152
|
+
for (const c of later.comments) {
|
|
153
|
+
const old = byId.get(c.id);
|
|
154
|
+
byId.set(c.id, old && !c.removed ? { ...viewerOf(old), ...c } : c);
|
|
155
|
+
}
|
|
156
|
+
const { liked_by_me, my_reactions, mine_held } = earlier;
|
|
157
|
+
const viewer = !later.mine_held && mine_held ? { liked_by_me: liked_by_me === true, ...my_reactions ? { my_reactions } : {}, mine_held } : {};
|
|
158
|
+
return { ...later, ...viewer, comments: [...byId.values()] };
|
|
159
|
+
}
|
|
160
|
+
function nextVote(current, clicked) {
|
|
161
|
+
const value = current.value === clicked ? null : clicked;
|
|
162
|
+
return { value, score: current.score - (current.value ?? 0) + (value ?? 0) };
|
|
96
163
|
}
|
|
97
164
|
var untilMs = (iso) => {
|
|
98
165
|
const t = iso ? Date.parse(iso) : NaN;
|
|
99
166
|
return Number.isFinite(t) ? t : void 0;
|
|
100
167
|
};
|
|
101
|
-
function buildThread(listing, localHeld) {
|
|
168
|
+
function buildThread(listing, localHeld, unseen = [], newestOnTop = false) {
|
|
102
169
|
const byId = /* @__PURE__ */ new Map();
|
|
103
170
|
const roots = [];
|
|
104
171
|
const place = (node, parentId) => {
|
|
@@ -116,11 +183,16 @@ function buildThread(listing, localHeld) {
|
|
|
116
183
|
mine: !removed && c.mine === true,
|
|
117
184
|
canEditUntil: untilMs(c.can_edit_until),
|
|
118
185
|
likedByMe: !removed && c.liked_by_me === true,
|
|
186
|
+
myReactions: removed ? void 0 : c.my_reactions,
|
|
119
187
|
name: removed ? null : c.author_name ?? null,
|
|
120
188
|
createdAt: c.created_at,
|
|
121
189
|
editedAt: c.edited_at,
|
|
122
190
|
likes: c.like_count,
|
|
191
|
+
score: c.score,
|
|
192
|
+
myVote: c.my_vote,
|
|
193
|
+
reactions: c.reaction_counts,
|
|
123
194
|
tree: c.body?.tree,
|
|
195
|
+
unrenderable: c.unrenderable,
|
|
124
196
|
text: void 0,
|
|
125
197
|
kids: []
|
|
126
198
|
};
|
|
@@ -138,24 +210,153 @@ function buildThread(listing, localHeld) {
|
|
|
138
210
|
for (const h of listing.mine_held ?? []) {
|
|
139
211
|
heldIds.add(h.id);
|
|
140
212
|
const parent = h.parent_id ? byId.get(h.parent_id) : void 0;
|
|
141
|
-
addHeld({ id: h.id, depth: Math.min(4, (parent?.depth ?? h.depth - 1) + 1), status: "held", removedBy: void 0, mine: true, canEditUntil: untilMs(h.can_edit_until), likedByMe: false, name: h.author_name, createdAt: h.created_at, editedAt: h.edited_at, likes: 0, tree: h.body?.tree, text: void 0, kids: [] }, h.parent_id, true);
|
|
213
|
+
addHeld({ id: h.id, depth: Math.min(4, (parent?.depth ?? h.depth - 1) + 1), status: "held", removedBy: void 0, mine: true, canEditUntil: untilMs(h.can_edit_until), likedByMe: false, name: h.author_name, createdAt: h.created_at, editedAt: h.edited_at, likes: 0, tree: h.body?.tree, unrenderable: h.unrenderable, text: void 0, kids: [] }, h.parent_id, true);
|
|
142
214
|
}
|
|
143
215
|
if (listing.mine_held === void 0) {
|
|
144
216
|
for (const h of localHeld) {
|
|
145
217
|
if (byId.has(h.id) || heldIds.has(h.id)) continue;
|
|
146
218
|
const parent = h.parentId ? byId.get(h.parentId) : void 0;
|
|
147
|
-
addHeld(
|
|
219
|
+
addHeld(localNode(h, "held", parent), h.parentId, false);
|
|
148
220
|
}
|
|
149
221
|
}
|
|
222
|
+
for (const u of [...unseen].reverse()) {
|
|
223
|
+
if (byId.has(u.id) || heldIds.has(u.id) || u.status === "held" && listing.mine_held === void 0) continue;
|
|
224
|
+
const parent = u.parentId ? byId.get(u.parentId) : void 0;
|
|
225
|
+
const node = localNode(u, u.status, parent);
|
|
226
|
+
if (u.status === "held") addHeld(node, u.parentId, true);
|
|
227
|
+
else if (parent) parent.kids.push(node);
|
|
228
|
+
else if (newestOnTop) roots.unshift(node);
|
|
229
|
+
else roots.push(node);
|
|
230
|
+
byId.set(u.id, node);
|
|
231
|
+
}
|
|
150
232
|
return [...mine, ...roots];
|
|
151
233
|
}
|
|
234
|
+
var localNode = (c, status, parent) => ({
|
|
235
|
+
id: c.id,
|
|
236
|
+
depth: Math.min(4, (parent?.depth ?? 0) + 1),
|
|
237
|
+
status,
|
|
238
|
+
removedBy: void 0,
|
|
239
|
+
mine: true,
|
|
240
|
+
canEditUntil: void 0,
|
|
241
|
+
likedByMe: false,
|
|
242
|
+
name: c.name,
|
|
243
|
+
createdAt: c.createdAt,
|
|
244
|
+
editedAt: null,
|
|
245
|
+
likes: 0,
|
|
246
|
+
tree: void 0,
|
|
247
|
+
text: c.text,
|
|
248
|
+
kids: []
|
|
249
|
+
});
|
|
250
|
+
var isSortable = (listing) => listing.comments.some((c) => c.score !== void 0);
|
|
251
|
+
var arrivesAs = (listing, sort) => isSortable(listing) ? sort : void 0;
|
|
252
|
+
function arrangeThread(listing, sort, localHeld, unseen) {
|
|
253
|
+
const from = arrivesAs(listing, sort);
|
|
254
|
+
const thread = buildThread(listing, localHeld, unseen, from === "new");
|
|
255
|
+
return isSortable(listing) && from === void 0 ? newestFirst(thread) : thread;
|
|
256
|
+
}
|
|
257
|
+
function stillUnseen(unseen, listing) {
|
|
258
|
+
const listed = new Set([...listing.comments, ...listing.mine_held ?? []].map((c) => c.id));
|
|
259
|
+
return unseen.some((c) => listed.has(c.id)) ? unseen.filter((c) => !listed.has(c.id)) : unseen;
|
|
260
|
+
}
|
|
261
|
+
function newestFirst(thread) {
|
|
262
|
+
return [...thread.filter((n) => n.status === "held"), ...thread.filter((n) => n.status !== "held").reverse()];
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// src/react/comments-listing.ts
|
|
266
|
+
var import_react = require("react");
|
|
267
|
+
function useCommentListing(endpoint, path, initial, active, onFresh, onReset) {
|
|
268
|
+
const [listing, setListing] = (0, import_react.useState)(initial ?? "loading");
|
|
269
|
+
const [order, setOrder] = (0, import_react.useState)("newest");
|
|
270
|
+
const [served, setServed] = (0, import_react.useState)(void 0);
|
|
271
|
+
const data = (0, import_react.useRef)({ listing: initial, order: "newest", pages: 1, sort: void 0 });
|
|
272
|
+
const legacy = (0, import_react.useRef)(false);
|
|
273
|
+
const queue = (0, import_react.useRef)(Promise.resolve());
|
|
274
|
+
const generation = (0, import_react.useRef)(0);
|
|
275
|
+
const callbacks = (0, import_react.useRef)({ onFresh, onReset });
|
|
276
|
+
callbacks.current = { onFresh, onReset };
|
|
277
|
+
const enqueue = (0, import_react.useCallback)((op) => {
|
|
278
|
+
const mine = generation.current;
|
|
279
|
+
const stale = () => mine !== generation.current;
|
|
280
|
+
const job = queue.current.then(() => stale() ? void 0 : op(stale));
|
|
281
|
+
queue.current = job.catch(() => void 0);
|
|
282
|
+
return job;
|
|
283
|
+
}, []);
|
|
284
|
+
const commit = (0, import_react.useCallback)((next) => {
|
|
285
|
+
data.current = next;
|
|
286
|
+
setListing(next.listing);
|
|
287
|
+
setOrder(next.order);
|
|
288
|
+
setServed(next.sort);
|
|
289
|
+
}, []);
|
|
290
|
+
const learn = (0, import_react.useCallback)((asked, r) => {
|
|
291
|
+
if (asked === "newest" && r.listing && r.sort === void 0) legacy.current = true;
|
|
292
|
+
return r;
|
|
293
|
+
}, []);
|
|
294
|
+
const reload = (0, import_react.useCallback)(
|
|
295
|
+
(silent) => enqueue(async (stale) => {
|
|
296
|
+
const { order: current, pages } = data.current;
|
|
297
|
+
const r = learn(current, await fetchPages(endpoint, path, current, pages, legacy.current));
|
|
298
|
+
if (stale()) return void 0;
|
|
299
|
+
if (r.status === 404) setListing("off");
|
|
300
|
+
else if (r.listing) {
|
|
301
|
+
commit({ listing: r.listing, order: current, pages: r.pages, sort: r.sort });
|
|
302
|
+
callbacks.current.onFresh(r.listing);
|
|
303
|
+
} else if (!silent) setListing("error");
|
|
304
|
+
return r.listing;
|
|
305
|
+
}),
|
|
306
|
+
[endpoint, path, enqueue, commit, learn]
|
|
307
|
+
);
|
|
308
|
+
const sort = (0, import_react.useCallback)(
|
|
309
|
+
(next) => enqueue(async (stale) => {
|
|
310
|
+
if (next === data.current.order) return next;
|
|
311
|
+
const r = learn(next, await fetchPages(endpoint, path, next, 1, legacy.current));
|
|
312
|
+
if (stale()) return void 0;
|
|
313
|
+
if (!r.listing) return data.current.order;
|
|
314
|
+
commit({ listing: r.listing, order: next, pages: 1, sort: r.sort });
|
|
315
|
+
callbacks.current.onFresh(r.listing);
|
|
316
|
+
return next;
|
|
317
|
+
}),
|
|
318
|
+
[endpoint, path, enqueue, commit, learn]
|
|
319
|
+
);
|
|
320
|
+
const more = (0, import_react.useCallback)(
|
|
321
|
+
() => enqueue(async (stale) => {
|
|
322
|
+
const { listing: before, order: current, pages, sort: wire } = data.current;
|
|
323
|
+
if (!before?.next_cursor) return void 0;
|
|
324
|
+
const r = await fetchNext(endpoint, path, current, { listing: before, pages, sort: wire }, legacy.current);
|
|
325
|
+
if (stale()) return void 0;
|
|
326
|
+
if (r.restarted) learn(current, r);
|
|
327
|
+
if (!r.listing) return { ok: false };
|
|
328
|
+
const known = new Set(before.comments.map((c) => c.id));
|
|
329
|
+
commit({ listing: r.listing, order: current, pages: r.pages, sort: r.sort });
|
|
330
|
+
if (r.restarted) callbacks.current.onFresh(r.listing);
|
|
331
|
+
return { ok: true, listing: r.listing, sort: r.sort, added: new Set(r.listing.comments.filter((c) => !c.removed && !known.has(c.id)).map((c) => c.id)) };
|
|
332
|
+
}),
|
|
333
|
+
[endpoint, path, enqueue, commit, learn]
|
|
334
|
+
);
|
|
335
|
+
(0, import_react.useEffect)(() => {
|
|
336
|
+
data.current = { listing: initial, order: "newest", pages: 1, sort: void 0 };
|
|
337
|
+
legacy.current = false;
|
|
338
|
+
queue.current = Promise.resolve();
|
|
339
|
+
setListing(initial ?? "loading");
|
|
340
|
+
setOrder("newest");
|
|
341
|
+
setServed(void 0);
|
|
342
|
+
callbacks.current.onReset();
|
|
343
|
+
return () => void (generation.current += 1);
|
|
344
|
+
}, [endpoint, path, initial]);
|
|
345
|
+
(0, import_react.useEffect)(() => {
|
|
346
|
+
if (active) void reload(initial !== void 0);
|
|
347
|
+
}, [active, reload, initial]);
|
|
348
|
+
return { listing, order, served, reload, sort, more, retry: () => {
|
|
349
|
+
setListing("loading");
|
|
350
|
+
void reload(false);
|
|
351
|
+
} };
|
|
352
|
+
}
|
|
152
353
|
|
|
153
354
|
// src/react/comments-parts.tsx
|
|
154
|
-
var
|
|
355
|
+
var import_react5 = require("react");
|
|
155
356
|
|
|
156
357
|
// src/react/comments-body.tsx
|
|
157
358
|
var import_hast_util_to_jsx_runtime = require("hast-util-to-jsx-runtime");
|
|
158
|
-
var
|
|
359
|
+
var import_react2 = require("react");
|
|
159
360
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
160
361
|
|
|
161
362
|
// src/asset-path.ts
|
|
@@ -179,7 +380,7 @@ var HastLimitError = class extends Error {
|
|
|
179
380
|
var MAX_NODES = 2e4;
|
|
180
381
|
var MAX_TEXT = 512 * 1024;
|
|
181
382
|
var MAX_DEPTH = 128;
|
|
182
|
-
var MAX_SRCDOC =
|
|
383
|
+
var MAX_SRCDOC = 1024 * 1024;
|
|
183
384
|
var DROP = /* @__PURE__ */ new Set(["script", "style", "template", "noscript"]);
|
|
184
385
|
var VOID = /* @__PURE__ */ new Set(["br", "hr", "img", "input", "path"]);
|
|
185
386
|
var isString = (v) => typeof v === "string";
|
|
@@ -187,8 +388,15 @@ var isScalar = (v) => typeof v === "string" || typeof v === "number" || typeof v
|
|
|
187
388
|
var matches = (re) => (v) => typeof v === "string" && re.test(v);
|
|
188
389
|
var ID_PREFIX = "user-content-";
|
|
189
390
|
var scopeId = (id) => id.startsWith(ID_PREFIX) ? id : ID_PREFIX + id;
|
|
190
|
-
var ID_BODY = /^[\p{L}\p{N}
|
|
191
|
-
|
|
391
|
+
var ID_BODY = /^[\p{L}\p{M}\p{N}\p{Pc}:.-]{1,180}$/u;
|
|
392
|
+
function isIdValue(v) {
|
|
393
|
+
if (typeof v !== "string") return false;
|
|
394
|
+
try {
|
|
395
|
+
return ID_BODY.test(decodeURIComponent(v.startsWith(ID_PREFIX) ? v.slice(ID_PREFIX.length) : v));
|
|
396
|
+
} catch {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
192
400
|
var CLASS_TOKEN = /^[A-Za-z_][\w:-]*$/;
|
|
193
401
|
var classTokens = (v) => {
|
|
194
402
|
const tokens = Array.isArray(v) ? v : typeof v === "string" ? v.split(/\s+/) : [];
|
|
@@ -196,10 +404,12 @@ var classTokens = (v) => {
|
|
|
196
404
|
};
|
|
197
405
|
var isClass = (v) => classTokens(v) !== void 0;
|
|
198
406
|
var isAlign = matches(/^(left|right|center)$/);
|
|
407
|
+
var isPixels = (v) => typeof v === "number" ? Number.isInteger(v) && v > 0 : typeof v === "string" && /^[1-9]\d*$/.test(v);
|
|
199
408
|
var isLength = matches(/^[\d.]+(em|px|%)?$/);
|
|
200
409
|
var STYLE_PROPS = /* @__PURE__ */ new Set(["height", "vertical-align", "margin-left", "margin-right", "margin-top", "margin-bottom", "top", "width", "min-width", "border-bottom-width", "padding-left"]);
|
|
201
410
|
var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
|
|
202
411
|
var MAX_STYLE_MAGNITUDE = 100;
|
|
412
|
+
var MAX_MARGIN_MAGNITUDE = 20;
|
|
203
413
|
function isKatexStyle(v, ctx) {
|
|
204
414
|
if (typeof v !== "string" || !ctx.katex) return false;
|
|
205
415
|
return v.split(";").filter((d) => d !== "").every((decl) => {
|
|
@@ -207,7 +417,8 @@ function isKatexStyle(v, ctx) {
|
|
|
207
417
|
if (extra.length > 0 || prop === void 0 || value === void 0) return false;
|
|
208
418
|
if (prop === "position") return value === "relative";
|
|
209
419
|
const m = STYLE_LENGTH.exec(value);
|
|
210
|
-
|
|
420
|
+
const max = prop.startsWith("margin-") ? MAX_MARGIN_MAGNITUDE : MAX_STYLE_MAGNITUDE;
|
|
421
|
+
return STYLE_PROPS.has(prop) && m !== null && Math.abs(Number(m[1])) <= max;
|
|
211
422
|
});
|
|
212
423
|
}
|
|
213
424
|
function isSafeUrl(value, kind) {
|
|
@@ -230,7 +441,10 @@ var MERMAID_SRCDOC = new RegExp(
|
|
|
230
441
|
`^<!doctype html><html><head><meta charset="utf-8"></head><body><div class="mermaid">([^<]*)</div><script src="${MERMAID_SCRIPT_URL.replace(/[.]/g, "\\.")}"></script><script>mermaid\\.initialize\\(\\{ startOnLoad: true, securityLevel: "strict" \\}\\);</script></body></html>$`
|
|
231
442
|
);
|
|
232
443
|
var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
|
|
233
|
-
var
|
|
444
|
+
var RENDER_REF = /^(\/assets\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.svg) ([1-9]\d{0,5}) ([1-9]\d{0,5})$/;
|
|
445
|
+
var isRenderRef = matches(RENDER_REF);
|
|
446
|
+
var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
|
|
447
|
+
var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
|
|
234
448
|
var heading = { id: isIdValue, className: isClass };
|
|
235
449
|
var ATTRS = new Map(
|
|
236
450
|
Object.entries({
|
|
@@ -246,6 +460,7 @@ var ATTRS = new Map(
|
|
|
246
460
|
tbody: {},
|
|
247
461
|
tr: {},
|
|
248
462
|
ol: {},
|
|
463
|
+
kbd: {},
|
|
249
464
|
ul: { className: isClass },
|
|
250
465
|
li: { id: isIdValue, className: isClass },
|
|
251
466
|
h1: heading,
|
|
@@ -254,8 +469,8 @@ var ATTRS = new Map(
|
|
|
254
469
|
h4: heading,
|
|
255
470
|
h5: heading,
|
|
256
471
|
h6: heading,
|
|
257
|
-
a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
|
|
258
|
-
img: { src: isSrc, alt: isString },
|
|
472
|
+
a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, dataEmbed: matches(/^youtube$/), className: isClass },
|
|
473
|
+
img: { src: isSrc, alt: isString, title: isString, width: isPixels, height: isPixels },
|
|
259
474
|
table: {},
|
|
260
475
|
th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
|
|
261
476
|
td: { align: isAlign },
|
|
@@ -269,7 +484,7 @@ var ATTRS = new Map(
|
|
|
269
484
|
video: { src: isSrc, controls: isScalar },
|
|
270
485
|
audio: { src: isSrc, controls: isScalar },
|
|
271
486
|
// hyle's sandboxed Mermaid frame (ADR 0001). The renderer emits `sandbox` as ["allow-scripts"]; it is normalized below.
|
|
272
|
-
iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc }
|
|
487
|
+
iframe: { sandbox: (v) => v === "allow-scripts" || Array.isArray(v) && v.length === 1 && v[0] === "allow-scripts", srcdoc: isMermaidSrcdoc, dataLight: isRenderRef, dataDark: isRenderRef }
|
|
273
488
|
})
|
|
274
489
|
);
|
|
275
490
|
var isObject2 = (v) => typeof v === "object" && v !== null;
|
|
@@ -278,8 +493,10 @@ function textOf(node, depth = 0) {
|
|
|
278
493
|
if (node.type === "text") return typeof node.value === "string" ? node.value : "";
|
|
279
494
|
return Array.isArray(node.children) ? node.children.map((c) => textOf(c, depth + 1)).join("") : "";
|
|
280
495
|
}
|
|
496
|
+
var holdsEmbed = (node, depth = 0) => isObject2(node) && depth <= MAX_DEPTH && (isObject2(node.properties) && "dataEmbed" in node.properties || Array.isArray(node.children) && node.children.some((c) => holdsEmbed(c, depth + 1)));
|
|
497
|
+
var collapse = (text) => text.replace(/\s+/g, " ").trim();
|
|
281
498
|
var CALLOUT_MARKER = /^\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/i;
|
|
282
|
-
var CALLOUT_KIND = { note: "note", tip: "tip", important: "
|
|
499
|
+
var CALLOUT_KIND = { note: "note", tip: "tip", important: "important", warning: "warning", caution: "caution" };
|
|
283
500
|
function toCallout(children) {
|
|
284
501
|
const first = children.find((c) => c.type === "element");
|
|
285
502
|
const lead = first?.tagName === "p" ? first.children[0] : void 0;
|
|
@@ -291,6 +508,21 @@ function toCallout(children) {
|
|
|
291
508
|
const kind = CALLOUT_KIND[(marker[1] ?? "note").toLowerCase()] ?? "note";
|
|
292
509
|
return { type: "element", tagName: "callout", properties: { kind }, children: [...body, ...children.slice(children.indexOf(first) + 1)] };
|
|
293
510
|
}
|
|
511
|
+
var isBlank = (node) => node.type === "text" && node.value.trim() === "";
|
|
512
|
+
function soleElement(children) {
|
|
513
|
+
const [only, ...more] = children.filter((c) => !isBlank(c));
|
|
514
|
+
return more.length === 0 && only?.type === "element" ? only : void 0;
|
|
515
|
+
}
|
|
516
|
+
function toFigure(children) {
|
|
517
|
+
const only = soleElement(children);
|
|
518
|
+
const img = only?.tagName === "a" ? soleElement(only.children) : only;
|
|
519
|
+
if (!only || img?.tagName !== "img" || typeof img.properties.src !== "string") return void 0;
|
|
520
|
+
const { title, ...properties } = img.properties;
|
|
521
|
+
const bare = { ...img, properties };
|
|
522
|
+
const media = only === img ? bare : { ...only, children: [bare] };
|
|
523
|
+
const caption = typeof title === "string" && title.trim() ? [{ type: "element", tagName: "figcaption", properties: {}, children: [{ type: "text", value: title }] }] : [];
|
|
524
|
+
return { type: "element", tagName: "figure", properties: { dataSlotComponent: "Image" }, children: [media, ...caption] };
|
|
525
|
+
}
|
|
294
526
|
function clean(node, depth, ctx, budget) {
|
|
295
527
|
if (!isObject2(node) || depth > MAX_DEPTH) return [];
|
|
296
528
|
if (++budget.nodes > MAX_NODES) throw new HastLimitError("content has too many nodes");
|
|
@@ -324,6 +556,11 @@ function clean(node, depth, ctx, budget) {
|
|
|
324
556
|
}
|
|
325
557
|
for (const key of ["id", "ariaDescribedBy"]) if (typeof properties[key] === "string") properties[key] = scopeId(properties[key]);
|
|
326
558
|
if (tag === "a" && typeof properties.href === "string" && properties.href.trim().startsWith("#")) properties.href = `#${scopeId(properties.href.trim().slice(1))}`;
|
|
559
|
+
if (tag === "a" && properties.dataEmbed !== void 0 && youtubeId(properties.href) === void 0) delete properties.dataEmbed;
|
|
560
|
+
if (tag === "p") {
|
|
561
|
+
const figure = toFigure(children);
|
|
562
|
+
if (figure) return [figure];
|
|
563
|
+
}
|
|
327
564
|
if (tag === "blockquote") {
|
|
328
565
|
const callout = toCallout(children);
|
|
329
566
|
if (callout) return [callout];
|
|
@@ -335,9 +572,9 @@ function sanitizeHast(tree, title, description) {
|
|
|
335
572
|
const raw = isObject2(tree) && tree.type === "root" && Array.isArray(tree.children) ? tree.children : [];
|
|
336
573
|
const elements = raw.filter((n) => isObject2(n) && n.type === "element");
|
|
337
574
|
const [first] = elements;
|
|
338
|
-
const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && textOf(first)
|
|
575
|
+
const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
|
|
339
576
|
const lead = elements[skip ? 1 : 0];
|
|
340
|
-
const repeat = description && isObject2(lead) && lead.tagName === "p" && textOf(lead)
|
|
577
|
+
const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)).startsWith(collapse(description)) && !holdsEmbed(lead) ? lead : void 0;
|
|
341
578
|
const budget = { nodes: 0, text: 0 };
|
|
342
579
|
return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
|
|
343
580
|
}
|
|
@@ -366,7 +603,7 @@ function CommentBody({ tree }) {
|
|
|
366
603
|
if (error instanceof HastLimitError) return null;
|
|
367
604
|
throw error;
|
|
368
605
|
}
|
|
369
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "hyle-cm-body", children: (0, import_hast_util_to_jsx_runtime.toJsxRuntime)({ type: "root", children }, { Fragment:
|
|
606
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "hyle-cm-body", children: (0, import_hast_util_to_jsx_runtime.toJsxRuntime)({ type: "root", children }, { Fragment: import_react2.Fragment, jsx: import_jsx_runtime.jsx, jsxs: import_jsx_runtime.jsxs, elementAttributeNameCase: "react", stylePropertyNameCase: "dom" }) });
|
|
370
607
|
}
|
|
371
608
|
|
|
372
609
|
// src/react/comments-markdown.ts
|
|
@@ -422,6 +659,9 @@ function hastToMarkdown(tree) {
|
|
|
422
659
|
}
|
|
423
660
|
}
|
|
424
661
|
|
|
662
|
+
// src/react/comments-votes.tsx
|
|
663
|
+
var import_react3 = require("react");
|
|
664
|
+
|
|
425
665
|
// src/react/icons.tsx
|
|
426
666
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
427
667
|
var SHAPES = {
|
|
@@ -451,9 +691,16 @@ var SHAPES = {
|
|
|
451
691
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M9 1.8v3h3" })
|
|
452
692
|
] }),
|
|
453
693
|
chev: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
|
|
694
|
+
"chev-up": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3.5 10 4.5-4.5L12.5 10" }),
|
|
454
695
|
"chev-down": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
|
|
455
696
|
"chev-left": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" }),
|
|
456
697
|
x: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" }),
|
|
698
|
+
important: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M3 2.5h10a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H8l-3.5 2.8v-2.8H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1zM8 5v2.8M8 9.5v.1" }),
|
|
699
|
+
copy: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
700
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "5.5", y: "5.5", width: "8", height: "8", rx: "1.3" }),
|
|
701
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M10.5 5.5v-2a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2" })
|
|
702
|
+
] }),
|
|
703
|
+
check: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3 8.5 3.2 3L13 4.5" }),
|
|
457
704
|
heart: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M8 13.5S2.2 10 2.2 6.1A3 3 0 0 1 8 5a3 3 0 0 1 5.8 1.1C13.8 10 8 13.5 8 13.5z" }),
|
|
458
705
|
reply: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M6.5 3.5 2.5 7.5l4 4M2.5 7.5h6a5 5 0 0 1 5 5" }),
|
|
459
706
|
clock: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
@@ -470,8 +717,149 @@ function Icon({ name, className }) {
|
|
|
470
717
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { className: className ? `hyle-ic ${className}` : "hyle-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: SHAPES[name] });
|
|
471
718
|
}
|
|
472
719
|
|
|
473
|
-
// src/react/comments-
|
|
720
|
+
// src/react/comments-votes.tsx
|
|
474
721
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
722
|
+
function useVotes(endpoint) {
|
|
723
|
+
const [overlay, setOverlay] = (0, import_react3.useState)({});
|
|
724
|
+
const pending = (0, import_react3.useRef)(/* @__PURE__ */ new Set());
|
|
725
|
+
async function cast(id, current, clicked) {
|
|
726
|
+
if (pending.current.has(id)) return void 0;
|
|
727
|
+
const next = nextVote(current, clicked);
|
|
728
|
+
pending.current.add(id);
|
|
729
|
+
setOverlay((o) => ({ ...o, [id]: next }));
|
|
730
|
+
const r = await call(endpoint, next.value === null ? "DELETE" : "PUT", "/votes", next.value === null ? { comment_id: id } : { comment_id: id, value: next.value });
|
|
731
|
+
pending.current.delete(id);
|
|
732
|
+
const vote = r.status === 200 && isObject(r.data) && isObject(r.data.vote) ? r.data.vote : void 0;
|
|
733
|
+
if (vote && Number.isSafeInteger(vote.score)) {
|
|
734
|
+
const state = { value: vote.value === 1 || vote.value === -1 ? vote.value : null, score: vote.score };
|
|
735
|
+
setOverlay((o) => ({ ...o, [id]: state }));
|
|
736
|
+
return { ok: true, state };
|
|
737
|
+
}
|
|
738
|
+
setOverlay((o) => ({ ...o, [id]: current }));
|
|
739
|
+
return { ok: false, status: r.status };
|
|
740
|
+
}
|
|
741
|
+
function settle(listing) {
|
|
742
|
+
const known = new Set(listing.comments.filter((c) => c.my_vote !== void 0).map((c) => c.id));
|
|
743
|
+
setOverlay((o) => Object.fromEntries(Object.entries(o).flatMap(([id, v]) => pending.current.has(id) ? [[id, v]] : v.value !== null && !known.has(id) ? [[id, { value: v.value }]] : [])));
|
|
744
|
+
}
|
|
745
|
+
return { overlay, cast, settle, reset: () => setOverlay({}) };
|
|
746
|
+
}
|
|
747
|
+
function VoteButtons({ s, name, state, own, access, signInHref, onVote }) {
|
|
748
|
+
function arrow(value) {
|
|
749
|
+
if (own) return null;
|
|
750
|
+
const icon = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: value === 1 ? "chev-up" : "chev-down" });
|
|
751
|
+
const label = value === 1 ? s.upvote : s.downvote;
|
|
752
|
+
if (access === "out") return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("a", { className: "hyle-cm-btn", href: signInHref, children: [
|
|
753
|
+
icon,
|
|
754
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: value === 1 ? s.upvoteSignIn : s.downvoteSignIn })
|
|
755
|
+
] });
|
|
756
|
+
if (access !== "in") return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-cm-btn", type: "button", "aria-disabled": "true", "aria-label": label, children: icon });
|
|
757
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { className: "hyle-cm-btn", type: "button", "aria-label": label, "aria-pressed": state.value === value, onClick: () => onVote(value), children: icon });
|
|
758
|
+
}
|
|
759
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hyle-cm-votes", role: "group", "aria-label": s.votesOn.replace("{name}", () => name), children: [
|
|
760
|
+
arrow(1),
|
|
761
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hyle-cm-score", children: [
|
|
762
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.score.replace("{n}", String(state.score)) }),
|
|
763
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": "true", children: state.score })
|
|
764
|
+
] }),
|
|
765
|
+
arrow(-1)
|
|
766
|
+
] });
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// src/react/reaction-bar.tsx
|
|
770
|
+
var import_react4 = require("react");
|
|
771
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
772
|
+
var reactionKey = (subject, kind) => `${subject}:${kind}`;
|
|
773
|
+
var kindName = (s, kind) => ({ like: s.reactionLike, love: s.reactionLove, insightful: s.reactionInsightful, celebrate: s.reactionCelebrate })[kind];
|
|
774
|
+
function settleReactions(overlay, pending, listing) {
|
|
775
|
+
const told = new Set(listing.comments.filter((c) => c.my_reactions).map((c) => c.id));
|
|
776
|
+
if (listing.my_reactions) told.add("article");
|
|
777
|
+
return Object.fromEntries(Object.entries(overlay).flatMap(([key, v]) => {
|
|
778
|
+
if (pending.has(key)) return [[key, v]];
|
|
779
|
+
return v.on && !key.endsWith(":like") && !told.has(key.slice(0, key.lastIndexOf(":"))) ? [[key, { on: true }]] : [];
|
|
780
|
+
}));
|
|
781
|
+
}
|
|
782
|
+
function useReactions(endpoint, path) {
|
|
783
|
+
const [overlay, setOverlay] = (0, import_react4.useState)({});
|
|
784
|
+
const pending = (0, import_react4.useRef)(/* @__PURE__ */ new Set());
|
|
785
|
+
async function toggle(subject, kind, count2, on) {
|
|
786
|
+
const key = reactionKey(subject, kind);
|
|
787
|
+
if (pending.current.has(key)) return void 0;
|
|
788
|
+
const before = { on: overlay[key]?.on ?? on, count: overlay[key]?.count ?? count2 };
|
|
789
|
+
pending.current.add(key);
|
|
790
|
+
setOverlay((o) => ({ ...o, [key]: { on: !before.on, count: Math.max(0, before.count + (before.on ? -1 : 1)) } }));
|
|
791
|
+
const target = subject === "article" ? { subject_type: "article", path } : { subject_type: "comment", comment_id: subject };
|
|
792
|
+
const r = await call(endpoint, before.on ? "DELETE" : "PUT", "/reactions", kind === "like" ? target : { ...target, kind });
|
|
793
|
+
pending.current.delete(key);
|
|
794
|
+
const reaction = r.status === 200 && isObject(r.data) && isObject(r.data.reaction) ? r.data.reaction : void 0;
|
|
795
|
+
const counts = parseCounts(reaction?.counts);
|
|
796
|
+
const settled = counts ? counts[kind] ?? 0 : kind === "like" && typeof reaction?.like_count === "number" ? reaction.like_count : void 0;
|
|
797
|
+
if (reaction && settled !== void 0) {
|
|
798
|
+
const active = reaction.active === true;
|
|
799
|
+
setOverlay((o) => ({ ...o, [key]: { on: active, count: settled } }));
|
|
800
|
+
return { ok: true, on: active };
|
|
801
|
+
}
|
|
802
|
+
setOverlay((o) => ({ ...o, [key]: before }));
|
|
803
|
+
return { ok: false, status: r.status };
|
|
804
|
+
}
|
|
805
|
+
const settle = (listing) => setOverlay((o) => settleReactions(o, pending.current, listing));
|
|
806
|
+
return { overlay, toggle, settle, reset: () => setOverlay({}) };
|
|
807
|
+
}
|
|
808
|
+
function ReactionBar({ s, scope, subject, likes, counts, likedByMe, mine, overlay, access, signInHref, onToggle }) {
|
|
809
|
+
const [open, setOpen] = (0, import_react4.useState)(false);
|
|
810
|
+
const first = (0, import_react4.useRef)(null);
|
|
811
|
+
const trigger = (0, import_react4.useRef)(null);
|
|
812
|
+
(0, import_react4.useEffect)(() => {
|
|
813
|
+
if (open) first.current?.focus();
|
|
814
|
+
}, [open]);
|
|
815
|
+
const base = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
|
|
816
|
+
function button(kind) {
|
|
817
|
+
const state = overlay[reactionKey(subject, kind)];
|
|
818
|
+
const server = kind === "like" ? likes : counts?.[kind] ?? 0;
|
|
819
|
+
const serverOn = mine ? mine.includes(kind) : kind === "like" && likedByMe;
|
|
820
|
+
const count2 = state?.count ?? server;
|
|
821
|
+
const on = state?.on ?? serverOn;
|
|
822
|
+
if (kind !== "like" && !open && !state && count2 === 0) return null;
|
|
823
|
+
const out = access === "out";
|
|
824
|
+
const content = kind !== "like" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
825
|
+
out ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: s.reactionSignIn }) : null,
|
|
826
|
+
kindName(s, kind),
|
|
827
|
+
" ",
|
|
828
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: count2 })
|
|
829
|
+
] }) : scope === "article" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
830
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "heart" }),
|
|
831
|
+
out ? s.likeArticle : on ? s.likedArticle : s.likeArticle,
|
|
832
|
+
" ",
|
|
833
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: out ? s.likeArticleSignIn : ", " }),
|
|
834
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: count2 })
|
|
835
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
836
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "heart" }),
|
|
837
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: out ? s.likeCommentSignIn : s.likeComment }),
|
|
838
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: count2 })
|
|
839
|
+
] });
|
|
840
|
+
const cls = kind === "like" ? base : `${base} chip`;
|
|
841
|
+
if (out && signInHref) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { className: cls, href: signInHref, children: content }, kind);
|
|
842
|
+
if (access !== "in") return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: cls, type: "button", "aria-disabled": "true", children: content }, kind);
|
|
843
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { ref: kind === "love" ? first : void 0, className: cls, type: "button", "aria-pressed": on, onClick: () => {
|
|
844
|
+
setOpen(false);
|
|
845
|
+
onToggle(kind, server, serverOn);
|
|
846
|
+
}, children: content }, kind);
|
|
847
|
+
}
|
|
848
|
+
if (!counts) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: button("like") });
|
|
849
|
+
const onKey = (e) => {
|
|
850
|
+
if (e.key !== "Escape" || !open) return;
|
|
851
|
+
e.preventDefault();
|
|
852
|
+
setOpen(false);
|
|
853
|
+
trigger.current?.focus();
|
|
854
|
+
};
|
|
855
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "hyle-reaction-set", role: "group", "aria-label": s.reactions, onKeyDown: onKey, children: [
|
|
856
|
+
REACTION_KINDS.map(button),
|
|
857
|
+
access === "in" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { ref: trigger, className: scope === "article" ? "hyle-btn" : "hyle-cm-btn", type: "button", "aria-expanded": open, onClick: () => setOpen((v) => !v), children: s.react }) : null
|
|
858
|
+
] });
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// src/react/comments-parts.tsx
|
|
862
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
475
863
|
var MAX_CHARS = 4e3;
|
|
476
864
|
var EDIT_WINDOW_MS = 10 * 60 * 1e3;
|
|
477
865
|
var MAX_DEPTH2 = 4;
|
|
@@ -479,6 +867,7 @@ var fill = (template, values) => template.replace(/\{(\w+)\}/g, (_, k) => String
|
|
|
479
867
|
var initials = (name) => name.trim().split(/\s+/).slice(0, 2).map((w) => [...w][0] ?? "").join("").toUpperCase() || "?";
|
|
480
868
|
var replyButtonId = (ui, id) => `${ui.idp}-reply-${id}`;
|
|
481
869
|
var nameId = (ui, id) => `${ui.idp}-${id}-n`;
|
|
870
|
+
var accessOf = (ui) => !ui.ready ? "pending" : !ui.me ? "out" : ui.banned ? "blocked" : "in";
|
|
482
871
|
function relative(iso, now, locale, s) {
|
|
483
872
|
const seconds = Math.round((now - Date.parse(iso)) / 1e3);
|
|
484
873
|
if (!Number.isFinite(seconds)) return iso;
|
|
@@ -501,56 +890,19 @@ var absolute = (iso, locale) => {
|
|
|
501
890
|
}
|
|
502
891
|
};
|
|
503
892
|
function Avatar({ name }) {
|
|
504
|
-
return /* @__PURE__ */ (0,
|
|
893
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-avatar", "aria-hidden": "true", children: name ? initials(name) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "ban" }) });
|
|
505
894
|
}
|
|
506
895
|
function SignInLink({ ui, className, children }) {
|
|
507
|
-
return /* @__PURE__ */ (0,
|
|
508
|
-
}
|
|
509
|
-
function LikeButton({ ui, itemKey, serverCount, serverOn, scope }) {
|
|
510
|
-
const { s } = ui;
|
|
511
|
-
const state = ui.likes[itemKey];
|
|
512
|
-
const count2 = state?.count ?? serverCount;
|
|
513
|
-
const on = state?.on ?? serverOn;
|
|
514
|
-
const cls = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
|
|
515
|
-
const lead = scope === "article" ? on ? s.likedArticle : s.likeArticle : null;
|
|
516
|
-
const sr = scope === "article" ? ", " : s.likeComment;
|
|
517
|
-
const icon = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "heart" });
|
|
518
|
-
if (ui.ready && !ui.me) {
|
|
519
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(SignInLink, { ui, className: cls, children: [
|
|
520
|
-
icon,
|
|
521
|
-
lead ?? null,
|
|
522
|
-
scope === "article" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
523
|
-
" ",
|
|
524
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.likeArticleSignIn })
|
|
525
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.likeCommentSignIn }),
|
|
526
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
|
|
527
|
-
] });
|
|
528
|
-
}
|
|
529
|
-
if (ui.banned || !ui.ready) {
|
|
530
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: cls, type: "button", "aria-disabled": "true", children: [
|
|
531
|
-
icon,
|
|
532
|
-
lead,
|
|
533
|
-
scope === "article" ? " " : null,
|
|
534
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: sr }),
|
|
535
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
|
|
536
|
-
] });
|
|
537
|
-
}
|
|
538
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: cls, type: "button", "aria-pressed": on, onClick: () => ui.actions.like(itemKey, serverCount, serverOn), children: [
|
|
539
|
-
icon,
|
|
540
|
-
lead,
|
|
541
|
-
scope === "article" ? " " : null,
|
|
542
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: sr }),
|
|
543
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
|
|
544
|
-
] });
|
|
896
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("a", { className, href: `#${ui.signInId}`, children });
|
|
545
897
|
}
|
|
546
898
|
function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
|
|
547
899
|
const { s } = ui;
|
|
548
|
-
const [text, setText] = (0,
|
|
549
|
-
const [busy, setBusy] = (0,
|
|
550
|
-
const [error, setError] = (0,
|
|
551
|
-
const area = (0,
|
|
900
|
+
const [text, setText] = (0, import_react5.useState)("");
|
|
901
|
+
const [busy, setBusy] = (0, import_react5.useState)(false);
|
|
902
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
903
|
+
const area = (0, import_react5.useRef)(null);
|
|
552
904
|
const limited = ui.rateLeft > 0;
|
|
553
|
-
(0,
|
|
905
|
+
(0, import_react5.useEffect)(() => {
|
|
554
906
|
if (autoFocus) area.current?.focus();
|
|
555
907
|
}, [autoFocus]);
|
|
556
908
|
async function submit() {
|
|
@@ -584,19 +936,19 @@ function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
|
|
|
584
936
|
};
|
|
585
937
|
const helpId = `${id}-help`;
|
|
586
938
|
const errId = `${id}-err`;
|
|
587
|
-
return /* @__PURE__ */ (0,
|
|
939
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { className: "hyle-cm-compose", onSubmit: (e) => {
|
|
588
940
|
e.preventDefault();
|
|
589
941
|
void submit();
|
|
590
942
|
}, children: [
|
|
591
|
-
/* @__PURE__ */ (0,
|
|
592
|
-
/* @__PURE__ */ (0,
|
|
593
|
-
/* @__PURE__ */ (0,
|
|
943
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { name }),
|
|
944
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
|
|
945
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-as", children: [
|
|
594
946
|
s.commentingAs.split("{name}")[0],
|
|
595
|
-
/* @__PURE__ */ (0,
|
|
947
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { children: name }),
|
|
596
948
|
s.commentingAs.split("{name}")[1]
|
|
597
949
|
] }),
|
|
598
|
-
/* @__PURE__ */ (0,
|
|
599
|
-
/* @__PURE__ */ (0,
|
|
950
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { className: "hyle-sr", htmlFor: id, children: parentId ? s.replyPlaceholder : s.write }),
|
|
951
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
600
952
|
"textarea",
|
|
601
953
|
{
|
|
602
954
|
ref: area,
|
|
@@ -613,26 +965,26 @@ function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
|
|
|
613
965
|
onKeyDown: onKey
|
|
614
966
|
}
|
|
615
967
|
),
|
|
616
|
-
error ? /* @__PURE__ */ (0,
|
|
617
|
-
/* @__PURE__ */ (0,
|
|
618
|
-
/* @__PURE__ */ (0,
|
|
968
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-err", id: errId, role: "alert", children: [
|
|
969
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "alert" }),
|
|
970
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: error })
|
|
619
971
|
] }) : null,
|
|
620
|
-
/* @__PURE__ */ (0,
|
|
621
|
-
/* @__PURE__ */ (0,
|
|
622
|
-
/* @__PURE__ */ (0,
|
|
623
|
-
onCancel ? /* @__PURE__ */ (0,
|
|
624
|
-
/* @__PURE__ */ (0,
|
|
972
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-foot", children: [
|
|
973
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "grow", id: helpId, children: limited ? fill(s.rateWait, { n: ui.rateLeft }) : s.help }),
|
|
974
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cnt", children: fill(s.chars, { n: [...text].length, max: MAX_CHARS }) }),
|
|
975
|
+
onCancel ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: onCancel, children: s.cancel }) : null,
|
|
976
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn primary", type: "submit", "aria-disabled": busy || limited ? true : void 0, "aria-busy": busy || void 0, children: busy ? s.posting : parentId ? s.reply : s.post })
|
|
625
977
|
] })
|
|
626
978
|
] })
|
|
627
979
|
] });
|
|
628
980
|
}
|
|
629
981
|
function EditForm({ ui, node, initial }) {
|
|
630
982
|
const { s } = ui;
|
|
631
|
-
const [text, setText] = (0,
|
|
632
|
-
const [busy, setBusy] = (0,
|
|
633
|
-
const [error, setError] = (0,
|
|
634
|
-
const area = (0,
|
|
635
|
-
(0,
|
|
983
|
+
const [text, setText] = (0, import_react5.useState)(initial);
|
|
984
|
+
const [busy, setBusy] = (0, import_react5.useState)(false);
|
|
985
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
986
|
+
const area = (0, import_react5.useRef)(null);
|
|
987
|
+
(0, import_react5.useEffect)(() => area.current?.focus(), []);
|
|
636
988
|
const id = `${ui.idp}-edit-${node.id}`;
|
|
637
989
|
async function save() {
|
|
638
990
|
if (busy) return;
|
|
@@ -644,12 +996,12 @@ function EditForm({ ui, node, initial }) {
|
|
|
644
996
|
setError(r.reason === "tooLong" ? s.tooLong : r.reason === "closed" ? s.editClosed : r.reason === "expired" ? s.expired : r.reason === "rate" ? s.rateTitle : s.postError);
|
|
645
997
|
area.current?.focus();
|
|
646
998
|
}
|
|
647
|
-
return /* @__PURE__ */ (0,
|
|
999
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { onSubmit: (e) => {
|
|
648
1000
|
e.preventDefault();
|
|
649
1001
|
void save();
|
|
650
1002
|
}, children: [
|
|
651
|
-
/* @__PURE__ */ (0,
|
|
652
|
-
/* @__PURE__ */ (0,
|
|
1003
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { className: "hyle-sr", htmlFor: id, children: s.edit }),
|
|
1004
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
653
1005
|
"textarea",
|
|
654
1006
|
{
|
|
655
1007
|
ref: area,
|
|
@@ -672,14 +1024,14 @@ function EditForm({ ui, node, initial }) {
|
|
|
672
1024
|
}
|
|
673
1025
|
}
|
|
674
1026
|
),
|
|
675
|
-
error ? /* @__PURE__ */ (0,
|
|
676
|
-
/* @__PURE__ */ (0,
|
|
677
|
-
/* @__PURE__ */ (0,
|
|
1027
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-err", id: `${id}-err`, role: "alert", children: [
|
|
1028
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "alert" }),
|
|
1029
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: error })
|
|
678
1030
|
] }) : null,
|
|
679
|
-
/* @__PURE__ */ (0,
|
|
680
|
-
/* @__PURE__ */ (0,
|
|
681
|
-
/* @__PURE__ */ (0,
|
|
682
|
-
/* @__PURE__ */ (0,
|
|
1031
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-foot", children: [
|
|
1032
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "grow" }),
|
|
1033
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: () => ui.actions.edit(null), children: s.cancel }),
|
|
1034
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn sm primary", type: "submit", "aria-disabled": busy ? true : void 0, children: s.save })
|
|
683
1035
|
] })
|
|
684
1036
|
] });
|
|
685
1037
|
}
|
|
@@ -690,46 +1042,49 @@ function Actions({ ui, node }) {
|
|
|
690
1042
|
const until = node.canEditUntil ?? (local ? local.at + EDIT_WINDOW_MS : void 0);
|
|
691
1043
|
const minutes = until === void 0 ? 0 : Math.min(10, Math.ceil((until - Math.max(ui.now, local?.at ?? 0)) / 6e4));
|
|
692
1044
|
const canReply = node.depth < MAX_DEPTH2 && node.status === "visible";
|
|
1045
|
+
const vote = ui.votes[node.id];
|
|
1046
|
+
const shownVote = { value: vote ? vote.value : node.myVote ?? null, score: vote?.score ?? node.score ?? 0 };
|
|
693
1047
|
if (ui.confirming === node.id) {
|
|
694
|
-
return /* @__PURE__ */ (0,
|
|
695
|
-
/* @__PURE__ */ (0,
|
|
696
|
-
/* @__PURE__ */ (0,
|
|
697
|
-
/* @__PURE__ */ (0,
|
|
698
|
-
] });
|
|
1048
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-acts", role: "group", "aria-label": s.deleteConfirm, children: [
|
|
1049
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-depth", children: s.deleteConfirm }),
|
|
1050
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-cm-btn danger", type: "button", onClick: () => ui.actions.remove(node.id), children: s.delete }),
|
|
1051
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-cm-btn", type: "button", autoFocus: true, onClick: () => ui.actions.confirm(null), children: s.keep })
|
|
1052
|
+
] }, "confirm");
|
|
699
1053
|
}
|
|
700
|
-
return /* @__PURE__ */ (0,
|
|
701
|
-
node.status === "visible" ? /* @__PURE__ */ (0,
|
|
702
|
-
|
|
703
|
-
|
|
1054
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-acts", children: [
|
|
1055
|
+
node.status === "visible" && node.score !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(VoteButtons, { s, name: node.name ?? "", state: shownVote, own: mine, access: accessOf(ui), signInHref: `#${ui.signInId}`, onVote: (clicked) => ui.actions.vote(node.id, shownVote, clicked) }) : null,
|
|
1056
|
+
node.status === "visible" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ReactionBar, { s, scope: "comment", subject: node.id, likes: node.likes, counts: node.reactions, likedByMe: node.likedByMe, mine: node.myReactions, overlay: ui.reactions, access: accessOf(ui), signInHref: `#${ui.signInId}`, onToggle: (kind, count2, on) => ui.actions.react(node.id, kind, count2, on) }) : null,
|
|
1057
|
+
canReply && ui.me && !ui.banned ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { className: "hyle-cm-btn", type: "button", id: replyButtonId(ui, node.id), "aria-label": fill(s.replyTo, { name: node.name ?? "" }), "aria-expanded": ui.replyOpen === node.id, onClick: () => ui.actions.reply(ui.replyOpen === node.id ? null : node.id), children: [
|
|
1058
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "reply" }),
|
|
704
1059
|
s.reply
|
|
705
1060
|
] }) : null,
|
|
706
|
-
canReply && !ui.me ? /* @__PURE__ */ (0,
|
|
707
|
-
/* @__PURE__ */ (0,
|
|
708
|
-
/* @__PURE__ */ (0,
|
|
709
|
-
/* @__PURE__ */ (0,
|
|
1061
|
+
canReply && !ui.me ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(SignInLink, { ui, className: "hyle-cm-btn", children: [
|
|
1062
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "reply" }),
|
|
1063
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-sr", children: fill(s.replyTo, { name: node.name ?? "" }) }),
|
|
1064
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", children: s.reply })
|
|
710
1065
|
] }) : null,
|
|
711
|
-
node.status === "visible" && node.depth >= MAX_DEPTH2 ? /* @__PURE__ */ (0,
|
|
712
|
-
mine && !ui.banned && minutes > 0 ? /* @__PURE__ */ (0,
|
|
1066
|
+
node.status === "visible" && node.depth >= MAX_DEPTH2 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-depth", children: s.depthEnd }) : null,
|
|
1067
|
+
mine && !ui.banned && minutes > 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { className: "hyle-cm-btn", type: "button", onClick: () => ui.actions.edit(node.id), children: [
|
|
713
1068
|
s.edit,
|
|
714
1069
|
" ",
|
|
715
|
-
/* @__PURE__ */ (0,
|
|
1070
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("small", { children: fill(s.editLeft, { n: minutes }) })
|
|
716
1071
|
] }) : null,
|
|
717
|
-
mine && !ui.banned ? /* @__PURE__ */ (0,
|
|
1072
|
+
mine && !ui.banned ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-cm-btn danger", type: "button", onClick: () => ui.actions.confirm(node.id), children: s.delete }) : null
|
|
718
1073
|
] });
|
|
719
1074
|
}
|
|
720
1075
|
function Thread({ ui, nodes }) {
|
|
721
|
-
return /* @__PURE__ */ (0,
|
|
1076
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ol", { className: "hyle-cm-list", role: "list", children: nodes.map((node) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CommentItem, { ui, node }, node.id)) });
|
|
722
1077
|
}
|
|
723
1078
|
function CommentItem({ ui, node }) {
|
|
724
1079
|
const { s } = ui;
|
|
725
1080
|
const li = `${ui.idp}-c-${node.id}`;
|
|
726
|
-
const kids = node.kids.length > 0 ? /* @__PURE__ */ (0,
|
|
1081
|
+
const kids = node.kids.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Thread, { ui, nodes: node.kids }) : null;
|
|
727
1082
|
if (node.status === "removed") {
|
|
728
1083
|
const why = node.removedBy === "moderator" ? s.removedByModerator : node.removedBy === "author" ? s.removedByAuthor : s.removed;
|
|
729
|
-
return /* @__PURE__ */ (0,
|
|
730
|
-
/* @__PURE__ */ (0,
|
|
731
|
-
/* @__PURE__ */ (0,
|
|
732
|
-
/* @__PURE__ */ (0,
|
|
1084
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "hyle-cm", id: li, "data-depth": node.depth, "data-status": "removed", "data-removed-by": node.removedBy, children: [
|
|
1085
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("article", { "aria-label": why, children: [
|
|
1086
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { name: null }),
|
|
1087
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-main", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: why }) }) })
|
|
733
1088
|
] }),
|
|
734
1089
|
kids
|
|
735
1090
|
] });
|
|
@@ -737,34 +1092,34 @@ function CommentItem({ ui, node }) {
|
|
|
737
1092
|
const local = ui.own[node.id];
|
|
738
1093
|
const mine = node.mine || !!local;
|
|
739
1094
|
const editing = ui.editing === node.id && mine;
|
|
740
|
-
return /* @__PURE__ */ (0,
|
|
741
|
-
/* @__PURE__ */ (0,
|
|
742
|
-
/* @__PURE__ */ (0,
|
|
743
|
-
/* @__PURE__ */ (0,
|
|
744
|
-
/* @__PURE__ */ (0,
|
|
745
|
-
/* @__PURE__ */ (0,
|
|
746
|
-
mine ? /* @__PURE__ */ (0,
|
|
747
|
-
/* @__PURE__ */ (0,
|
|
748
|
-
/* @__PURE__ */ (0,
|
|
749
|
-
node.editedAt ? /* @__PURE__ */ (0,
|
|
1095
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "hyle-cm", id: li, "data-depth": node.depth, "data-status": node.status, children: [
|
|
1096
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("article", { "aria-labelledby": nameId(ui, node.id), children: [
|
|
1097
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { name: node.name }),
|
|
1098
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-main", children: [
|
|
1099
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-by", children: [
|
|
1100
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { id: nameId(ui, node.id), tabIndex: -1, children: node.name }),
|
|
1101
|
+
mine ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-tag", children: s.you }) : null,
|
|
1102
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
|
|
1103
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("time", { dateTime: node.createdAt, title: absolute(node.createdAt, ui.locale), children: relative(node.createdAt, ui.now, ui.locale, s) }),
|
|
1104
|
+
node.editedAt ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
750
1105
|
" ",
|
|
751
|
-
/* @__PURE__ */ (0,
|
|
1106
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", children: "\xB7" }),
|
|
752
1107
|
" ",
|
|
753
|
-
/* @__PURE__ */ (0,
|
|
1108
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("a", { href: `#${li}`, title: absolute(node.editedAt, ui.locale), children: s.edited })
|
|
754
1109
|
] }) : null
|
|
755
1110
|
] })
|
|
756
1111
|
] }),
|
|
757
|
-
editing ? /* @__PURE__ */ (0,
|
|
758
|
-
node.status === "held" ? /* @__PURE__ */ (0,
|
|
759
|
-
/* @__PURE__ */ (0,
|
|
760
|
-
/* @__PURE__ */ (0,
|
|
761
|
-
/* @__PURE__ */ (0,
|
|
1112
|
+
editing ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EditForm, { ui, node, initial: local?.text ?? node.text ?? hastToMarkdown(node.tree) }) : node.text !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { style: { whiteSpace: "pre-wrap" }, children: node.text }) }) : node.unrenderable ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "hyle-cm-body", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { children: s.unrenderable }) }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CommentBody, { tree: node.tree }),
|
|
1113
|
+
node.status === "held" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-held", role: "status", children: [
|
|
1114
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "clock" }),
|
|
1115
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
|
|
1116
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { children: s.held }),
|
|
762
1117
|
" ",
|
|
763
1118
|
s.heldNote
|
|
764
1119
|
] })
|
|
765
1120
|
] }) : null,
|
|
766
|
-
editing ? null : /* @__PURE__ */ (0,
|
|
767
|
-
ui.replyOpen === node.id && ui.me ? /* @__PURE__ */ (0,
|
|
1121
|
+
editing ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Actions, { ui, node }),
|
|
1122
|
+
ui.replyOpen === node.id && ui.me ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Composer, { ui, id: `${ui.idp}-rc-${node.id}`, parentId: node.id, name: ui.me, autoFocus: true, onCancel: () => ui.actions.reply(null) }) : null
|
|
768
1123
|
] })
|
|
769
1124
|
] }),
|
|
770
1125
|
kids
|
|
@@ -772,114 +1127,179 @@ function CommentItem({ ui, node }) {
|
|
|
772
1127
|
}
|
|
773
1128
|
|
|
774
1129
|
// src/react/comments.tsx
|
|
775
|
-
var
|
|
1130
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
776
1131
|
var PAGE = 20;
|
|
777
1132
|
var TICK_MS = 1e4;
|
|
778
|
-
var
|
|
1133
|
+
var NEAR = "600px 0px";
|
|
1134
|
+
var firstOf = (nodes, wanted) => {
|
|
1135
|
+
for (const n of nodes) {
|
|
1136
|
+
const found = wanted.has(n.id) ? n.id : firstOf(n.kids, wanted);
|
|
1137
|
+
if (found) return found;
|
|
1138
|
+
}
|
|
1139
|
+
return void 0;
|
|
1140
|
+
};
|
|
779
1141
|
var fill2 = (t, n) => t.replace("{n}", String(n));
|
|
780
|
-
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
const [
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
const
|
|
793
|
-
const [
|
|
794
|
-
const [
|
|
795
|
-
const [
|
|
796
|
-
const [
|
|
797
|
-
const [
|
|
798
|
-
const
|
|
799
|
-
const
|
|
800
|
-
const
|
|
801
|
-
(0,
|
|
1142
|
+
var readerOf = (data) => {
|
|
1143
|
+
const reader = isObject(data) && isObject(data.reader) ? data.reader : void 0;
|
|
1144
|
+
if (typeof reader?.name !== "string") return void 0;
|
|
1145
|
+
return { id: typeof reader.id === "string" ? reader.id : reader.name, name: reader.name };
|
|
1146
|
+
};
|
|
1147
|
+
function Comments(props) {
|
|
1148
|
+
const [readers, setReaders] = (0, import_react6.useState)(0);
|
|
1149
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ArticleComments, { ...props, onNewReader: () => setReaders((n) => n + 1) }, `${props.endpoint}
|
|
1150
|
+
${props.path}
|
|
1151
|
+
${readers}`);
|
|
1152
|
+
}
|
|
1153
|
+
function ArticleComments({ path, endpoint, signInHref, locale, labels: s, initial, initialAt, lazy = false, articleReactions = true, onNewReader }) {
|
|
1154
|
+
const idp = `hc${(0, import_react6.useId)().replace(/[^A-Za-z0-9]/g, "")}`;
|
|
1155
|
+
const [session, setSession] = (0, import_react6.useState)("loading");
|
|
1156
|
+
const [own, setOwn] = (0, import_react6.useState)({});
|
|
1157
|
+
const [held, setHeld] = (0, import_react6.useState)([]);
|
|
1158
|
+
const [unseen, setUnseen] = (0, import_react6.useState)([]);
|
|
1159
|
+
const [replyOpen, setReplyOpen] = (0, import_react6.useState)(null);
|
|
1160
|
+
const [editing, setEditing] = (0, import_react6.useState)(null);
|
|
1161
|
+
const [confirming, setConfirming] = (0, import_react6.useState)(null);
|
|
1162
|
+
const [banned, setBanned] = (0, import_react6.useState)(false);
|
|
1163
|
+
const [expired, setExpired] = (0, import_react6.useState)(false);
|
|
1164
|
+
const [rateUntil, setRateUntil] = (0, import_react6.useState)(0);
|
|
1165
|
+
const [now, setNow] = (0, import_react6.useState)(() => initialAt ?? Date.now());
|
|
1166
|
+
const [live, setLive] = (0, import_react6.useState)("");
|
|
1167
|
+
const [actionError, setActionError] = (0, import_react6.useState)(null);
|
|
1168
|
+
const [shown, setShown] = (0, import_react6.useState)(PAGE);
|
|
1169
|
+
const [focusId, setFocusId] = (0, import_react6.useState)(null);
|
|
1170
|
+
const [near, setNear] = (0, import_react6.useState)(!lazy);
|
|
1171
|
+
const [chosen, setChosen] = (0, import_react6.useState)("newest");
|
|
1172
|
+
const [loadingMore, setLoadingMore] = (0, import_react6.useState)(false);
|
|
1173
|
+
const [moreFailed, setMoreFailed] = (0, import_react6.useState)(false);
|
|
1174
|
+
const root = (0, import_react6.useRef)(null);
|
|
1175
|
+
const sortClicks = (0, import_react6.useRef)(0);
|
|
1176
|
+
const reactions = useReactions(endpoint, path);
|
|
1177
|
+
const votes = useVotes(endpoint);
|
|
1178
|
+
const { listing, order, served, reload, sort, more, retry } = useCommentListing(
|
|
1179
|
+
endpoint,
|
|
1180
|
+
path,
|
|
1181
|
+
initial,
|
|
1182
|
+
near,
|
|
1183
|
+
(fresh) => {
|
|
1184
|
+
reactions.settle(fresh);
|
|
1185
|
+
votes.settle(fresh);
|
|
1186
|
+
},
|
|
1187
|
+
() => {
|
|
1188
|
+
reactions.reset();
|
|
1189
|
+
votes.reset();
|
|
1190
|
+
setUnseen([]);
|
|
1191
|
+
setChosen("newest");
|
|
1192
|
+
setLoadingMore(false);
|
|
1193
|
+
setMoreFailed(false);
|
|
1194
|
+
}
|
|
1195
|
+
);
|
|
1196
|
+
const alive = (0, import_react6.useRef)(true);
|
|
1197
|
+
const write404 = (0, import_react6.useRef)(0);
|
|
1198
|
+
(0, import_react6.useEffect)(() => {
|
|
802
1199
|
alive.current = true;
|
|
803
1200
|
return () => void (alive.current = false);
|
|
804
1201
|
}, []);
|
|
805
|
-
(0,
|
|
1202
|
+
(0, import_react6.useEffect)(() => {
|
|
806
1203
|
if (initialAt !== void 0) setNow(Date.now());
|
|
807
1204
|
const t = setInterval(() => setNow(Date.now()), TICK_MS);
|
|
808
1205
|
return () => clearInterval(t);
|
|
809
1206
|
}, [initialAt]);
|
|
810
|
-
(0,
|
|
1207
|
+
(0, import_react6.useEffect)(() => {
|
|
811
1208
|
if (rateUntil <= Date.now()) return;
|
|
812
1209
|
const t = setTimeout(() => setNow(Date.now()), rateUntil - Date.now() + 50);
|
|
813
1210
|
return () => clearTimeout(t);
|
|
814
1211
|
}, [rateUntil]);
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
return
|
|
825
|
-
}, [endpoint, path]);
|
|
826
|
-
(0, import_react3.useEffect)(() => {
|
|
827
|
-
setListing(initial ?? "loading");
|
|
828
|
-
void load(initial !== void 0);
|
|
1212
|
+
(0, import_react6.useEffect)(() => {
|
|
1213
|
+
if (near) return;
|
|
1214
|
+
const el = root.current;
|
|
1215
|
+
if (!el || typeof IntersectionObserver === "undefined") return setNear(true);
|
|
1216
|
+
const observer = new IntersectionObserver((entries) => entries.some((e) => e.isIntersecting) && setNear(true), { rootMargin: NEAR });
|
|
1217
|
+
observer.observe(el);
|
|
1218
|
+
return () => observer.disconnect();
|
|
1219
|
+
}, [near]);
|
|
1220
|
+
(0, import_react6.useEffect)(() => {
|
|
1221
|
+
if (!near) return;
|
|
829
1222
|
void call(endpoint, "GET", "/session").then((r) => {
|
|
830
1223
|
if (!alive.current) return;
|
|
831
|
-
const reader =
|
|
832
|
-
setSession(r.status === 404 ? "off" :
|
|
1224
|
+
const reader = r.status === 200 ? readerOf(r.data) : void 0;
|
|
1225
|
+
setSession(r.status === 404 ? "off" : reader ?? null);
|
|
833
1226
|
});
|
|
834
|
-
}, [endpoint,
|
|
835
|
-
(0,
|
|
1227
|
+
}, [endpoint, near]);
|
|
1228
|
+
(0, import_react6.useEffect)(() => {
|
|
1229
|
+
if (typeof listing === "object") setUnseen((u) => stillUnseen(u, listing));
|
|
1230
|
+
}, [listing]);
|
|
1231
|
+
(0, import_react6.useEffect)(() => {
|
|
836
1232
|
if (!focusId) return;
|
|
837
1233
|
const el = document.getElementById(`${idp}-${focusId}-n`);
|
|
838
1234
|
if (el) {
|
|
839
1235
|
el.focus();
|
|
840
1236
|
setFocusId(null);
|
|
841
1237
|
}
|
|
842
|
-
}, [focusId, listing, held, idp]);
|
|
843
|
-
const
|
|
1238
|
+
}, [focusId, listing, held, unseen, idp]);
|
|
1239
|
+
const signedIn = typeof session === "object" ? session : null;
|
|
1240
|
+
const me = signedIn?.name ?? null;
|
|
844
1241
|
const rateLeft = Math.max(0, Math.ceil((rateUntil - now) / 1e3));
|
|
845
1242
|
const signInId = `${idp}-signin`;
|
|
846
|
-
function
|
|
1243
|
+
async function recheck(status) {
|
|
1244
|
+
if (status !== 401 && !expired) return;
|
|
1245
|
+
const r = await call(endpoint, "GET", "/session");
|
|
1246
|
+
const reader = r.status === 200 ? readerOf(r.data) : void 0;
|
|
1247
|
+
if (alive.current && reader && reader.id !== signedIn?.id) onNewReader();
|
|
1248
|
+
}
|
|
1249
|
+
function failed(status, refusal) {
|
|
847
1250
|
if (status === 401) setExpired(true);
|
|
848
|
-
setActionError(status === 401 ? s.expired : s.actionError);
|
|
1251
|
+
setActionError(status === 401 ? s.expired : status === 429 ? s.slowDown : refusal ?? s.actionError);
|
|
849
1252
|
}
|
|
850
|
-
async function
|
|
851
|
-
if (!me || banned
|
|
852
|
-
const prev = likes[key] ?? { on: serverOn, count: serverCount };
|
|
853
|
-
const count2 = prev.count ?? serverCount;
|
|
854
|
-
pending.current.add(key);
|
|
1253
|
+
async function react(subject, kind, count2, on) {
|
|
1254
|
+
if (!me || banned) return;
|
|
855
1255
|
setActionError(null);
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
if (!
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
1256
|
+
const r = await reactions.toggle(subject, kind, count2, on);
|
|
1257
|
+
if (!r || !alive.current) return;
|
|
1258
|
+
void recheck(r.ok ? 200 : r.status);
|
|
1259
|
+
if (!r.ok) return failed(r.status);
|
|
1260
|
+
setLive((r.on ? s.reactionAddedLive : s.reactionRemovedLive).replace("{kind}", kindName(s, kind)));
|
|
1261
|
+
}
|
|
1262
|
+
async function vote(id, current, clicked) {
|
|
1263
|
+
if (!me || banned) return;
|
|
1264
|
+
setActionError(null);
|
|
1265
|
+
const r = await votes.cast(id, current, clicked);
|
|
1266
|
+
if (!r || !alive.current) return;
|
|
1267
|
+
void recheck(r.ok ? 200 : r.status);
|
|
1268
|
+
if (!r.ok) return failed(r.status, r.status === 400 ? s.voteRefused : void 0);
|
|
1269
|
+
setLive(fill2(r.state.value === 1 ? s.upvotedLive : r.state.value === -1 ? s.downvotedLive : s.voteRemovedLive, r.state.score));
|
|
1270
|
+
}
|
|
1271
|
+
async function choose(next) {
|
|
1272
|
+
if (next === chosen) return;
|
|
1273
|
+
const click = sortClicks.current += 1;
|
|
1274
|
+
setChosen(next);
|
|
1275
|
+
setActionError(null);
|
|
1276
|
+
setMoreFailed(false);
|
|
1277
|
+
const showing = await sort(next);
|
|
1278
|
+
if (!alive.current || click !== sortClicks.current || showing === void 0) return;
|
|
1279
|
+
if (showing !== next) {
|
|
1280
|
+
setChosen(showing);
|
|
1281
|
+
return setActionError(s.sortError);
|
|
864
1282
|
}
|
|
865
|
-
|
|
866
|
-
|
|
1283
|
+
setShown(PAGE);
|
|
1284
|
+
setLive(next === "top" ? s.sortedTopLive : s.sortedNewestLive);
|
|
867
1285
|
}
|
|
868
1286
|
async function post(text, parentId) {
|
|
869
1287
|
const r = await call(endpoint, "POST", "/comments", { path, body: text, ...parentId ? { parent_id: parentId } : {} });
|
|
870
|
-
|
|
1288
|
+
void recheck(r.status);
|
|
1289
|
+
const created = r.status === 201 && isObject(r.data) && isObject(r.data.comment) ? r.data.comment : void 0;
|
|
871
1290
|
if (typeof created?.id === "string" && alive.current) {
|
|
872
1291
|
const id = created.id;
|
|
873
1292
|
write404.current = 0;
|
|
874
1293
|
setOwn((o) => ({ ...o, [id]: { text, at: Date.now(), parentId } }));
|
|
875
1294
|
setExpired(false);
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
1295
|
+
const status = created.status === "held" ? "held" : "visible";
|
|
1296
|
+
const local = { id, parentId, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1297
|
+
setUnseen((u) => [{ ...local, status }, ...u]);
|
|
1298
|
+
if (status === "held") setHeld((h) => [local, ...h]);
|
|
1299
|
+
setLive(status === "held" ? s.heldLive : s.postedLive);
|
|
880
1300
|
setShown(Number.MAX_SAFE_INTEGER);
|
|
881
1301
|
setFocusId(id);
|
|
882
|
-
await
|
|
1302
|
+
await reload(true);
|
|
883
1303
|
return { ok: true };
|
|
884
1304
|
}
|
|
885
1305
|
if (r.status === 429) {
|
|
@@ -888,10 +1308,11 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
888
1308
|
return { ok: false, reason: "rate" };
|
|
889
1309
|
}
|
|
890
1310
|
if (r.status === 404) {
|
|
891
|
-
const [again, who] = await Promise.all([
|
|
1311
|
+
const [again, who] = await Promise.all([reload(true), call(endpoint, "GET", "/session")]);
|
|
892
1312
|
write404.current += 1;
|
|
893
|
-
const
|
|
894
|
-
if (alive.current &&
|
|
1313
|
+
const reader = who.status === 200 ? readerOf(who.data) : void 0;
|
|
1314
|
+
if (alive.current && reader && reader.id !== signedIn?.id) onNewReader();
|
|
1315
|
+
else if (alive.current && reader && again && write404.current >= 2) setBanned(true);
|
|
895
1316
|
return { ok: false, reason: "error" };
|
|
896
1317
|
}
|
|
897
1318
|
if (r.status === 401) setExpired(true);
|
|
@@ -899,15 +1320,20 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
899
1320
|
}
|
|
900
1321
|
async function save(id, text) {
|
|
901
1322
|
const r = await call(endpoint, "PATCH", `/comments/${id}`, { body: text });
|
|
1323
|
+
void recheck(r.status);
|
|
902
1324
|
if (r.status === 200 && alive.current) {
|
|
903
1325
|
const meta = own[id];
|
|
904
1326
|
setOwn((o) => ({ ...o, [id]: { text, at: o[id]?.at ?? Date.now(), parentId: o[id]?.parentId ?? null } }));
|
|
905
1327
|
setHeld((h) => h.map((c) => c.id === id ? { ...c, text } : c));
|
|
1328
|
+
setUnseen((u) => u.map((c) => c.id === id ? { ...c, text } : c));
|
|
906
1329
|
setEditing(null);
|
|
907
1330
|
setLive(s.savedLive);
|
|
908
1331
|
setFocusId(id);
|
|
909
|
-
const fresh = await
|
|
910
|
-
if (fresh && !fresh.
|
|
1332
|
+
const fresh = await reload(true);
|
|
1333
|
+
if (fresh && !fresh.truncated && !fresh.next_cursor && !fresh.comments.some((c) => c.id === id)) {
|
|
1334
|
+
setUnseen((u) => u.filter((c) => c.id !== id));
|
|
1335
|
+
setHeld((h) => h.some((c) => c.id === id) ? h : [{ id, parentId: meta?.parentId ?? null, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() }, ...h]);
|
|
1336
|
+
}
|
|
911
1337
|
return { ok: true };
|
|
912
1338
|
}
|
|
913
1339
|
if (r.status === 429) {
|
|
@@ -922,15 +1348,38 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
922
1348
|
setActionError(null);
|
|
923
1349
|
const r = await call(endpoint, "DELETE", `/comments/${id}`);
|
|
924
1350
|
if (!alive.current) return;
|
|
1351
|
+
void recheck(r.status);
|
|
925
1352
|
setConfirming(null);
|
|
926
1353
|
if (r.status !== 200) return failed(r.status);
|
|
927
1354
|
setHeld((h) => h.filter((c) => c.id !== id));
|
|
1355
|
+
setUnseen((u) => u.filter((c) => c.id !== id));
|
|
928
1356
|
setOwn(({ [id]: _gone, ...rest }) => rest);
|
|
929
1357
|
setLive(s.deletedLive);
|
|
930
|
-
await
|
|
1358
|
+
await reload(true);
|
|
931
1359
|
}
|
|
932
|
-
if (session === "off" || listing === "off") return null;
|
|
933
1360
|
const loaded = typeof listing === "object" ? listing : void 0;
|
|
1361
|
+
const sortable = !!loaded && isSortable(loaded);
|
|
1362
|
+
const thread = loaded ? arrangeThread(loaded, served, held, unseen) : [];
|
|
1363
|
+
const oldestFirstPages = !!loaded && arrivesAs(loaded, served) === void 0;
|
|
1364
|
+
async function showMore() {
|
|
1365
|
+
if (thread.length > shown) {
|
|
1366
|
+
setShown(shown + PAGE);
|
|
1367
|
+
setFocusId(thread.slice(shown).find((n) => n.status !== "removed")?.id ?? null);
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
if (loadingMore) return;
|
|
1371
|
+
setLoadingMore(true);
|
|
1372
|
+
setMoreFailed(false);
|
|
1373
|
+
const r = await more();
|
|
1374
|
+
if (!alive.current) return;
|
|
1375
|
+
setLoadingMore(false);
|
|
1376
|
+
if (!r) return;
|
|
1377
|
+
if (!r.ok) return setMoreFailed(true);
|
|
1378
|
+
setShown(arrivesAs(r.listing, r.sort) === void 0 ? Number.MAX_SAFE_INTEGER : Math.min(shown, thread.length) + PAGE);
|
|
1379
|
+
setFocusId(firstOf(arrangeThread(r.listing, r.sort, held, unseen), r.added) ?? null);
|
|
1380
|
+
setLive(fill2(s.loadedLive, r.added.size));
|
|
1381
|
+
}
|
|
1382
|
+
if (session === "off" || listing === "off") return null;
|
|
934
1383
|
const ui = {
|
|
935
1384
|
s,
|
|
936
1385
|
locale,
|
|
@@ -938,17 +1387,18 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
938
1387
|
ready: session !== "loading",
|
|
939
1388
|
me,
|
|
940
1389
|
banned,
|
|
941
|
-
signInHref,
|
|
942
1390
|
signInId,
|
|
943
1391
|
idp,
|
|
944
1392
|
rateLeft,
|
|
945
1393
|
own,
|
|
946
|
-
|
|
1394
|
+
reactions: reactions.overlay,
|
|
1395
|
+
votes: votes.overlay,
|
|
947
1396
|
replyOpen,
|
|
948
1397
|
editing,
|
|
949
1398
|
confirming,
|
|
950
1399
|
actions: {
|
|
951
|
-
|
|
1400
|
+
react: (subject, kind, count2, on) => void react(subject, kind, count2, on),
|
|
1401
|
+
vote: (id, current, clicked) => void vote(id, current, clicked),
|
|
952
1402
|
reply: (id) => {
|
|
953
1403
|
const previous = replyOpen;
|
|
954
1404
|
setReplyOpen(id);
|
|
@@ -961,83 +1411,88 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
961
1411
|
remove: (id) => void remove(id)
|
|
962
1412
|
}
|
|
963
1413
|
};
|
|
964
|
-
const thread = loaded ? buildThread(loaded, held) : [];
|
|
965
1414
|
const hid = `${idp}-h`;
|
|
966
1415
|
const canWrite = !!me && !banned;
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
/* @__PURE__ */ (0,
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
/* @__PURE__ */ (0,
|
|
978
|
-
|
|
1416
|
+
const unfetched = !!loaded?.next_cursor;
|
|
1417
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: "hyle-comments", ref: root, "aria-labelledby": hid, "data-slot-component": "Comments", children: [
|
|
1418
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-head", children: [
|
|
1419
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("h2", { id: hid, children: [
|
|
1420
|
+
s.heading,
|
|
1421
|
+
loaded ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1422
|
+
" ",
|
|
1423
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-cm-count", "aria-label": fill2(s.countLabel, loaded.comment_count), children: loaded.comment_count })
|
|
1424
|
+
] }) : null
|
|
1425
|
+
] }),
|
|
1426
|
+
sortable && (order === "top" || thread.length > 1) ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-cm-sort", role: "group", "aria-label": s.sort, children: ["newest", "top"].map((o) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { className: "hyle-cm-btn", type: "button", "aria-pressed": chosen === o, onClick: () => void choose(o), children: o === "top" ? s.sortTop : s.sortNewest }, o)) }) : null
|
|
1427
|
+
] }),
|
|
1428
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-sr", role: "status", "aria-live": "polite", children: live }),
|
|
1429
|
+
actionError ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
|
|
1430
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
|
|
1431
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: actionError })
|
|
979
1432
|
] }) : null,
|
|
980
|
-
listing === "error" ? /* @__PURE__ */ (0,
|
|
981
|
-
/* @__PURE__ */ (0,
|
|
982
|
-
/* @__PURE__ */ (0,
|
|
983
|
-
/* @__PURE__ */ (0,
|
|
984
|
-
/* @__PURE__ */ (0,
|
|
1433
|
+
listing === "error" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "bad", role: "alert", children: [
|
|
1434
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
|
|
1435
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
|
|
1436
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.loadError }),
|
|
1437
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.loadErrorBody })
|
|
985
1438
|
] }),
|
|
986
|
-
/* @__PURE__ */ (0,
|
|
987
|
-
|
|
988
|
-
void load(false);
|
|
989
|
-
}, children: [
|
|
990
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "refresh" }),
|
|
1439
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { className: "hyle-btn sm", type: "button", onClick: retry, children: [
|
|
1440
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "refresh" }),
|
|
991
1441
|
s.retry
|
|
992
1442
|
] })
|
|
993
|
-
] }) : /* @__PURE__ */ (0,
|
|
994
|
-
loaded ? /* @__PURE__ */ (0,
|
|
995
|
-
held.length > 0 || (loaded?.mine_held?.length ?? 0) > 0 ? /* @__PURE__ */ (0,
|
|
996
|
-
/* @__PURE__ */ (0,
|
|
997
|
-
/* @__PURE__ */ (0,
|
|
998
|
-
/* @__PURE__ */ (0,
|
|
999
|
-
/* @__PURE__ */ (0,
|
|
1443
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1444
|
+
loaded && articleReactions ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-react", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ReactionBar, { s, scope: "article", subject: "article", likes: loaded.like_count, counts: loaded.reaction_counts, likedByMe: loaded.liked_by_me === true, mine: loaded.my_reactions, overlay: reactions.overlay, access: accessOf(ui), signInHref: `#${signInId}`, onToggle: (kind, count2, on) => void react("article", kind, count2, on) }) }) : null,
|
|
1445
|
+
held.length > 0 || (loaded?.mine_held?.length ?? 0) > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1446
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "clock" }),
|
|
1447
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
|
|
1448
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.heldBanner }),
|
|
1449
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.heldBannerBody })
|
|
1000
1450
|
] })
|
|
1001
1451
|
] }) : null,
|
|
1002
|
-
rateLeft > 0 ? /* @__PURE__ */ (0,
|
|
1003
|
-
/* @__PURE__ */ (0,
|
|
1004
|
-
/* @__PURE__ */ (0,
|
|
1005
|
-
/* @__PURE__ */ (0,
|
|
1006
|
-
/* @__PURE__ */ (0,
|
|
1452
|
+
rateLeft > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", children: [
|
|
1453
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "clock" }),
|
|
1454
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
|
|
1455
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.rateTitle }),
|
|
1456
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.rateBody })
|
|
1007
1457
|
] })
|
|
1008
1458
|
] }) : null,
|
|
1009
|
-
banned ? /* @__PURE__ */ (0,
|
|
1010
|
-
/* @__PURE__ */ (0,
|
|
1011
|
-
/* @__PURE__ */ (0,
|
|
1012
|
-
/* @__PURE__ */ (0,
|
|
1013
|
-
/* @__PURE__ */ (0,
|
|
1459
|
+
banned ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", children: [
|
|
1460
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "ban" }),
|
|
1461
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
|
|
1462
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.bannedTitle }),
|
|
1463
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.bannedBody })
|
|
1014
1464
|
] })
|
|
1015
1465
|
] }) : null,
|
|
1016
|
-
session !== "loading" && (!me || expired) ? /* @__PURE__ */ (0,
|
|
1017
|
-
/* @__PURE__ */ (0,
|
|
1018
|
-
/* @__PURE__ */ (0,
|
|
1466
|
+
session !== "loading" && (!me || expired) ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-signin", id: signInId, children: [
|
|
1467
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { children: [
|
|
1468
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.signInTitle }),
|
|
1019
1469
|
s.signInBody
|
|
1020
1470
|
] }),
|
|
1021
|
-
signInHref ? /* @__PURE__ */ (0,
|
|
1471
|
+
signInHref ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { className: "hyle-btn primary", href: signInHref, children: s.signIn }) : null
|
|
1022
1472
|
] }) : null,
|
|
1023
|
-
canWrite ? /* @__PURE__ */ (0,
|
|
1024
|
-
!loaded ? /* @__PURE__ */ (0,
|
|
1025
|
-
/* @__PURE__ */ (0,
|
|
1026
|
-
/* @__PURE__ */ (0,
|
|
1027
|
-
/* @__PURE__ */ (0,
|
|
1028
|
-
/* @__PURE__ */ (0,
|
|
1029
|
-
/* @__PURE__ */ (0,
|
|
1030
|
-
/* @__PURE__ */ (0,
|
|
1031
|
-
/* @__PURE__ */ (0,
|
|
1473
|
+
canWrite ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Composer, { ui, id: `${idp}-new`, parentId: null, name: me }) : null,
|
|
1474
|
+
!loaded ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { role: "status", "aria-live": "polite", "aria-busy": "true", children: [
|
|
1475
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sr", children: s.loading }),
|
|
1476
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { "aria-hidden": "true", children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-sk", children: [
|
|
1477
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk c" }),
|
|
1478
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1479
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: 120 } }),
|
|
1480
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "100%" } }),
|
|
1481
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "72%" } })
|
|
1032
1482
|
] })
|
|
1033
1483
|
] }, i)) })
|
|
1034
|
-
] }) : thread.length === 0 ? /* @__PURE__ */ (0,
|
|
1035
|
-
/* @__PURE__ */ (0,
|
|
1036
|
-
/* @__PURE__ */ (0,
|
|
1037
|
-
] }) : /* @__PURE__ */ (0,
|
|
1038
|
-
/* @__PURE__ */ (0,
|
|
1039
|
-
|
|
1040
|
-
|
|
1484
|
+
] }) : thread.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-empty", children: [
|
|
1485
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.empty }),
|
|
1486
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: s.emptyBody })
|
|
1487
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1488
|
+
sortable && oldestFirstPages && unfetched ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-cm-note", children: s.newerLater }) : null,
|
|
1489
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Thread, { ui, nodes: thread.slice(0, shown) }),
|
|
1490
|
+
moreFailed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
|
|
1491
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
|
|
1492
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: s.moreError })
|
|
1493
|
+
] }) : null,
|
|
1494
|
+
thread.length > shown || unfetched ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "hyle-cm-more", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { className: "hyle-btn", type: "button", "aria-disabled": loadingMore || void 0, "aria-busy": loadingMore || void 0, onClick: () => void showMore(), children: s.more }) }) : null,
|
|
1495
|
+
loaded.truncated && !unfetched ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-cm-note", children: s.truncated }) : null
|
|
1041
1496
|
] })
|
|
1042
1497
|
] })
|
|
1043
1498
|
] });
|