@timpel/forumkit-sdk-web 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-FASHQ6GM.js +7204 -0
- package/dist/chunk-FASHQ6GM.js.map +1 -0
- package/dist/chunk-YICVG5QM.js +1008 -0
- package/dist/chunk-YICVG5QM.js.map +1 -0
- package/dist/index.css +4539 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/rich-text-editor-KDOTSXCV.css +172 -0
- package/dist/rich-text-editor-KDOTSXCV.css.map +1 -0
- package/dist/rich-text-editor-T54NZOYU.js +217 -0
- package/dist/rich-text-editor-T54NZOYU.js.map +1 -0
- package/dist/wrappers/react.css +4539 -0
- package/dist/wrappers/react.css.map +1 -0
- package/dist/wrappers/react.d.ts +21 -0
- package/dist/wrappers/react.js +25 -0
- package/dist/wrappers/react.js.map +1 -0
- package/dist/wrappers/vue.css +4539 -0
- package/dist/wrappers/vue.css.map +1 -0
- package/dist/wrappers/vue.d.ts +53 -0
- package/dist/wrappers/vue.js +41 -0
- package/dist/wrappers/vue.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,1008 @@
|
|
|
1
|
+
// src/views/components/composer/editor/extensions.ts
|
|
2
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
3
|
+
import Link from "@tiptap/extension-link";
|
|
4
|
+
import ImageExtension from "@tiptap/extension-image";
|
|
5
|
+
import Placeholder from "@tiptap/extension-placeholder";
|
|
6
|
+
import { Table } from "@tiptap/extension-table";
|
|
7
|
+
import { TableRow } from "@tiptap/extension-table-row";
|
|
8
|
+
import { TableCell } from "@tiptap/extension-table-cell";
|
|
9
|
+
import { TableHeader } from "@tiptap/extension-table-header";
|
|
10
|
+
import { Markdown } from "tiptap-markdown";
|
|
11
|
+
|
|
12
|
+
// src/views/components/composer/editor/video-extension.ts
|
|
13
|
+
import { Node, mergeAttributes } from "@tiptap/core";
|
|
14
|
+
var Video = Node.create({
|
|
15
|
+
name: "video",
|
|
16
|
+
group: "inline",
|
|
17
|
+
inline: true,
|
|
18
|
+
atom: true,
|
|
19
|
+
addOptions() {
|
|
20
|
+
return { HTMLAttributes: {} };
|
|
21
|
+
},
|
|
22
|
+
addAttributes() {
|
|
23
|
+
return {
|
|
24
|
+
src: { default: null }
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
parseHTML() {
|
|
28
|
+
return [{ tag: "video[src]" }];
|
|
29
|
+
},
|
|
30
|
+
renderHTML({ HTMLAttributes }) {
|
|
31
|
+
return ["video", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, { controls: "true" })];
|
|
32
|
+
},
|
|
33
|
+
addCommands() {
|
|
34
|
+
return {
|
|
35
|
+
setVideo: (options) => ({ commands }) => commands.insertContent({ type: this.name, attrs: options })
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
addStorage() {
|
|
39
|
+
return {
|
|
40
|
+
markdown: {
|
|
41
|
+
serialize(state, node) {
|
|
42
|
+
const src = String(node.attrs.src ?? "").replace(/[()]/g, "\\$&");
|
|
43
|
+
state.write(``);
|
|
44
|
+
},
|
|
45
|
+
parse: {
|
|
46
|
+
updateDOM(element) {
|
|
47
|
+
element.querySelectorAll('img[alt="video"]').forEach((img) => {
|
|
48
|
+
const video = document.createElement("video");
|
|
49
|
+
const src = img.getAttribute("src");
|
|
50
|
+
if (src) video.setAttribute("src", src);
|
|
51
|
+
video.setAttribute("controls", "true");
|
|
52
|
+
img.replaceWith(video);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// src/views/components/composer/editor/spoiler-mark.ts
|
|
62
|
+
import { Mark, mergeAttributes as mergeAttributes2 } from "@tiptap/core";
|
|
63
|
+
var SPOILER_CLASS = "fk-spoiler-md";
|
|
64
|
+
function spoilerTokenize(state, silent) {
|
|
65
|
+
const start = state.pos;
|
|
66
|
+
const marker = state.src.charCodeAt(start);
|
|
67
|
+
if (silent || marker !== 124) return false;
|
|
68
|
+
const scanned = state.scanDelims(state.pos, true);
|
|
69
|
+
let len = scanned.length;
|
|
70
|
+
if (len < 2) return false;
|
|
71
|
+
if (len % 2) {
|
|
72
|
+
const token = state.push("text", "", 0);
|
|
73
|
+
token.content = "|";
|
|
74
|
+
len--;
|
|
75
|
+
}
|
|
76
|
+
for (let i = 0; i < len; i += 2) {
|
|
77
|
+
const token = state.push("text", "", 0);
|
|
78
|
+
token.content = "||";
|
|
79
|
+
state.delimiters.push({
|
|
80
|
+
marker,
|
|
81
|
+
length: 0,
|
|
82
|
+
token: state.tokens.length - 1,
|
|
83
|
+
end: -1,
|
|
84
|
+
open: scanned.can_open,
|
|
85
|
+
close: scanned.can_close
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
state.pos += scanned.length;
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
function postProcess(state, delimiters) {
|
|
92
|
+
for (let i = 0; i < delimiters.length; i++) {
|
|
93
|
+
const startDelim = delimiters[i];
|
|
94
|
+
if (!startDelim || startDelim.marker !== 124 || startDelim.end === -1) continue;
|
|
95
|
+
const endDelim = delimiters[startDelim.end];
|
|
96
|
+
if (!endDelim) continue;
|
|
97
|
+
const openToken = state.tokens[startDelim.token];
|
|
98
|
+
if (openToken) Object.assign(openToken, { type: "spoiler_open", tag: "span", nesting: 1, markup: "||", content: "" });
|
|
99
|
+
const closeToken = state.tokens[endDelim.token];
|
|
100
|
+
if (closeToken) Object.assign(closeToken, { type: "spoiler_close", tag: "span", nesting: -1, markup: "||", content: "" });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function spoilerPostProcess(state) {
|
|
104
|
+
postProcess(state, state.delimiters);
|
|
105
|
+
for (const meta of state.tokens_meta) {
|
|
106
|
+
if (meta?.delimiters) postProcess(state, meta.delimiters);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
var Spoiler = Mark.create({
|
|
110
|
+
name: "spoiler",
|
|
111
|
+
parseHTML() {
|
|
112
|
+
return [{ tag: `span.${SPOILER_CLASS}` }];
|
|
113
|
+
},
|
|
114
|
+
renderHTML({ HTMLAttributes }) {
|
|
115
|
+
return ["span", mergeAttributes2(HTMLAttributes, { class: SPOILER_CLASS }), 0];
|
|
116
|
+
},
|
|
117
|
+
addCommands() {
|
|
118
|
+
return {
|
|
119
|
+
toggleSpoiler: () => ({ commands }) => commands.toggleMark(this.name)
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
addStorage() {
|
|
123
|
+
return {
|
|
124
|
+
markdown: {
|
|
125
|
+
serialize: { open: "||", close: "||", expelEnclosingWhitespace: true },
|
|
126
|
+
parse: {
|
|
127
|
+
setup(md) {
|
|
128
|
+
md.inline.ruler.before("emphasis", "spoiler", spoilerTokenize);
|
|
129
|
+
md.inline.ruler2.before("emphasis", "spoiler", spoilerPostProcess);
|
|
130
|
+
md.renderer.rules.spoiler_open = () => `<span class="${SPOILER_CLASS}">`;
|
|
131
|
+
md.renderer.rules.spoiler_close = () => "</span>";
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// src/views/components/composer/editor/superscript-extension.ts
|
|
140
|
+
import TiptapSuperscript from "@tiptap/extension-superscript";
|
|
141
|
+
import markdownItSup from "markdown-it-sup";
|
|
142
|
+
var Superscript = TiptapSuperscript.extend({
|
|
143
|
+
addStorage() {
|
|
144
|
+
return {
|
|
145
|
+
markdown: {
|
|
146
|
+
serialize: { open: "^", close: "^", expelEnclosingWhitespace: true },
|
|
147
|
+
parse: {
|
|
148
|
+
setup(md) {
|
|
149
|
+
md.use(markdownItSup);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// src/views/components/composer/editor/extensions.ts
|
|
158
|
+
function createEditorExtensions(placeholder) {
|
|
159
|
+
return [
|
|
160
|
+
StarterKit.configure({
|
|
161
|
+
heading: { levels: [2] }
|
|
162
|
+
}),
|
|
163
|
+
Link.configure({ openOnClick: false }),
|
|
164
|
+
ImageExtension,
|
|
165
|
+
Superscript,
|
|
166
|
+
Table.configure({ resizable: false }),
|
|
167
|
+
TableRow,
|
|
168
|
+
TableHeader,
|
|
169
|
+
TableCell,
|
|
170
|
+
Video,
|
|
171
|
+
Spoiler,
|
|
172
|
+
// Renders via a ::before on the empty paragraph (see .is-editor-empty in
|
|
173
|
+
// rich-text-editor.css) — TipTap has no native `placeholder` attribute
|
|
174
|
+
// like a plain <textarea>, so this extension is what the body field
|
|
175
|
+
// needs to show its explainer text when empty.
|
|
176
|
+
Placeholder.configure({ placeholder }),
|
|
177
|
+
Markdown.configure({
|
|
178
|
+
html: false,
|
|
179
|
+
tightLists: true,
|
|
180
|
+
bulletListMarker: "-",
|
|
181
|
+
linkify: false,
|
|
182
|
+
breaks: false
|
|
183
|
+
})
|
|
184
|
+
];
|
|
185
|
+
}
|
|
186
|
+
var editorExtensions = createEditorExtensions("What are your thoughts?");
|
|
187
|
+
|
|
188
|
+
// src/views/components/composer/editor/toolbar-buttons.tsx
|
|
189
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
190
|
+
var svgBase = {
|
|
191
|
+
viewBox: "0 0 24 24",
|
|
192
|
+
width: 18,
|
|
193
|
+
height: 18,
|
|
194
|
+
fill: "none",
|
|
195
|
+
stroke: "currentColor",
|
|
196
|
+
strokeWidth: 1.7,
|
|
197
|
+
strokeLinecap: "round",
|
|
198
|
+
strokeLinejoin: "round"
|
|
199
|
+
};
|
|
200
|
+
function LinkIcon() {
|
|
201
|
+
return /* @__PURE__ */ jsxs("svg", { ...svgBase, children: [
|
|
202
|
+
/* @__PURE__ */ jsx("path", { d: "M10 13a5 5 0 007 0l2-2a5 5 0 00-7-7l-1 1" }),
|
|
203
|
+
/* @__PURE__ */ jsx("path", { d: "M14 11a5 5 0 00-7 0l-2 2a5 5 0 007 7l1-1" })
|
|
204
|
+
] });
|
|
205
|
+
}
|
|
206
|
+
function ImageIcon() {
|
|
207
|
+
return /* @__PURE__ */ jsxs("svg", { ...svgBase, children: [
|
|
208
|
+
/* @__PURE__ */ jsx("rect", { x: "3.5", y: "4.5", width: "17", height: "15", rx: "2.5" }),
|
|
209
|
+
/* @__PURE__ */ jsx("circle", { cx: "9", cy: "10", r: "2" }),
|
|
210
|
+
/* @__PURE__ */ jsx("path", { d: "M4 17l5-4 4 3 3-2 4 3" })
|
|
211
|
+
] });
|
|
212
|
+
}
|
|
213
|
+
function VideoIcon() {
|
|
214
|
+
return /* @__PURE__ */ jsxs("svg", { ...svgBase, children: [
|
|
215
|
+
/* @__PURE__ */ jsx("rect", { x: "3.5", y: "5.5", width: "13", height: "13", rx: "2.5" }),
|
|
216
|
+
/* @__PURE__ */ jsx("path", { d: "M16.5 10l4-2.5v9l-4-2.5" })
|
|
217
|
+
] });
|
|
218
|
+
}
|
|
219
|
+
function BulletListIcon() {
|
|
220
|
+
return /* @__PURE__ */ jsxs("svg", { ...svgBase, children: [
|
|
221
|
+
/* @__PURE__ */ jsx("path", { d: "M8 6h12M8 12h12M8 18h12" }),
|
|
222
|
+
/* @__PURE__ */ jsx("circle", { cx: "4", cy: "6", r: "1" }),
|
|
223
|
+
/* @__PURE__ */ jsx("circle", { cx: "4", cy: "12", r: "1" }),
|
|
224
|
+
/* @__PURE__ */ jsx("circle", { cx: "4", cy: "18", r: "1" })
|
|
225
|
+
] });
|
|
226
|
+
}
|
|
227
|
+
function NumberedListIcon() {
|
|
228
|
+
return /* @__PURE__ */ jsxs("svg", { ...svgBase, children: [
|
|
229
|
+
/* @__PURE__ */ jsx("path", { d: "M9 6h11M9 12h11M9 18h11" }),
|
|
230
|
+
/* @__PURE__ */ jsx("path", { d: "M4 6h1v3M4 12h2M4 18h2" })
|
|
231
|
+
] });
|
|
232
|
+
}
|
|
233
|
+
function SpoilerIcon() {
|
|
234
|
+
return /* @__PURE__ */ jsx("svg", { ...svgBase, children: /* @__PURE__ */ jsx("path", { d: "M9 8l-4 4 4 4M15 8l4 4-4 4" }) });
|
|
235
|
+
}
|
|
236
|
+
function CodeBlockIcon() {
|
|
237
|
+
return /* @__PURE__ */ jsxs("svg", { ...svgBase, children: [
|
|
238
|
+
/* @__PURE__ */ jsx("rect", { x: "3.5", y: "4.5", width: "17", height: "15", rx: "2" }),
|
|
239
|
+
/* @__PURE__ */ jsx("path", { d: "M9.5 9l-2.5 3 2.5 3M14.5 9l2.5 3-2.5 3" })
|
|
240
|
+
] });
|
|
241
|
+
}
|
|
242
|
+
function TableIcon() {
|
|
243
|
+
return /* @__PURE__ */ jsxs("svg", { ...svgBase, children: [
|
|
244
|
+
/* @__PURE__ */ jsx("rect", { x: "3.5", y: "4.5", width: "17", height: "15", rx: "2" }),
|
|
245
|
+
/* @__PURE__ */ jsx("path", { d: "M3.5 9h17M9 9v10.5" })
|
|
246
|
+
] });
|
|
247
|
+
}
|
|
248
|
+
function GifIcon() {
|
|
249
|
+
return /* @__PURE__ */ jsxs("svg", { ...svgBase, children: [
|
|
250
|
+
/* @__PURE__ */ jsx("rect", { x: "3.5", y: "5.5", width: "17", height: "13", rx: "2.5" }),
|
|
251
|
+
/* @__PURE__ */ jsx("path", { d: "M8 9.5v5M12.5 9.5v5M12.5 12h1.7M17.5 9.5h-2v5M15.5 12h1.7" })
|
|
252
|
+
] });
|
|
253
|
+
}
|
|
254
|
+
function ToolbarButton({ label, active, onClick, style, children }) {
|
|
255
|
+
return /* @__PURE__ */ jsx(
|
|
256
|
+
"button",
|
|
257
|
+
{
|
|
258
|
+
type: "button",
|
|
259
|
+
className: `fk-rte-btn${active ? " fk-rte-btn--active" : ""}`,
|
|
260
|
+
"aria-label": label,
|
|
261
|
+
"aria-pressed": active,
|
|
262
|
+
"data-tooltip": label,
|
|
263
|
+
style,
|
|
264
|
+
onClick,
|
|
265
|
+
children
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// ../shared/src/tokens.ts
|
|
271
|
+
var darkTokens = {
|
|
272
|
+
"bg": "#0b0e12",
|
|
273
|
+
"surface": "#14171c",
|
|
274
|
+
"surface-2": "#1a1e25",
|
|
275
|
+
"elev": "#1f242c",
|
|
276
|
+
"nav": "#0e1116",
|
|
277
|
+
"border": "rgba(255, 255, 255, 0.09)",
|
|
278
|
+
"border-strong": "rgba(255, 255, 255, 0.16)",
|
|
279
|
+
"text": "#e7eaef",
|
|
280
|
+
"text-2": "#c3c9d2",
|
|
281
|
+
"muted": "#868e9b",
|
|
282
|
+
"faint": "#5b6470",
|
|
283
|
+
"hover": "rgba(255, 255, 255, 0.06)",
|
|
284
|
+
"hover-2": "rgba(255, 255, 255, 0.1)",
|
|
285
|
+
"accent": "#3f7ee2",
|
|
286
|
+
"accent-2": "#5a92ea",
|
|
287
|
+
"accent-fg": "#ffffff",
|
|
288
|
+
"accent-soft": "rgba(63, 126, 226, 0.16)",
|
|
289
|
+
"up": "#ff6a3d",
|
|
290
|
+
"down": "#8b6dff",
|
|
291
|
+
"success": "#3fb950",
|
|
292
|
+
// Precomputed tints of `success` (rgb(63,185,80)) — matches the
|
|
293
|
+
// `accent-soft` pattern above rather than a runtime hex→rgba conversion
|
|
294
|
+
// (RN has no color-mix()). Used for the accepted-answer comment's row wash
|
|
295
|
+
// (6%) and badge fill (16%).
|
|
296
|
+
"success-soft": "rgba(63, 185, 80, 0.06)",
|
|
297
|
+
"success-soft-strong": "rgba(63, 185, 80, 0.16)",
|
|
298
|
+
"danger": "#e0463a",
|
|
299
|
+
"ring": "rgba(63, 126, 226, 0.55)",
|
|
300
|
+
"thumb-shadow": "rgba(0, 0, 0, 0.5)",
|
|
301
|
+
// A tint layered over a native blur (mobile's floating bottom bar +
|
|
302
|
+
// hamburger drawer + hamburger button) — the classic "frosted glass" look.
|
|
303
|
+
// Used to be the same white tint in both themes on purpose (the blur
|
|
304
|
+
// itself, not this tint, is what makes it read as "glass"), but on an
|
|
305
|
+
// actual dark-mode device that reads as a bright panel contradicting the
|
|
306
|
+
// rest of the UI — so this is now dark by default, with lightTokens below
|
|
307
|
+
// overriding back to the original white.
|
|
308
|
+
"glass": "rgba(12, 14, 18, 0.35)"
|
|
309
|
+
};
|
|
310
|
+
var lightTokens = {
|
|
311
|
+
...darkTokens,
|
|
312
|
+
"bg": "#f6f8fa",
|
|
313
|
+
"surface": "#ffffff",
|
|
314
|
+
"surface-2": "#eef1f4",
|
|
315
|
+
"elev": "#ffffff",
|
|
316
|
+
"nav": "#ffffff",
|
|
317
|
+
"border": "rgba(0, 0, 0, 0.1)",
|
|
318
|
+
"border-strong": "rgba(0, 0, 0, 0.16)",
|
|
319
|
+
"text": "#16181c",
|
|
320
|
+
"text-2": "#2b2f36",
|
|
321
|
+
"muted": "#5c6773",
|
|
322
|
+
"faint": "#7c8794",
|
|
323
|
+
"hover": "rgba(0, 0, 0, 0.05)",
|
|
324
|
+
"hover-2": "rgba(0, 0, 0, 0.08)",
|
|
325
|
+
"accent": "#2f6fd6",
|
|
326
|
+
"accent-2": "#2560c4",
|
|
327
|
+
"accent-soft": "rgba(47, 111, 214, 0.12)",
|
|
328
|
+
"up": "#f0521f",
|
|
329
|
+
"success": "#1f9d3c",
|
|
330
|
+
// rgb(31,157,60) tints — see darkTokens' comment.
|
|
331
|
+
"success-soft": "rgba(31, 157, 60, 0.06)",
|
|
332
|
+
"success-soft-strong": "rgba(31, 157, 60, 0.16)",
|
|
333
|
+
"danger": "#d1372b",
|
|
334
|
+
"ring": "rgba(47, 111, 214, 0.5)",
|
|
335
|
+
"thumb-shadow": "rgba(0, 0, 0, 0.18)",
|
|
336
|
+
"glass": "rgba(255, 255, 255, 0.10)"
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// ../shared/src/format-time.ts
|
|
340
|
+
function fmtRelativeTime(iso) {
|
|
341
|
+
const seconds = Math.floor((Date.now() - new Date(iso).getTime()) / 1e3);
|
|
342
|
+
if (seconds < 60) return "now";
|
|
343
|
+
const minutes = Math.floor(seconds / 60);
|
|
344
|
+
if (minutes < 60) return `${minutes}m`;
|
|
345
|
+
const hours = Math.floor(minutes / 60);
|
|
346
|
+
if (hours < 24) return `${hours}h`;
|
|
347
|
+
const days = Math.floor(hours / 24);
|
|
348
|
+
return `${days}d`;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ../shared/src/author-avatar.ts
|
|
352
|
+
var AVATAR_GRADIENT_ANGLE = 135;
|
|
353
|
+
var AVATAR_GRADIENT_PAIRS = [
|
|
354
|
+
["#3f7ee2", "#5ee6d0"],
|
|
355
|
+
["#ff6a3d", "#ff5b7f"],
|
|
356
|
+
["#8b5cf6", "#3f7ee2"],
|
|
357
|
+
["#5ee6d0", "#3f7ee2"],
|
|
358
|
+
["#f0521f", "#ff8a5b"],
|
|
359
|
+
["#8360c3", "#2ebf91"]
|
|
360
|
+
];
|
|
361
|
+
var DEFAULT_PAIR = ["#3f7ee2", "#5ee6d0"];
|
|
362
|
+
function authorAvatar(authorId, authorName) {
|
|
363
|
+
const key = authorId ?? authorName;
|
|
364
|
+
let hash = 0;
|
|
365
|
+
for (let i = 0; i < key.length; i++) hash = hash * 31 + key.charCodeAt(i) >>> 0;
|
|
366
|
+
return {
|
|
367
|
+
colors: AVATAR_GRADIENT_PAIRS[hash % AVATAR_GRADIENT_PAIRS.length] ?? DEFAULT_PAIR,
|
|
368
|
+
letter: (authorName.trim()[0] ?? "?").toUpperCase()
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ../shared/src/feed.ts
|
|
373
|
+
function threadToFeedRow(thread) {
|
|
374
|
+
const attachments = thread.attachments ?? [];
|
|
375
|
+
const firstImage = attachments.find((a) => a.mimeType.startsWith("image/"));
|
|
376
|
+
const firstVideo = attachments.find((a) => a.mimeType.startsWith("video/"));
|
|
377
|
+
return {
|
|
378
|
+
id: thread.id,
|
|
379
|
+
authorId: thread.authorId,
|
|
380
|
+
author: thread.authorDisplayName ?? "Member",
|
|
381
|
+
authorAvatarUrl: thread.authorAvatarUrl ?? null,
|
|
382
|
+
time: fmtRelativeTime(thread.createdAt),
|
|
383
|
+
title: thread.title,
|
|
384
|
+
body: thread.body,
|
|
385
|
+
imageUrl: firstImage?.downloadUrl ?? null,
|
|
386
|
+
videoUrl: firstImage ? null : firstVideo?.downloadUrl ?? null,
|
|
387
|
+
mediaCount: attachments.length,
|
|
388
|
+
voteCounts: thread.voteCounts ?? { up: 0, down: 0 },
|
|
389
|
+
myVote: thread.myVote ?? null,
|
|
390
|
+
commentCount: thread.commentCount ?? 0,
|
|
391
|
+
saved: thread.isSaved ?? false
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// ../shared/src/comments.ts
|
|
396
|
+
function netVotes(v) {
|
|
397
|
+
return (v?.up ?? 0) - (v?.down ?? 0);
|
|
398
|
+
}
|
|
399
|
+
function commentsToCommentTree(comments) {
|
|
400
|
+
const byId = /* @__PURE__ */ new Map();
|
|
401
|
+
const roots = [];
|
|
402
|
+
for (const p of comments) {
|
|
403
|
+
const voteCounts = p.voteCounts ?? { up: 0, down: 0 };
|
|
404
|
+
byId.set(p.id, {
|
|
405
|
+
id: p.id,
|
|
406
|
+
authorId: p.authorId,
|
|
407
|
+
author: p.authorDisplayName ?? "Member",
|
|
408
|
+
authorAvatarUrl: p.authorAvatarUrl ?? null,
|
|
409
|
+
time: fmtRelativeTime(p.createdAt),
|
|
410
|
+
body: p.body,
|
|
411
|
+
votes: netVotes(voteCounts),
|
|
412
|
+
voteCounts,
|
|
413
|
+
myVote: p.myVote ?? null,
|
|
414
|
+
isSaved: p.isSaved ?? false,
|
|
415
|
+
isAcceptedAnswer: p.isAcceptedAnswer,
|
|
416
|
+
replies: []
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
for (const p of comments) {
|
|
420
|
+
const node = byId.get(p.id);
|
|
421
|
+
if (!node) continue;
|
|
422
|
+
const parent = p.parentCommentId ? byId.get(p.parentCommentId) : void 0;
|
|
423
|
+
if (parent) parent.replies.push(node);
|
|
424
|
+
else roots.push(node);
|
|
425
|
+
}
|
|
426
|
+
return roots;
|
|
427
|
+
}
|
|
428
|
+
function filterComments(list, q) {
|
|
429
|
+
const lower = q.toLowerCase();
|
|
430
|
+
return list.reduce((acc, c) => {
|
|
431
|
+
const filteredReplies = filterComments(c.replies, lower);
|
|
432
|
+
if (c.body.toLowerCase().includes(lower) || filteredReplies.length > 0) {
|
|
433
|
+
acc.push({ ...c, replies: filteredReplies });
|
|
434
|
+
}
|
|
435
|
+
return acc;
|
|
436
|
+
}, []);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// ../shared/src/notifications.ts
|
|
440
|
+
function describeNotification(n) {
|
|
441
|
+
const actor = n.actorDisplayName ?? "Someone";
|
|
442
|
+
switch (n.type) {
|
|
443
|
+
case "share":
|
|
444
|
+
return `${actor} shared a post with you`;
|
|
445
|
+
case "comment_reply":
|
|
446
|
+
return `${actor} replied to your comment`;
|
|
447
|
+
case "vote": {
|
|
448
|
+
const verb = n.message === "down" ? "downvoted" : "upvoted";
|
|
449
|
+
const target = n.commentId ? "your comment" : "your thread";
|
|
450
|
+
return `${actor} ${verb} ${target}`;
|
|
451
|
+
}
|
|
452
|
+
case "report":
|
|
453
|
+
return `${actor} reported ${n.commentId ? "a comment" : "a thread"}`;
|
|
454
|
+
default:
|
|
455
|
+
return `${actor} did something`;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ../shared/src/profile.ts
|
|
460
|
+
var PROFILE_TABS = ["Overview", "Posts", "Comments", "Saved", "Upvoted", "Downvoted"];
|
|
461
|
+
var DEFAULT_EMPTY_STATE_COPY = {
|
|
462
|
+
title: "You don\u2019t have any activity yet",
|
|
463
|
+
description: "Once you post, comment, or vote, it\u2019ll show up here. If you\u2019d rather hide your activity, update your settings."
|
|
464
|
+
};
|
|
465
|
+
var EMPTY_STATE_COPY = {
|
|
466
|
+
Overview: {
|
|
467
|
+
title: "You don\u2019t have any activity yet",
|
|
468
|
+
description: "Once you post, comment, or vote, it\u2019ll show up here. If you\u2019d rather hide your activity, update your settings."
|
|
469
|
+
},
|
|
470
|
+
Posts: {
|
|
471
|
+
title: "You don\u2019t have any posts yet",
|
|
472
|
+
description: "Once you post, it\u2019ll show up here. If you\u2019d rather hide your posts, update your settings."
|
|
473
|
+
},
|
|
474
|
+
Comments: {
|
|
475
|
+
title: "You don\u2019t have any comments yet",
|
|
476
|
+
description: "Once you comment on a post, it\u2019ll show up here. If you\u2019d rather hide your comments, update your settings."
|
|
477
|
+
},
|
|
478
|
+
Saved: {
|
|
479
|
+
title: "Looks like you haven\u2019t saved anything yet",
|
|
480
|
+
description: "Save posts and comments to find them here later."
|
|
481
|
+
},
|
|
482
|
+
Upvoted: {
|
|
483
|
+
title: "Looks like you haven\u2019t upvoted anything yet",
|
|
484
|
+
description: "Posts and comments you upvote will show up here."
|
|
485
|
+
},
|
|
486
|
+
Downvoted: {
|
|
487
|
+
title: "Looks like you haven\u2019t downvoted anything yet",
|
|
488
|
+
description: "Posts and comments you downvote will show up here."
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
function profileEmptyCopy(tab) {
|
|
492
|
+
return EMPTY_STATE_COPY[tab] ?? DEFAULT_EMPTY_STATE_COPY;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// ../shared/src/social.ts
|
|
496
|
+
var SOCIAL_PLATFORMS = [
|
|
497
|
+
"Website",
|
|
498
|
+
"Portfolio",
|
|
499
|
+
"GitHub",
|
|
500
|
+
"LinkedIn",
|
|
501
|
+
"Twitter/X",
|
|
502
|
+
"Behance",
|
|
503
|
+
"Dribbble",
|
|
504
|
+
"Other"
|
|
505
|
+
];
|
|
506
|
+
var PLATFORM_META = {
|
|
507
|
+
"Website": { prefix: "", placeholder: "https://yoursite.com" },
|
|
508
|
+
"Portfolio": { prefix: "", placeholder: "https://portfolio.io" },
|
|
509
|
+
"GitHub": { prefix: "https://github.com/", placeholder: "username" },
|
|
510
|
+
"LinkedIn": { prefix: "https://linkedin.com/in/", placeholder: "your-name" },
|
|
511
|
+
"Twitter/X": { prefix: "https://x.com/", placeholder: "username" },
|
|
512
|
+
"Behance": { prefix: "https://behance.net/", placeholder: "username" },
|
|
513
|
+
"Dribbble": { prefix: "https://dribbble.com/", placeholder: "username" },
|
|
514
|
+
"Other": { prefix: "", placeholder: "https://" }
|
|
515
|
+
};
|
|
516
|
+
function socialPrefix(platform) {
|
|
517
|
+
return PLATFORM_META[platform].prefix;
|
|
518
|
+
}
|
|
519
|
+
function socialPlaceholder(platform) {
|
|
520
|
+
return PLATFORM_META[platform].placeholder;
|
|
521
|
+
}
|
|
522
|
+
function socialToSuffix(platform, url) {
|
|
523
|
+
const { prefix } = PLATFORM_META[platform];
|
|
524
|
+
return prefix && url.startsWith(prefix) ? url.slice(prefix.length) : url;
|
|
525
|
+
}
|
|
526
|
+
function socialToUrl(platform, suffix) {
|
|
527
|
+
const { prefix } = PLATFORM_META[platform];
|
|
528
|
+
const trimmed = suffix.trim().replace(/^\/+|\/+$/g, "");
|
|
529
|
+
if (!prefix) {
|
|
530
|
+
return trimmed && !/^https?:\/\//i.test(trimmed) ? `https://${trimmed}` : trimmed;
|
|
531
|
+
}
|
|
532
|
+
return `${prefix}${trimmed}`;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// ../shared/src/notification-prefs.ts
|
|
536
|
+
var NOTIFICATION_PREF_ROWS = [
|
|
537
|
+
{ key: "commentReply", label: "Comment replies", sub: "When someone replies to your comment" },
|
|
538
|
+
{ key: "share", label: "Shares", sub: "When someone shares a post with you" },
|
|
539
|
+
{ key: "vote", label: "Upvotes & downvotes", sub: "When someone votes on your post or comment" },
|
|
540
|
+
{ key: "moderationReport", label: "Moderation reports", sub: "When a member reports a post or comment", modOnly: true }
|
|
541
|
+
];
|
|
542
|
+
|
|
543
|
+
// ../shared/src/api.ts
|
|
544
|
+
function authHeaders(token) {
|
|
545
|
+
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
546
|
+
}
|
|
547
|
+
async function okJson(res) {
|
|
548
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
549
|
+
return await res.json();
|
|
550
|
+
}
|
|
551
|
+
async function okVoid(res) {
|
|
552
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
553
|
+
}
|
|
554
|
+
async function unwrapJson(res) {
|
|
555
|
+
if (!res.ok) {
|
|
556
|
+
const message = await res.json().then((data) => data.message).catch(() => void 0);
|
|
557
|
+
throw new Error(message ?? `HTTP ${res.status}`);
|
|
558
|
+
}
|
|
559
|
+
return await res.json();
|
|
560
|
+
}
|
|
561
|
+
function buildQuery(params) {
|
|
562
|
+
const parts = [];
|
|
563
|
+
for (const [key, value] of Object.entries(params)) {
|
|
564
|
+
if (value === void 0) continue;
|
|
565
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
566
|
+
}
|
|
567
|
+
return parts.length ? `?${parts.join("&")}` : "";
|
|
568
|
+
}
|
|
569
|
+
async function createSession(apiUrl, hostToken) {
|
|
570
|
+
const res = await fetch(`${apiUrl}/auth/session`, {
|
|
571
|
+
method: "POST",
|
|
572
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${hostToken}` },
|
|
573
|
+
body: JSON.stringify({ token: hostToken })
|
|
574
|
+
});
|
|
575
|
+
return okJson(res);
|
|
576
|
+
}
|
|
577
|
+
async function listThreads(apiUrl, forumId, token, params) {
|
|
578
|
+
const suffix = buildQuery({
|
|
579
|
+
sort: params?.sort,
|
|
580
|
+
tagId: params?.tagId,
|
|
581
|
+
tagName: params?.tagName,
|
|
582
|
+
pinned: params?.pinned,
|
|
583
|
+
topWindow: params?.topWindow,
|
|
584
|
+
limit: params?.limit,
|
|
585
|
+
page: params?.page
|
|
586
|
+
});
|
|
587
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads${suffix}`, {
|
|
588
|
+
method: "GET",
|
|
589
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) }
|
|
590
|
+
});
|
|
591
|
+
return okJson(res);
|
|
592
|
+
}
|
|
593
|
+
async function saveThread(apiUrl, forumId, threadId, token) {
|
|
594
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads/${threadId}/save`, {
|
|
595
|
+
method: "POST",
|
|
596
|
+
headers: authHeaders(token)
|
|
597
|
+
});
|
|
598
|
+
return okVoid(res);
|
|
599
|
+
}
|
|
600
|
+
async function unsaveThread(apiUrl, forumId, threadId, token) {
|
|
601
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads/${threadId}/save`, {
|
|
602
|
+
method: "DELETE",
|
|
603
|
+
headers: authHeaders(token)
|
|
604
|
+
});
|
|
605
|
+
return okVoid(res);
|
|
606
|
+
}
|
|
607
|
+
async function reportThread(apiUrl, forumId, threadId, reason, token) {
|
|
608
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads/${threadId}/report`, {
|
|
609
|
+
method: "POST",
|
|
610
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
611
|
+
body: JSON.stringify({ reason })
|
|
612
|
+
});
|
|
613
|
+
return okVoid(res);
|
|
614
|
+
}
|
|
615
|
+
async function voteOnThread(apiUrl, forumId, threadId, direction, token) {
|
|
616
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads/${threadId}/vote`, {
|
|
617
|
+
method: "POST",
|
|
618
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
619
|
+
body: JSON.stringify({ direction })
|
|
620
|
+
});
|
|
621
|
+
return okJson(res);
|
|
622
|
+
}
|
|
623
|
+
async function removeVoteFromThread(apiUrl, forumId, threadId, token) {
|
|
624
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads/${threadId}/vote`, {
|
|
625
|
+
method: "DELETE",
|
|
626
|
+
headers: authHeaders(token)
|
|
627
|
+
});
|
|
628
|
+
return okJson(res);
|
|
629
|
+
}
|
|
630
|
+
async function getThread(apiUrl, forumId, threadId, token) {
|
|
631
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads/${threadId}`, {
|
|
632
|
+
method: "GET",
|
|
633
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) }
|
|
634
|
+
});
|
|
635
|
+
return okJson(res);
|
|
636
|
+
}
|
|
637
|
+
async function createThread(apiUrl, forumId, body, token) {
|
|
638
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads`, {
|
|
639
|
+
method: "POST",
|
|
640
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
641
|
+
body: JSON.stringify(body)
|
|
642
|
+
});
|
|
643
|
+
return unwrapJson(res);
|
|
644
|
+
}
|
|
645
|
+
async function createReply(apiUrl, threadId, body, token) {
|
|
646
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments`, {
|
|
647
|
+
method: "POST",
|
|
648
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
649
|
+
body: JSON.stringify(body)
|
|
650
|
+
});
|
|
651
|
+
return unwrapJson(res);
|
|
652
|
+
}
|
|
653
|
+
async function saveComment(apiUrl, threadId, commentId, token) {
|
|
654
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments/${commentId}/save`, {
|
|
655
|
+
method: "POST",
|
|
656
|
+
headers: authHeaders(token)
|
|
657
|
+
});
|
|
658
|
+
return okVoid(res);
|
|
659
|
+
}
|
|
660
|
+
async function unsaveComment(apiUrl, threadId, commentId, token) {
|
|
661
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments/${commentId}/save`, {
|
|
662
|
+
method: "DELETE",
|
|
663
|
+
headers: authHeaders(token)
|
|
664
|
+
});
|
|
665
|
+
return okVoid(res);
|
|
666
|
+
}
|
|
667
|
+
async function reportComment(apiUrl, threadId, commentId, reason, token) {
|
|
668
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments/${commentId}/report`, {
|
|
669
|
+
method: "POST",
|
|
670
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
671
|
+
body: JSON.stringify({ reason })
|
|
672
|
+
});
|
|
673
|
+
return okVoid(res);
|
|
674
|
+
}
|
|
675
|
+
async function voteOnComment(apiUrl, threadId, commentId, direction, token) {
|
|
676
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments/${commentId}/vote`, {
|
|
677
|
+
method: "POST",
|
|
678
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
679
|
+
body: JSON.stringify({ direction })
|
|
680
|
+
});
|
|
681
|
+
return okJson(res);
|
|
682
|
+
}
|
|
683
|
+
async function removeVoteFromComment(apiUrl, threadId, commentId, token) {
|
|
684
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments/${commentId}/vote`, {
|
|
685
|
+
method: "DELETE",
|
|
686
|
+
headers: authHeaders(token)
|
|
687
|
+
});
|
|
688
|
+
return okJson(res);
|
|
689
|
+
}
|
|
690
|
+
async function listNotifications(apiUrl, forumId, opts, token) {
|
|
691
|
+
const suffix = buildQuery({ page: opts?.page, limit: opts?.limit });
|
|
692
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/notifications${suffix}`, {
|
|
693
|
+
headers: authHeaders(token)
|
|
694
|
+
});
|
|
695
|
+
return okJson(res);
|
|
696
|
+
}
|
|
697
|
+
async function markNotificationRead(apiUrl, forumId, id, token) {
|
|
698
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/notifications/${id}/read`, {
|
|
699
|
+
method: "PATCH",
|
|
700
|
+
headers: authHeaders(token)
|
|
701
|
+
});
|
|
702
|
+
return okVoid(res);
|
|
703
|
+
}
|
|
704
|
+
async function markAllNotificationsRead(apiUrl, forumId, token) {
|
|
705
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/notifications/read-all`, {
|
|
706
|
+
method: "PATCH",
|
|
707
|
+
headers: authHeaders(token)
|
|
708
|
+
});
|
|
709
|
+
return okVoid(res);
|
|
710
|
+
}
|
|
711
|
+
async function deleteNotification(apiUrl, forumId, id, token) {
|
|
712
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/notifications/${id}`, {
|
|
713
|
+
method: "DELETE",
|
|
714
|
+
headers: authHeaders(token)
|
|
715
|
+
});
|
|
716
|
+
return okVoid(res);
|
|
717
|
+
}
|
|
718
|
+
async function createDraft(apiUrl, forumId, title, content, token) {
|
|
719
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/drafts`, {
|
|
720
|
+
method: "POST",
|
|
721
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
722
|
+
body: JSON.stringify({ title, content })
|
|
723
|
+
});
|
|
724
|
+
return unwrapJson(res);
|
|
725
|
+
}
|
|
726
|
+
async function getMyProfile(apiUrl, forumId, token) {
|
|
727
|
+
try {
|
|
728
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/me`, { headers: authHeaders(token) });
|
|
729
|
+
if (!res.ok) return null;
|
|
730
|
+
return await res.json();
|
|
731
|
+
} catch {
|
|
732
|
+
return null;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
async function updateMyProfile(apiUrl, forumId, body, token) {
|
|
736
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/me`, {
|
|
737
|
+
method: "PATCH",
|
|
738
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
739
|
+
body: JSON.stringify(body)
|
|
740
|
+
});
|
|
741
|
+
return unwrapJson(res);
|
|
742
|
+
}
|
|
743
|
+
async function updateNotificationPrefs(apiUrl, forumId, prefs, token) {
|
|
744
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/me/notification-prefs`, {
|
|
745
|
+
method: "PATCH",
|
|
746
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
747
|
+
body: JSON.stringify(prefs)
|
|
748
|
+
});
|
|
749
|
+
return okVoid(res);
|
|
750
|
+
}
|
|
751
|
+
async function getProfileActivity(apiUrl, forumId, scope, page, limit, sort, contentType, token) {
|
|
752
|
+
const suffix = buildQuery({ scope, page, limit, sort, contentType });
|
|
753
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/me/activity${suffix}`, { headers: authHeaders(token) });
|
|
754
|
+
return okJson(res);
|
|
755
|
+
}
|
|
756
|
+
async function updateReply(apiUrl, threadId, commentId, body, token) {
|
|
757
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments/${commentId}`, {
|
|
758
|
+
method: "PATCH",
|
|
759
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
760
|
+
body: JSON.stringify({ body })
|
|
761
|
+
});
|
|
762
|
+
return unwrapJson(res);
|
|
763
|
+
}
|
|
764
|
+
async function deleteComment(apiUrl, threadId, commentId, token) {
|
|
765
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments/${commentId}`, {
|
|
766
|
+
method: "DELETE",
|
|
767
|
+
headers: authHeaders(token)
|
|
768
|
+
});
|
|
769
|
+
return okVoid(res);
|
|
770
|
+
}
|
|
771
|
+
async function acceptAnswer(apiUrl, threadId, commentId, token) {
|
|
772
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments/${commentId}/accept`, {
|
|
773
|
+
method: "POST",
|
|
774
|
+
headers: authHeaders(token)
|
|
775
|
+
});
|
|
776
|
+
return unwrapJson(res);
|
|
777
|
+
}
|
|
778
|
+
async function unacceptAnswer(apiUrl, threadId, commentId, token) {
|
|
779
|
+
const res = await fetch(`${apiUrl}/threads/${threadId}/comments/${commentId}/accept`, {
|
|
780
|
+
method: "DELETE",
|
|
781
|
+
headers: authHeaders(token)
|
|
782
|
+
});
|
|
783
|
+
return unwrapJson(res);
|
|
784
|
+
}
|
|
785
|
+
async function updateThread(apiUrl, forumId, threadId, body, token) {
|
|
786
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads/${threadId}`, {
|
|
787
|
+
method: "PATCH",
|
|
788
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
789
|
+
body: JSON.stringify(body)
|
|
790
|
+
});
|
|
791
|
+
return unwrapJson(res);
|
|
792
|
+
}
|
|
793
|
+
async function deleteThread(apiUrl, forumId, threadId, token) {
|
|
794
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads/${threadId}`, {
|
|
795
|
+
method: "DELETE",
|
|
796
|
+
headers: authHeaders(token)
|
|
797
|
+
});
|
|
798
|
+
return okVoid(res);
|
|
799
|
+
}
|
|
800
|
+
async function shareThreadWithUsers(apiUrl, forumId, threadId, recipientUserIds, message, token) {
|
|
801
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/threads/${threadId}/share`, {
|
|
802
|
+
method: "POST",
|
|
803
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
804
|
+
body: JSON.stringify({ recipientUserIds, message })
|
|
805
|
+
});
|
|
806
|
+
return okVoid(res);
|
|
807
|
+
}
|
|
808
|
+
async function requestUploadUrl(apiUrl, forumId, opts, token) {
|
|
809
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/attachments/upload-url`, {
|
|
810
|
+
method: "POST",
|
|
811
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
812
|
+
body: JSON.stringify(opts)
|
|
813
|
+
});
|
|
814
|
+
return okJson(res);
|
|
815
|
+
}
|
|
816
|
+
async function confirmUpload(apiUrl, forumId, attachmentId, dimensions, token) {
|
|
817
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/attachments/${attachmentId}/confirm`, {
|
|
818
|
+
method: "POST",
|
|
819
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
820
|
+
body: JSON.stringify(dimensions)
|
|
821
|
+
});
|
|
822
|
+
return okJson(res);
|
|
823
|
+
}
|
|
824
|
+
async function deleteAttachment(apiUrl, forumId, attachmentId, token) {
|
|
825
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/attachments/${attachmentId}`, {
|
|
826
|
+
method: "DELETE",
|
|
827
|
+
headers: authHeaders(token)
|
|
828
|
+
});
|
|
829
|
+
return okVoid(res);
|
|
830
|
+
}
|
|
831
|
+
var GifSearchNotConfiguredError = class extends Error {
|
|
832
|
+
};
|
|
833
|
+
async function searchGifs(apiUrl, forumId, query, token, limit = 24) {
|
|
834
|
+
const suffix = buildQuery({ q: query, limit });
|
|
835
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/gifs/search${suffix}`, {
|
|
836
|
+
method: "GET",
|
|
837
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) }
|
|
838
|
+
});
|
|
839
|
+
if (res.status === 503) throw new GifSearchNotConfiguredError("GIF search is not configured for this forum yet.");
|
|
840
|
+
const body = await okJson(res);
|
|
841
|
+
return body.results;
|
|
842
|
+
}
|
|
843
|
+
async function searchThreads(apiUrl, forumId, q, opts, token) {
|
|
844
|
+
const suffix = buildQuery({ q, page: opts?.page, limit: opts?.limit });
|
|
845
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/search${suffix}`, { headers: authHeaders(token) });
|
|
846
|
+
return okJson(res);
|
|
847
|
+
}
|
|
848
|
+
async function searchUsers(apiUrl, forumId, q, opts, token) {
|
|
849
|
+
const suffix = buildQuery({ q, page: opts?.page, limit: opts?.limit });
|
|
850
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/search/users${suffix}`, { headers: authHeaders(token) });
|
|
851
|
+
return okJson(res);
|
|
852
|
+
}
|
|
853
|
+
async function listDrafts(apiUrl, forumId, token) {
|
|
854
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/drafts`, { headers: authHeaders(token) });
|
|
855
|
+
const data = await okJson(res);
|
|
856
|
+
return data.drafts;
|
|
857
|
+
}
|
|
858
|
+
async function updateDraft(apiUrl, forumId, draftId, fields, token) {
|
|
859
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/drafts/${draftId}`, {
|
|
860
|
+
method: "PATCH",
|
|
861
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
862
|
+
body: JSON.stringify(fields)
|
|
863
|
+
});
|
|
864
|
+
return unwrapJson(res);
|
|
865
|
+
}
|
|
866
|
+
async function deleteDraft(apiUrl, forumId, draftId, token) {
|
|
867
|
+
const res = await fetch(`${apiUrl}/forums/${forumId}/drafts/${draftId}`, {
|
|
868
|
+
method: "DELETE",
|
|
869
|
+
headers: authHeaders(token)
|
|
870
|
+
});
|
|
871
|
+
return okVoid(res);
|
|
872
|
+
}
|
|
873
|
+
async function getModerationQueue(apiUrl, params, token) {
|
|
874
|
+
const suffix = buildQuery({ page: params?.page, limit: params?.limit });
|
|
875
|
+
const res = await fetch(`${apiUrl}/moderation/queue${suffix}`, { headers: authHeaders(token) });
|
|
876
|
+
return unwrapJson(res);
|
|
877
|
+
}
|
|
878
|
+
async function resolveModerationItem(apiUrl, itemId, action, token) {
|
|
879
|
+
const res = await fetch(`${apiUrl}/moderation/queue/${itemId}`, {
|
|
880
|
+
method: "PATCH",
|
|
881
|
+
headers: { "Content-Type": "application/json", ...authHeaders(token) },
|
|
882
|
+
body: JSON.stringify({ action })
|
|
883
|
+
});
|
|
884
|
+
return unwrapJson(res);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// src/views/api/attachments.ts
|
|
888
|
+
var API_BASE = typeof window !== "undefined" ? window.FK_API_URL ?? "" : "";
|
|
889
|
+
function requestUploadUrl2(opts) {
|
|
890
|
+
return requestUploadUrl(
|
|
891
|
+
API_BASE,
|
|
892
|
+
opts.forumId,
|
|
893
|
+
{ filename: opts.filename, mimeType: opts.mimeType, byteSize: opts.byteSize, purpose: opts.purpose },
|
|
894
|
+
opts.token
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
async function putFile(uploadUrl, uploadHeaders, file) {
|
|
898
|
+
const res = await fetch(uploadUrl, { method: "PUT", headers: uploadHeaders, body: file });
|
|
899
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
900
|
+
}
|
|
901
|
+
function confirmUpload2(forumId, attachmentId, dimensions, token) {
|
|
902
|
+
return confirmUpload(API_BASE, forumId, attachmentId, dimensions, token);
|
|
903
|
+
}
|
|
904
|
+
function deleteAttachment2(forumId, attachmentId, token) {
|
|
905
|
+
return deleteAttachment(API_BASE, forumId, attachmentId, token);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/views/components/composer/editor/upload-inline.ts
|
|
909
|
+
async function uploadInline(forumId, sessionToken, file) {
|
|
910
|
+
const upload = await requestUploadUrl2({ forumId, filename: file.name, mimeType: file.type, byteSize: file.size, purpose: "attachment", token: sessionToken });
|
|
911
|
+
await putFile(upload.uploadUrl, upload.uploadHeaders, file);
|
|
912
|
+
let width = null;
|
|
913
|
+
let height = null;
|
|
914
|
+
if (file.type.startsWith("image/")) {
|
|
915
|
+
try {
|
|
916
|
+
const bitmap = await createImageBitmap(file);
|
|
917
|
+
width = bitmap.width;
|
|
918
|
+
height = bitmap.height;
|
|
919
|
+
bitmap.close();
|
|
920
|
+
} catch {
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
const attachment = await confirmUpload2(forumId, upload.attachmentId, { width, height }, sessionToken);
|
|
924
|
+
return { url: attachment.downloadUrl, attachmentId: upload.attachmentId };
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// src/views/lib/accepted-media-types.ts
|
|
928
|
+
var IMAGE_ACCEPT = "image/png,image/jpeg,image/gif,image/webp";
|
|
929
|
+
var IMAGE_VIDEO_ACCEPT = `${IMAGE_ACCEPT},video/mp4,video/webm`;
|
|
930
|
+
|
|
931
|
+
export {
|
|
932
|
+
fmtRelativeTime,
|
|
933
|
+
AVATAR_GRADIENT_ANGLE,
|
|
934
|
+
authorAvatar,
|
|
935
|
+
threadToFeedRow,
|
|
936
|
+
commentsToCommentTree,
|
|
937
|
+
filterComments,
|
|
938
|
+
describeNotification,
|
|
939
|
+
PROFILE_TABS,
|
|
940
|
+
profileEmptyCopy,
|
|
941
|
+
SOCIAL_PLATFORMS,
|
|
942
|
+
socialPrefix,
|
|
943
|
+
socialPlaceholder,
|
|
944
|
+
socialToSuffix,
|
|
945
|
+
socialToUrl,
|
|
946
|
+
NOTIFICATION_PREF_ROWS,
|
|
947
|
+
authHeaders,
|
|
948
|
+
createSession,
|
|
949
|
+
listThreads,
|
|
950
|
+
saveThread,
|
|
951
|
+
unsaveThread,
|
|
952
|
+
reportThread,
|
|
953
|
+
voteOnThread,
|
|
954
|
+
removeVoteFromThread,
|
|
955
|
+
getThread,
|
|
956
|
+
createThread,
|
|
957
|
+
createReply,
|
|
958
|
+
saveComment,
|
|
959
|
+
unsaveComment,
|
|
960
|
+
reportComment,
|
|
961
|
+
voteOnComment,
|
|
962
|
+
removeVoteFromComment,
|
|
963
|
+
listNotifications,
|
|
964
|
+
markNotificationRead,
|
|
965
|
+
markAllNotificationsRead,
|
|
966
|
+
deleteNotification,
|
|
967
|
+
createDraft,
|
|
968
|
+
getMyProfile,
|
|
969
|
+
updateMyProfile,
|
|
970
|
+
updateNotificationPrefs,
|
|
971
|
+
getProfileActivity,
|
|
972
|
+
updateReply,
|
|
973
|
+
deleteComment,
|
|
974
|
+
acceptAnswer,
|
|
975
|
+
unacceptAnswer,
|
|
976
|
+
updateThread,
|
|
977
|
+
deleteThread,
|
|
978
|
+
shareThreadWithUsers,
|
|
979
|
+
GifSearchNotConfiguredError,
|
|
980
|
+
searchGifs,
|
|
981
|
+
searchThreads,
|
|
982
|
+
searchUsers,
|
|
983
|
+
listDrafts,
|
|
984
|
+
updateDraft,
|
|
985
|
+
deleteDraft,
|
|
986
|
+
getModerationQueue,
|
|
987
|
+
resolveModerationItem,
|
|
988
|
+
requestUploadUrl2 as requestUploadUrl,
|
|
989
|
+
putFile,
|
|
990
|
+
confirmUpload2 as confirmUpload,
|
|
991
|
+
deleteAttachment2 as deleteAttachment,
|
|
992
|
+
createEditorExtensions,
|
|
993
|
+
editorExtensions,
|
|
994
|
+
LinkIcon,
|
|
995
|
+
ImageIcon,
|
|
996
|
+
VideoIcon,
|
|
997
|
+
BulletListIcon,
|
|
998
|
+
NumberedListIcon,
|
|
999
|
+
SpoilerIcon,
|
|
1000
|
+
CodeBlockIcon,
|
|
1001
|
+
TableIcon,
|
|
1002
|
+
GifIcon,
|
|
1003
|
+
ToolbarButton,
|
|
1004
|
+
uploadInline,
|
|
1005
|
+
IMAGE_ACCEPT,
|
|
1006
|
+
IMAGE_VIDEO_ACCEPT
|
|
1007
|
+
};
|
|
1008
|
+
//# sourceMappingURL=chunk-YICVG5QM.js.map
|