g-comments 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { createTranslator, PACKAGE_NAME, currentUrlWithoutHash, findComment, createComposerTimer, normalizeForum, resolveLocale, clientRegistry, STORAGE_PREFIX, isCommentsError, CommentsError, encodeRef, defaultPageUrl } from './chunk-WACVXJHD.js';
2
+ import { createTranslator, PACKAGE_NAME, currentUrlWithoutHash, findComment, findByNumber, createComposerTimer, normalizeForum, resolveLocale, clientRegistry, STORAGE_PREFIX, isCommentsError, CommentsError, encodeRef, defaultPageUrl } from './chunk-EWWBVJ2B.js';
3
3
  import { createContext, useState, useRef, useCallback, useEffect, useMemo, Fragment as Fragment$1, useId, useContext, useLayoutEffect, useSyncExternalStore } from 'react';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
 
@@ -1659,7 +1659,7 @@ function UserAvatar({
1659
1659
  return /* @__PURE__ */ jsx("span", { className: cx("gc-avatar", "gc-avatar--placeholder", className), "aria-hidden": "true", children: initial3 });
1660
1660
  }
1661
1661
  function Meta({ className }) {
1662
- const { comment } = useItemContext("Comments.Meta");
1662
+ const { comment, depth } = useItemContext("Comments.Meta");
1663
1663
  const { t, locale, client, elements } = useRootContext("Comments.Meta");
1664
1664
  const author = comment.author;
1665
1665
  const name = author ? author.name || author.username : null;
@@ -1680,9 +1680,31 @@ function Meta({ className }) {
1680
1680
  t("pinned")
1681
1681
  ] }),
1682
1682
  /* @__PURE__ */ jsx("a", { className: "gc-comment__time", href: `#gc-${comment.id}`, children: /* @__PURE__ */ jsx(RelativeTime, { iso: comment.created_at, locale }) }),
1683
- comment.edited && /* @__PURE__ */ jsx("span", { className: "gc-comment__edited", title: formatAbsolute(comment.updated_at, locale), children: t("edited") })
1683
+ comment.edited && /* @__PURE__ */ jsx("span", { className: "gc-comment__edited", title: formatAbsolute(comment.updated_at, locale), children: t("edited") }),
1684
+ comment.reply_to && depth === 0 && /* @__PURE__ */ jsx(ReplyReference, { reference: comment.reply_to })
1684
1685
  ] });
1685
1686
  }
1687
+ function ReplyReference({ reference }) {
1688
+ const { t, snapshot, focusComment } = useRootContext("Comments.Meta");
1689
+ const label = t("replyingTo", { username: reference.username ?? "" });
1690
+ const parent = snapshot ? findByNumber(snapshot.comments, reference.number) : null;
1691
+ if (!parent) {
1692
+ return /* @__PURE__ */ jsx("span", { className: "gc-comment__reply-to", children: label });
1693
+ }
1694
+ const id = parent.node.id;
1695
+ return /* @__PURE__ */ jsx(
1696
+ "a",
1697
+ {
1698
+ className: "gc-comment__reply-to",
1699
+ href: `#gc-${id}`,
1700
+ onClick: (event) => {
1701
+ event.preventDefault();
1702
+ focusComment(id, { scroll: true });
1703
+ },
1704
+ children: label
1705
+ }
1706
+ );
1707
+ }
1686
1708
  function RelativeTime({ iso, locale }) {
1687
1709
  const [now, setNow] = useState(Date.now);
1688
1710
  useEffect(() => onMinuteTick(() => setNow(Date.now())), []);