@tdacorp/hyle-sdk 0.17.0 → 0.22.2
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 +261 -42
- package/dist/check-routes-bin.js +190 -53
- package/dist/{chunk-6VOHFFA5.js → chunk-7T5EEJHK.js} +2 -2
- package/dist/chunk-DUPT6XLB.js +57 -0
- package/dist/chunk-IW3TUD4G.js +841 -0
- package/dist/{chunk-MGSUQBDW.js → chunk-KU7LWK4E.js} +249 -24
- package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
- package/dist/chunk-SFFBZFEN.js +178 -0
- package/dist/chunk-U74B7AUG.js +398 -0
- package/dist/chunk-ZIW6FDU2.js +1126 -0
- package/dist/client-BGjmEWhN.d.cts +207 -0
- package/dist/client-D0LTpr3Y.d.ts +207 -0
- package/dist/code-copy.cjs +74 -0
- package/dist/code-copy.d.cts +18 -0
- package/dist/code-copy.d.ts +18 -0
- package/dist/code-copy.js +50 -0
- package/dist/comments.cjs +738 -280
- package/dist/comments.d.cts +66 -3
- package/dist/comments.d.ts +66 -3
- package/dist/comments.js +419 -331
- package/dist/{diagram-viewer-FJPED4SN.js → diagram-viewer-XY3CG75U.js} +62 -21
- package/dist/docs-enhance.cjs +7 -4
- package/dist/docs-enhance.d.cts +5 -3
- package/dist/docs-enhance.d.ts +5 -3
- package/dist/docs-enhance.js +8 -5
- package/dist/{embed-DNTZ2UXv.d.ts → embed-CbtsbZs3.d.cts} +5 -3
- package/dist/{embed-BmdwA2G9.d.cts → embed-Cf_2ZR5x.d.ts} +5 -3
- 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 +886 -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 +244 -24
- package/dist/index.d.cts +22 -68
- package/dist/index.d.ts +22 -68
- package/dist/index.js +12 -2
- package/dist/{labels-nmukKYgL.d.cts → labels-CrA-iqTN.d.cts} +9 -0
- package/dist/{labels-nmukKYgL.d.ts → labels-CrA-iqTN.d.ts} +9 -0
- package/dist/mermaid-diagram.cjs +441 -125
- package/dist/mermaid-diagram.d.cts +23 -7
- package/dist/mermaid-diagram.d.ts +23 -7
- package/dist/mermaid-diagram.js +213 -51
- package/dist/mermaid-image.cjs +137 -60
- package/dist/mermaid-image.d.cts +4 -3
- package/dist/mermaid-image.d.ts +4 -3
- package/dist/mermaid-image.js +27 -28
- package/dist/next.cjs +836 -304
- package/dist/next.d.cts +45 -20
- package/dist/next.d.ts +45 -20
- package/dist/next.js +151 -40
- 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 +603 -240
- package/dist/react.d.cts +148 -30
- package/dist/react.d.ts +148 -30
- package/dist/react.js +26 -4
- 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-euZ4-aC9.d.cts → resolve-BnIv7aB7.d.cts} +2 -2
- package/dist/{resolve-Ae7UFjsQ.d.ts → resolve-BysHtZ_i.d.ts} +2 -2
- package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
- package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
- package/dist/sanitize-BpY_AdZh.d.cts +23 -0
- package/dist/sanitize-BpY_AdZh.d.ts +23 -0
- package/dist/styles.css +100 -29
- package/dist/toc-spy.cjs +60 -0
- package/dist/toc-spy.d.cts +15 -0
- package/dist/toc-spy.d.ts +15 -0
- package/dist/toc-spy.js +36 -0
- package/dist/{types-Czt887Iv.d.cts → types-D09Z072G.d.cts} +57 -2
- package/dist/{types-Czt887Iv.d.ts → types-D09Z072G.d.ts} +57 -2
- package/dist/use-cache.cjs +89 -13
- package/dist/use-cache.d.cts +12 -5
- package/dist/use-cache.d.ts +12 -5
- package/dist/use-cache.js +8 -8
- 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-67IOIAVW.js +0 -35
- package/dist/chunk-DMK4XQLU.js +0 -1556
- package/dist/chunk-PJMJMP66.js +0 -63
- 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,35 +210,169 @@ 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
|
|
162
363
|
var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
|
|
163
364
|
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
164
|
-
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
|
|
365
|
+
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg|woff2";
|
|
165
366
|
var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
|
|
166
|
-
var
|
|
367
|
+
var THEME_FONT = new RegExp(`^/assets/${UUID}\\.woff2$`);
|
|
368
|
+
var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
|
|
369
|
+
var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
370
|
+
var PREVIEW_PARAM = "hyle_preview";
|
|
371
|
+
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
372
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
|
|
167
373
|
function hostAssetSrc(src) {
|
|
168
|
-
const file = HYLE_ASSET_URL.exec(src)
|
|
169
|
-
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
|
|
374
|
+
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
375
|
+
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
|
|
170
376
|
}
|
|
171
377
|
|
|
172
378
|
// src/react/sanitize.ts
|
|
@@ -187,8 +393,15 @@ var isScalar = (v) => typeof v === "string" || typeof v === "number" || typeof v
|
|
|
187
393
|
var matches = (re) => (v) => typeof v === "string" && re.test(v);
|
|
188
394
|
var ID_PREFIX = "user-content-";
|
|
189
395
|
var scopeId = (id) => id.startsWith(ID_PREFIX) ? id : ID_PREFIX + id;
|
|
190
|
-
var ID_BODY = /^[\p{L}\p{N}
|
|
191
|
-
|
|
396
|
+
var ID_BODY = /^[\p{L}\p{M}\p{N}\p{Pc}:.-]{1,180}$/u;
|
|
397
|
+
function isIdValue(v) {
|
|
398
|
+
if (typeof v !== "string") return false;
|
|
399
|
+
try {
|
|
400
|
+
return ID_BODY.test(decodeURIComponent(v.startsWith(ID_PREFIX) ? v.slice(ID_PREFIX.length) : v));
|
|
401
|
+
} catch {
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
192
405
|
var CLASS_TOKEN = /^[A-Za-z_][\w:-]*$/;
|
|
193
406
|
var classTokens = (v) => {
|
|
194
407
|
const tokens = Array.isArray(v) ? v : typeof v === "string" ? v.split(/\s+/) : [];
|
|
@@ -201,6 +414,7 @@ var isLength = matches(/^[\d.]+(em|px|%)?$/);
|
|
|
201
414
|
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"]);
|
|
202
415
|
var STYLE_LENGTH = /^(-?\d+(?:\.\d+)?)(em|px|%)?$/;
|
|
203
416
|
var MAX_STYLE_MAGNITUDE = 100;
|
|
417
|
+
var MAX_MARGIN_MAGNITUDE = 20;
|
|
204
418
|
function isKatexStyle(v, ctx) {
|
|
205
419
|
if (typeof v !== "string" || !ctx.katex) return false;
|
|
206
420
|
return v.split(";").filter((d) => d !== "").every((decl) => {
|
|
@@ -208,7 +422,8 @@ function isKatexStyle(v, ctx) {
|
|
|
208
422
|
if (extra.length > 0 || prop === void 0 || value === void 0) return false;
|
|
209
423
|
if (prop === "position") return value === "relative";
|
|
210
424
|
const m = STYLE_LENGTH.exec(value);
|
|
211
|
-
|
|
425
|
+
const max = prop.startsWith("margin-") ? MAX_MARGIN_MAGNITUDE : MAX_STYLE_MAGNITUDE;
|
|
426
|
+
return STYLE_PROPS.has(prop) && m !== null && Math.abs(Number(m[1])) <= max;
|
|
212
427
|
});
|
|
213
428
|
}
|
|
214
429
|
function isSafeUrl(value, kind) {
|
|
@@ -231,8 +446,10 @@ var MERMAID_SRCDOC = new RegExp(
|
|
|
231
446
|
`^<!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>$`
|
|
232
447
|
);
|
|
233
448
|
var isMermaidSrcdoc = (v) => typeof v === "string" && v.length <= MAX_SRCDOC && MERMAID_SRCDOC.test(v);
|
|
234
|
-
var RENDER_REF =
|
|
449
|
+
var RENDER_REF = new RegExp(`^(/assets/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\.svg(?:${PREVIEW_QUERY_SOURCE})?) ([1-9]\\d{0,5}) ([1-9]\\d{0,5})$`);
|
|
235
450
|
var isRenderRef = matches(RENDER_REF);
|
|
451
|
+
var YOUTUBE_WATCH = /^https:\/\/www\.youtube\.com\/watch\?v=([A-Za-z0-9_-]{11})$/;
|
|
452
|
+
var youtubeId = (href) => typeof href === "string" ? YOUTUBE_WATCH.exec(href)?.[1] : void 0;
|
|
236
453
|
var heading = { id: isIdValue, className: isClass };
|
|
237
454
|
var ATTRS = new Map(
|
|
238
455
|
Object.entries({
|
|
@@ -248,6 +465,7 @@ var ATTRS = new Map(
|
|
|
248
465
|
tbody: {},
|
|
249
466
|
tr: {},
|
|
250
467
|
ol: {},
|
|
468
|
+
kbd: {},
|
|
251
469
|
ul: { className: isClass },
|
|
252
470
|
li: { id: isIdValue, className: isClass },
|
|
253
471
|
h1: heading,
|
|
@@ -256,8 +474,8 @@ var ATTRS = new Map(
|
|
|
256
474
|
h4: heading,
|
|
257
475
|
h5: heading,
|
|
258
476
|
h6: heading,
|
|
259
|
-
a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, className: isClass },
|
|
260
|
-
img: { src: isSrc, alt: isString, width: isPixels, height: isPixels },
|
|
477
|
+
a: { href: isHref, id: isIdValue, ariaDescribedBy: isIdValue, ariaLabel: isString, dataFootnoteRef: isScalar, dataFootnoteBackref: isScalar, dataEmbed: matches(/^youtube$/), className: isClass },
|
|
478
|
+
img: { src: isSrc, alt: isString, title: isString, width: isPixels, height: isPixels },
|
|
261
479
|
table: {},
|
|
262
480
|
th: { scope: matches(/^(row|col|rowgroup|colgroup)$/), align: isAlign },
|
|
263
481
|
td: { align: isAlign },
|
|
@@ -280,8 +498,10 @@ function textOf(node, depth = 0) {
|
|
|
280
498
|
if (node.type === "text") return typeof node.value === "string" ? node.value : "";
|
|
281
499
|
return Array.isArray(node.children) ? node.children.map((c) => textOf(c, depth + 1)).join("") : "";
|
|
282
500
|
}
|
|
501
|
+
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)));
|
|
502
|
+
var collapse = (text) => text.replace(/\s+/g, " ").trim();
|
|
283
503
|
var CALLOUT_MARKER = /^\s*\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/i;
|
|
284
|
-
var CALLOUT_KIND = { note: "note", tip: "tip", important: "
|
|
504
|
+
var CALLOUT_KIND = { note: "note", tip: "tip", important: "important", warning: "warning", caution: "caution" };
|
|
285
505
|
function toCallout(children) {
|
|
286
506
|
const first = children.find((c) => c.type === "element");
|
|
287
507
|
const lead = first?.tagName === "p" ? first.children[0] : void 0;
|
|
@@ -293,6 +513,21 @@ function toCallout(children) {
|
|
|
293
513
|
const kind = CALLOUT_KIND[(marker[1] ?? "note").toLowerCase()] ?? "note";
|
|
294
514
|
return { type: "element", tagName: "callout", properties: { kind }, children: [...body, ...children.slice(children.indexOf(first) + 1)] };
|
|
295
515
|
}
|
|
516
|
+
var isBlank = (node) => node.type === "text" && node.value.trim() === "";
|
|
517
|
+
function soleElement(children) {
|
|
518
|
+
const [only, ...more] = children.filter((c) => !isBlank(c));
|
|
519
|
+
return more.length === 0 && only?.type === "element" ? only : void 0;
|
|
520
|
+
}
|
|
521
|
+
function toFigure(children) {
|
|
522
|
+
const only = soleElement(children);
|
|
523
|
+
const img = only?.tagName === "a" ? soleElement(only.children) : only;
|
|
524
|
+
if (!only || img?.tagName !== "img" || typeof img.properties.src !== "string") return void 0;
|
|
525
|
+
const { title, ...properties } = img.properties;
|
|
526
|
+
const bare = { ...img, properties };
|
|
527
|
+
const media = only === img ? bare : { ...only, children: [bare] };
|
|
528
|
+
const caption = typeof title === "string" && title.trim() ? [{ type: "element", tagName: "figcaption", properties: {}, children: [{ type: "text", value: title }] }] : [];
|
|
529
|
+
return { type: "element", tagName: "figure", properties: { dataSlotComponent: "Image" }, children: [media, ...caption] };
|
|
530
|
+
}
|
|
296
531
|
function clean(node, depth, ctx, budget) {
|
|
297
532
|
if (!isObject2(node) || depth > MAX_DEPTH) return [];
|
|
298
533
|
if (++budget.nodes > MAX_NODES) throw new HastLimitError("content has too many nodes");
|
|
@@ -326,6 +561,11 @@ function clean(node, depth, ctx, budget) {
|
|
|
326
561
|
}
|
|
327
562
|
for (const key of ["id", "ariaDescribedBy"]) if (typeof properties[key] === "string") properties[key] = scopeId(properties[key]);
|
|
328
563
|
if (tag === "a" && typeof properties.href === "string" && properties.href.trim().startsWith("#")) properties.href = `#${scopeId(properties.href.trim().slice(1))}`;
|
|
564
|
+
if (tag === "a" && properties.dataEmbed !== void 0 && youtubeId(properties.href) === void 0) delete properties.dataEmbed;
|
|
565
|
+
if (tag === "p") {
|
|
566
|
+
const figure = toFigure(children);
|
|
567
|
+
if (figure) return [figure];
|
|
568
|
+
}
|
|
329
569
|
if (tag === "blockquote") {
|
|
330
570
|
const callout = toCallout(children);
|
|
331
571
|
if (callout) return [callout];
|
|
@@ -337,9 +577,9 @@ function sanitizeHast(tree, title, description) {
|
|
|
337
577
|
const raw = isObject2(tree) && tree.type === "root" && Array.isArray(tree.children) ? tree.children : [];
|
|
338
578
|
const elements = raw.filter((n) => isObject2(n) && n.type === "element");
|
|
339
579
|
const [first] = elements;
|
|
340
|
-
const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && textOf(first)
|
|
580
|
+
const skip = title !== void 0 && isObject2(first) && first.tagName === "h1" && collapse(textOf(first)) === collapse(title) ? first : void 0;
|
|
341
581
|
const lead = elements[skip ? 1 : 0];
|
|
342
|
-
const repeat = description && isObject2(lead) && lead.tagName === "p" && textOf(lead)
|
|
582
|
+
const repeat = description && isObject2(lead) && lead.tagName === "p" && collapse(textOf(lead)) === collapse(description) && !holdsEmbed(lead) ? lead : void 0;
|
|
343
583
|
const budget = { nodes: 0, text: 0 };
|
|
344
584
|
return { type: "root", children: raw.filter((n) => n !== skip && n !== repeat).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
|
|
345
585
|
}
|
|
@@ -368,7 +608,7 @@ function CommentBody({ tree }) {
|
|
|
368
608
|
if (error instanceof HastLimitError) return null;
|
|
369
609
|
throw error;
|
|
370
610
|
}
|
|
371
|
-
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:
|
|
611
|
+
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" }) });
|
|
372
612
|
}
|
|
373
613
|
|
|
374
614
|
// src/react/comments-markdown.ts
|
|
@@ -424,6 +664,9 @@ function hastToMarkdown(tree) {
|
|
|
424
664
|
}
|
|
425
665
|
}
|
|
426
666
|
|
|
667
|
+
// src/react/comments-votes.tsx
|
|
668
|
+
var import_react3 = require("react");
|
|
669
|
+
|
|
427
670
|
// src/react/icons.tsx
|
|
428
671
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
429
672
|
var SHAPES = {
|
|
@@ -453,9 +696,16 @@ var SHAPES = {
|
|
|
453
696
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M9 1.8v3h3" })
|
|
454
697
|
] }),
|
|
455
698
|
chev: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
|
|
699
|
+
"chev-up": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3.5 10 4.5-4.5L12.5 10" }),
|
|
456
700
|
"chev-down": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
|
|
457
701
|
"chev-left": /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" }),
|
|
458
702
|
x: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" }),
|
|
703
|
+
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" }),
|
|
704
|
+
copy: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
705
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "5.5", y: "5.5", width: "8", height: "8", rx: "1.3" }),
|
|
706
|
+
/* @__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" })
|
|
707
|
+
] }),
|
|
708
|
+
check: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m3 8.5 3.2 3L13 4.5" }),
|
|
459
709
|
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" }),
|
|
460
710
|
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" }),
|
|
461
711
|
clock: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
@@ -472,8 +722,149 @@ function Icon({ name, className }) {
|
|
|
472
722
|
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] });
|
|
473
723
|
}
|
|
474
724
|
|
|
475
|
-
// src/react/comments-
|
|
725
|
+
// src/react/comments-votes.tsx
|
|
476
726
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
727
|
+
function useVotes(endpoint) {
|
|
728
|
+
const [overlay, setOverlay] = (0, import_react3.useState)({});
|
|
729
|
+
const pending = (0, import_react3.useRef)(/* @__PURE__ */ new Set());
|
|
730
|
+
async function cast(id, current, clicked) {
|
|
731
|
+
if (pending.current.has(id)) return void 0;
|
|
732
|
+
const next = nextVote(current, clicked);
|
|
733
|
+
pending.current.add(id);
|
|
734
|
+
setOverlay((o) => ({ ...o, [id]: next }));
|
|
735
|
+
const r = await call(endpoint, next.value === null ? "DELETE" : "PUT", "/votes", next.value === null ? { comment_id: id } : { comment_id: id, value: next.value });
|
|
736
|
+
pending.current.delete(id);
|
|
737
|
+
const vote = r.status === 200 && isObject(r.data) && isObject(r.data.vote) ? r.data.vote : void 0;
|
|
738
|
+
if (vote && Number.isSafeInteger(vote.score)) {
|
|
739
|
+
const state = { value: vote.value === 1 || vote.value === -1 ? vote.value : null, score: vote.score };
|
|
740
|
+
setOverlay((o) => ({ ...o, [id]: state }));
|
|
741
|
+
return { ok: true, state };
|
|
742
|
+
}
|
|
743
|
+
setOverlay((o) => ({ ...o, [id]: current }));
|
|
744
|
+
return { ok: false, status: r.status };
|
|
745
|
+
}
|
|
746
|
+
function settle(listing) {
|
|
747
|
+
const known = new Set(listing.comments.filter((c) => c.my_vote !== void 0).map((c) => c.id));
|
|
748
|
+
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 }]] : [])));
|
|
749
|
+
}
|
|
750
|
+
return { overlay, cast, settle, reset: () => setOverlay({}) };
|
|
751
|
+
}
|
|
752
|
+
function VoteButtons({ s, name, state, own, access, signInHref, onVote }) {
|
|
753
|
+
function arrow(value) {
|
|
754
|
+
if (own) return null;
|
|
755
|
+
const icon = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: value === 1 ? "chev-up" : "chev-down" });
|
|
756
|
+
const label = value === 1 ? s.upvote : s.downvote;
|
|
757
|
+
if (access === "out") return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("a", { className: "hyle-cm-btn", href: signInHref, children: [
|
|
758
|
+
icon,
|
|
759
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: value === 1 ? s.upvoteSignIn : s.downvoteSignIn })
|
|
760
|
+
] });
|
|
761
|
+
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 });
|
|
762
|
+
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 });
|
|
763
|
+
}
|
|
764
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hyle-cm-votes", role: "group", "aria-label": s.votesOn.replace("{name}", () => name), children: [
|
|
765
|
+
arrow(1),
|
|
766
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "hyle-cm-score", children: [
|
|
767
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.score.replace("{n}", String(state.score)) }),
|
|
768
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": "true", children: state.score })
|
|
769
|
+
] }),
|
|
770
|
+
arrow(-1)
|
|
771
|
+
] });
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// src/react/reaction-bar.tsx
|
|
775
|
+
var import_react4 = require("react");
|
|
776
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
777
|
+
var reactionKey = (subject, kind) => `${subject}:${kind}`;
|
|
778
|
+
var kindName = (s, kind) => ({ like: s.reactionLike, love: s.reactionLove, insightful: s.reactionInsightful, celebrate: s.reactionCelebrate })[kind];
|
|
779
|
+
function settleReactions(overlay, pending, listing) {
|
|
780
|
+
const told = new Set(listing.comments.filter((c) => c.my_reactions).map((c) => c.id));
|
|
781
|
+
if (listing.my_reactions) told.add("article");
|
|
782
|
+
return Object.fromEntries(Object.entries(overlay).flatMap(([key, v]) => {
|
|
783
|
+
if (pending.has(key)) return [[key, v]];
|
|
784
|
+
return v.on && !key.endsWith(":like") && !told.has(key.slice(0, key.lastIndexOf(":"))) ? [[key, { on: true }]] : [];
|
|
785
|
+
}));
|
|
786
|
+
}
|
|
787
|
+
function useReactions(endpoint, path) {
|
|
788
|
+
const [overlay, setOverlay] = (0, import_react4.useState)({});
|
|
789
|
+
const pending = (0, import_react4.useRef)(/* @__PURE__ */ new Set());
|
|
790
|
+
async function toggle(subject, kind, count2, on) {
|
|
791
|
+
const key = reactionKey(subject, kind);
|
|
792
|
+
if (pending.current.has(key)) return void 0;
|
|
793
|
+
const before = { on: overlay[key]?.on ?? on, count: overlay[key]?.count ?? count2 };
|
|
794
|
+
pending.current.add(key);
|
|
795
|
+
setOverlay((o) => ({ ...o, [key]: { on: !before.on, count: Math.max(0, before.count + (before.on ? -1 : 1)) } }));
|
|
796
|
+
const target = subject === "article" ? { subject_type: "article", path } : { subject_type: "comment", comment_id: subject };
|
|
797
|
+
const r = await call(endpoint, before.on ? "DELETE" : "PUT", "/reactions", kind === "like" ? target : { ...target, kind });
|
|
798
|
+
pending.current.delete(key);
|
|
799
|
+
const reaction = r.status === 200 && isObject(r.data) && isObject(r.data.reaction) ? r.data.reaction : void 0;
|
|
800
|
+
const counts = parseCounts(reaction?.counts);
|
|
801
|
+
const settled = counts ? counts[kind] ?? 0 : kind === "like" && typeof reaction?.like_count === "number" ? reaction.like_count : void 0;
|
|
802
|
+
if (reaction && settled !== void 0) {
|
|
803
|
+
const active = reaction.active === true;
|
|
804
|
+
setOverlay((o) => ({ ...o, [key]: { on: active, count: settled } }));
|
|
805
|
+
return { ok: true, on: active };
|
|
806
|
+
}
|
|
807
|
+
setOverlay((o) => ({ ...o, [key]: before }));
|
|
808
|
+
return { ok: false, status: r.status };
|
|
809
|
+
}
|
|
810
|
+
const settle = (listing) => setOverlay((o) => settleReactions(o, pending.current, listing));
|
|
811
|
+
return { overlay, toggle, settle, reset: () => setOverlay({}) };
|
|
812
|
+
}
|
|
813
|
+
function ReactionBar({ s, scope, subject, likes, counts, likedByMe, mine, overlay, access, signInHref, onToggle }) {
|
|
814
|
+
const [open, setOpen] = (0, import_react4.useState)(false);
|
|
815
|
+
const first = (0, import_react4.useRef)(null);
|
|
816
|
+
const trigger = (0, import_react4.useRef)(null);
|
|
817
|
+
(0, import_react4.useEffect)(() => {
|
|
818
|
+
if (open) first.current?.focus();
|
|
819
|
+
}, [open]);
|
|
820
|
+
const base = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
|
|
821
|
+
function button(kind) {
|
|
822
|
+
const state = overlay[reactionKey(subject, kind)];
|
|
823
|
+
const server = kind === "like" ? likes : counts?.[kind] ?? 0;
|
|
824
|
+
const serverOn = mine ? mine.includes(kind) : kind === "like" && likedByMe;
|
|
825
|
+
const count2 = state?.count ?? server;
|
|
826
|
+
const on = state?.on ?? serverOn;
|
|
827
|
+
if (kind !== "like" && !open && !state && count2 === 0) return null;
|
|
828
|
+
const out = access === "out";
|
|
829
|
+
const content = kind !== "like" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
830
|
+
out ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: s.reactionSignIn }) : null,
|
|
831
|
+
kindName(s, kind),
|
|
832
|
+
" ",
|
|
833
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: count2 })
|
|
834
|
+
] }) : scope === "article" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
835
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "heart" }),
|
|
836
|
+
out ? s.likeArticle : on ? s.likedArticle : s.likeArticle,
|
|
837
|
+
" ",
|
|
838
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: out ? s.likeArticleSignIn : ", " }),
|
|
839
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: count2 })
|
|
840
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
841
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "heart" }),
|
|
842
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-sr", children: out ? s.likeCommentSignIn : s.likeComment }),
|
|
843
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: count2 })
|
|
844
|
+
] });
|
|
845
|
+
const cls = kind === "like" ? base : `${base} chip`;
|
|
846
|
+
if (out && signInHref) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("a", { className: cls, href: signInHref, children: content }, kind);
|
|
847
|
+
if (access !== "in") return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: cls, type: "button", "aria-disabled": "true", children: content }, kind);
|
|
848
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { ref: kind === "love" ? first : void 0, className: cls, type: "button", "aria-pressed": on, onClick: () => {
|
|
849
|
+
setOpen(false);
|
|
850
|
+
onToggle(kind, server, serverOn);
|
|
851
|
+
}, children: content }, kind);
|
|
852
|
+
}
|
|
853
|
+
if (!counts) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: button("like") });
|
|
854
|
+
const onKey = (e) => {
|
|
855
|
+
if (e.key !== "Escape" || !open) return;
|
|
856
|
+
e.preventDefault();
|
|
857
|
+
setOpen(false);
|
|
858
|
+
trigger.current?.focus();
|
|
859
|
+
};
|
|
860
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "hyle-reaction-set", role: "group", "aria-label": s.reactions, onKeyDown: onKey, children: [
|
|
861
|
+
REACTION_KINDS.map(button),
|
|
862
|
+
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
|
|
863
|
+
] });
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// src/react/comments-parts.tsx
|
|
867
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
477
868
|
var MAX_CHARS = 4e3;
|
|
478
869
|
var EDIT_WINDOW_MS = 10 * 60 * 1e3;
|
|
479
870
|
var MAX_DEPTH2 = 4;
|
|
@@ -481,6 +872,7 @@ var fill = (template, values) => template.replace(/\{(\w+)\}/g, (_, k) => String
|
|
|
481
872
|
var initials = (name) => name.trim().split(/\s+/).slice(0, 2).map((w) => [...w][0] ?? "").join("").toUpperCase() || "?";
|
|
482
873
|
var replyButtonId = (ui, id) => `${ui.idp}-reply-${id}`;
|
|
483
874
|
var nameId = (ui, id) => `${ui.idp}-${id}-n`;
|
|
875
|
+
var accessOf = (ui) => !ui.ready ? "pending" : !ui.me ? "out" : ui.banned ? "blocked" : "in";
|
|
484
876
|
function relative(iso, now, locale, s) {
|
|
485
877
|
const seconds = Math.round((now - Date.parse(iso)) / 1e3);
|
|
486
878
|
if (!Number.isFinite(seconds)) return iso;
|
|
@@ -503,56 +895,19 @@ var absolute = (iso, locale) => {
|
|
|
503
895
|
}
|
|
504
896
|
};
|
|
505
897
|
function Avatar({ name }) {
|
|
506
|
-
return /* @__PURE__ */ (0,
|
|
898
|
+
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" }) });
|
|
507
899
|
}
|
|
508
900
|
function SignInLink({ ui, className, children }) {
|
|
509
|
-
return /* @__PURE__ */ (0,
|
|
510
|
-
}
|
|
511
|
-
function LikeButton({ ui, itemKey, serverCount, serverOn, scope }) {
|
|
512
|
-
const { s } = ui;
|
|
513
|
-
const state = ui.likes[itemKey];
|
|
514
|
-
const count2 = state?.count ?? serverCount;
|
|
515
|
-
const on = state?.on ?? serverOn;
|
|
516
|
-
const cls = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
|
|
517
|
-
const lead = scope === "article" ? on ? s.likedArticle : s.likeArticle : null;
|
|
518
|
-
const sr = scope === "article" ? ", " : s.likeComment;
|
|
519
|
-
const icon = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Icon, { name: "heart" });
|
|
520
|
-
if (ui.ready && !ui.me) {
|
|
521
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(SignInLink, { ui, className: cls, children: [
|
|
522
|
-
icon,
|
|
523
|
-
lead ?? null,
|
|
524
|
-
scope === "article" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
525
|
-
" ",
|
|
526
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.likeArticleSignIn })
|
|
527
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: s.likeCommentSignIn }),
|
|
528
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
|
|
529
|
-
] });
|
|
530
|
-
}
|
|
531
|
-
if (ui.banned || !ui.ready) {
|
|
532
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: cls, type: "button", "aria-disabled": "true", children: [
|
|
533
|
-
icon,
|
|
534
|
-
lead,
|
|
535
|
-
scope === "article" ? " " : null,
|
|
536
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: sr }),
|
|
537
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
|
|
538
|
-
] });
|
|
539
|
-
}
|
|
540
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { className: cls, type: "button", "aria-pressed": on, onClick: () => ui.actions.like(itemKey, serverCount, serverOn), children: [
|
|
541
|
-
icon,
|
|
542
|
-
lead,
|
|
543
|
-
scope === "article" ? " " : null,
|
|
544
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "hyle-sr", children: sr }),
|
|
545
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: count2 })
|
|
546
|
-
] });
|
|
901
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("a", { className, href: `#${ui.signInId}`, children });
|
|
547
902
|
}
|
|
548
903
|
function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
|
|
549
904
|
const { s } = ui;
|
|
550
|
-
const [text, setText] = (0,
|
|
551
|
-
const [busy, setBusy] = (0,
|
|
552
|
-
const [error, setError] = (0,
|
|
553
|
-
const area = (0,
|
|
905
|
+
const [text, setText] = (0, import_react5.useState)("");
|
|
906
|
+
const [busy, setBusy] = (0, import_react5.useState)(false);
|
|
907
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
908
|
+
const area = (0, import_react5.useRef)(null);
|
|
554
909
|
const limited = ui.rateLeft > 0;
|
|
555
|
-
(0,
|
|
910
|
+
(0, import_react5.useEffect)(() => {
|
|
556
911
|
if (autoFocus) area.current?.focus();
|
|
557
912
|
}, [autoFocus]);
|
|
558
913
|
async function submit() {
|
|
@@ -586,19 +941,19 @@ function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
|
|
|
586
941
|
};
|
|
587
942
|
const helpId = `${id}-help`;
|
|
588
943
|
const errId = `${id}-err`;
|
|
589
|
-
return /* @__PURE__ */ (0,
|
|
944
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { className: "hyle-cm-compose", onSubmit: (e) => {
|
|
590
945
|
e.preventDefault();
|
|
591
946
|
void submit();
|
|
592
947
|
}, children: [
|
|
593
|
-
/* @__PURE__ */ (0,
|
|
594
|
-
/* @__PURE__ */ (0,
|
|
595
|
-
/* @__PURE__ */ (0,
|
|
948
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { name }),
|
|
949
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { children: [
|
|
950
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-as", children: [
|
|
596
951
|
s.commentingAs.split("{name}")[0],
|
|
597
|
-
/* @__PURE__ */ (0,
|
|
952
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { children: name }),
|
|
598
953
|
s.commentingAs.split("{name}")[1]
|
|
599
954
|
] }),
|
|
600
|
-
/* @__PURE__ */ (0,
|
|
601
|
-
/* @__PURE__ */ (0,
|
|
955
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { className: "hyle-sr", htmlFor: id, children: parentId ? s.replyPlaceholder : s.write }),
|
|
956
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
602
957
|
"textarea",
|
|
603
958
|
{
|
|
604
959
|
ref: area,
|
|
@@ -615,26 +970,26 @@ function Composer({ ui, id, parentId, name, autoFocus, onCancel }) {
|
|
|
615
970
|
onKeyDown: onKey
|
|
616
971
|
}
|
|
617
972
|
),
|
|
618
|
-
error ? /* @__PURE__ */ (0,
|
|
619
|
-
/* @__PURE__ */ (0,
|
|
620
|
-
/* @__PURE__ */ (0,
|
|
973
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-err", id: errId, role: "alert", children: [
|
|
974
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "alert" }),
|
|
975
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: error })
|
|
621
976
|
] }) : null,
|
|
622
|
-
/* @__PURE__ */ (0,
|
|
623
|
-
/* @__PURE__ */ (0,
|
|
624
|
-
/* @__PURE__ */ (0,
|
|
625
|
-
onCancel ? /* @__PURE__ */ (0,
|
|
626
|
-
/* @__PURE__ */ (0,
|
|
977
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-foot", children: [
|
|
978
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "grow", id: helpId, children: limited ? fill(s.rateWait, { n: ui.rateLeft }) : s.help }),
|
|
979
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "cnt", children: fill(s.chars, { n: [...text].length, max: MAX_CHARS }) }),
|
|
980
|
+
onCancel ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: onCancel, children: s.cancel }) : null,
|
|
981
|
+
/* @__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 })
|
|
627
982
|
] })
|
|
628
983
|
] })
|
|
629
984
|
] });
|
|
630
985
|
}
|
|
631
986
|
function EditForm({ ui, node, initial }) {
|
|
632
987
|
const { s } = ui;
|
|
633
|
-
const [text, setText] = (0,
|
|
634
|
-
const [busy, setBusy] = (0,
|
|
635
|
-
const [error, setError] = (0,
|
|
636
|
-
const area = (0,
|
|
637
|
-
(0,
|
|
988
|
+
const [text, setText] = (0, import_react5.useState)(initial);
|
|
989
|
+
const [busy, setBusy] = (0, import_react5.useState)(false);
|
|
990
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
991
|
+
const area = (0, import_react5.useRef)(null);
|
|
992
|
+
(0, import_react5.useEffect)(() => area.current?.focus(), []);
|
|
638
993
|
const id = `${ui.idp}-edit-${node.id}`;
|
|
639
994
|
async function save() {
|
|
640
995
|
if (busy) return;
|
|
@@ -646,12 +1001,12 @@ function EditForm({ ui, node, initial }) {
|
|
|
646
1001
|
setError(r.reason === "tooLong" ? s.tooLong : r.reason === "closed" ? s.editClosed : r.reason === "expired" ? s.expired : r.reason === "rate" ? s.rateTitle : s.postError);
|
|
647
1002
|
area.current?.focus();
|
|
648
1003
|
}
|
|
649
|
-
return /* @__PURE__ */ (0,
|
|
1004
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { onSubmit: (e) => {
|
|
650
1005
|
e.preventDefault();
|
|
651
1006
|
void save();
|
|
652
1007
|
}, children: [
|
|
653
|
-
/* @__PURE__ */ (0,
|
|
654
|
-
/* @__PURE__ */ (0,
|
|
1008
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("label", { className: "hyle-sr", htmlFor: id, children: s.edit }),
|
|
1009
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
655
1010
|
"textarea",
|
|
656
1011
|
{
|
|
657
1012
|
ref: area,
|
|
@@ -674,14 +1029,14 @@ function EditForm({ ui, node, initial }) {
|
|
|
674
1029
|
}
|
|
675
1030
|
}
|
|
676
1031
|
),
|
|
677
|
-
error ? /* @__PURE__ */ (0,
|
|
678
|
-
/* @__PURE__ */ (0,
|
|
679
|
-
/* @__PURE__ */ (0,
|
|
1032
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-err", id: `${id}-err`, role: "alert", children: [
|
|
1033
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "alert" }),
|
|
1034
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: error })
|
|
680
1035
|
] }) : null,
|
|
681
|
-
/* @__PURE__ */ (0,
|
|
682
|
-
/* @__PURE__ */ (0,
|
|
683
|
-
/* @__PURE__ */ (0,
|
|
684
|
-
/* @__PURE__ */ (0,
|
|
1036
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-foot", children: [
|
|
1037
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "grow" }),
|
|
1038
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn sm", type: "button", onClick: () => ui.actions.edit(null), children: s.cancel }),
|
|
1039
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-btn sm primary", type: "submit", "aria-disabled": busy ? true : void 0, children: s.save })
|
|
685
1040
|
] })
|
|
686
1041
|
] });
|
|
687
1042
|
}
|
|
@@ -692,46 +1047,49 @@ function Actions({ ui, node }) {
|
|
|
692
1047
|
const until = node.canEditUntil ?? (local ? local.at + EDIT_WINDOW_MS : void 0);
|
|
693
1048
|
const minutes = until === void 0 ? 0 : Math.min(10, Math.ceil((until - Math.max(ui.now, local?.at ?? 0)) / 6e4));
|
|
694
1049
|
const canReply = node.depth < MAX_DEPTH2 && node.status === "visible";
|
|
1050
|
+
const vote = ui.votes[node.id];
|
|
1051
|
+
const shownVote = { value: vote ? vote.value : node.myVote ?? null, score: vote?.score ?? node.score ?? 0 };
|
|
695
1052
|
if (ui.confirming === node.id) {
|
|
696
|
-
return /* @__PURE__ */ (0,
|
|
697
|
-
/* @__PURE__ */ (0,
|
|
698
|
-
/* @__PURE__ */ (0,
|
|
699
|
-
/* @__PURE__ */ (0,
|
|
700
|
-
] });
|
|
1053
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-acts", role: "group", "aria-label": s.deleteConfirm, children: [
|
|
1054
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-depth", children: s.deleteConfirm }),
|
|
1055
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-cm-btn danger", type: "button", onClick: () => ui.actions.remove(node.id), children: s.delete }),
|
|
1056
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { className: "hyle-cm-btn", type: "button", autoFocus: true, onClick: () => ui.actions.confirm(null), children: s.keep })
|
|
1057
|
+
] }, "confirm");
|
|
701
1058
|
}
|
|
702
|
-
return /* @__PURE__ */ (0,
|
|
703
|
-
node.status === "visible" ? /* @__PURE__ */ (0,
|
|
704
|
-
|
|
705
|
-
|
|
1059
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-acts", children: [
|
|
1060
|
+
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,
|
|
1061
|
+
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,
|
|
1062
|
+
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: [
|
|
1063
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "reply" }),
|
|
706
1064
|
s.reply
|
|
707
1065
|
] }) : null,
|
|
708
|
-
canReply && !ui.me ? /* @__PURE__ */ (0,
|
|
709
|
-
/* @__PURE__ */ (0,
|
|
710
|
-
/* @__PURE__ */ (0,
|
|
711
|
-
/* @__PURE__ */ (0,
|
|
1066
|
+
canReply && !ui.me ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(SignInLink, { ui, className: "hyle-cm-btn", children: [
|
|
1067
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "reply" }),
|
|
1068
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-sr", children: fill(s.replyTo, { name: node.name ?? "" }) }),
|
|
1069
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", children: s.reply })
|
|
712
1070
|
] }) : null,
|
|
713
|
-
node.status === "visible" && node.depth >= MAX_DEPTH2 ? /* @__PURE__ */ (0,
|
|
714
|
-
mine && !ui.banned && minutes > 0 ? /* @__PURE__ */ (0,
|
|
1071
|
+
node.status === "visible" && node.depth >= MAX_DEPTH2 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-depth", children: s.depthEnd }) : null,
|
|
1072
|
+
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: [
|
|
715
1073
|
s.edit,
|
|
716
1074
|
" ",
|
|
717
|
-
/* @__PURE__ */ (0,
|
|
1075
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("small", { children: fill(s.editLeft, { n: minutes }) })
|
|
718
1076
|
] }) : null,
|
|
719
|
-
mine && !ui.banned ? /* @__PURE__ */ (0,
|
|
1077
|
+
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
|
|
720
1078
|
] });
|
|
721
1079
|
}
|
|
722
1080
|
function Thread({ ui, nodes }) {
|
|
723
|
-
return /* @__PURE__ */ (0,
|
|
1081
|
+
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)) });
|
|
724
1082
|
}
|
|
725
1083
|
function CommentItem({ ui, node }) {
|
|
726
1084
|
const { s } = ui;
|
|
727
1085
|
const li = `${ui.idp}-c-${node.id}`;
|
|
728
|
-
const kids = node.kids.length > 0 ? /* @__PURE__ */ (0,
|
|
1086
|
+
const kids = node.kids.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Thread, { ui, nodes: node.kids }) : null;
|
|
729
1087
|
if (node.status === "removed") {
|
|
730
1088
|
const why = node.removedBy === "moderator" ? s.removedByModerator : node.removedBy === "author" ? s.removedByAuthor : s.removed;
|
|
731
|
-
return /* @__PURE__ */ (0,
|
|
732
|
-
/* @__PURE__ */ (0,
|
|
733
|
-
/* @__PURE__ */ (0,
|
|
734
|
-
/* @__PURE__ */ (0,
|
|
1089
|
+
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: [
|
|
1090
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("article", { "aria-label": why, children: [
|
|
1091
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { name: null }),
|
|
1092
|
+
/* @__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 }) }) })
|
|
735
1093
|
] }),
|
|
736
1094
|
kids
|
|
737
1095
|
] });
|
|
@@ -739,34 +1097,34 @@ function CommentItem({ ui, node }) {
|
|
|
739
1097
|
const local = ui.own[node.id];
|
|
740
1098
|
const mine = node.mine || !!local;
|
|
741
1099
|
const editing = ui.editing === node.id && mine;
|
|
742
|
-
return /* @__PURE__ */ (0,
|
|
743
|
-
/* @__PURE__ */ (0,
|
|
744
|
-
/* @__PURE__ */ (0,
|
|
745
|
-
/* @__PURE__ */ (0,
|
|
746
|
-
/* @__PURE__ */ (0,
|
|
747
|
-
/* @__PURE__ */ (0,
|
|
748
|
-
mine ? /* @__PURE__ */ (0,
|
|
749
|
-
/* @__PURE__ */ (0,
|
|
750
|
-
/* @__PURE__ */ (0,
|
|
751
|
-
node.editedAt ? /* @__PURE__ */ (0,
|
|
1100
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { className: "hyle-cm", id: li, "data-depth": node.depth, "data-status": node.status, children: [
|
|
1101
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("article", { "aria-labelledby": nameId(ui, node.id), children: [
|
|
1102
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Avatar, { name: node.name }),
|
|
1103
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-main", children: [
|
|
1104
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "hyle-cm-by", children: [
|
|
1105
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { id: nameId(ui, node.id), tabIndex: -1, children: node.name }),
|
|
1106
|
+
mine ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "hyle-cm-tag", children: s.you }) : null,
|
|
1107
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
|
|
1108
|
+
/* @__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) }),
|
|
1109
|
+
node.editedAt ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
752
1110
|
" ",
|
|
753
|
-
/* @__PURE__ */ (0,
|
|
1111
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", children: "\xB7" }),
|
|
754
1112
|
" ",
|
|
755
|
-
/* @__PURE__ */ (0,
|
|
1113
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("a", { href: `#${li}`, title: absolute(node.editedAt, ui.locale), children: s.edited })
|
|
756
1114
|
] }) : null
|
|
757
1115
|
] })
|
|
758
1116
|
] }),
|
|
759
|
-
editing ? /* @__PURE__ */ (0,
|
|
760
|
-
node.status === "held" ? /* @__PURE__ */ (0,
|
|
761
|
-
/* @__PURE__ */ (0,
|
|
762
|
-
/* @__PURE__ */ (0,
|
|
763
|
-
/* @__PURE__ */ (0,
|
|
1117
|
+
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 }),
|
|
1118
|
+
node.status === "held" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "hyle-cm-held", role: "status", children: [
|
|
1119
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "clock" }),
|
|
1120
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
|
|
1121
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("b", { children: s.held }),
|
|
764
1122
|
" ",
|
|
765
1123
|
s.heldNote
|
|
766
1124
|
] })
|
|
767
1125
|
] }) : null,
|
|
768
|
-
editing ? null : /* @__PURE__ */ (0,
|
|
769
|
-
ui.replyOpen === node.id && ui.me ? /* @__PURE__ */ (0,
|
|
1126
|
+
editing ? null : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Actions, { ui, node }),
|
|
1127
|
+
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
|
|
770
1128
|
] })
|
|
771
1129
|
] }),
|
|
772
1130
|
kids
|
|
@@ -774,114 +1132,179 @@ function CommentItem({ ui, node }) {
|
|
|
774
1132
|
}
|
|
775
1133
|
|
|
776
1134
|
// src/react/comments.tsx
|
|
777
|
-
var
|
|
1135
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
778
1136
|
var PAGE = 20;
|
|
779
1137
|
var TICK_MS = 1e4;
|
|
780
|
-
var
|
|
1138
|
+
var NEAR = "600px 0px";
|
|
1139
|
+
var firstOf = (nodes, wanted) => {
|
|
1140
|
+
for (const n of nodes) {
|
|
1141
|
+
const found = wanted.has(n.id) ? n.id : firstOf(n.kids, wanted);
|
|
1142
|
+
if (found) return found;
|
|
1143
|
+
}
|
|
1144
|
+
return void 0;
|
|
1145
|
+
};
|
|
781
1146
|
var fill2 = (t, n) => t.replace("{n}", String(n));
|
|
782
|
-
|
|
783
|
-
const
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
const [
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
const
|
|
795
|
-
const [
|
|
796
|
-
const [
|
|
797
|
-
const [
|
|
798
|
-
const [
|
|
799
|
-
const [
|
|
800
|
-
const
|
|
801
|
-
const
|
|
802
|
-
const
|
|
803
|
-
(0,
|
|
1147
|
+
var readerOf = (data) => {
|
|
1148
|
+
const reader = isObject(data) && isObject(data.reader) ? data.reader : void 0;
|
|
1149
|
+
if (typeof reader?.name !== "string") return void 0;
|
|
1150
|
+
return { id: typeof reader.id === "string" ? reader.id : reader.name, name: reader.name };
|
|
1151
|
+
};
|
|
1152
|
+
function Comments(props) {
|
|
1153
|
+
const [readers, setReaders] = (0, import_react6.useState)(0);
|
|
1154
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ArticleComments, { ...props, onNewReader: () => setReaders((n) => n + 1) }, `${props.endpoint}
|
|
1155
|
+
${props.path}
|
|
1156
|
+
${readers}`);
|
|
1157
|
+
}
|
|
1158
|
+
function ArticleComments({ path, endpoint, signInHref, locale, labels: s, initial, initialAt, lazy = false, articleReactions = true, onNewReader }) {
|
|
1159
|
+
const idp = `hc${(0, import_react6.useId)().replace(/[^A-Za-z0-9]/g, "")}`;
|
|
1160
|
+
const [session, setSession] = (0, import_react6.useState)("loading");
|
|
1161
|
+
const [own, setOwn] = (0, import_react6.useState)({});
|
|
1162
|
+
const [held, setHeld] = (0, import_react6.useState)([]);
|
|
1163
|
+
const [unseen, setUnseen] = (0, import_react6.useState)([]);
|
|
1164
|
+
const [replyOpen, setReplyOpen] = (0, import_react6.useState)(null);
|
|
1165
|
+
const [editing, setEditing] = (0, import_react6.useState)(null);
|
|
1166
|
+
const [confirming, setConfirming] = (0, import_react6.useState)(null);
|
|
1167
|
+
const [banned, setBanned] = (0, import_react6.useState)(false);
|
|
1168
|
+
const [expired, setExpired] = (0, import_react6.useState)(false);
|
|
1169
|
+
const [rateUntil, setRateUntil] = (0, import_react6.useState)(0);
|
|
1170
|
+
const [now, setNow] = (0, import_react6.useState)(() => initialAt ?? Date.now());
|
|
1171
|
+
const [live, setLive] = (0, import_react6.useState)("");
|
|
1172
|
+
const [actionError, setActionError] = (0, import_react6.useState)(null);
|
|
1173
|
+
const [shown, setShown] = (0, import_react6.useState)(PAGE);
|
|
1174
|
+
const [focusId, setFocusId] = (0, import_react6.useState)(null);
|
|
1175
|
+
const [near, setNear] = (0, import_react6.useState)(!lazy);
|
|
1176
|
+
const [chosen, setChosen] = (0, import_react6.useState)("newest");
|
|
1177
|
+
const [loadingMore, setLoadingMore] = (0, import_react6.useState)(false);
|
|
1178
|
+
const [moreFailed, setMoreFailed] = (0, import_react6.useState)(false);
|
|
1179
|
+
const root = (0, import_react6.useRef)(null);
|
|
1180
|
+
const sortClicks = (0, import_react6.useRef)(0);
|
|
1181
|
+
const reactions = useReactions(endpoint, path);
|
|
1182
|
+
const votes = useVotes(endpoint);
|
|
1183
|
+
const { listing, order, served, reload, sort, more, retry } = useCommentListing(
|
|
1184
|
+
endpoint,
|
|
1185
|
+
path,
|
|
1186
|
+
initial,
|
|
1187
|
+
near,
|
|
1188
|
+
(fresh) => {
|
|
1189
|
+
reactions.settle(fresh);
|
|
1190
|
+
votes.settle(fresh);
|
|
1191
|
+
},
|
|
1192
|
+
() => {
|
|
1193
|
+
reactions.reset();
|
|
1194
|
+
votes.reset();
|
|
1195
|
+
setUnseen([]);
|
|
1196
|
+
setChosen("newest");
|
|
1197
|
+
setLoadingMore(false);
|
|
1198
|
+
setMoreFailed(false);
|
|
1199
|
+
}
|
|
1200
|
+
);
|
|
1201
|
+
const alive = (0, import_react6.useRef)(true);
|
|
1202
|
+
const write404 = (0, import_react6.useRef)(0);
|
|
1203
|
+
(0, import_react6.useEffect)(() => {
|
|
804
1204
|
alive.current = true;
|
|
805
1205
|
return () => void (alive.current = false);
|
|
806
1206
|
}, []);
|
|
807
|
-
(0,
|
|
1207
|
+
(0, import_react6.useEffect)(() => {
|
|
808
1208
|
if (initialAt !== void 0) setNow(Date.now());
|
|
809
1209
|
const t = setInterval(() => setNow(Date.now()), TICK_MS);
|
|
810
1210
|
return () => clearInterval(t);
|
|
811
1211
|
}, [initialAt]);
|
|
812
|
-
(0,
|
|
1212
|
+
(0, import_react6.useEffect)(() => {
|
|
813
1213
|
if (rateUntil <= Date.now()) return;
|
|
814
1214
|
const t = setTimeout(() => setNow(Date.now()), rateUntil - Date.now() + 50);
|
|
815
1215
|
return () => clearTimeout(t);
|
|
816
1216
|
}, [rateUntil]);
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
return
|
|
827
|
-
}, [endpoint, path]);
|
|
828
|
-
(0, import_react3.useEffect)(() => {
|
|
829
|
-
setListing(initial ?? "loading");
|
|
830
|
-
void load(initial !== void 0);
|
|
1217
|
+
(0, import_react6.useEffect)(() => {
|
|
1218
|
+
if (near) return;
|
|
1219
|
+
const el = root.current;
|
|
1220
|
+
if (!el || typeof IntersectionObserver === "undefined") return setNear(true);
|
|
1221
|
+
const observer = new IntersectionObserver((entries) => entries.some((e) => e.isIntersecting) && setNear(true), { rootMargin: NEAR });
|
|
1222
|
+
observer.observe(el);
|
|
1223
|
+
return () => observer.disconnect();
|
|
1224
|
+
}, [near]);
|
|
1225
|
+
(0, import_react6.useEffect)(() => {
|
|
1226
|
+
if (!near) return;
|
|
831
1227
|
void call(endpoint, "GET", "/session").then((r) => {
|
|
832
1228
|
if (!alive.current) return;
|
|
833
|
-
const reader =
|
|
834
|
-
setSession(r.status === 404 ? "off" :
|
|
1229
|
+
const reader = r.status === 200 ? readerOf(r.data) : void 0;
|
|
1230
|
+
setSession(r.status === 404 ? "off" : reader ?? null);
|
|
835
1231
|
});
|
|
836
|
-
}, [endpoint,
|
|
837
|
-
(0,
|
|
1232
|
+
}, [endpoint, near]);
|
|
1233
|
+
(0, import_react6.useEffect)(() => {
|
|
1234
|
+
if (typeof listing === "object") setUnseen((u) => stillUnseen(u, listing));
|
|
1235
|
+
}, [listing]);
|
|
1236
|
+
(0, import_react6.useEffect)(() => {
|
|
838
1237
|
if (!focusId) return;
|
|
839
1238
|
const el = document.getElementById(`${idp}-${focusId}-n`);
|
|
840
1239
|
if (el) {
|
|
841
1240
|
el.focus();
|
|
842
1241
|
setFocusId(null);
|
|
843
1242
|
}
|
|
844
|
-
}, [focusId, listing, held, idp]);
|
|
845
|
-
const
|
|
1243
|
+
}, [focusId, listing, held, unseen, idp]);
|
|
1244
|
+
const signedIn = typeof session === "object" ? session : null;
|
|
1245
|
+
const me = signedIn?.name ?? null;
|
|
846
1246
|
const rateLeft = Math.max(0, Math.ceil((rateUntil - now) / 1e3));
|
|
847
1247
|
const signInId = `${idp}-signin`;
|
|
848
|
-
function
|
|
1248
|
+
async function recheck(status) {
|
|
1249
|
+
if (status !== 401 && !expired) return;
|
|
1250
|
+
const r = await call(endpoint, "GET", "/session");
|
|
1251
|
+
const reader = r.status === 200 ? readerOf(r.data) : void 0;
|
|
1252
|
+
if (alive.current && reader && reader.id !== signedIn?.id) onNewReader();
|
|
1253
|
+
}
|
|
1254
|
+
function failed(status, refusal) {
|
|
849
1255
|
if (status === 401) setExpired(true);
|
|
850
|
-
setActionError(status === 401 ? s.expired : s.actionError);
|
|
1256
|
+
setActionError(status === 401 ? s.expired : status === 429 ? s.slowDown : refusal ?? s.actionError);
|
|
851
1257
|
}
|
|
852
|
-
async function
|
|
853
|
-
if (!me || banned
|
|
854
|
-
const prev = likes[key] ?? { on: serverOn, count: serverCount };
|
|
855
|
-
const count2 = prev.count ?? serverCount;
|
|
856
|
-
pending.current.add(key);
|
|
1258
|
+
async function react(subject, kind, count2, on) {
|
|
1259
|
+
if (!me || banned) return;
|
|
857
1260
|
setActionError(null);
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
if (!
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
1261
|
+
const r = await reactions.toggle(subject, kind, count2, on);
|
|
1262
|
+
if (!r || !alive.current) return;
|
|
1263
|
+
void recheck(r.ok ? 200 : r.status);
|
|
1264
|
+
if (!r.ok) return failed(r.status);
|
|
1265
|
+
setLive((r.on ? s.reactionAddedLive : s.reactionRemovedLive).replace("{kind}", kindName(s, kind)));
|
|
1266
|
+
}
|
|
1267
|
+
async function vote(id, current, clicked) {
|
|
1268
|
+
if (!me || banned) return;
|
|
1269
|
+
setActionError(null);
|
|
1270
|
+
const r = await votes.cast(id, current, clicked);
|
|
1271
|
+
if (!r || !alive.current) return;
|
|
1272
|
+
void recheck(r.ok ? 200 : r.status);
|
|
1273
|
+
if (!r.ok) return failed(r.status, r.status === 400 ? s.voteRefused : void 0);
|
|
1274
|
+
setLive(fill2(r.state.value === 1 ? s.upvotedLive : r.state.value === -1 ? s.downvotedLive : s.voteRemovedLive, r.state.score));
|
|
1275
|
+
}
|
|
1276
|
+
async function choose(next) {
|
|
1277
|
+
if (next === chosen) return;
|
|
1278
|
+
const click = sortClicks.current += 1;
|
|
1279
|
+
setChosen(next);
|
|
1280
|
+
setActionError(null);
|
|
1281
|
+
setMoreFailed(false);
|
|
1282
|
+
const showing = await sort(next);
|
|
1283
|
+
if (!alive.current || click !== sortClicks.current || showing === void 0) return;
|
|
1284
|
+
if (showing !== next) {
|
|
1285
|
+
setChosen(showing);
|
|
1286
|
+
return setActionError(s.sortError);
|
|
866
1287
|
}
|
|
867
|
-
|
|
868
|
-
|
|
1288
|
+
setShown(PAGE);
|
|
1289
|
+
setLive(next === "top" ? s.sortedTopLive : s.sortedNewestLive);
|
|
869
1290
|
}
|
|
870
1291
|
async function post(text, parentId) {
|
|
871
1292
|
const r = await call(endpoint, "POST", "/comments", { path, body: text, ...parentId ? { parent_id: parentId } : {} });
|
|
872
|
-
|
|
1293
|
+
void recheck(r.status);
|
|
1294
|
+
const created = r.status === 201 && isObject(r.data) && isObject(r.data.comment) ? r.data.comment : void 0;
|
|
873
1295
|
if (typeof created?.id === "string" && alive.current) {
|
|
874
1296
|
const id = created.id;
|
|
875
1297
|
write404.current = 0;
|
|
876
1298
|
setOwn((o) => ({ ...o, [id]: { text, at: Date.now(), parentId } }));
|
|
877
1299
|
setExpired(false);
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
1300
|
+
const status = created.status === "held" ? "held" : "visible";
|
|
1301
|
+
const local = { id, parentId, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1302
|
+
setUnseen((u) => [{ ...local, status }, ...u]);
|
|
1303
|
+
if (status === "held") setHeld((h) => [local, ...h]);
|
|
1304
|
+
setLive(status === "held" ? s.heldLive : s.postedLive);
|
|
882
1305
|
setShown(Number.MAX_SAFE_INTEGER);
|
|
883
1306
|
setFocusId(id);
|
|
884
|
-
await
|
|
1307
|
+
await reload(true);
|
|
885
1308
|
return { ok: true };
|
|
886
1309
|
}
|
|
887
1310
|
if (r.status === 429) {
|
|
@@ -890,10 +1313,11 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
890
1313
|
return { ok: false, reason: "rate" };
|
|
891
1314
|
}
|
|
892
1315
|
if (r.status === 404) {
|
|
893
|
-
const [again, who] = await Promise.all([
|
|
1316
|
+
const [again, who] = await Promise.all([reload(true), call(endpoint, "GET", "/session")]);
|
|
894
1317
|
write404.current += 1;
|
|
895
|
-
const
|
|
896
|
-
if (alive.current &&
|
|
1318
|
+
const reader = who.status === 200 ? readerOf(who.data) : void 0;
|
|
1319
|
+
if (alive.current && reader && reader.id !== signedIn?.id) onNewReader();
|
|
1320
|
+
else if (alive.current && reader && again && write404.current >= 2) setBanned(true);
|
|
897
1321
|
return { ok: false, reason: "error" };
|
|
898
1322
|
}
|
|
899
1323
|
if (r.status === 401) setExpired(true);
|
|
@@ -901,15 +1325,20 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
901
1325
|
}
|
|
902
1326
|
async function save(id, text) {
|
|
903
1327
|
const r = await call(endpoint, "PATCH", `/comments/${id}`, { body: text });
|
|
1328
|
+
void recheck(r.status);
|
|
904
1329
|
if (r.status === 200 && alive.current) {
|
|
905
1330
|
const meta = own[id];
|
|
906
1331
|
setOwn((o) => ({ ...o, [id]: { text, at: o[id]?.at ?? Date.now(), parentId: o[id]?.parentId ?? null } }));
|
|
907
1332
|
setHeld((h) => h.map((c) => c.id === id ? { ...c, text } : c));
|
|
1333
|
+
setUnseen((u) => u.map((c) => c.id === id ? { ...c, text } : c));
|
|
908
1334
|
setEditing(null);
|
|
909
1335
|
setLive(s.savedLive);
|
|
910
1336
|
setFocusId(id);
|
|
911
|
-
const fresh = await
|
|
912
|
-
if (fresh && !fresh.
|
|
1337
|
+
const fresh = await reload(true);
|
|
1338
|
+
if (fresh && !fresh.truncated && !fresh.next_cursor && !fresh.comments.some((c) => c.id === id)) {
|
|
1339
|
+
setUnseen((u) => u.filter((c) => c.id !== id));
|
|
1340
|
+
setHeld((h) => h.some((c) => c.id === id) ? h : [{ id, parentId: meta?.parentId ?? null, text, name: me ?? "", createdAt: (/* @__PURE__ */ new Date()).toISOString() }, ...h]);
|
|
1341
|
+
}
|
|
913
1342
|
return { ok: true };
|
|
914
1343
|
}
|
|
915
1344
|
if (r.status === 429) {
|
|
@@ -924,15 +1353,38 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
924
1353
|
setActionError(null);
|
|
925
1354
|
const r = await call(endpoint, "DELETE", `/comments/${id}`);
|
|
926
1355
|
if (!alive.current) return;
|
|
1356
|
+
void recheck(r.status);
|
|
927
1357
|
setConfirming(null);
|
|
928
1358
|
if (r.status !== 200) return failed(r.status);
|
|
929
1359
|
setHeld((h) => h.filter((c) => c.id !== id));
|
|
1360
|
+
setUnseen((u) => u.filter((c) => c.id !== id));
|
|
930
1361
|
setOwn(({ [id]: _gone, ...rest }) => rest);
|
|
931
1362
|
setLive(s.deletedLive);
|
|
932
|
-
await
|
|
1363
|
+
await reload(true);
|
|
933
1364
|
}
|
|
934
|
-
if (session === "off" || listing === "off") return null;
|
|
935
1365
|
const loaded = typeof listing === "object" ? listing : void 0;
|
|
1366
|
+
const sortable = !!loaded && isSortable(loaded);
|
|
1367
|
+
const thread = loaded ? arrangeThread(loaded, served, held, unseen) : [];
|
|
1368
|
+
const oldestFirstPages = !!loaded && arrivesAs(loaded, served) === void 0;
|
|
1369
|
+
async function showMore() {
|
|
1370
|
+
if (thread.length > shown) {
|
|
1371
|
+
setShown(shown + PAGE);
|
|
1372
|
+
setFocusId(thread.slice(shown).find((n) => n.status !== "removed")?.id ?? null);
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
if (loadingMore) return;
|
|
1376
|
+
setLoadingMore(true);
|
|
1377
|
+
setMoreFailed(false);
|
|
1378
|
+
const r = await more();
|
|
1379
|
+
if (!alive.current) return;
|
|
1380
|
+
setLoadingMore(false);
|
|
1381
|
+
if (!r) return;
|
|
1382
|
+
if (!r.ok) return setMoreFailed(true);
|
|
1383
|
+
setShown(arrivesAs(r.listing, r.sort) === void 0 ? Number.MAX_SAFE_INTEGER : Math.min(shown, thread.length) + PAGE);
|
|
1384
|
+
setFocusId(firstOf(arrangeThread(r.listing, r.sort, held, unseen), r.added) ?? null);
|
|
1385
|
+
setLive(fill2(s.loadedLive, r.added.size));
|
|
1386
|
+
}
|
|
1387
|
+
if (session === "off" || listing === "off") return null;
|
|
936
1388
|
const ui = {
|
|
937
1389
|
s,
|
|
938
1390
|
locale,
|
|
@@ -940,17 +1392,18 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
940
1392
|
ready: session !== "loading",
|
|
941
1393
|
me,
|
|
942
1394
|
banned,
|
|
943
|
-
signInHref,
|
|
944
1395
|
signInId,
|
|
945
1396
|
idp,
|
|
946
1397
|
rateLeft,
|
|
947
1398
|
own,
|
|
948
|
-
|
|
1399
|
+
reactions: reactions.overlay,
|
|
1400
|
+
votes: votes.overlay,
|
|
949
1401
|
replyOpen,
|
|
950
1402
|
editing,
|
|
951
1403
|
confirming,
|
|
952
1404
|
actions: {
|
|
953
|
-
|
|
1405
|
+
react: (subject, kind, count2, on) => void react(subject, kind, count2, on),
|
|
1406
|
+
vote: (id, current, clicked) => void vote(id, current, clicked),
|
|
954
1407
|
reply: (id) => {
|
|
955
1408
|
const previous = replyOpen;
|
|
956
1409
|
setReplyOpen(id);
|
|
@@ -963,83 +1416,88 @@ function Comments({ path, endpoint, signInHref, locale, labels: s, initial, init
|
|
|
963
1416
|
remove: (id) => void remove(id)
|
|
964
1417
|
}
|
|
965
1418
|
};
|
|
966
|
-
const thread = loaded ? buildThread(loaded, held) : [];
|
|
967
1419
|
const hid = `${idp}-h`;
|
|
968
1420
|
const canWrite = !!me && !banned;
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
/* @__PURE__ */ (0,
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
/* @__PURE__ */ (0,
|
|
980
|
-
|
|
1421
|
+
const unfetched = !!loaded?.next_cursor;
|
|
1422
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: "hyle-comments", ref: root, "aria-labelledby": hid, "data-slot-component": "Comments", children: [
|
|
1423
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-head", children: [
|
|
1424
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("h2", { id: hid, children: [
|
|
1425
|
+
s.heading,
|
|
1426
|
+
loaded ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1427
|
+
" ",
|
|
1428
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-cm-count", "aria-label": fill2(s.countLabel, loaded.comment_count), children: loaded.comment_count })
|
|
1429
|
+
] }) : null
|
|
1430
|
+
] }),
|
|
1431
|
+
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
|
|
1432
|
+
] }),
|
|
1433
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-sr", role: "status", "aria-live": "polite", children: live }),
|
|
1434
|
+
actionError ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
|
|
1435
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
|
|
1436
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: actionError })
|
|
981
1437
|
] }) : null,
|
|
982
|
-
listing === "error" ? /* @__PURE__ */ (0,
|
|
983
|
-
/* @__PURE__ */ (0,
|
|
984
|
-
/* @__PURE__ */ (0,
|
|
985
|
-
/* @__PURE__ */ (0,
|
|
986
|
-
/* @__PURE__ */ (0,
|
|
1438
|
+
listing === "error" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "bad", role: "alert", children: [
|
|
1439
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
|
|
1440
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
|
|
1441
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.loadError }),
|
|
1442
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.loadErrorBody })
|
|
987
1443
|
] }),
|
|
988
|
-
/* @__PURE__ */ (0,
|
|
989
|
-
|
|
990
|
-
void load(false);
|
|
991
|
-
}, children: [
|
|
992
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "refresh" }),
|
|
1444
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { className: "hyle-btn sm", type: "button", onClick: retry, children: [
|
|
1445
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "refresh" }),
|
|
993
1446
|
s.retry
|
|
994
1447
|
] })
|
|
995
|
-
] }) : /* @__PURE__ */ (0,
|
|
996
|
-
loaded ? /* @__PURE__ */ (0,
|
|
997
|
-
held.length > 0 || (loaded?.mine_held?.length ?? 0) > 0 ? /* @__PURE__ */ (0,
|
|
998
|
-
/* @__PURE__ */ (0,
|
|
999
|
-
/* @__PURE__ */ (0,
|
|
1000
|
-
/* @__PURE__ */ (0,
|
|
1001
|
-
/* @__PURE__ */ (0,
|
|
1448
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1449
|
+
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,
|
|
1450
|
+
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: [
|
|
1451
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "clock" }),
|
|
1452
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
|
|
1453
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.heldBanner }),
|
|
1454
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.heldBannerBody })
|
|
1002
1455
|
] })
|
|
1003
1456
|
] }) : null,
|
|
1004
|
-
rateLeft > 0 ? /* @__PURE__ */ (0,
|
|
1005
|
-
/* @__PURE__ */ (0,
|
|
1006
|
-
/* @__PURE__ */ (0,
|
|
1007
|
-
/* @__PURE__ */ (0,
|
|
1008
|
-
/* @__PURE__ */ (0,
|
|
1457
|
+
rateLeft > 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", children: [
|
|
1458
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "clock" }),
|
|
1459
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
|
|
1460
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.rateTitle }),
|
|
1461
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.rateBody })
|
|
1009
1462
|
] })
|
|
1010
1463
|
] }) : null,
|
|
1011
|
-
banned ? /* @__PURE__ */ (0,
|
|
1012
|
-
/* @__PURE__ */ (0,
|
|
1013
|
-
/* @__PURE__ */ (0,
|
|
1014
|
-
/* @__PURE__ */ (0,
|
|
1015
|
-
/* @__PURE__ */ (0,
|
|
1464
|
+
banned ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-banner", children: [
|
|
1465
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "ban" }),
|
|
1466
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-bt", children: [
|
|
1467
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.bannedTitle }),
|
|
1468
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: s.bannedBody })
|
|
1016
1469
|
] })
|
|
1017
1470
|
] }) : null,
|
|
1018
|
-
session !== "loading" && (!me || expired) ? /* @__PURE__ */ (0,
|
|
1019
|
-
/* @__PURE__ */ (0,
|
|
1020
|
-
/* @__PURE__ */ (0,
|
|
1471
|
+
session !== "loading" && (!me || expired) ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-signin", id: signInId, children: [
|
|
1472
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { children: [
|
|
1473
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.signInTitle }),
|
|
1021
1474
|
s.signInBody
|
|
1022
1475
|
] }),
|
|
1023
|
-
signInHref ? /* @__PURE__ */ (0,
|
|
1476
|
+
signInHref ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { className: "hyle-btn primary", href: signInHref, children: s.signIn }) : null
|
|
1024
1477
|
] }) : null,
|
|
1025
|
-
canWrite ? /* @__PURE__ */ (0,
|
|
1026
|
-
!loaded ? /* @__PURE__ */ (0,
|
|
1027
|
-
/* @__PURE__ */ (0,
|
|
1028
|
-
/* @__PURE__ */ (0,
|
|
1029
|
-
/* @__PURE__ */ (0,
|
|
1030
|
-
/* @__PURE__ */ (0,
|
|
1031
|
-
/* @__PURE__ */ (0,
|
|
1032
|
-
/* @__PURE__ */ (0,
|
|
1033
|
-
/* @__PURE__ */ (0,
|
|
1478
|
+
canWrite ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Composer, { ui, id: `${idp}-new`, parentId: null, name: me }) : null,
|
|
1479
|
+
!loaded ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { role: "status", "aria-live": "polite", "aria-busy": "true", children: [
|
|
1480
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sr", children: s.loading }),
|
|
1481
|
+
/* @__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: [
|
|
1482
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk c" }),
|
|
1483
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
|
|
1484
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: 120 } }),
|
|
1485
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "100%" } }),
|
|
1486
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "hyle-sk l", style: { width: "72%" } })
|
|
1034
1487
|
] })
|
|
1035
1488
|
] }, i)) })
|
|
1036
|
-
] }) : thread.length === 0 ? /* @__PURE__ */ (0,
|
|
1037
|
-
/* @__PURE__ */ (0,
|
|
1038
|
-
/* @__PURE__ */ (0,
|
|
1039
|
-
] }) : /* @__PURE__ */ (0,
|
|
1040
|
-
/* @__PURE__ */ (0,
|
|
1041
|
-
|
|
1042
|
-
|
|
1489
|
+
] }) : thread.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "hyle-cm-empty", children: [
|
|
1490
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("b", { children: s.empty }),
|
|
1491
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: s.emptyBody })
|
|
1492
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
|
|
1493
|
+
sortable && oldestFirstPages && unfetched ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-cm-note", children: s.newerLater }) : null,
|
|
1494
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Thread, { ui, nodes: thread.slice(0, shown) }),
|
|
1495
|
+
moreFailed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("p", { className: "hyle-cm-err", role: "alert", children: [
|
|
1496
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "alert" }),
|
|
1497
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: s.moreError })
|
|
1498
|
+
] }) : null,
|
|
1499
|
+
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,
|
|
1500
|
+
loaded.truncated && !unfetched ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "hyle-cm-note", children: s.truncated }) : null
|
|
1043
1501
|
] })
|
|
1044
1502
|
] })
|
|
1045
1503
|
] });
|