g-comments 0.1.0 → 0.2.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/CHANGELOG.md +17 -0
- package/README.md +40 -5
- 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 +22 -18
- 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 +232 -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 +202 -6
- package/dist/react.js.map +1 -1
- package/package.json +9 -9
- 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,146 @@ 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
|
+
for (const font of Object.values(theme.fonts)) {
|
|
357
|
+
for (const face of font?.faces ?? []) {
|
|
358
|
+
const weight = String(face.weight);
|
|
359
|
+
if (SAFE_FAMILY.test(face.family) && FONT_SOURCE.test(face.src) && FONT_WEIGHT.test(weight)) {
|
|
360
|
+
css += `@font-face{font-family:"${face.family}";src:${face.src};font-weight:${weight};font-display:swap;}
|
|
361
|
+
`;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return css;
|
|
366
|
+
}
|
|
367
|
+
function forumStylesheetUrls(theme, forum) {
|
|
368
|
+
const secure = forum.startsWith("https:");
|
|
369
|
+
const urls = [];
|
|
370
|
+
for (const href of theme.stylesheets) {
|
|
371
|
+
let url;
|
|
372
|
+
try {
|
|
373
|
+
url = new URL(href);
|
|
374
|
+
} catch {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (url.protocol === "https:" || !secure && url.protocol === "http:") {
|
|
378
|
+
urls.push(url.href);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return urls;
|
|
382
|
+
}
|
|
383
|
+
function documentOf(root) {
|
|
384
|
+
return root.nodeType === 9 ? root : root.ownerDocument;
|
|
385
|
+
}
|
|
386
|
+
function replaceNodes(container, attribute, forum, key, create) {
|
|
387
|
+
let current = false;
|
|
388
|
+
for (const node of container.querySelectorAll(`[${attribute}]`)) {
|
|
389
|
+
const value = node.getAttribute(attribute);
|
|
390
|
+
if (value === key) {
|
|
391
|
+
current = true;
|
|
392
|
+
} else if (value?.startsWith(`${forum}#`)) {
|
|
393
|
+
node.remove();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
if (!current) {
|
|
397
|
+
container.append(...create());
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function applyForumTheme(root, theme, forum) {
|
|
401
|
+
const doc = documentOf(root);
|
|
402
|
+
const container = root.nodeType === 9 ? doc.head : root;
|
|
403
|
+
const key = `${forum}#${theme.version}`;
|
|
404
|
+
replaceNodes(container, STYLE_ATTRIBUTE, forum, key, () => {
|
|
405
|
+
const style = doc.createElement("style");
|
|
406
|
+
style.setAttribute(STYLE_ATTRIBUTE, key);
|
|
407
|
+
style.textContent = forumThemeCss(theme);
|
|
408
|
+
const links = forumStylesheetUrls(theme, forum).map((href) => {
|
|
409
|
+
const link = doc.createElement("link");
|
|
410
|
+
link.rel = "stylesheet";
|
|
411
|
+
link.href = href;
|
|
412
|
+
link.setAttribute(STYLE_ATTRIBUTE, key);
|
|
413
|
+
return link;
|
|
414
|
+
});
|
|
415
|
+
return [style, ...links];
|
|
416
|
+
});
|
|
417
|
+
const faces = forumFontFacesCss(theme);
|
|
418
|
+
if (faces) {
|
|
419
|
+
replaceNodes(doc.head, FONTS_ATTRIBUTE, forum, key, () => {
|
|
420
|
+
const style = doc.createElement("style");
|
|
421
|
+
style.setAttribute(FONTS_ATTRIBUTE, key);
|
|
422
|
+
style.textContent = faces;
|
|
423
|
+
return [style];
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
287
427
|
var loaded = /* @__PURE__ */ new WeakMap();
|
|
288
428
|
function initial(client) {
|
|
289
429
|
return { client, config: loaded.get(client) ?? null, error: null };
|
|
@@ -353,6 +493,49 @@ function useCommenterFor(client, config) {
|
|
|
353
493
|
[state, providers, actions]
|
|
354
494
|
);
|
|
355
495
|
}
|
|
496
|
+
var loaded2 = /* @__PURE__ */ new WeakMap();
|
|
497
|
+
function initial2(client) {
|
|
498
|
+
return { client, theme: loaded2.get(client) ?? null, error: null };
|
|
499
|
+
}
|
|
500
|
+
function useForumThemeFor(client, enabled) {
|
|
501
|
+
const [stored, setState] = react.useState(() => initial2(client));
|
|
502
|
+
let state = stored;
|
|
503
|
+
if (stored.client !== client) {
|
|
504
|
+
state = initial2(client);
|
|
505
|
+
setState(state);
|
|
506
|
+
}
|
|
507
|
+
react.useEffect(() => {
|
|
508
|
+
if (!enabled) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
let active = true;
|
|
512
|
+
client.theme().then(
|
|
513
|
+
(theme) => {
|
|
514
|
+
loaded2.set(client, theme);
|
|
515
|
+
if (active) {
|
|
516
|
+
setState(
|
|
517
|
+
(current) => current.client === client && current.theme !== theme ? { client, theme, error: null } : current
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
(error) => {
|
|
522
|
+
if (active) {
|
|
523
|
+
setState(
|
|
524
|
+
(current) => current.client === client ? { ...current, error: toCommentsError(error) } : current
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
);
|
|
529
|
+
return () => {
|
|
530
|
+
active = false;
|
|
531
|
+
};
|
|
532
|
+
}, [client, enabled]);
|
|
533
|
+
return { theme: state.theme, error: state.error };
|
|
534
|
+
}
|
|
535
|
+
function useForumTheme() {
|
|
536
|
+
const { client } = useCommentsContext();
|
|
537
|
+
return useForumThemeFor(client, true);
|
|
538
|
+
}
|
|
356
539
|
function useThread(options = {}) {
|
|
357
540
|
const { client } = useCommentsContext(options.forum);
|
|
358
541
|
return useThreadFor(client, options);
|
|
@@ -362,7 +545,7 @@ function useThreadFor(client, { identifier, url, title, sort }, onOpenError) {
|
|
|
362
545
|
const [opened, setOpened] = react.useState(
|
|
363
546
|
{ thread: null, error: null }
|
|
364
547
|
);
|
|
365
|
-
const pageKey = url === void 0 ?
|
|
548
|
+
const pageKey = url === void 0 ? chunkIBNNENCZ_cjs.currentUrlWithoutHash() ?? "" : "";
|
|
366
549
|
const latest = react.useRef({ title, sort, onOpenError });
|
|
367
550
|
latest.current = { title, sort, onOpenError };
|
|
368
551
|
const requestedSort = react.useRef(sort);
|
|
@@ -428,14 +611,14 @@ var RootContext = react.createContext(null);
|
|
|
428
611
|
function useRootContext(component = "This component") {
|
|
429
612
|
const value = react.useContext(RootContext);
|
|
430
613
|
if (!value) {
|
|
431
|
-
throw new Error(`${
|
|
614
|
+
throw new Error(`${chunkIBNNENCZ_cjs.PACKAGE_NAME}: ${component} must be rendered inside <Comments.Root>`);
|
|
432
615
|
}
|
|
433
616
|
return value;
|
|
434
617
|
}
|
|
435
618
|
function Root(props) {
|
|
436
619
|
const context = useOptionalCommentsContext(props.forum);
|
|
437
620
|
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: `${
|
|
621
|
+
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
622
|
}
|
|
440
623
|
return /* @__PURE__ */ jsxRuntime.jsx(ConfiguredRoot, { ...props });
|
|
441
624
|
}
|
|
@@ -464,10 +647,10 @@ function ConfiguredRoot(props) {
|
|
|
464
647
|
const { client, emit } = context;
|
|
465
648
|
const rootRef = react.useRef(null);
|
|
466
649
|
const t = react.useMemo(
|
|
467
|
-
() => localeProp ?
|
|
650
|
+
() => localeProp ? chunkIBNNENCZ_cjs.createTranslator(localeProp, context.messages) : context.t,
|
|
468
651
|
[localeProp, context.messages, context.t]
|
|
469
652
|
);
|
|
470
|
-
const locale = localeProp ?
|
|
653
|
+
const locale = localeProp ? chunkIBNNENCZ_cjs.resolveLocale(localeProp) : context.locale;
|
|
471
654
|
const theme = themeProp ?? context.theme;
|
|
472
655
|
const { variables, elements } = react.useMemo(
|
|
473
656
|
() => mergeAppearance(context.appearance, appearance),
|
|
@@ -486,6 +669,19 @@ function ConfiguredRoot(props) {
|
|
|
486
669
|
threadIdRef.current = thread?.id;
|
|
487
670
|
const { config, error: configError, reload: reloadConfig } = useConfig(client);
|
|
488
671
|
const commenter = useCommenterFor(client, config);
|
|
672
|
+
const forumTheme = useForumThemeFor(client, theme === "forum");
|
|
673
|
+
react.useEffect(() => {
|
|
674
|
+
const element = rootRef.current;
|
|
675
|
+
if (theme === "forum" && forumTheme.theme && element) {
|
|
676
|
+
applyForumTheme(rootNodeOf(element), forumTheme.theme, client.forum);
|
|
677
|
+
}
|
|
678
|
+
}, [theme, forumTheme.theme, client.forum]);
|
|
679
|
+
const themeError = theme === "forum" ? forumTheme.error : null;
|
|
680
|
+
react.useEffect(() => {
|
|
681
|
+
if (themeError) {
|
|
682
|
+
reportError("theme", themeError);
|
|
683
|
+
}
|
|
684
|
+
}, [themeError, reportError]);
|
|
489
685
|
const retry = react.useCallback(() => {
|
|
490
686
|
retryThread();
|
|
491
687
|
if (configError) {
|
|
@@ -583,7 +779,7 @@ function ConfiguredRoot(props) {
|
|
|
583
779
|
const id = requestedHighlight;
|
|
584
780
|
const request = ++viewRequest.current;
|
|
585
781
|
void (async () => {
|
|
586
|
-
let location =
|
|
782
|
+
let location = chunkIBNNENCZ_cjs.findComment(thread.snapshot().comments, id);
|
|
587
783
|
if (!location) {
|
|
588
784
|
try {
|
|
589
785
|
await thread.context(id);
|
|
@@ -593,7 +789,7 @@ function ConfiguredRoot(props) {
|
|
|
593
789
|
}
|
|
594
790
|
return;
|
|
595
791
|
}
|
|
596
|
-
location =
|
|
792
|
+
location = chunkIBNNENCZ_cjs.findComment(thread.snapshot().comments, id);
|
|
597
793
|
}
|
|
598
794
|
if (!location || request !== viewRequest.current) {
|
|
599
795
|
return;
|
|
@@ -601,7 +797,7 @@ function ConfiguredRoot(props) {
|
|
|
601
797
|
if (location.depth > maxDepth) {
|
|
602
798
|
const cut = location.depth - maxDepth;
|
|
603
799
|
const tree = thread.snapshot().comments;
|
|
604
|
-
const ancestors = location.path.slice(0, cut).map((ancestorId) =>
|
|
800
|
+
const ancestors = location.path.slice(0, cut).map((ancestorId) => chunkIBNNENCZ_cjs.findComment(tree, ancestorId)?.node).filter((node) => node !== void 0);
|
|
605
801
|
setFocusView({ id: location.path[cut], ancestors, truncated: false });
|
|
606
802
|
} else {
|
|
607
803
|
setFocusView(null);
|
|
@@ -628,7 +824,7 @@ function ConfiguredRoot(props) {
|
|
|
628
824
|
}, [client, signInMode]);
|
|
629
825
|
const threadKey = snapshot?.thread.key;
|
|
630
826
|
const draftKey = react.useCallback(
|
|
631
|
-
(scope) => threadKey === void 0 ? null : `${
|
|
827
|
+
(scope) => threadKey === void 0 ? null : `${chunkIBNNENCZ_cjs.STORAGE_PREFIX}:${client.forum}:draft:${threadKey}:${scope}`,
|
|
632
828
|
[client.forum, threadKey]
|
|
633
829
|
);
|
|
634
830
|
const value = {
|
|
@@ -872,7 +1068,7 @@ function ComposerForm({
|
|
|
872
1068
|
const textareaRef = react.useRef(null);
|
|
873
1069
|
const fileRef = react.useRef(null);
|
|
874
1070
|
const pendingSelection = react.useRef(null);
|
|
875
|
-
const [timer] = react.useState(
|
|
1071
|
+
const [timer] = react.useState(chunkIBNNENCZ_cjs.createComposerTimer);
|
|
876
1072
|
const draftKey = editing ? null : root.draftKey(replyTo ? `reply:${replyTo.id}` : "root");
|
|
877
1073
|
const [value, setValueState] = react.useState(() => draftKey ? readDraft(draftKey) : "");
|
|
878
1074
|
const valueRef = react.useRef(value);
|
|
@@ -1432,7 +1628,7 @@ var ItemContext = react.createContext(null);
|
|
|
1432
1628
|
function useItemContext(component) {
|
|
1433
1629
|
const value = react.useContext(ItemContext);
|
|
1434
1630
|
if (!value) {
|
|
1435
|
-
throw new Error(`${
|
|
1631
|
+
throw new Error(`${chunkIBNNENCZ_cjs.PACKAGE_NAME}: ${component} must be rendered inside <Comments.Item>`);
|
|
1436
1632
|
}
|
|
1437
1633
|
return value;
|
|
1438
1634
|
}
|
|
@@ -1457,8 +1653,8 @@ function UserAvatar({
|
|
|
1457
1653
|
}
|
|
1458
1654
|
);
|
|
1459
1655
|
}
|
|
1460
|
-
const
|
|
1461
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cx("gc-avatar", "gc-avatar--placeholder", className), "aria-hidden": "true", children:
|
|
1656
|
+
const initial3 = (user?.name || user?.username || "").charAt(0).toUpperCase();
|
|
1657
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cx("gc-avatar", "gc-avatar--placeholder", className), "aria-hidden": "true", children: initial3 });
|
|
1462
1658
|
}
|
|
1463
1659
|
function Meta({ className }) {
|
|
1464
1660
|
const { comment } = useItemContext("Comments.Meta");
|
|
@@ -1553,7 +1749,7 @@ function Actions({ className }) {
|
|
|
1553
1749
|
key: "copy",
|
|
1554
1750
|
label: t("copyLink"),
|
|
1555
1751
|
onSelect: () => {
|
|
1556
|
-
const href = `${
|
|
1752
|
+
const href = `${chunkIBNNENCZ_cjs.currentUrlWithoutHash() ?? ""}#gc-${comment.id}`;
|
|
1557
1753
|
const clipboard = typeof navigator === "undefined" ? void 0 : navigator.clipboard;
|
|
1558
1754
|
if (!clipboard) {
|
|
1559
1755
|
window.location.hash = `gc-${comment.id}`;
|
|
@@ -1895,7 +2091,7 @@ function DevPanel({ className }) {
|
|
|
1895
2091
|
}
|
|
1896
2092
|
return /* @__PURE__ */ jsxRuntime.jsxs("details", { className: cx("gc-devpanel", "gc-devpanel--ok", className), children: [
|
|
1897
2093
|
/* @__PURE__ */ jsxRuntime.jsxs("summary", { className: "gc-devpanel__title", children: [
|
|
1898
|
-
|
|
2094
|
+
chunkIBNNENCZ_cjs.PACKAGE_NAME,
|
|
1899
2095
|
" diagnostics"
|
|
1900
2096
|
] }),
|
|
1901
2097
|
/* @__PURE__ */ jsxRuntime.jsxs("dl", { className: "gc-devpanel__details", children: [
|
|
@@ -1924,10 +2120,10 @@ function DevPanel({ className }) {
|
|
|
1924
2120
|
"aside",
|
|
1925
2121
|
{
|
|
1926
2122
|
className: cx("gc-devpanel", className),
|
|
1927
|
-
"aria-label": `${
|
|
2123
|
+
"aria-label": `${chunkIBNNENCZ_cjs.PACKAGE_NAME} setup diagnostics`,
|
|
1928
2124
|
children: [
|
|
1929
2125
|
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: "gc-devpanel__title", children: [
|
|
1930
|
-
|
|
2126
|
+
chunkIBNNENCZ_cjs.PACKAGE_NAME,
|
|
1931
2127
|
" could not load comments"
|
|
1932
2128
|
] }),
|
|
1933
2129
|
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "gc-devpanel__summary", children: summary }),
|
|
@@ -2105,7 +2301,7 @@ function List({ children, className }) {
|
|
|
2105
2301
|
const listClass = cx("gc-list", elements.list, className);
|
|
2106
2302
|
if (focusView) {
|
|
2107
2303
|
const tree = snapshot.comments;
|
|
2108
|
-
const target =
|
|
2304
|
+
const target = chunkIBNNENCZ_cjs.findComment(tree, focusView.id)?.node;
|
|
2109
2305
|
return /* @__PURE__ */ jsxRuntime.jsx(ListContext.Provider, { value: render, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "gc-focus", children: [
|
|
2110
2306
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
2111
2307
|
"button",
|
|
@@ -2123,7 +2319,7 @@ function List({ children, className }) {
|
|
|
2123
2319
|
focusView.ancestors.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ol", { className: "gc-context", children: focusView.ancestors.map((ancestor) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2124
2320
|
Item,
|
|
2125
2321
|
{
|
|
2126
|
-
comment:
|
|
2322
|
+
comment: chunkIBNNENCZ_cjs.findComment(tree, ancestor.id)?.node ?? ancestor,
|
|
2127
2323
|
showReplies: false
|
|
2128
2324
|
},
|
|
2129
2325
|
ancestor.id
|
|
@@ -2276,8 +2472,8 @@ function Replies() {
|
|
|
2276
2472
|
root.reportError("loadReplies", error);
|
|
2277
2473
|
return;
|
|
2278
2474
|
}
|
|
2279
|
-
const
|
|
2280
|
-
const first =
|
|
2475
|
+
const loaded3 = chunkIBNNENCZ_cjs.findComment(thread.snapshot().comments, comment.id)?.node.children ?? [];
|
|
2476
|
+
const first = loaded3.find((child) => !before.has(child.id));
|
|
2281
2477
|
if (first) {
|
|
2282
2478
|
root.focusComment(first.id);
|
|
2283
2479
|
}
|
|
@@ -2521,7 +2717,7 @@ function useCommentCount(ref, options = {}) {
|
|
|
2521
2717
|
}
|
|
2522
2718
|
function safeEncode(ref) {
|
|
2523
2719
|
try {
|
|
2524
|
-
return
|
|
2720
|
+
return chunkIBNNENCZ_cjs.encodeRef(ref);
|
|
2525
2721
|
} catch {
|
|
2526
2722
|
return null;
|
|
2527
2723
|
}
|
|
@@ -2536,7 +2732,7 @@ function CommentCount({
|
|
|
2536
2732
|
className
|
|
2537
2733
|
}) {
|
|
2538
2734
|
const context = useOptionalCommentsContext(forum);
|
|
2539
|
-
const pageUrl = url ??
|
|
2735
|
+
const pageUrl = url ?? chunkIBNNENCZ_cjs.defaultPageUrl();
|
|
2540
2736
|
const ref = topicId !== void 0 ? { topicId } : identifier !== void 0 ? { identifier, host } : pageUrl ? { url: pageUrl } : null;
|
|
2541
2737
|
const { count } = useCommentCount(ref, { forum });
|
|
2542
2738
|
if (!context) {
|
|
@@ -2552,6 +2748,7 @@ exports.DiscourseComments = DiscourseComments;
|
|
|
2552
2748
|
exports.useClient = useClient;
|
|
2553
2749
|
exports.useCommentCount = useCommentCount;
|
|
2554
2750
|
exports.useCommenter = useCommenter;
|
|
2751
|
+
exports.useForumTheme = useForumTheme;
|
|
2555
2752
|
exports.useThread = useThread;
|
|
2556
2753
|
//# sourceMappingURL=react.cjs.map
|
|
2557
2754
|
//# sourceMappingURL=react.cjs.map
|