g-comments 0.1.0 → 0.2.1
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/CHANGELOG.md +27 -0
- package/README.md +44 -8
- package/dist/{chunk-X6RAR374.cjs → chunk-IBNNENCZ.cjs} +14 -2
- package/dist/chunk-IBNNENCZ.cjs.map +1 -0
- package/dist/{chunk-6E3M3PQN.js → chunk-WACVXJHD.js} +14 -2
- package/dist/chunk-WACVXJHD.js.map +1 -0
- package/dist/element.d.ts +58 -5
- package/dist/element.js +983 -965
- package/dist/element.js.map +1 -1
- package/dist/index.cjs +16 -16
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{messages-BlBkT6Kr.d.cts → messages-C9bMljl3.d.cts} +51 -1
- package/dist/{messages-BlBkT6Kr.d.ts → messages-C9bMljl3.d.ts} +51 -1
- package/dist/react.cjs +236 -35
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +20 -5
- package/dist/react.d.ts +20 -5
- package/dist/react.js +206 -6
- package/dist/react.js.map +1 -1
- package/package.json +9 -9
- package/styles/styles.css +957 -947
- package/dist/chunk-6E3M3PQN.js.map +0 -1
- package/dist/chunk-X6RAR374.cjs.map +0 -1
package/dist/react.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var chunkIBNNENCZ_cjs = require('./chunk-IBNNENCZ.cjs');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
|
|
8
8
|
var useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
9
9
|
function toCommentsError(error) {
|
|
10
|
-
if (
|
|
10
|
+
if (chunkIBNNENCZ_cjs.isCommentsError(error)) {
|
|
11
11
|
return error;
|
|
12
12
|
}
|
|
13
|
-
return new
|
|
13
|
+
return new chunkIBNNENCZ_cjs.CommentsError("unknown", error instanceof Error ? error.message : String(error), {
|
|
14
14
|
cause: error
|
|
15
15
|
});
|
|
16
16
|
}
|
|
@@ -87,12 +87,12 @@ function formatAbsolute(iso, locale) {
|
|
|
87
87
|
|
|
88
88
|
// src/react/context.ts
|
|
89
89
|
var CommentsContext = react.createContext(null);
|
|
90
|
-
var defaultTranslator =
|
|
90
|
+
var defaultTranslator = chunkIBNNENCZ_cjs.createTranslator();
|
|
91
91
|
function useCommentsContext(forum) {
|
|
92
92
|
const value = useOptionalCommentsContext(forum);
|
|
93
93
|
if (!value) {
|
|
94
94
|
throw new Error(
|
|
95
|
-
`${
|
|
95
|
+
`${chunkIBNNENCZ_cjs.PACKAGE_NAME}: render this inside <DiscourseComments forum="\u2026"> or pass a \`forum\` prop`
|
|
96
96
|
);
|
|
97
97
|
}
|
|
98
98
|
return value;
|
|
@@ -100,13 +100,13 @@ function useCommentsContext(forum) {
|
|
|
100
100
|
function useOptionalCommentsContext(forum) {
|
|
101
101
|
const context = react.useContext(CommentsContext);
|
|
102
102
|
const standalone = react.useMemo(() => {
|
|
103
|
-
if (forum === void 0 || context &&
|
|
103
|
+
if (forum === void 0 || context && chunkIBNNENCZ_cjs.normalizeForum(forum).base === context.client.forum) {
|
|
104
104
|
return null;
|
|
105
105
|
}
|
|
106
106
|
return {
|
|
107
|
-
client:
|
|
107
|
+
client: chunkIBNNENCZ_cjs.clientRegistry.acquire({ forum }),
|
|
108
108
|
t: context?.t ?? defaultTranslator,
|
|
109
|
-
locale: context?.locale ??
|
|
109
|
+
locale: context?.locale ?? chunkIBNNENCZ_cjs.resolveLocale(void 0),
|
|
110
110
|
messages: context?.messages,
|
|
111
111
|
theme: context?.theme ?? "auto",
|
|
112
112
|
appearance: context?.appearance,
|
|
@@ -119,7 +119,7 @@ function useOptionalCommentsContext(forum) {
|
|
|
119
119
|
function useClient() {
|
|
120
120
|
const context = react.useContext(CommentsContext);
|
|
121
121
|
if (!context) {
|
|
122
|
-
throw new Error(`${
|
|
122
|
+
throw new Error(`${chunkIBNNENCZ_cjs.PACKAGE_NAME}: useClient() needs a <DiscourseComments> provider`);
|
|
123
123
|
}
|
|
124
124
|
return context.client;
|
|
125
125
|
}
|
|
@@ -138,11 +138,11 @@ function DiscourseComments(props) {
|
|
|
138
138
|
debug
|
|
139
139
|
};
|
|
140
140
|
const client = react.useMemo(
|
|
141
|
-
() => explicitClient ??
|
|
141
|
+
() => explicitClient ?? chunkIBNNENCZ_cjs.clientRegistry.acquire(creation),
|
|
142
142
|
[explicitClient, forum]
|
|
143
143
|
);
|
|
144
144
|
const messagesKey = messages ? JSON.stringify(messages) : "";
|
|
145
|
-
const t = react.useMemo(() =>
|
|
145
|
+
const t = react.useMemo(() => chunkIBNNENCZ_cjs.createTranslator(locale, messages), [locale, messagesKey]);
|
|
146
146
|
const onEventRef = react.useRef(onEvent);
|
|
147
147
|
react.useEffect(() => {
|
|
148
148
|
onEventRef.current = onEvent;
|
|
@@ -151,7 +151,7 @@ function DiscourseComments(props) {
|
|
|
151
151
|
() => ({
|
|
152
152
|
client,
|
|
153
153
|
t,
|
|
154
|
-
locale:
|
|
154
|
+
locale: chunkIBNNENCZ_cjs.resolveLocale(locale),
|
|
155
155
|
messages,
|
|
156
156
|
theme,
|
|
157
157
|
appearance,
|
|
@@ -284,6 +284,150 @@ function ImageIcon() {
|
|
|
284
284
|
function BackIcon() {
|
|
285
285
|
return /* @__PURE__ */ jsxRuntime.jsx(Icon, { children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "m15 18-6-6 6-6" }) });
|
|
286
286
|
}
|
|
287
|
+
|
|
288
|
+
// src/react/forum-theme.ts
|
|
289
|
+
var FORUM_ROOT = '.gc-root[data-gc-theme="forum"]';
|
|
290
|
+
var FORUM_STYLED_ROOT = '.gc-root--styled[data-gc-theme="forum"]';
|
|
291
|
+
var TOKEN_SOURCES = [
|
|
292
|
+
["fg", "primary"],
|
|
293
|
+
["fg-muted", "primary-medium"],
|
|
294
|
+
["bg", "secondary"],
|
|
295
|
+
["bg-subtle", "primary-very-low"],
|
|
296
|
+
["border", "primary-low"],
|
|
297
|
+
["accent", "tertiary"],
|
|
298
|
+
["accent-fg", "secondary"],
|
|
299
|
+
["danger", "danger"]
|
|
300
|
+
];
|
|
301
|
+
var SAFE_NAME = /^[\w-]+$/;
|
|
302
|
+
var SAFE_VALUE = /^[^;{}<>]+$/;
|
|
303
|
+
var SAFE_FAMILY = /^[^"'\;{}<>]+$/;
|
|
304
|
+
var FONT_SOURCE = /^url\("https?:\/\/[^"\s<>]+"\)(?:\s+format\("[\w-]+"\))?$|^local\("[^"\\<>]+"\)$/;
|
|
305
|
+
var FONT_WEIGHT = /^(?:[1-9]\d{0,2}|normal|bold)$/;
|
|
306
|
+
var SCHEME_TYPES = /* @__PURE__ */ new Set(["light", "dark"]);
|
|
307
|
+
var STYLE_ATTRIBUTE = "data-gc-forum-theme";
|
|
308
|
+
var FONTS_ATTRIBUTE = "data-gc-forum-fonts";
|
|
309
|
+
function colorDeclarations(scheme) {
|
|
310
|
+
let css = "";
|
|
311
|
+
for (const [name, value] of Object.entries(scheme.colors)) {
|
|
312
|
+
if (SAFE_NAME.test(name) && SAFE_VALUE.test(value)) {
|
|
313
|
+
css += `--gc-forum-${name}:${value};`;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (SCHEME_TYPES.has(scheme.type)) {
|
|
317
|
+
css += `color-scheme:${scheme.type};`;
|
|
318
|
+
}
|
|
319
|
+
return css;
|
|
320
|
+
}
|
|
321
|
+
function fontDeclarations(fonts) {
|
|
322
|
+
let css = "";
|
|
323
|
+
for (const [role, font] of Object.entries(fonts)) {
|
|
324
|
+
if (font && SAFE_NAME.test(role) && SAFE_VALUE.test(font.stack)) {
|
|
325
|
+
css += `--gc-forum-font-${role}:${font.stack};`;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return css;
|
|
329
|
+
}
|
|
330
|
+
function tokenDeclarations(theme) {
|
|
331
|
+
let css = "";
|
|
332
|
+
for (const [token, color] of TOKEN_SOURCES) {
|
|
333
|
+
if (color in theme.schemes.light.colors) {
|
|
334
|
+
css += `--_gc-${token}:var(--gc-${token},var(--gc-forum-${color}));`;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (theme.fonts.body) {
|
|
338
|
+
css += "--_gc-font:var(--gc-font,var(--gc-forum-font-body));";
|
|
339
|
+
}
|
|
340
|
+
return css;
|
|
341
|
+
}
|
|
342
|
+
function forumThemeCss(theme) {
|
|
343
|
+
const { light, dark } = theme.schemes;
|
|
344
|
+
let css = `${FORUM_ROOT}{${colorDeclarations(light)}${fontDeclarations(theme.fonts)}}
|
|
345
|
+
`;
|
|
346
|
+
css += `${FORUM_STYLED_ROOT}{${tokenDeclarations(theme)}}
|
|
347
|
+
`;
|
|
348
|
+
if (dark) {
|
|
349
|
+
css += `@media (prefers-color-scheme: dark){${FORUM_ROOT}{${colorDeclarations(dark)}}}
|
|
350
|
+
`;
|
|
351
|
+
}
|
|
352
|
+
return css;
|
|
353
|
+
}
|
|
354
|
+
function forumFontFacesCss(theme) {
|
|
355
|
+
let css = "";
|
|
356
|
+
const seen = /* @__PURE__ */ new Set();
|
|
357
|
+
for (const font of Object.values(theme.fonts)) {
|
|
358
|
+
for (const face of font?.faces ?? []) {
|
|
359
|
+
const weight = String(face.weight);
|
|
360
|
+
const rule = `@font-face{font-family:"${face.family}";src:${face.src};font-weight:${weight};font-display:swap;}
|
|
361
|
+
`;
|
|
362
|
+
if (SAFE_FAMILY.test(face.family) && FONT_SOURCE.test(face.src) && FONT_WEIGHT.test(weight) && !seen.has(rule)) {
|
|
363
|
+
seen.add(rule);
|
|
364
|
+
css += rule;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return css;
|
|
369
|
+
}
|
|
370
|
+
function forumStylesheetUrls(theme, forum) {
|
|
371
|
+
const secure = forum.startsWith("https:");
|
|
372
|
+
const urls = [];
|
|
373
|
+
for (const href of theme.stylesheets) {
|
|
374
|
+
let url;
|
|
375
|
+
try {
|
|
376
|
+
url = new URL(href);
|
|
377
|
+
} catch {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (url.protocol === "https:" || !secure && url.protocol === "http:") {
|
|
381
|
+
urls.push(url.href);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return urls;
|
|
385
|
+
}
|
|
386
|
+
function forumThemeStyleText(theme, forum) {
|
|
387
|
+
const imports = forumStylesheetUrls(theme, forum).map((href) => `@import url(${JSON.stringify(href)}) layer(gc-forum);
|
|
388
|
+
`).join("");
|
|
389
|
+
return `@layer gc-defaults, gc-forum;
|
|
390
|
+
${imports}@layer gc-forum{
|
|
391
|
+
${forumThemeCss(theme)}}
|
|
392
|
+
`;
|
|
393
|
+
}
|
|
394
|
+
function documentOf(root) {
|
|
395
|
+
return root.nodeType === 9 ? root : root.ownerDocument;
|
|
396
|
+
}
|
|
397
|
+
function replaceNodes(container, attribute, forum, key, create) {
|
|
398
|
+
let current = false;
|
|
399
|
+
for (const node of container.querySelectorAll(`[${attribute}]`)) {
|
|
400
|
+
const value = node.getAttribute(attribute);
|
|
401
|
+
if (value === key) {
|
|
402
|
+
current = true;
|
|
403
|
+
} else if (value?.startsWith(`${forum}#`)) {
|
|
404
|
+
node.remove();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (!current) {
|
|
408
|
+
container.append(...create());
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function applyForumTheme(root, theme, forum) {
|
|
412
|
+
const doc = documentOf(root);
|
|
413
|
+
const container = root.nodeType === 9 ? doc.head : root;
|
|
414
|
+
const key = `${forum}#${theme.version}`;
|
|
415
|
+
replaceNodes(container, STYLE_ATTRIBUTE, forum, key, () => {
|
|
416
|
+
const style = doc.createElement("style");
|
|
417
|
+
style.setAttribute(STYLE_ATTRIBUTE, key);
|
|
418
|
+
style.textContent = forumThemeStyleText(theme, forum);
|
|
419
|
+
return [style];
|
|
420
|
+
});
|
|
421
|
+
const faces = forumFontFacesCss(theme);
|
|
422
|
+
if (faces) {
|
|
423
|
+
replaceNodes(doc.head, FONTS_ATTRIBUTE, forum, key, () => {
|
|
424
|
+
const style = doc.createElement("style");
|
|
425
|
+
style.setAttribute(FONTS_ATTRIBUTE, key);
|
|
426
|
+
style.textContent = faces;
|
|
427
|
+
return [style];
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
287
431
|
var loaded = /* @__PURE__ */ new WeakMap();
|
|
288
432
|
function initial(client) {
|
|
289
433
|
return { client, config: loaded.get(client) ?? null, error: null };
|
|
@@ -353,6 +497,49 @@ function useCommenterFor(client, config) {
|
|
|
353
497
|
[state, providers, actions]
|
|
354
498
|
);
|
|
355
499
|
}
|
|
500
|
+
var loaded2 = /* @__PURE__ */ new WeakMap();
|
|
501
|
+
function initial2(client) {
|
|
502
|
+
return { client, theme: loaded2.get(client) ?? null, error: null };
|
|
503
|
+
}
|
|
504
|
+
function useForumThemeFor(client, enabled) {
|
|
505
|
+
const [stored, setState] = react.useState(() => initial2(client));
|
|
506
|
+
let state = stored;
|
|
507
|
+
if (stored.client !== client) {
|
|
508
|
+
state = initial2(client);
|
|
509
|
+
setState(state);
|
|
510
|
+
}
|
|
511
|
+
react.useEffect(() => {
|
|
512
|
+
if (!enabled) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
let active = true;
|
|
516
|
+
client.theme().then(
|
|
517
|
+
(theme) => {
|
|
518
|
+
loaded2.set(client, theme);
|
|
519
|
+
if (active) {
|
|
520
|
+
setState(
|
|
521
|
+
(current) => current.client === client && current.theme !== theme ? { client, theme, error: null } : current
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
(error) => {
|
|
526
|
+
if (active) {
|
|
527
|
+
setState(
|
|
528
|
+
(current) => current.client === client ? { ...current, error: toCommentsError(error) } : current
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
);
|
|
533
|
+
return () => {
|
|
534
|
+
active = false;
|
|
535
|
+
};
|
|
536
|
+
}, [client, enabled]);
|
|
537
|
+
return { theme: state.theme, error: state.error };
|
|
538
|
+
}
|
|
539
|
+
function useForumTheme() {
|
|
540
|
+
const { client } = useCommentsContext();
|
|
541
|
+
return useForumThemeFor(client, true);
|
|
542
|
+
}
|
|
356
543
|
function useThread(options = {}) {
|
|
357
544
|
const { client } = useCommentsContext(options.forum);
|
|
358
545
|
return useThreadFor(client, options);
|
|
@@ -362,7 +549,7 @@ function useThreadFor(client, { identifier, url, title, sort }, onOpenError) {
|
|
|
362
549
|
const [opened, setOpened] = react.useState(
|
|
363
550
|
{ thread: null, error: null }
|
|
364
551
|
);
|
|
365
|
-
const pageKey = url === void 0 ?
|
|
552
|
+
const pageKey = url === void 0 ? chunkIBNNENCZ_cjs.currentUrlWithoutHash() ?? "" : "";
|
|
366
553
|
const latest = react.useRef({ title, sort, onOpenError });
|
|
367
554
|
latest.current = { title, sort, onOpenError };
|
|
368
555
|
const requestedSort = react.useRef(sort);
|
|
@@ -428,14 +615,14 @@ var RootContext = react.createContext(null);
|
|
|
428
615
|
function useRootContext(component = "This component") {
|
|
429
616
|
const value = react.useContext(RootContext);
|
|
430
617
|
if (!value) {
|
|
431
|
-
throw new Error(`${
|
|
618
|
+
throw new Error(`${chunkIBNNENCZ_cjs.PACKAGE_NAME}: ${component} must be rendered inside <Comments.Root>`);
|
|
432
619
|
}
|
|
433
620
|
return value;
|
|
434
621
|
}
|
|
435
622
|
function Root(props) {
|
|
436
623
|
const context = useOptionalCommentsContext(props.forum);
|
|
437
624
|
if (!context) {
|
|
438
|
-
return /* @__PURE__ */ jsxRuntime.jsx("section", { className: cx("gc-root", "gc-root--unconfigured", props.className), "data-gc-unconfigured": "", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "gc-notice", children: `${
|
|
625
|
+
return /* @__PURE__ */ jsxRuntime.jsx("section", { className: cx("gc-root", "gc-root--unconfigured", props.className), "data-gc-unconfigured": "", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "gc-notice", children: `${chunkIBNNENCZ_cjs.PACKAGE_NAME}: render <Comments> inside <DiscourseComments forum="\u2026"> or pass a forum prop.` }) });
|
|
439
626
|
}
|
|
440
627
|
return /* @__PURE__ */ jsxRuntime.jsx(ConfiguredRoot, { ...props });
|
|
441
628
|
}
|
|
@@ -464,10 +651,10 @@ function ConfiguredRoot(props) {
|
|
|
464
651
|
const { client, emit } = context;
|
|
465
652
|
const rootRef = react.useRef(null);
|
|
466
653
|
const t = react.useMemo(
|
|
467
|
-
() => localeProp ?
|
|
654
|
+
() => localeProp ? chunkIBNNENCZ_cjs.createTranslator(localeProp, context.messages) : context.t,
|
|
468
655
|
[localeProp, context.messages, context.t]
|
|
469
656
|
);
|
|
470
|
-
const locale = localeProp ?
|
|
657
|
+
const locale = localeProp ? chunkIBNNENCZ_cjs.resolveLocale(localeProp) : context.locale;
|
|
471
658
|
const theme = themeProp ?? context.theme;
|
|
472
659
|
const { variables, elements } = react.useMemo(
|
|
473
660
|
() => mergeAppearance(context.appearance, appearance),
|
|
@@ -486,6 +673,19 @@ function ConfiguredRoot(props) {
|
|
|
486
673
|
threadIdRef.current = thread?.id;
|
|
487
674
|
const { config, error: configError, reload: reloadConfig } = useConfig(client);
|
|
488
675
|
const commenter = useCommenterFor(client, config);
|
|
676
|
+
const forumTheme = useForumThemeFor(client, theme === "forum");
|
|
677
|
+
react.useEffect(() => {
|
|
678
|
+
const element = rootRef.current;
|
|
679
|
+
if (theme === "forum" && forumTheme.theme && element) {
|
|
680
|
+
applyForumTheme(rootNodeOf(element), forumTheme.theme, client.forum);
|
|
681
|
+
}
|
|
682
|
+
}, [theme, forumTheme.theme, client.forum]);
|
|
683
|
+
const themeError = theme === "forum" ? forumTheme.error : null;
|
|
684
|
+
react.useEffect(() => {
|
|
685
|
+
if (themeError) {
|
|
686
|
+
reportError("theme", themeError);
|
|
687
|
+
}
|
|
688
|
+
}, [themeError, reportError]);
|
|
489
689
|
const retry = react.useCallback(() => {
|
|
490
690
|
retryThread();
|
|
491
691
|
if (configError) {
|
|
@@ -583,7 +783,7 @@ function ConfiguredRoot(props) {
|
|
|
583
783
|
const id = requestedHighlight;
|
|
584
784
|
const request = ++viewRequest.current;
|
|
585
785
|
void (async () => {
|
|
586
|
-
let location =
|
|
786
|
+
let location = chunkIBNNENCZ_cjs.findComment(thread.snapshot().comments, id);
|
|
587
787
|
if (!location) {
|
|
588
788
|
try {
|
|
589
789
|
await thread.context(id);
|
|
@@ -593,7 +793,7 @@ function ConfiguredRoot(props) {
|
|
|
593
793
|
}
|
|
594
794
|
return;
|
|
595
795
|
}
|
|
596
|
-
location =
|
|
796
|
+
location = chunkIBNNENCZ_cjs.findComment(thread.snapshot().comments, id);
|
|
597
797
|
}
|
|
598
798
|
if (!location || request !== viewRequest.current) {
|
|
599
799
|
return;
|
|
@@ -601,7 +801,7 @@ function ConfiguredRoot(props) {
|
|
|
601
801
|
if (location.depth > maxDepth) {
|
|
602
802
|
const cut = location.depth - maxDepth;
|
|
603
803
|
const tree = thread.snapshot().comments;
|
|
604
|
-
const ancestors = location.path.slice(0, cut).map((ancestorId) =>
|
|
804
|
+
const ancestors = location.path.slice(0, cut).map((ancestorId) => chunkIBNNENCZ_cjs.findComment(tree, ancestorId)?.node).filter((node) => node !== void 0);
|
|
605
805
|
setFocusView({ id: location.path[cut], ancestors, truncated: false });
|
|
606
806
|
} else {
|
|
607
807
|
setFocusView(null);
|
|
@@ -628,7 +828,7 @@ function ConfiguredRoot(props) {
|
|
|
628
828
|
}, [client, signInMode]);
|
|
629
829
|
const threadKey = snapshot?.thread.key;
|
|
630
830
|
const draftKey = react.useCallback(
|
|
631
|
-
(scope) => threadKey === void 0 ? null : `${
|
|
831
|
+
(scope) => threadKey === void 0 ? null : `${chunkIBNNENCZ_cjs.STORAGE_PREFIX}:${client.forum}:draft:${threadKey}:${scope}`,
|
|
632
832
|
[client.forum, threadKey]
|
|
633
833
|
);
|
|
634
834
|
const value = {
|
|
@@ -872,7 +1072,7 @@ function ComposerForm({
|
|
|
872
1072
|
const textareaRef = react.useRef(null);
|
|
873
1073
|
const fileRef = react.useRef(null);
|
|
874
1074
|
const pendingSelection = react.useRef(null);
|
|
875
|
-
const [timer] = react.useState(
|
|
1075
|
+
const [timer] = react.useState(chunkIBNNENCZ_cjs.createComposerTimer);
|
|
876
1076
|
const draftKey = editing ? null : root.draftKey(replyTo ? `reply:${replyTo.id}` : "root");
|
|
877
1077
|
const [value, setValueState] = react.useState(() => draftKey ? readDraft(draftKey) : "");
|
|
878
1078
|
const valueRef = react.useRef(value);
|
|
@@ -1432,7 +1632,7 @@ var ItemContext = react.createContext(null);
|
|
|
1432
1632
|
function useItemContext(component) {
|
|
1433
1633
|
const value = react.useContext(ItemContext);
|
|
1434
1634
|
if (!value) {
|
|
1435
|
-
throw new Error(`${
|
|
1635
|
+
throw new Error(`${chunkIBNNENCZ_cjs.PACKAGE_NAME}: ${component} must be rendered inside <Comments.Item>`);
|
|
1436
1636
|
}
|
|
1437
1637
|
return value;
|
|
1438
1638
|
}
|
|
@@ -1457,8 +1657,8 @@ function UserAvatar({
|
|
|
1457
1657
|
}
|
|
1458
1658
|
);
|
|
1459
1659
|
}
|
|
1460
|
-
const
|
|
1461
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cx("gc-avatar", "gc-avatar--placeholder", className), "aria-hidden": "true", children:
|
|
1660
|
+
const initial3 = (user?.name || user?.username || "").charAt(0).toUpperCase();
|
|
1661
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cx("gc-avatar", "gc-avatar--placeholder", className), "aria-hidden": "true", children: initial3 });
|
|
1462
1662
|
}
|
|
1463
1663
|
function Meta({ className }) {
|
|
1464
1664
|
const { comment } = useItemContext("Comments.Meta");
|
|
@@ -1553,7 +1753,7 @@ function Actions({ className }) {
|
|
|
1553
1753
|
key: "copy",
|
|
1554
1754
|
label: t("copyLink"),
|
|
1555
1755
|
onSelect: () => {
|
|
1556
|
-
const href = `${
|
|
1756
|
+
const href = `${chunkIBNNENCZ_cjs.currentUrlWithoutHash() ?? ""}#gc-${comment.id}`;
|
|
1557
1757
|
const clipboard = typeof navigator === "undefined" ? void 0 : navigator.clipboard;
|
|
1558
1758
|
if (!clipboard) {
|
|
1559
1759
|
window.location.hash = `gc-${comment.id}`;
|
|
@@ -1895,7 +2095,7 @@ function DevPanel({ className }) {
|
|
|
1895
2095
|
}
|
|
1896
2096
|
return /* @__PURE__ */ jsxRuntime.jsxs("details", { className: cx("gc-devpanel", "gc-devpanel--ok", className), children: [
|
|
1897
2097
|
/* @__PURE__ */ jsxRuntime.jsxs("summary", { className: "gc-devpanel__title", children: [
|
|
1898
|
-
|
|
2098
|
+
chunkIBNNENCZ_cjs.PACKAGE_NAME,
|
|
1899
2099
|
" diagnostics"
|
|
1900
2100
|
] }),
|
|
1901
2101
|
/* @__PURE__ */ jsxRuntime.jsxs("dl", { className: "gc-devpanel__details", children: [
|
|
@@ -1924,10 +2124,10 @@ function DevPanel({ className }) {
|
|
|
1924
2124
|
"aside",
|
|
1925
2125
|
{
|
|
1926
2126
|
className: cx("gc-devpanel", className),
|
|
1927
|
-
"aria-label": `${
|
|
2127
|
+
"aria-label": `${chunkIBNNENCZ_cjs.PACKAGE_NAME} setup diagnostics`,
|
|
1928
2128
|
children: [
|
|
1929
2129
|
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "gc-devpanel__title", children: [
|
|
1930
|
-
|
|
2130
|
+
chunkIBNNENCZ_cjs.PACKAGE_NAME,
|
|
1931
2131
|
" could not load comments"
|
|
1932
2132
|
] }),
|
|
1933
2133
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "gc-devpanel__summary", children: summary }),
|
|
@@ -2105,7 +2305,7 @@ function List({ children, className }) {
|
|
|
2105
2305
|
const listClass = cx("gc-list", elements.list, className);
|
|
2106
2306
|
if (focusView) {
|
|
2107
2307
|
const tree = snapshot.comments;
|
|
2108
|
-
const target =
|
|
2308
|
+
const target = chunkIBNNENCZ_cjs.findComment(tree, focusView.id)?.node;
|
|
2109
2309
|
return /* @__PURE__ */ jsxRuntime.jsx(ListContext.Provider, { value: render, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gc-focus", children: [
|
|
2110
2310
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2111
2311
|
"button",
|
|
@@ -2123,7 +2323,7 @@ function List({ children, className }) {
|
|
|
2123
2323
|
focusView.ancestors.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ol", { className: "gc-context", children: focusView.ancestors.map((ancestor) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2124
2324
|
Item,
|
|
2125
2325
|
{
|
|
2126
|
-
comment:
|
|
2326
|
+
comment: chunkIBNNENCZ_cjs.findComment(tree, ancestor.id)?.node ?? ancestor,
|
|
2127
2327
|
showReplies: false
|
|
2128
2328
|
},
|
|
2129
2329
|
ancestor.id
|
|
@@ -2276,8 +2476,8 @@ function Replies() {
|
|
|
2276
2476
|
root.reportError("loadReplies", error);
|
|
2277
2477
|
return;
|
|
2278
2478
|
}
|
|
2279
|
-
const
|
|
2280
|
-
const first =
|
|
2479
|
+
const loaded3 = chunkIBNNENCZ_cjs.findComment(thread.snapshot().comments, comment.id)?.node.children ?? [];
|
|
2480
|
+
const first = loaded3.find((child) => !before.has(child.id));
|
|
2281
2481
|
if (first) {
|
|
2282
2482
|
root.focusComment(first.id);
|
|
2283
2483
|
}
|
|
@@ -2521,7 +2721,7 @@ function useCommentCount(ref, options = {}) {
|
|
|
2521
2721
|
}
|
|
2522
2722
|
function safeEncode(ref) {
|
|
2523
2723
|
try {
|
|
2524
|
-
return
|
|
2724
|
+
return chunkIBNNENCZ_cjs.encodeRef(ref);
|
|
2525
2725
|
} catch {
|
|
2526
2726
|
return null;
|
|
2527
2727
|
}
|
|
@@ -2536,7 +2736,7 @@ function CommentCount({
|
|
|
2536
2736
|
className
|
|
2537
2737
|
}) {
|
|
2538
2738
|
const context = useOptionalCommentsContext(forum);
|
|
2539
|
-
const pageUrl = url ??
|
|
2739
|
+
const pageUrl = url ?? chunkIBNNENCZ_cjs.defaultPageUrl();
|
|
2540
2740
|
const ref = topicId !== void 0 ? { topicId } : identifier !== void 0 ? { identifier, host } : pageUrl ? { url: pageUrl } : null;
|
|
2541
2741
|
const { count } = useCommentCount(ref, { forum });
|
|
2542
2742
|
if (!context) {
|
|
@@ -2552,6 +2752,7 @@ exports.DiscourseComments = DiscourseComments;
|
|
|
2552
2752
|
exports.useClient = useClient;
|
|
2553
2753
|
exports.useCommentCount = useCommentCount;
|
|
2554
2754
|
exports.useCommenter = useCommenter;
|
|
2755
|
+
exports.useForumTheme = useForumTheme;
|
|
2555
2756
|
exports.useThread = useThread;
|
|
2556
2757
|
//# sourceMappingURL=react.cjs.map
|
|
2557
2758
|
//# sourceMappingURL=react.cjs.map
|