@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
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
// src/react/comments-api.ts
|
|
2
|
+
var CSRF_HEADER = "x-hyle-engage";
|
|
3
|
+
var TIMEOUT_MS = 15e3;
|
|
4
|
+
var reading = /* @__PURE__ */ new Map();
|
|
5
|
+
function call(endpoint, method, path, body) {
|
|
6
|
+
if (method !== "GET") {
|
|
7
|
+
reading.clear();
|
|
8
|
+
return send(endpoint, method, path, body).finally(() => reading.clear());
|
|
9
|
+
}
|
|
10
|
+
const key = `${endpoint}${path}`;
|
|
11
|
+
const shared = reading.get(key);
|
|
12
|
+
if (shared) return shared;
|
|
13
|
+
const request = send(endpoint, method, path).finally(() => {
|
|
14
|
+
if (reading.get(key) === request) reading.delete(key);
|
|
15
|
+
});
|
|
16
|
+
reading.set(key, request);
|
|
17
|
+
return request;
|
|
18
|
+
}
|
|
19
|
+
async function send(endpoint, method, path, body) {
|
|
20
|
+
try {
|
|
21
|
+
const res = await fetch(`${endpoint}${path}`, {
|
|
22
|
+
method,
|
|
23
|
+
credentials: "same-origin",
|
|
24
|
+
cache: "no-store",
|
|
25
|
+
headers: { accept: "application/json", [CSRF_HEADER]: "1", ...body ? { "content-type": "application/json" } : {} },
|
|
26
|
+
...body ? { body: JSON.stringify(body) } : {},
|
|
27
|
+
signal: AbortSignal.timeout(TIMEOUT_MS)
|
|
28
|
+
});
|
|
29
|
+
let data;
|
|
30
|
+
try {
|
|
31
|
+
data = (await res.json()).data;
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
const retry = Number(res.headers.get("retry-after"));
|
|
35
|
+
return { status: res.status, data, retryAfter: Number.isFinite(retry) && retry > 0 ? retry : void 0 };
|
|
36
|
+
} catch {
|
|
37
|
+
return { status: 0, data: void 0, retryAfter: void 0 };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var REACTION_KINDS = ["like", "love", "insightful", "celebrate"];
|
|
41
|
+
var isCursor = (v) => typeof v === "string" && /^[A-Za-z0-9_-]{1,200}$/.test(v);
|
|
42
|
+
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
43
|
+
var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.trunc(v) : 0;
|
|
44
|
+
function parseCounts(v) {
|
|
45
|
+
if (!isObject(v)) return void 0;
|
|
46
|
+
return Object.fromEntries(REACTION_KINDS.map((kind) => [kind, count(v[kind])]).filter(([, n]) => n > 0));
|
|
47
|
+
}
|
|
48
|
+
var toVote = (v) => v === 1 || v === -1 ? v : null;
|
|
49
|
+
var toUnrenderable = (v) => v === true ? { unrenderable: true } : {};
|
|
50
|
+
var toMine = (v) => Array.isArray(v) ? { my_reactions: REACTION_KINDS.filter((kind) => v.includes(kind)) } : {};
|
|
51
|
+
function toComment(raw) {
|
|
52
|
+
if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string") return void 0;
|
|
53
|
+
const depth = typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1;
|
|
54
|
+
const author = isObject(raw.author) && typeof raw.author.name === "string" ? raw.author.name : void 0;
|
|
55
|
+
const name = typeof raw.author_name === "string" ? raw.author_name : author;
|
|
56
|
+
const body = isObject(raw.body) && raw.body.format === "hast" ? { format: "hast", tree: raw.body.tree } : null;
|
|
57
|
+
const removed = raw.removed === true || body === null;
|
|
58
|
+
const reactions = parseCounts(raw.reaction_counts);
|
|
59
|
+
return {
|
|
60
|
+
id: raw.id,
|
|
61
|
+
parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
|
|
62
|
+
depth,
|
|
63
|
+
author_name: name ?? null,
|
|
64
|
+
created_at: raw.created_at,
|
|
65
|
+
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
66
|
+
like_count: count(raw.like_count),
|
|
67
|
+
...Number.isSafeInteger(raw.score) ? { score: raw.score } : {},
|
|
68
|
+
...reactions ? { reaction_counts: reactions } : {},
|
|
69
|
+
removed,
|
|
70
|
+
...removed && (raw.removed_by === "moderator" || raw.removed_by === "author") ? { removed_by: raw.removed_by } : {},
|
|
71
|
+
...removed ? {} : toUnrenderable(raw.unrenderable),
|
|
72
|
+
body,
|
|
73
|
+
// 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, ..."my_vote" in raw ? { my_vote: toVote(raw.my_vote) } : {}, ...toMine(raw.my_reactions) } : {}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function toHeld(raw) {
|
|
78
|
+
if (!isObject(raw) || typeof raw.id !== "string" || typeof raw.created_at !== "string" || !isObject(raw.body) || raw.body.format !== "hast") return void 0;
|
|
79
|
+
const author = isObject(raw.author) && typeof raw.author.name === "string" ? raw.author.name : null;
|
|
80
|
+
return {
|
|
81
|
+
id: raw.id,
|
|
82
|
+
parent_id: typeof raw.parent_id === "string" ? raw.parent_id : null,
|
|
83
|
+
depth: typeof raw.depth === "number" ? Math.min(4, Math.max(1, Math.trunc(raw.depth))) : 1,
|
|
84
|
+
author_name: author,
|
|
85
|
+
created_at: raw.created_at,
|
|
86
|
+
edited_at: typeof raw.edited_at === "string" ? raw.edited_at : null,
|
|
87
|
+
can_edit_until: typeof raw.can_edit_until === "string" ? raw.can_edit_until : null,
|
|
88
|
+
...toUnrenderable(raw.unrenderable),
|
|
89
|
+
body: { format: "hast", tree: raw.body.tree }
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function parseListing(data) {
|
|
93
|
+
if (!isObject(data) || data.kind !== "comments" || !Array.isArray(data.comments)) return void 0;
|
|
94
|
+
const comments = data.comments.map(toComment).filter((c) => c !== void 0);
|
|
95
|
+
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) } : {};
|
|
96
|
+
const reactions = parseCounts(data.reaction_counts);
|
|
97
|
+
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 };
|
|
98
|
+
}
|
|
99
|
+
async function fetchPage(endpoint, path, sort, cursor) {
|
|
100
|
+
const query = new URLSearchParams({ path, ...cursor ? { cursor } : {}, ...sort ? { sort } : {} });
|
|
101
|
+
const r = await call(endpoint, "GET", `/comments?${query}`);
|
|
102
|
+
let listing = r.status === 200 ? parseListing(r.data) : void 0;
|
|
103
|
+
if (listing?.next_cursor && (listing.comments.length === 0 || listing.next_cursor === cursor)) listing = { ...listing, next_cursor: null };
|
|
104
|
+
return { status: r.status, listing, pages: listing ? 1 : 0, sort };
|
|
105
|
+
}
|
|
106
|
+
async function fetchPages(endpoint, path, order, pages, legacy = false) {
|
|
107
|
+
let out = await fetchPage(endpoint, path, order === "top" ? "top" : legacy ? void 0 : "new");
|
|
108
|
+
if (out.status === 400 && out.sort === "new") out = await fetchPage(endpoint, path, void 0);
|
|
109
|
+
while (out.listing?.next_cursor && out.pages < pages) {
|
|
110
|
+
const next = await fetchPage(endpoint, path, out.sort, out.listing.next_cursor);
|
|
111
|
+
if (!next.listing) return { ...next, status: next.status === 404 ? 502 : next.status, pages: 0 };
|
|
112
|
+
out = { ...next, listing: mergeListings(out.listing, next.listing), pages: out.pages + 1 };
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
async function fetchNext(endpoint, path, order, loaded, legacy = false) {
|
|
117
|
+
const next = await fetchPage(endpoint, path, loaded.sort, loaded.listing.next_cursor ?? void 0);
|
|
118
|
+
if (next.status === 400) return { ...await fetchPages(endpoint, path, order, loaded.pages + 1, legacy), restarted: true };
|
|
119
|
+
return { ...next, ...next.listing ? { listing: mergeListings(loaded.listing, next.listing), pages: loaded.pages + 1 } : {}, restarted: false };
|
|
120
|
+
}
|
|
121
|
+
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 } };
|
|
122
|
+
function mergeListings(earlier, later) {
|
|
123
|
+
const byId = new Map(earlier.comments.map((c) => [c.id, c]));
|
|
124
|
+
for (const c of later.comments) {
|
|
125
|
+
const old = byId.get(c.id);
|
|
126
|
+
byId.set(c.id, old && !c.removed ? { ...viewerOf(old), ...c } : c);
|
|
127
|
+
}
|
|
128
|
+
const { liked_by_me, my_reactions, mine_held } = earlier;
|
|
129
|
+
const viewer = !later.mine_held && mine_held ? { liked_by_me: liked_by_me === true, ...my_reactions ? { my_reactions } : {}, mine_held } : {};
|
|
130
|
+
return { ...later, ...viewer, comments: [...byId.values()] };
|
|
131
|
+
}
|
|
132
|
+
function nextVote(current, clicked) {
|
|
133
|
+
const value = current.value === clicked ? null : clicked;
|
|
134
|
+
return { value, score: current.score - (current.value ?? 0) + (value ?? 0) };
|
|
135
|
+
}
|
|
136
|
+
var untilMs = (iso) => {
|
|
137
|
+
const t = iso ? Date.parse(iso) : NaN;
|
|
138
|
+
return Number.isFinite(t) ? t : void 0;
|
|
139
|
+
};
|
|
140
|
+
function buildThread(listing, localHeld, unseen = [], newestOnTop = false) {
|
|
141
|
+
const byId = /* @__PURE__ */ new Map();
|
|
142
|
+
const roots = [];
|
|
143
|
+
const place = (node, parentId) => {
|
|
144
|
+
const parent = parentId ? byId.get(parentId) : void 0;
|
|
145
|
+
(parent ? parent.kids : roots).push(node);
|
|
146
|
+
};
|
|
147
|
+
for (const c of listing.comments) {
|
|
148
|
+
if (byId.has(c.id)) continue;
|
|
149
|
+
const removed = c.removed;
|
|
150
|
+
const node = {
|
|
151
|
+
id: c.id,
|
|
152
|
+
depth: c.depth,
|
|
153
|
+
status: removed ? "removed" : "visible",
|
|
154
|
+
removedBy: removed ? c.removed_by : void 0,
|
|
155
|
+
mine: !removed && c.mine === true,
|
|
156
|
+
canEditUntil: untilMs(c.can_edit_until),
|
|
157
|
+
likedByMe: !removed && c.liked_by_me === true,
|
|
158
|
+
myReactions: removed ? void 0 : c.my_reactions,
|
|
159
|
+
name: removed ? null : c.author_name ?? null,
|
|
160
|
+
createdAt: c.created_at,
|
|
161
|
+
editedAt: c.edited_at,
|
|
162
|
+
likes: c.like_count,
|
|
163
|
+
score: c.score,
|
|
164
|
+
myVote: c.my_vote,
|
|
165
|
+
reactions: c.reaction_counts,
|
|
166
|
+
tree: c.body?.tree,
|
|
167
|
+
unrenderable: c.unrenderable,
|
|
168
|
+
text: void 0,
|
|
169
|
+
kids: []
|
|
170
|
+
};
|
|
171
|
+
place(node, c.parent_id === c.id ? null : c.parent_id);
|
|
172
|
+
byId.set(c.id, node);
|
|
173
|
+
}
|
|
174
|
+
const mine = [];
|
|
175
|
+
const addHeld = (node, parentId, oldestFirst) => {
|
|
176
|
+
const parent = parentId ? byId.get(parentId) : void 0;
|
|
177
|
+
if (parent) parent.kids.push(node);
|
|
178
|
+
else if (oldestFirst) mine.unshift(node);
|
|
179
|
+
else mine.push(node);
|
|
180
|
+
};
|
|
181
|
+
const heldIds = /* @__PURE__ */ new Set();
|
|
182
|
+
for (const h of listing.mine_held ?? []) {
|
|
183
|
+
heldIds.add(h.id);
|
|
184
|
+
const parent = h.parent_id ? byId.get(h.parent_id) : void 0;
|
|
185
|
+
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);
|
|
186
|
+
}
|
|
187
|
+
if (listing.mine_held === void 0) {
|
|
188
|
+
for (const h of localHeld) {
|
|
189
|
+
if (byId.has(h.id) || heldIds.has(h.id)) continue;
|
|
190
|
+
const parent = h.parentId ? byId.get(h.parentId) : void 0;
|
|
191
|
+
addHeld(localNode(h, "held", parent), h.parentId, false);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
for (const u of [...unseen].reverse()) {
|
|
195
|
+
if (byId.has(u.id) || heldIds.has(u.id) || u.status === "held" && listing.mine_held === void 0) continue;
|
|
196
|
+
const parent = u.parentId ? byId.get(u.parentId) : void 0;
|
|
197
|
+
const node = localNode(u, u.status, parent);
|
|
198
|
+
if (u.status === "held") addHeld(node, u.parentId, true);
|
|
199
|
+
else if (parent) parent.kids.push(node);
|
|
200
|
+
else if (newestOnTop) roots.unshift(node);
|
|
201
|
+
else roots.push(node);
|
|
202
|
+
byId.set(u.id, node);
|
|
203
|
+
}
|
|
204
|
+
return [...mine, ...roots];
|
|
205
|
+
}
|
|
206
|
+
var localNode = (c, status, parent) => ({
|
|
207
|
+
id: c.id,
|
|
208
|
+
depth: Math.min(4, (parent?.depth ?? 0) + 1),
|
|
209
|
+
status,
|
|
210
|
+
removedBy: void 0,
|
|
211
|
+
mine: true,
|
|
212
|
+
canEditUntil: void 0,
|
|
213
|
+
likedByMe: false,
|
|
214
|
+
name: c.name,
|
|
215
|
+
createdAt: c.createdAt,
|
|
216
|
+
editedAt: null,
|
|
217
|
+
likes: 0,
|
|
218
|
+
tree: void 0,
|
|
219
|
+
text: c.text,
|
|
220
|
+
kids: []
|
|
221
|
+
});
|
|
222
|
+
var isSortable = (listing) => listing.comments.some((c) => c.score !== void 0);
|
|
223
|
+
var arrivesAs = (listing, sort) => isSortable(listing) ? sort : void 0;
|
|
224
|
+
function arrangeThread(listing, sort, localHeld, unseen) {
|
|
225
|
+
const from = arrivesAs(listing, sort);
|
|
226
|
+
const thread = buildThread(listing, localHeld, unseen, from === "new");
|
|
227
|
+
return isSortable(listing) && from === void 0 ? newestFirst(thread) : thread;
|
|
228
|
+
}
|
|
229
|
+
function stillUnseen(unseen, listing) {
|
|
230
|
+
const listed = new Set([...listing.comments, ...listing.mine_held ?? []].map((c) => c.id));
|
|
231
|
+
return unseen.some((c) => listed.has(c.id)) ? unseen.filter((c) => !listed.has(c.id)) : unseen;
|
|
232
|
+
}
|
|
233
|
+
function newestFirst(thread) {
|
|
234
|
+
return [...thread.filter((n) => n.status === "held"), ...thread.filter((n) => n.status !== "held").reverse()];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/react/icons.tsx
|
|
238
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
239
|
+
var SHAPES = {
|
|
240
|
+
info: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
241
|
+
/* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6" }),
|
|
242
|
+
/* @__PURE__ */ jsx("path", { d: "M8 7.3V11M8 5v.1" })
|
|
243
|
+
] }),
|
|
244
|
+
"check-circle": /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
245
|
+
/* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6" }),
|
|
246
|
+
/* @__PURE__ */ jsx("path", { d: "m5.3 8.3 1.9 1.9 3.5-3.9" })
|
|
247
|
+
] }),
|
|
248
|
+
alert: /* @__PURE__ */ jsx("path", { d: "M8 2 1.8 13h12.4zM8 6.5v3M8 11.3v.1" }),
|
|
249
|
+
"x-circle": /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
250
|
+
/* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6" }),
|
|
251
|
+
/* @__PURE__ */ jsx("path", { d: "m5.8 5.8 4.4 4.4M10.2 5.8l-4.4 4.4" })
|
|
252
|
+
] }),
|
|
253
|
+
calendar: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
254
|
+
/* @__PURE__ */ jsx("rect", { x: "2", y: "3", width: "12", height: "11", rx: "1.3" }),
|
|
255
|
+
/* @__PURE__ */ jsx("path", { d: "M2 6.5h12M5.5 1.7v2.6M10.5 1.7v2.6" })
|
|
256
|
+
] }),
|
|
257
|
+
globe: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
258
|
+
/* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6" }),
|
|
259
|
+
/* @__PURE__ */ jsx("path", { d: "M2 8h12M8 2c2 1.7 2.8 3.7 2.8 6S10 12.3 8 14M8 2C6 3.7 5.2 5.7 5.2 8S6 12.3 8 14" })
|
|
260
|
+
] }),
|
|
261
|
+
file: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
262
|
+
/* @__PURE__ */ jsx("path", { d: "M4 1.8h5l3 3v8.4a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2.8a1 1 0 0 1 1-1z" }),
|
|
263
|
+
/* @__PURE__ */ jsx("path", { d: "M9 1.8v3h3" })
|
|
264
|
+
] }),
|
|
265
|
+
chev: /* @__PURE__ */ jsx("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
|
|
266
|
+
"chev-up": /* @__PURE__ */ jsx("path", { d: "m3.5 10 4.5-4.5L12.5 10" }),
|
|
267
|
+
"chev-down": /* @__PURE__ */ jsx("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
|
|
268
|
+
"chev-left": /* @__PURE__ */ jsx("path", { d: "M10 3.5 5.5 8 10 12.5" }),
|
|
269
|
+
x: /* @__PURE__ */ jsx("path", { d: "m4 4 8 8M12 4l-8 8" }),
|
|
270
|
+
important: /* @__PURE__ */ 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" }),
|
|
271
|
+
copy: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
272
|
+
/* @__PURE__ */ jsx("rect", { x: "5.5", y: "5.5", width: "8", height: "8", rx: "1.3" }),
|
|
273
|
+
/* @__PURE__ */ 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" })
|
|
274
|
+
] }),
|
|
275
|
+
check: /* @__PURE__ */ jsx("path", { d: "m3 8.5 3.2 3L13 4.5" }),
|
|
276
|
+
heart: /* @__PURE__ */ 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" }),
|
|
277
|
+
reply: /* @__PURE__ */ jsx("path", { d: "M6.5 3.5 2.5 7.5l4 4M2.5 7.5h6a5 5 0 0 1 5 5" }),
|
|
278
|
+
clock: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
279
|
+
/* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6" }),
|
|
280
|
+
/* @__PURE__ */ jsx("path", { d: "M8 4.5V8l2.3 1.5" })
|
|
281
|
+
] }),
|
|
282
|
+
ban: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
283
|
+
/* @__PURE__ */ jsx("circle", { cx: "8", cy: "8", r: "6" }),
|
|
284
|
+
/* @__PURE__ */ jsx("path", { d: "m3.8 12.2 8.4-8.4" })
|
|
285
|
+
] }),
|
|
286
|
+
refresh: /* @__PURE__ */ jsx("path", { d: "M13 8a5 5 0 1 1-1.6-3.7M13 2.5v2.8h-2.8" })
|
|
287
|
+
};
|
|
288
|
+
function Icon({ name, className }) {
|
|
289
|
+
return /* @__PURE__ */ jsx("svg", { className: className ? `hyle-ic ${className}` : "hyle-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: SHAPES[name] });
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/react/reaction-bar.tsx
|
|
293
|
+
import { useEffect, useRef, useState } from "react";
|
|
294
|
+
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
295
|
+
var reactionKey = (subject, kind) => `${subject}:${kind}`;
|
|
296
|
+
var kindName = (s, kind) => ({ like: s.reactionLike, love: s.reactionLove, insightful: s.reactionInsightful, celebrate: s.reactionCelebrate })[kind];
|
|
297
|
+
function settleReactions(overlay, pending, listing) {
|
|
298
|
+
const told = new Set(listing.comments.filter((c) => c.my_reactions).map((c) => c.id));
|
|
299
|
+
if (listing.my_reactions) told.add("article");
|
|
300
|
+
return Object.fromEntries(Object.entries(overlay).flatMap(([key, v]) => {
|
|
301
|
+
if (pending.has(key)) return [[key, v]];
|
|
302
|
+
return v.on && !key.endsWith(":like") && !told.has(key.slice(0, key.lastIndexOf(":"))) ? [[key, { on: true }]] : [];
|
|
303
|
+
}));
|
|
304
|
+
}
|
|
305
|
+
function useReactions(endpoint, path) {
|
|
306
|
+
const [overlay, setOverlay] = useState({});
|
|
307
|
+
const pending = useRef(/* @__PURE__ */ new Set());
|
|
308
|
+
async function toggle(subject, kind, count2, on) {
|
|
309
|
+
const key = reactionKey(subject, kind);
|
|
310
|
+
if (pending.current.has(key)) return void 0;
|
|
311
|
+
const before = { on: overlay[key]?.on ?? on, count: overlay[key]?.count ?? count2 };
|
|
312
|
+
pending.current.add(key);
|
|
313
|
+
setOverlay((o) => ({ ...o, [key]: { on: !before.on, count: Math.max(0, before.count + (before.on ? -1 : 1)) } }));
|
|
314
|
+
const target = subject === "article" ? { subject_type: "article", path } : { subject_type: "comment", comment_id: subject };
|
|
315
|
+
const r = await call(endpoint, before.on ? "DELETE" : "PUT", "/reactions", kind === "like" ? target : { ...target, kind });
|
|
316
|
+
pending.current.delete(key);
|
|
317
|
+
const reaction = r.status === 200 && isObject(r.data) && isObject(r.data.reaction) ? r.data.reaction : void 0;
|
|
318
|
+
const counts = parseCounts(reaction?.counts);
|
|
319
|
+
const settled = counts ? counts[kind] ?? 0 : kind === "like" && typeof reaction?.like_count === "number" ? reaction.like_count : void 0;
|
|
320
|
+
if (reaction && settled !== void 0) {
|
|
321
|
+
const active = reaction.active === true;
|
|
322
|
+
setOverlay((o) => ({ ...o, [key]: { on: active, count: settled } }));
|
|
323
|
+
return { ok: true, on: active };
|
|
324
|
+
}
|
|
325
|
+
setOverlay((o) => ({ ...o, [key]: before }));
|
|
326
|
+
return { ok: false, status: r.status };
|
|
327
|
+
}
|
|
328
|
+
const settle = (listing) => setOverlay((o) => settleReactions(o, pending.current, listing));
|
|
329
|
+
return { overlay, toggle, settle, reset: () => setOverlay({}) };
|
|
330
|
+
}
|
|
331
|
+
function ReactionBar({ s, scope, subject, likes, counts, likedByMe, mine, overlay, access, signInHref, onToggle }) {
|
|
332
|
+
const [open, setOpen] = useState(false);
|
|
333
|
+
const first = useRef(null);
|
|
334
|
+
const trigger = useRef(null);
|
|
335
|
+
useEffect(() => {
|
|
336
|
+
if (open) first.current?.focus();
|
|
337
|
+
}, [open]);
|
|
338
|
+
const base = scope === "article" ? "hyle-btn" : "hyle-cm-btn cnt";
|
|
339
|
+
function button(kind) {
|
|
340
|
+
const state = overlay[reactionKey(subject, kind)];
|
|
341
|
+
const server = kind === "like" ? likes : counts?.[kind] ?? 0;
|
|
342
|
+
const serverOn = mine ? mine.includes(kind) : kind === "like" && likedByMe;
|
|
343
|
+
const count2 = state?.count ?? server;
|
|
344
|
+
const on = state?.on ?? serverOn;
|
|
345
|
+
if (kind !== "like" && !open && !state && count2 === 0) return null;
|
|
346
|
+
const out = access === "out";
|
|
347
|
+
const content = kind !== "like" ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
348
|
+
out ? /* @__PURE__ */ jsx2("span", { className: "hyle-sr", children: s.reactionSignIn }) : null,
|
|
349
|
+
kindName(s, kind),
|
|
350
|
+
" ",
|
|
351
|
+
/* @__PURE__ */ jsx2("span", { children: count2 })
|
|
352
|
+
] }) : scope === "article" ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
353
|
+
/* @__PURE__ */ jsx2(Icon, { name: "heart" }),
|
|
354
|
+
out ? s.likeArticle : on ? s.likedArticle : s.likeArticle,
|
|
355
|
+
" ",
|
|
356
|
+
/* @__PURE__ */ jsx2("span", { className: "hyle-sr", children: out ? s.likeArticleSignIn : ", " }),
|
|
357
|
+
/* @__PURE__ */ jsx2("span", { children: count2 })
|
|
358
|
+
] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
359
|
+
/* @__PURE__ */ jsx2(Icon, { name: "heart" }),
|
|
360
|
+
/* @__PURE__ */ jsx2("span", { className: "hyle-sr", children: out ? s.likeCommentSignIn : s.likeComment }),
|
|
361
|
+
/* @__PURE__ */ jsx2("span", { children: count2 })
|
|
362
|
+
] });
|
|
363
|
+
const cls = kind === "like" ? base : `${base} chip`;
|
|
364
|
+
if (out && signInHref) return /* @__PURE__ */ jsx2("a", { className: cls, href: signInHref, children: content }, kind);
|
|
365
|
+
if (access !== "in") return /* @__PURE__ */ jsx2("button", { className: cls, type: "button", "aria-disabled": "true", children: content }, kind);
|
|
366
|
+
return /* @__PURE__ */ jsx2("button", { ref: kind === "love" ? first : void 0, className: cls, type: "button", "aria-pressed": on, onClick: () => {
|
|
367
|
+
setOpen(false);
|
|
368
|
+
onToggle(kind, server, serverOn);
|
|
369
|
+
}, children: content }, kind);
|
|
370
|
+
}
|
|
371
|
+
if (!counts) return /* @__PURE__ */ jsx2(Fragment2, { children: button("like") });
|
|
372
|
+
const onKey = (e) => {
|
|
373
|
+
if (e.key !== "Escape" || !open) return;
|
|
374
|
+
e.preventDefault();
|
|
375
|
+
setOpen(false);
|
|
376
|
+
trigger.current?.focus();
|
|
377
|
+
};
|
|
378
|
+
return /* @__PURE__ */ jsxs2("span", { className: "hyle-reaction-set", role: "group", "aria-label": s.reactions, onKeyDown: onKey, children: [
|
|
379
|
+
REACTION_KINDS.map(button),
|
|
380
|
+
access === "in" ? /* @__PURE__ */ jsx2("button", { ref: trigger, className: scope === "article" ? "hyle-btn" : "hyle-cm-btn", type: "button", "aria-expanded": open, onClick: () => setOpen((v) => !v), children: s.react }) : null
|
|
381
|
+
] });
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export {
|
|
385
|
+
call,
|
|
386
|
+
isObject,
|
|
387
|
+
fetchPages,
|
|
388
|
+
fetchNext,
|
|
389
|
+
nextVote,
|
|
390
|
+
isSortable,
|
|
391
|
+
arrivesAs,
|
|
392
|
+
arrangeThread,
|
|
393
|
+
stillUnseen,
|
|
394
|
+
Icon,
|
|
395
|
+
kindName,
|
|
396
|
+
useReactions,
|
|
397
|
+
ReactionBar
|
|
398
|
+
};
|