@blocklet/discuss-kit 2.4.1 → 2.4.3

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