@blocklet/discuss-kit 2.5.31 → 2.5.33

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.
@@ -1,8 +1,8 @@
1
- "use strict";const n=require("react/jsx-runtime"),f=require("react"),Q=require("@arcblock/ux/lib/Theme"),t=require("prop-types"),X=require("@arcblock/did-connect-react/lib/Session"),l=require("@mui/material"),D=require("@arcblock/ux/lib/Locale/context"),Y=require("react-error-boundary"),a=require("@blocklet/discuss-kit-ux"),Z=require("ahooks"),ee=require("./components/error-fallback.js"),te=require("./locales/index.js"),ne=require("./lib/utils.js"),r=require("./api.js"),oe=require("./hooks/topic-info-sync.js"),se=()=>{const e=s=>s.endsWith("/")?s:`${s}/`;return window.blocklet?.componentMountPoints?.find(s=>e(s.mountPoint)===e(window.blocklet?.prefix))?.title},u=e=>({...e,rootId:e.rootCommentId,createdAt:e.createdAt?new Date(e.createdAt):null,updatedAt:e.updatedAt?new Date(e.updatedAt):null,deletedAt:e.deletedAt?new Date(e.deletedAt):null,pinnedAt:e.pinnedAt?new Date(e.pinnedAt):null,replies:e.replies?.map(u)}),ie={fetchComments:async e=>{const o={...e,embed:e.rootId?"rating":"replies,rating",size:e.limit},{data:{data:s,nextCursor:c,total:x}}=await r.default.get("/comments",{params:o});return{data:s?.map(u),nextCursor:c,total:x}},fetchPinnedComments:async e=>{const{data:o}=await r.default.get("/comments/pinned",{params:{objectId:e}});return(o?.data||[]).map(u)},fetchCommentPosition:async({id:e,...o})=>{const{data:s}=await r.default.get(`/comments/${e}/position`,{params:o});return s},deleteComment:async({id:e})=>{const{data:o}=await r.default.delete(`/comments/${e}`);return o},updateComment:async({id:e,updatedAt:o},s)=>{const{data:c}=await r.default.put(`/comments/${e}`,{content:s,updatedAt:o});return u(c)},reply:async({id:e},o)=>{const{data:s}=await r.default.post("/comments/replies",{content:o,parentId:e,link:window.location.href});return u(s)},rate:async(e,o,s)=>{await r.default.post(`/topics/${e.topicId}/comments/${e.id}/ratings`,{ratingType:s,value:o})},unrate:async e=>{await r.default.delete(`/topics/${e.topicId}/comments/${e.id}/ratings`)},fetchRatings:async e=>{const{data:o}=await r.default.get(`/ratings/${e}`);return o},togglePin:async({post:e,value:o})=>{o?await r.default.put(`/posts/${e.id}/pinned`):await r.default.delete(`/posts/${e.id}/pinned`)}},re=()=>{const[e,o]=f.useState(!0);return Z.useRequest(()=>r.default.get("/status",{muteError:!0}).then(()=>o(!0)).catch(()=>o(!1)),{cacheKey:"discuss-kit-status",staleTime:-1}),{available:e}};function K({ref:e=void 0,displayReaction:o=!0,object:s,onChange:c=()=>{},onSendComment:x=()=>{},commentInputPosition:h="top",autoFocus:y=!1,disabledSend:j=void 0,initialContent:A="",sendText:q="",sendIcon:v=null,showTopbar:S=!0,sendComment:C=null,reactionAppend:I=null,skeleton:P=null,placeholder:k="",onInput:T=()=>{},draftKey:b="",inputSx:g={},editorRef:w=null,disableCmdEnter:O=!1}){a.useDefaultApiErrorHandler({request:r.default});const{available:U}=re(),{session:E}=f.useContext(X.SessionContext)||{},{state:B,sort:W,add:M,updateCommentState:N,interactive:$,findById:z,renderInnerFooter:G}=a.useCommentsContext(),{total:R,order:_,initialized:H}=B,{t:p}=D.useLocaleContext();oe.useTopicInfoSync(s);const V={ADD_COMMENT:i=>{M(u(i)),c?.()},UPDATE_COMMENT:i=>{const d=z(i.id);d&&d.content!==i.content&&N(i.id,m=>(m.content=i.content,m.updatedAt=i.updatedAt,m.synced=Date.now(),m))},RATING_COMMENT:async({commentId:i})=>{const d=await r.fetchRatings(i);N(i,m=>({...m,rating:d}))}};if(a.useSubscription(s.id,({event:i,data:d})=>{V[i]?.(d)},[s.id,B]),!U)return n.jsxs(l.Alert,{severity:"info",children:[n.jsx(l.AlertTitle,{children:p("apiUnavailable.title")}),p("apiUnavailable.desc")]});if(!H)return P||n.jsx(l.Box,{sx:{width:"100%",display:"flex",justifyContent:"center"},children:n.jsx(l.CircularProgress,{})});const J=async i=>{const{data:d}=await(C?C({content:i,object:s}):r.default.post("/comments",{content:i,object:s}));M(u(d)),x?.(d)},F=()=>n.jsx(f.Suspense,{fallback:n.jsxs(n.Fragment,{children:[n.jsx(l.Skeleton,{}),n.jsx(l.Skeleton,{width:"80%"}),n.jsx(l.Skeleton,{width:"60%"}),n.jsx(l.Skeleton,{width:"40%"})]}),children:n.jsx(a.CommentInput,{editorRef:w,placeholder:k,send:J,draftKey:b||`object-${s.id}`,autoFocus:y,disabledSend:j,initialContent:A,sendText:q,sendIcon:v,renderInnerFooter:G,onChange:T,disableCmdEnter:O})});return n.jsxs(ae,{ref:e,children:[n.jsxs(n.Fragment,{children:[n.jsx(l.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"end"},children:o&&n.jsxs(a.IconButtonGroup,{sx:{alignItems:"flex-end"},children:[n.jsx(a.GithubReactionContainer,{id:s.id,request:r.default,interactive:$}),I]})}),E.user&&$&&h==="top"&&n.jsx(l.Box,{className:"comment-editor",sx:{mt:2},children:F()})]}),!!R&&S&&n.jsxs(l.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:3},children:[n.jsxs(l.Box,{sx:{fontWeight:"medium"},children:[R>0?`${R} ${p("comments")}`:p("comment")," "]}),n.jsx(a.SegmentedControl,{value:_,options:[{value:"desc",label:p("newest")},{value:"asc",label:p("oldest")}],onChange:i=>W(i)})]}),n.jsx(a.CommentList,{className:"comment-list"}),E.user&&$&&h==="bottom"&&n.jsx(l.Box,{sx:{mt:6,...g},children:F()})]})}K.propTypes={ref:t.any,displayReaction:t.bool,object:t.object.isRequired,onChange:t.func,onSendComment:t.func,disabledSend:t.bool,autoFocus:t.bool,initialContent:t.string,sendText:t.string,sendIcon:t.node,commentInputPosition:t.oneOf(["top","bottom"]),showTopbar:t.bool,sendComment:t.func,reactionAppend:t.any,skeleton:t.node,placeholder:t.string,onInput:t.func,draftKey:t.string,editorRef:t.object,inputSx:t.object,disableCmdEnter:t.bool};function L({target:e,flatView:o=!1,autoCollapse:s=!1,autoLoadComments:c=!0,order:x=void 0,allowCopyLink:h=!1,showProfileCard:y=!1,interactive:j=!0,renderComments:A=null,renderDonation:q=null,renderActions:v=null,renderEditorPlugins:S=null,enableAutoTranslate:C=!1,renderInnerFooter:I=null,...P}){const k=Object.assign({},{displayReaction:!0,onChange:()=>{},onSendComment:()=>{},disabledSend:void 0,sendComment:null,reactionAppend:null},P);if(!e?.id)throw new Error("target is required.");const{locale:T="en"}=D.useLocaleContext()||{},b=f.useRef(),g=f.useMemo(()=>({link:window.location.href,blockletName:se(),...e}),[e]),w=a.getWsClient(ne.discussKitPrefix);return f.useEffect(()=>(w.connect(),()=>{w.isConnected()}),[]),n.jsx(Y.ErrorBoundary,{FallbackComponent:ee,children:n.jsx(D.LocaleProvider,{translations:te.translations,locale:T,children:n.jsx(a.UploaderProvider,{children:n.jsx(a.InternalThemeProvider,{children:n.jsx(a.ConfirmProvider,{children:n.jsx(a.DefaultEditorConfigProvider,{request:r.default,children:n.jsx(a.CommentsProvider,{target:g,api:ie,flatView:o,order:x,autoCollapse:s,autoLoadComments:c,allowCopyLink:h,showProfileCard:y,interactive:j,containerRef:b,renderDonation:q,renderActions:v,renderEditorPlugins:S,enableAutoTranslate:C,renderComments:A,renderInnerFooter:I,children:n.jsx(K,{...k,object:g,ref:b})})})})})})})})}L.propTypes={target:t.shape({id:t.string.isRequired,title:t.string,desc:t.string,owner:t.string}).isRequired,displayReaction:t.bool,onChange:t.func,flatView:t.bool,autoCollapse:t.bool,autoLoadComments:t.bool,allowCopyLink:t.bool,disabledSend:t.bool,showProfileCard:t.bool,order:t.oneOf(["asc","desc"]),interactive:t.bool,renderComments:t.func,renderDonation:t.any,renderActions:t.func,renderEditorPlugins:t.func,enableAutoTranslate:t.bool,renderInnerFooter:t.func,sendComment:t.func,reactionAppend:t.any};const ae=Q.styled("div")`
1
+ "use strict";const n=require("react/jsx-runtime"),p=require("react"),M=require("@arcblock/ux/lib/Theme"),t=require("prop-types"),H=require("@arcblock/did-connect-react/lib/Session"),i=require("@mui/material"),R=require("@arcblock/ux/lib/Locale/context"),V=require("react-error-boundary"),a=require("@blocklet/discuss-kit-ux"),J=require("ahooks"),Q=require("./components/error-fallback.js"),X=require("./locales/index.js"),Y=require("./lib/utils.js"),r=require("./api.js"),Z=require("./hooks/topic-info-sync.js"),_=()=>{const e=s=>s.endsWith("/")?s:`${s}/`;return window.blocklet?.componentMountPoints?.find(s=>e(s.mountPoint)===e(window.blocklet?.prefix))?.title},u=e=>({...e,rootId:e.rootCommentId,createdAt:e.createdAt?new Date(e.createdAt):null,updatedAt:e.updatedAt?new Date(e.updatedAt):null,deletedAt:e.deletedAt?new Date(e.deletedAt):null,pinnedAt:e.pinnedAt?new Date(e.pinnedAt):null,replies:e.replies?.map(u)}),ee={fetchComments:async e=>{const o={...e,embed:e.rootId?"rating":"replies,rating",size:e.limit},{data:{data:s,nextCursor:l,total:d}}=await r.default.get("/comments",{params:o});return{data:s?.map(u),nextCursor:l,total:d}},fetchPinnedComments:async e=>{const{data:o}=await r.default.get("/comments/pinned",{params:{objectId:e}});return(o?.data||[]).map(u)},fetchCommentPosition:async({id:e,...o})=>{const{data:s}=await r.default.get(`/comments/${e}/position`,{params:o});return s},deleteComment:async({id:e})=>{const{data:o}=await r.default.delete(`/comments/${e}`);return o},updateComment:async({id:e,updatedAt:o},s)=>{const{data:l}=await r.default.put(`/comments/${e}`,{content:s,updatedAt:o});return u(l)},reply:async({id:e},o)=>{const{data:s}=await r.default.post("/comments/replies",{content:o,parentId:e,link:window.location.href});return u(s)},rate:async(e,o,s)=>{await r.default.post(`/topics/${e.topicId}/comments/${e.id}/ratings`,{ratingType:s,value:o})},unrate:async e=>{await r.default.delete(`/topics/${e.topicId}/comments/${e.id}/ratings`)},fetchRatings:async e=>{const{data:o}=await r.default.get(`/ratings/${e}`);return o},togglePin:async({post:e,value:o})=>{o?await r.default.put(`/posts/${e.id}/pinned`):await r.default.delete(`/posts/${e.id}/pinned`)}},te=()=>{const[e,o]=p.useState(!0);return J.useRequest(()=>r.default.get("/status",{muteError:!0}).then(()=>o(!0)).catch(()=>o(!1)),{cacheKey:"discuss-kit-status",staleTime:-1}),{available:e}};function E({ref:e=void 0,displayReaction:o=!0,object:s,onSendComment:l=()=>{},commentInputPosition:d="top",autoFocus:b=!1,disabledSend:g=void 0,initialContent:w="",sendText:y="",sendIcon:j=null,showTopbar:q=!0,sendComment:m=null,reactionAppend:v=null,skeleton:A=null,placeholder:I="",onInput:S=()=>{},draftKey:k="",inputSx:f={},editorRef:x=null,disableCmdEnter:h=!1}){a.useDefaultApiErrorHandler({request:r.default});const{available:K}=te(),{session:T}=p.useContext(H.SessionContext)||{},{state:L,sort:N,add:U,interactive:P,renderInnerFooter:W}=a.useCommentsContext(),{total:$,order:z,initialized:O}=L,{t:c}=R.useLocaleContext();if(Z.useTopicInfoSync(s),!K)return n.jsxs(i.Alert,{severity:"info",children:[n.jsx(i.AlertTitle,{children:c("apiUnavailable.title")}),c("apiUnavailable.desc")]});if(!O)return A||n.jsx(i.Box,{sx:{width:"100%",display:"flex",justifyContent:"center"},children:n.jsx(i.CircularProgress,{})});const G=async C=>{const{data:D}=await(m?m({content:C,object:s}):r.default.post("/comments",{content:C,object:s}));U(u(D)),l?.(D)},B=()=>n.jsx(p.Suspense,{fallback:n.jsxs(n.Fragment,{children:[n.jsx(i.Skeleton,{}),n.jsx(i.Skeleton,{width:"80%"}),n.jsx(i.Skeleton,{width:"60%"}),n.jsx(i.Skeleton,{width:"40%"})]}),children:n.jsx(a.CommentInput,{editorRef:x,placeholder:I,send:G,draftKey:k||`object-${s.id}`,autoFocus:b,disabledSend:g,initialContent:w,sendText:y,sendIcon:j,renderInnerFooter:W,onChange:S,disableCmdEnter:h})});return n.jsxs(ne,{ref:e,children:[n.jsxs(n.Fragment,{children:[n.jsx(i.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"end"},children:o&&n.jsxs(a.IconButtonGroup,{sx:{alignItems:"flex-end"},children:[n.jsx(a.GithubReactionContainer,{id:s.id,request:r.default,interactive:P}),v]})}),T.user&&P&&d==="top"&&n.jsx(i.Box,{className:"comment-editor",sx:{mt:2},children:B()})]}),!!$&&q&&n.jsxs(i.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:3},children:[n.jsxs(i.Box,{sx:{fontWeight:"medium"},children:[$>0?`${$} ${c("comments")}`:c("comment")," "]}),n.jsx(a.SegmentedControl,{value:z,options:[{value:"desc",label:c("newest")},{value:"asc",label:c("oldest")}],onChange:C=>N(C)})]}),n.jsx(a.CommentList,{className:"comment-list"}),T.user&&P&&d==="bottom"&&n.jsx(i.Box,{sx:{mt:6,...f},children:B()})]})}E.propTypes={ref:t.any,displayReaction:t.bool,object:t.object.isRequired,onSendComment:t.func,disabledSend:t.bool,autoFocus:t.bool,initialContent:t.string,sendText:t.string,sendIcon:t.node,commentInputPosition:t.oneOf(["top","bottom"]),showTopbar:t.bool,sendComment:t.func,reactionAppend:t.any,skeleton:t.node,placeholder:t.string,onInput:t.func,draftKey:t.string,editorRef:t.object,inputSx:t.object,disableCmdEnter:t.bool};function F({target:e,flatView:o=!1,autoCollapse:s=!1,autoLoadComments:l=!0,order:d=void 0,allowCopyLink:b=!1,showProfileCard:g=!1,interactive:w=!0,renderComments:y=null,renderDonation:j=null,renderActions:q=null,renderEditorPlugins:m=null,enableAutoTranslate:v=!1,renderInnerFooter:A=null,...I}){const S=Object.assign({},{displayReaction:!0,onChange:()=>{},onSendComment:()=>{},disabledSend:void 0,sendComment:null,reactionAppend:null},I);if(!e?.id)throw new Error("target is required.");const{locale:k="en"}=R.useLocaleContext()||{},f=p.useRef(),x=p.useMemo(()=>({link:window.location.href,blockletName:_(),...e}),[e]),h=a.getWsClient(Y.discussKitPrefix);return p.useEffect(()=>(h.connect(),()=>{h.isConnected()}),[]),n.jsx(V.ErrorBoundary,{FallbackComponent:Q,children:n.jsx(R.LocaleProvider,{translations:X.translations,locale:k,children:n.jsx(a.UploaderProvider,{children:n.jsx(a.InternalThemeProvider,{children:n.jsx(a.ConfirmProvider,{children:n.jsx(a.DefaultEditorConfigProvider,{request:r.default,children:n.jsx(a.CommentsProvider,{target:x,api:ee,flatView:o,order:d,autoCollapse:s,autoLoadComments:l,allowCopyLink:b,showProfileCard:g,interactive:w,containerRef:f,renderDonation:j,renderActions:q,renderEditorPlugins:m,enableAutoTranslate:v,renderComments:y,renderInnerFooter:A,children:n.jsx(E,{...S,object:x,ref:f})})})})})})})})}F.propTypes={target:t.shape({id:t.string.isRequired,title:t.string,desc:t.string,owner:t.string}).isRequired,displayReaction:t.bool,onChange:t.func,flatView:t.bool,autoCollapse:t.bool,autoLoadComments:t.bool,allowCopyLink:t.bool,disabledSend:t.bool,showProfileCard:t.bool,order:t.oneOf(["asc","desc"]),interactive:t.bool,renderComments:t.func,renderDonation:t.any,renderActions:t.func,renderEditorPlugins:t.func,enableAutoTranslate:t.bool,renderInnerFooter:t.func,sendComment:t.func,reactionAppend:t.any};const ne=M.styled("div")`
2
2
  width: 100%;
3
3
  margin: 0 auto;
4
4
  box-sizing: border-box;
5
5
  padding: ${e=>e.padding?"20px":"0"};
6
6
  border: ${e=>e.border?"1px solid rgb(208, 215, 222)":"none"};
7
7
  border-radius: 6px;
8
- `;module.exports=L;
8
+ `;module.exports=F;
@@ -1,216 +1,192 @@
1
- import { jsx as i, jsxs as d, Fragment as K } from "react/jsx-runtime";
2
- import { useRef as Q, useMemo as X, useEffect as Y, useContext as Z, useState as ee, Suspense as te } from "react";
3
- import { styled as ne } from "@arcblock/ux/lib/Theme";
1
+ import { jsx as r, jsxs as a, Fragment as j } from "react/jsx-runtime";
2
+ import { useRef as M, useMemo as H, useEffect as V, useContext as J, useState as Q, Suspense as X } from "react";
3
+ import { styled as Y } from "@arcblock/ux/lib/Theme";
4
4
  import t from "prop-types";
5
- import { SessionContext as oe } from "@arcblock/did-connect-react/lib/Session";
6
- import { Alert as ie, AlertTitle as re, Box as p, CircularProgress as se, Skeleton as y } from "@mui/material";
7
- import { useLocaleContext as O, LocaleProvider as ae } from "@arcblock/ux/lib/Locale/context";
8
- import { ErrorBoundary as le } from "react-error-boundary";
9
- import { getWsClient as de, UploaderProvider as ce, InternalThemeProvider as ue, ConfirmProvider as me, DefaultEditorConfigProvider as pe, CommentsProvider as fe, useDefaultApiErrorHandler as he, useCommentsContext as Ce, useSubscription as be, IconButtonGroup as ge, GithubReactionContainer as we, SegmentedControl as ye, CommentList as xe, CommentInput as Ae } from "@blocklet/discuss-kit-ux";
10
- import { useRequest as ve } from "ahooks";
11
- import Ie from "./components/error-fallback.js";
12
- import { translations as Pe } from "./locales/index.js";
13
- import { discussKitPrefix as Se } from "./lib/utils.js";
14
- import s, { fetchRatings as Te } from "./api.js";
15
- import { useTopicInfoSync as $e } from "./hooks/topic-info-sync.js";
16
- const Re = () => {
5
+ import { SessionContext as Z } from "@arcblock/did-connect-react/lib/Session";
6
+ import { Alert as _, AlertTitle as ee, Box as c, CircularProgress as te, Skeleton as C } from "@mui/material";
7
+ import { useLocaleContext as F, LocaleProvider as ne } from "@arcblock/ux/lib/Locale/context";
8
+ import { ErrorBoundary as oe } from "react-error-boundary";
9
+ import { getWsClient as re, UploaderProvider as ie, InternalThemeProvider as se, ConfirmProvider as ae, DefaultEditorConfigProvider as le, CommentsProvider as de, useDefaultApiErrorHandler as ce, useCommentsContext as ue, IconButtonGroup as me, GithubReactionContainer as pe, SegmentedControl as fe, CommentList as he, CommentInput as be } from "@blocklet/discuss-kit-ux";
10
+ import { useRequest as Ce } from "ahooks";
11
+ import ge from "./components/error-fallback.js";
12
+ import { translations as we } from "./locales/index.js";
13
+ import { discussKitPrefix as ye } from "./lib/utils.js";
14
+ import i from "./api.js";
15
+ import { useTopicInfoSync as xe } from "./hooks/topic-info-sync.js";
16
+ const ve = () => {
17
17
  const e = (o) => o.endsWith("/") ? o : `${o}/`;
18
18
  return window.blocklet?.componentMountPoints?.find(
19
19
  (o) => e(o.mountPoint) === e(window.blocklet?.prefix)
20
20
  )?.title;
21
- }, c = (e) => ({
21
+ }, u = (e) => ({
22
22
  ...e,
23
23
  rootId: e.rootCommentId,
24
24
  createdAt: e.createdAt ? new Date(e.createdAt) : null,
25
25
  updatedAt: e.updatedAt ? new Date(e.updatedAt) : null,
26
26
  deletedAt: e.deletedAt ? new Date(e.deletedAt) : null,
27
27
  pinnedAt: e.pinnedAt ? new Date(e.pinnedAt) : null,
28
- replies: e.replies?.map(c)
29
- }), ke = {
28
+ replies: e.replies?.map(u)
29
+ }), Ae = {
30
30
  fetchComments: async (e) => {
31
31
  const n = {
32
32
  ...e,
33
33
  embed: e.rootId ? "rating" : "replies,rating",
34
34
  size: e.limit
35
35
  }, {
36
- data: { data: o, nextCursor: l, total: f }
37
- } = await s.get("/comments", { params: n });
38
- return { data: o?.map(c), nextCursor: l, total: f };
36
+ data: { data: o, nextCursor: s, total: l }
37
+ } = await i.get("/comments", { params: n });
38
+ return { data: o?.map(u), nextCursor: s, total: l };
39
39
  },
40
40
  fetchPinnedComments: async (e) => {
41
- const { data: n } = await s.get("/comments/pinned", { params: { objectId: e } });
42
- return (n?.data || []).map(c);
41
+ const { data: n } = await i.get("/comments/pinned", { params: { objectId: e } });
42
+ return (n?.data || []).map(u);
43
43
  },
44
44
  fetchCommentPosition: async ({ id: e, ...n }) => {
45
- const { data: o } = await s.get(`/comments/${e}/position`, { params: n });
45
+ const { data: o } = await i.get(`/comments/${e}/position`, { params: n });
46
46
  return o;
47
47
  },
48
48
  deleteComment: async ({ id: e }) => {
49
- const { data: n } = await s.delete(`/comments/${e}`);
49
+ const { data: n } = await i.delete(`/comments/${e}`);
50
50
  return n;
51
51
  },
52
52
  updateComment: async ({ id: e, updatedAt: n }, o) => {
53
- const { data: l } = await s.put(`/comments/${e}`, { content: o, updatedAt: n });
54
- return c(l);
53
+ const { data: s } = await i.put(`/comments/${e}`, { content: o, updatedAt: n });
54
+ return u(s);
55
55
  },
56
56
  reply: async ({ id: e }, n) => {
57
- const { data: o } = await s.post("/comments/replies", {
57
+ const { data: o } = await i.post("/comments/replies", {
58
58
  content: n,
59
59
  parentId: e,
60
60
  link: window.location.href
61
61
  });
62
- return c(o);
62
+ return u(o);
63
63
  },
64
64
  rate: async (e, n, o) => {
65
- await s.post(`/topics/${e.topicId}/comments/${e.id}/ratings`, { ratingType: o, value: n });
65
+ await i.post(`/topics/${e.topicId}/comments/${e.id}/ratings`, { ratingType: o, value: n });
66
66
  },
67
67
  unrate: async (e) => {
68
- await s.delete(`/topics/${e.topicId}/comments/${e.id}/ratings`);
68
+ await i.delete(`/topics/${e.topicId}/comments/${e.id}/ratings`);
69
69
  },
70
70
  fetchRatings: async (e) => {
71
- const { data: n } = await s.get(`/ratings/${e}`);
71
+ const { data: n } = await i.get(`/ratings/${e}`);
72
72
  return n;
73
73
  },
74
74
  togglePin: async ({ post: e, value: n }) => {
75
- n ? await s.put(`/posts/${e.id}/pinned`) : await s.delete(`/posts/${e.id}/pinned`);
75
+ n ? await i.put(`/posts/${e.id}/pinned`) : await i.delete(`/posts/${e.id}/pinned`);
76
76
  }
77
- }, De = () => {
78
- const [e, n] = ee(!0);
79
- return ve(
80
- () => s.get("/status", { muteError: !0 }).then(() => n(!0)).catch(() => n(!1)),
77
+ }, Ie = () => {
78
+ const [e, n] = Q(!0);
79
+ return Ce(
80
+ () => i.get("/status", { muteError: !0 }).then(() => n(!0)).catch(() => n(!1)),
81
81
  { cacheKey: "discuss-kit-status", staleTime: -1 }
82
82
  ), { available: e };
83
83
  };
84
- function B({
84
+ function K({
85
85
  ref: e = void 0,
86
86
  displayReaction: n = !0,
87
87
  object: o,
88
- onChange: l = () => {
88
+ // onChange = () => {},
89
+ onSendComment: s = () => {
89
90
  },
90
- onSendComment: f = () => {
91
+ commentInputPosition: l = "top",
92
+ autoFocus: g = !1,
93
+ disabledSend: w = void 0,
94
+ initialContent: y = "",
95
+ sendText: x = "",
96
+ sendIcon: v = null,
97
+ showTopbar: A = !0,
98
+ sendComment: m = null,
99
+ reactionAppend: I = null,
100
+ skeleton: P = null,
101
+ placeholder: $ = "",
102
+ onInput: S = () => {
91
103
  },
92
- commentInputPosition: h = "top",
93
- autoFocus: x = !1,
94
- disabledSend: A = void 0,
95
- initialContent: v = "",
96
- sendText: I = "",
97
- sendIcon: P = null,
98
- showTopbar: S = !0,
99
- sendComment: C = null,
100
- reactionAppend: T = null,
101
- skeleton: $ = null,
102
- placeholder: R = "",
103
- onInput: k = () => {
104
- },
105
- draftKey: b = "",
106
- inputSx: g = {},
107
- editorRef: w = null,
108
- disableCmdEnter: L = !1
104
+ draftKey: k = "",
105
+ inputSx: p = {},
106
+ editorRef: f = null,
107
+ disableCmdEnter: h = !1
109
108
  }) {
110
- he({
111
- request: s
109
+ ce({
110
+ request: i
112
111
  });
113
- const { available: U } = De(), { session: q } = Z(oe) || {}, { state: M, sort: W, add: N, updateCommentState: j, interactive: D, findById: z, renderInnerFooter: G } = Ce(), { total: E, order: _, initialized: H } = M, { t: u } = O();
114
- $e(o);
115
- const V = {
116
- ADD_COMMENT: (r) => {
117
- N(c(r)), l?.();
118
- },
119
- UPDATE_COMMENT: (r) => {
120
- const a = z(r.id);
121
- a && a.content !== r.content && j(r.id, (m) => (m.content = r.content, m.updatedAt = r.updatedAt, m.synced = Date.now(), m));
122
- },
123
- RATING_COMMENT: async ({ commentId: r }) => {
124
- const a = await Te(r);
125
- j(r, (m) => ({
126
- ...m,
127
- rating: a
128
- }));
129
- }
130
- };
131
- if (be(
132
- o.id,
133
- ({ event: r, data: a }) => {
134
- V[r]?.(a);
135
- },
136
- [o.id, M]
137
- ), !U)
138
- return /* @__PURE__ */ d(ie, { severity: "info", children: [
139
- /* @__PURE__ */ i(re, { children: u("apiUnavailable.title") }),
140
- u("apiUnavailable.desc")
112
+ const { available: L } = Ie(), { session: q } = J(Z) || {}, { state: B, sort: N, add: W, interactive: R, renderInnerFooter: z } = ue(), { total: T, order: O, initialized: U } = B, { t: d } = F();
113
+ if (xe(o), !L)
114
+ return /* @__PURE__ */ a(_, { severity: "info", children: [
115
+ /* @__PURE__ */ r(ee, { children: d("apiUnavailable.title") }),
116
+ d("apiUnavailable.desc")
141
117
  ] });
142
- if (!H)
143
- return $ || /* @__PURE__ */ i(
144
- p,
118
+ if (!U)
119
+ return P || /* @__PURE__ */ r(
120
+ c,
145
121
  {
146
122
  sx: {
147
123
  width: "100%",
148
124
  display: "flex",
149
125
  justifyContent: "center"
150
126
  },
151
- children: /* @__PURE__ */ i(se, {})
127
+ children: /* @__PURE__ */ r(te, {})
152
128
  }
153
129
  );
154
- const J = async (r) => {
155
- const { data: a } = await (C ? C({ content: r, object: o }) : s.post("/comments", { content: r, object: o }));
156
- N(c(a)), f?.(a);
157
- }, F = () => /* @__PURE__ */ i(
158
- te,
130
+ const G = async (b) => {
131
+ const { data: E } = await (m ? m({ content: b, object: o }) : i.post("/comments", { content: b, object: o }));
132
+ W(u(E)), s?.(E);
133
+ }, D = () => /* @__PURE__ */ r(
134
+ X,
159
135
  {
160
- fallback: /* @__PURE__ */ d(K, { children: [
161
- /* @__PURE__ */ i(y, {}),
162
- /* @__PURE__ */ i(y, { width: "80%" }),
163
- /* @__PURE__ */ i(y, { width: "60%" }),
164
- /* @__PURE__ */ i(y, { width: "40%" })
136
+ fallback: /* @__PURE__ */ a(j, { children: [
137
+ /* @__PURE__ */ r(C, {}),
138
+ /* @__PURE__ */ r(C, { width: "80%" }),
139
+ /* @__PURE__ */ r(C, { width: "60%" }),
140
+ /* @__PURE__ */ r(C, { width: "40%" })
165
141
  ] }),
166
- children: /* @__PURE__ */ i(
167
- Ae,
142
+ children: /* @__PURE__ */ r(
143
+ be,
168
144
  {
169
- editorRef: w,
170
- placeholder: R,
171
- send: J,
172
- draftKey: b || `object-${o.id}`,
173
- autoFocus: x,
174
- disabledSend: A,
175
- initialContent: v,
176
- sendText: I,
177
- sendIcon: P,
178
- renderInnerFooter: G,
179
- onChange: k,
180
- disableCmdEnter: L
145
+ editorRef: f,
146
+ placeholder: $,
147
+ send: G,
148
+ draftKey: k || `object-${o.id}`,
149
+ autoFocus: g,
150
+ disabledSend: w,
151
+ initialContent: y,
152
+ sendText: x,
153
+ sendIcon: v,
154
+ renderInnerFooter: z,
155
+ onChange: S,
156
+ disableCmdEnter: h
181
157
  }
182
158
  )
183
159
  }
184
160
  );
185
- return /* @__PURE__ */ d(qe, { ref: e, children: [
186
- /* @__PURE__ */ d(K, { children: [
187
- /* @__PURE__ */ i(
188
- p,
161
+ return /* @__PURE__ */ a($e, { ref: e, children: [
162
+ /* @__PURE__ */ a(j, { children: [
163
+ /* @__PURE__ */ r(
164
+ c,
189
165
  {
190
166
  sx: {
191
167
  display: "flex",
192
168
  justifyContent: "space-between",
193
169
  alignItems: "end"
194
170
  },
195
- children: n && /* @__PURE__ */ d(ge, { sx: { alignItems: "flex-end" }, children: [
196
- /* @__PURE__ */ i(we, { id: o.id, request: s, interactive: D }),
197
- T
171
+ children: n && /* @__PURE__ */ a(me, { sx: { alignItems: "flex-end" }, children: [
172
+ /* @__PURE__ */ r(pe, { id: o.id, request: i, interactive: R }),
173
+ I
198
174
  ] })
199
175
  }
200
176
  ),
201
- q.user && D && h === "top" && /* @__PURE__ */ i(
202
- p,
177
+ q.user && R && l === "top" && /* @__PURE__ */ r(
178
+ c,
203
179
  {
204
180
  className: "comment-editor",
205
181
  sx: {
206
182
  mt: 2
207
183
  },
208
- children: F()
184
+ children: D()
209
185
  }
210
186
  )
211
187
  ] }),
212
- !!E && S && /* @__PURE__ */ d(
213
- p,
188
+ !!T && A && /* @__PURE__ */ a(
189
+ c,
214
190
  {
215
191
  sx: {
216
192
  display: "flex",
@@ -219,33 +195,33 @@ function B({
219
195
  mt: 3
220
196
  },
221
197
  children: [
222
- /* @__PURE__ */ d(p, { sx: { fontWeight: "medium" }, children: [
223
- E > 0 ? `${E} ${u("comments")}` : u("comment"),
198
+ /* @__PURE__ */ a(c, { sx: { fontWeight: "medium" }, children: [
199
+ T > 0 ? `${T} ${d("comments")}` : d("comment"),
224
200
  " "
225
201
  ] }),
226
- /* @__PURE__ */ i(
227
- ye,
202
+ /* @__PURE__ */ r(
203
+ fe,
228
204
  {
229
- value: _,
205
+ value: O,
230
206
  options: [
231
- { value: "desc", label: u("newest") },
232
- { value: "asc", label: u("oldest") }
207
+ { value: "desc", label: d("newest") },
208
+ { value: "asc", label: d("oldest") }
233
209
  ],
234
- onChange: (r) => W(r)
210
+ onChange: (b) => N(b)
235
211
  }
236
212
  )
237
213
  ]
238
214
  }
239
215
  ),
240
- /* @__PURE__ */ i(xe, { className: "comment-list" }),
241
- q.user && D && h === "bottom" && /* @__PURE__ */ i(p, { sx: { mt: 6, ...g }, children: F() })
216
+ /* @__PURE__ */ r(he, { className: "comment-list" }),
217
+ q.user && R && l === "bottom" && /* @__PURE__ */ r(c, { sx: { mt: 6, ...p }, children: D() })
242
218
  ] });
243
219
  }
244
- B.propTypes = {
220
+ K.propTypes = {
245
221
  ref: t.any,
246
222
  displayReaction: t.bool,
247
223
  object: t.object.isRequired,
248
- onChange: t.func,
224
+ // onChange: PropTypes.func,
249
225
  onSendComment: t.func,
250
226
  disabledSend: t.bool,
251
227
  autoFocus: t.bool,
@@ -264,24 +240,24 @@ B.propTypes = {
264
240
  inputSx: t.object,
265
241
  disableCmdEnter: t.bool
266
242
  };
267
- function Ee({
243
+ function Pe({
268
244
  target: e,
269
245
  flatView: n = !1,
270
246
  autoCollapse: o = !1,
271
- autoLoadComments: l = !0,
272
- order: f = void 0,
273
- allowCopyLink: h = !1,
274
- showProfileCard: x = !1,
275
- interactive: A = !0,
276
- renderComments: v = null,
277
- renderDonation: I = null,
278
- renderActions: P = null,
279
- renderEditorPlugins: S = null,
280
- enableAutoTranslate: C = !1,
281
- renderInnerFooter: T = null,
247
+ autoLoadComments: s = !0,
248
+ order: l = void 0,
249
+ allowCopyLink: g = !1,
250
+ showProfileCard: w = !1,
251
+ interactive: y = !0,
252
+ renderComments: x = null,
253
+ renderDonation: v = null,
254
+ renderActions: A = null,
255
+ renderEditorPlugins: m = null,
256
+ enableAutoTranslate: I = !1,
257
+ renderInnerFooter: P = null,
282
258
  ...$
283
259
  }) {
284
- const R = Object.assign(
260
+ const S = Object.assign(
285
261
  {},
286
262
  {
287
263
  displayReaction: !0,
@@ -297,41 +273,41 @@ function Ee({
297
273
  );
298
274
  if (!e?.id)
299
275
  throw new Error("target is required.");
300
- const { locale: k = "en" } = O() || {}, b = Q(), g = X(
276
+ const { locale: k = "en" } = F() || {}, p = M(), f = H(
301
277
  () => ({
302
278
  link: window.location.href,
303
- blockletName: Re(),
279
+ blockletName: ve(),
304
280
  ...e
305
281
  }),
306
282
  // eslint-disable-next-line react-hooks/exhaustive-deps
307
283
  [e]
308
- ), w = de(Se);
309
- return Y(() => (w.connect(), () => {
310
- w.isConnected();
311
- }), []), /* @__PURE__ */ i(le, { FallbackComponent: Ie, children: /* @__PURE__ */ i(ae, { translations: Pe, locale: k, children: /* @__PURE__ */ i(ce, { children: /* @__PURE__ */ i(ue, { children: /* @__PURE__ */ i(me, { children: /* @__PURE__ */ i(pe, { request: s, children: /* @__PURE__ */ i(
312
- fe,
284
+ ), h = re(ye);
285
+ return V(() => (h.connect(), () => {
286
+ h.isConnected();
287
+ }), []), /* @__PURE__ */ r(oe, { FallbackComponent: ge, children: /* @__PURE__ */ r(ne, { translations: we, locale: k, children: /* @__PURE__ */ r(ie, { children: /* @__PURE__ */ r(se, { children: /* @__PURE__ */ r(ae, { children: /* @__PURE__ */ r(le, { request: i, children: /* @__PURE__ */ r(
288
+ de,
313
289
  {
314
- target: g,
315
- api: ke,
290
+ target: f,
291
+ api: Ae,
316
292
  flatView: n,
317
- order: f,
293
+ order: l,
318
294
  autoCollapse: o,
319
- autoLoadComments: l,
320
- allowCopyLink: h,
321
- showProfileCard: x,
322
- interactive: A,
323
- containerRef: b,
324
- renderDonation: I,
325
- renderActions: P,
326
- renderEditorPlugins: S,
327
- enableAutoTranslate: C,
328
- renderComments: v,
329
- renderInnerFooter: T,
330
- children: /* @__PURE__ */ i(B, { ...R, object: g, ref: b })
295
+ autoLoadComments: s,
296
+ allowCopyLink: g,
297
+ showProfileCard: w,
298
+ interactive: y,
299
+ containerRef: p,
300
+ renderDonation: v,
301
+ renderActions: A,
302
+ renderEditorPlugins: m,
303
+ enableAutoTranslate: I,
304
+ renderComments: x,
305
+ renderInnerFooter: P,
306
+ children: /* @__PURE__ */ r(K, { ...S, object: f, ref: p })
331
307
  }
332
308
  ) }) }) }) }) }) });
333
309
  }
334
- Ee.propTypes = {
310
+ Pe.propTypes = {
335
311
  target: t.shape({
336
312
  id: t.string.isRequired,
337
313
  title: t.string,
@@ -357,7 +333,7 @@ Ee.propTypes = {
357
333
  sendComment: t.func,
358
334
  reactionAppend: t.any
359
335
  };
360
- const qe = ne("div")`
336
+ const $e = Y("div")`
361
337
  width: 100%;
362
338
  margin: 0 auto;
363
339
  box-sizing: border-box;
@@ -366,5 +342,5 @@ const qe = ne("div")`
366
342
  border-radius: 6px;
367
343
  `;
368
344
  export {
369
- Ee as default
345
+ Pe as default
370
346
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/discuss-kit",
3
- "version": "2.5.31",
3
+ "version": "2.5.33",
4
4
  "description": "A react component for Discuss Kit blocklet.",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/es/index.js",
@@ -49,8 +49,8 @@
49
49
  "rehype-sanitize": "^5.0.1",
50
50
  "timeago.js": "^4.0.2",
51
51
  "url-join": "^4.0.1",
52
- "@blocklet/discuss-kit-ux": "2.5.31",
53
- "@blocklet/editor": "2.5.31"
52
+ "@blocklet/discuss-kit-ux": "2.5.33",
53
+ "@blocklet/editor": "2.5.33"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@arcblock/did-connect-react": "^3.1.5",