@blocklet/discuss-kit-lite 2.6.3 → 2.6.5
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/lib/cjs/comments.js +2 -2
- package/lib/es/comments.js +35 -32
- package/package.json +3 -3
package/lib/cjs/comments.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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"),
|
|
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"),T=require("@arcblock/ux/lib/Locale/context"),V=require("react-error-boundary"),a=require("@blocklet/discuss-kit-ux-lite"),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 F({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:P={},editorRef:f=null,disableCmdEnter:x=!1}){a.useDefaultApiErrorHandler({request:r.default});const{available:h}=te(),{session:B}=p.useContext(H.SessionContext)||{},{state:L,sort:U,add:N,interactive:$,renderInnerFooter:W}=a.useCommentsContext(),{total:R,order:z,initialized:O}=L,{t:c}=T.useLocaleContext();if(Z.useTopicInfoSync(s),!h)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:E}=await(m?m({content:C,object:s}):r.default.post("/comments",{content:C,object:s}));N(u(E)),l?.(E)},D=()=>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:f,placeholder:I,send:G,draftKey:k||`object-${s.id}`,autoFocus:b,disabledSend:g,initialContent:w,sendText:y,sendIcon:j,renderInnerFooter:W,onChange:S,disableCmdEnter:x})});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:$}),v]})}),B.user&&$&&d==="top"&&n.jsx(i.Box,{className:"comment-editor",sx:{mt:2},children:D()})]}),!!R&&q&&n.jsxs(i.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mt:3},children:[n.jsxs(i.Box,{sx:{fontWeight:"medium"},children:[R>0?`${R} ${c("comments")}`:c("comment")," "]}),n.jsx(a.SegmentedControl,{value:z,options:[{value:"desc",label:c("newest")},{value:"asc",label:c("oldest")}],onChange:C=>U(C)})]}),n.jsx(a.CommentList,{className:"comment-list"}),B.user&&$&&d==="bottom"&&n.jsx(i.Box,{sx:{mt:6,...P},children:D()})]})}F.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 K({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,profileUrl:I=null,...S}){const k=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:P="en"}=T.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(T.LocaleProvider,{translations:X.translations,locale:P,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,profileUrl:I,children:n.jsx(F,{...k,object:x,ref:f})})})})})})})})}K.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,profileUrl:t.func};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=
|
|
8
|
+
`;module.exports=K;
|
package/lib/es/comments.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { jsx as r, jsxs as a, Fragment as
|
|
1
|
+
import { jsx as r, jsxs as a, Fragment as F } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as M, useMemo as H, useEffect as V, useContext as J, useState as Q, Suspense as X } from "react";
|
|
3
3
|
import { styled as Y } from "@arcblock/ux/lib/Theme";
|
|
4
4
|
import t from "prop-types";
|
|
5
5
|
import { SessionContext as Z } from "@arcblock/did-connect-react/lib/Session";
|
|
6
6
|
import { Alert as _, AlertTitle as ee, Box as c, CircularProgress as te, Skeleton as C } from "@mui/material";
|
|
7
|
-
import { useLocaleContext as
|
|
7
|
+
import { useLocaleContext as K, LocaleProvider as ne } from "@arcblock/ux/lib/Locale/context";
|
|
8
8
|
import { ErrorBoundary as oe } from "react-error-boundary";
|
|
9
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-lite";
|
|
10
10
|
import { useRequest as Ce } from "ahooks";
|
|
@@ -81,7 +81,7 @@ const ve = () => {
|
|
|
81
81
|
{ cacheKey: "discuss-kit-status", staleTime: -1 }
|
|
82
82
|
), { available: e };
|
|
83
83
|
};
|
|
84
|
-
function
|
|
84
|
+
function L({
|
|
85
85
|
ref: e = void 0,
|
|
86
86
|
displayReaction: n = !0,
|
|
87
87
|
object: o,
|
|
@@ -102,20 +102,20 @@ function K({
|
|
|
102
102
|
onInput: S = () => {
|
|
103
103
|
},
|
|
104
104
|
draftKey: k = "",
|
|
105
|
-
inputSx:
|
|
106
|
-
editorRef:
|
|
107
|
-
disableCmdEnter:
|
|
105
|
+
inputSx: R = {},
|
|
106
|
+
editorRef: p = null,
|
|
107
|
+
disableCmdEnter: f = !1
|
|
108
108
|
}) {
|
|
109
109
|
ce({
|
|
110
110
|
request: i
|
|
111
111
|
});
|
|
112
|
-
const { available:
|
|
113
|
-
if (xe(o), !
|
|
112
|
+
const { available: h } = Ie(), { session: D } = J(Z) || {}, { state: B, sort: N, add: U, interactive: T, renderInnerFooter: W } = ue(), { total: q, order: z, initialized: O } = B, { t: d } = K();
|
|
113
|
+
if (xe(o), !h)
|
|
114
114
|
return /* @__PURE__ */ a(_, { severity: "info", children: [
|
|
115
115
|
/* @__PURE__ */ r(ee, { children: d("apiUnavailable.title") }),
|
|
116
116
|
d("apiUnavailable.desc")
|
|
117
117
|
] });
|
|
118
|
-
if (!
|
|
118
|
+
if (!O)
|
|
119
119
|
return P || /* @__PURE__ */ r(
|
|
120
120
|
c,
|
|
121
121
|
{
|
|
@@ -128,12 +128,12 @@ function K({
|
|
|
128
128
|
}
|
|
129
129
|
);
|
|
130
130
|
const G = async (b) => {
|
|
131
|
-
const { data:
|
|
132
|
-
|
|
133
|
-
},
|
|
131
|
+
const { data: j } = await (m ? m({ content: b, object: o }) : i.post("/comments", { content: b, object: o }));
|
|
132
|
+
U(u(j)), s?.(j);
|
|
133
|
+
}, E = () => /* @__PURE__ */ r(
|
|
134
134
|
X,
|
|
135
135
|
{
|
|
136
|
-
fallback: /* @__PURE__ */ a(
|
|
136
|
+
fallback: /* @__PURE__ */ a(F, { children: [
|
|
137
137
|
/* @__PURE__ */ r(C, {}),
|
|
138
138
|
/* @__PURE__ */ r(C, { width: "80%" }),
|
|
139
139
|
/* @__PURE__ */ r(C, { width: "60%" }),
|
|
@@ -142,7 +142,7 @@ function K({
|
|
|
142
142
|
children: /* @__PURE__ */ r(
|
|
143
143
|
be,
|
|
144
144
|
{
|
|
145
|
-
editorRef:
|
|
145
|
+
editorRef: p,
|
|
146
146
|
placeholder: $,
|
|
147
147
|
send: G,
|
|
148
148
|
draftKey: k || `object-${o.id}`,
|
|
@@ -151,15 +151,15 @@ function K({
|
|
|
151
151
|
initialContent: y,
|
|
152
152
|
sendText: x,
|
|
153
153
|
sendIcon: v,
|
|
154
|
-
renderInnerFooter:
|
|
154
|
+
renderInnerFooter: W,
|
|
155
155
|
onChange: S,
|
|
156
|
-
disableCmdEnter:
|
|
156
|
+
disableCmdEnter: f
|
|
157
157
|
}
|
|
158
158
|
)
|
|
159
159
|
}
|
|
160
160
|
);
|
|
161
161
|
return /* @__PURE__ */ a($e, { ref: e, children: [
|
|
162
|
-
/* @__PURE__ */ a(
|
|
162
|
+
/* @__PURE__ */ a(F, { children: [
|
|
163
163
|
/* @__PURE__ */ r(
|
|
164
164
|
c,
|
|
165
165
|
{
|
|
@@ -169,23 +169,23 @@ function K({
|
|
|
169
169
|
alignItems: "end"
|
|
170
170
|
},
|
|
171
171
|
children: n && /* @__PURE__ */ a(me, { sx: { alignItems: "flex-end" }, children: [
|
|
172
|
-
/* @__PURE__ */ r(pe, { id: o.id, request: i, interactive:
|
|
172
|
+
/* @__PURE__ */ r(pe, { id: o.id, request: i, interactive: T }),
|
|
173
173
|
I
|
|
174
174
|
] })
|
|
175
175
|
}
|
|
176
176
|
),
|
|
177
|
-
|
|
177
|
+
D.user && T && l === "top" && /* @__PURE__ */ r(
|
|
178
178
|
c,
|
|
179
179
|
{
|
|
180
180
|
className: "comment-editor",
|
|
181
181
|
sx: {
|
|
182
182
|
mt: 2
|
|
183
183
|
},
|
|
184
|
-
children:
|
|
184
|
+
children: E()
|
|
185
185
|
}
|
|
186
186
|
)
|
|
187
187
|
] }),
|
|
188
|
-
!!
|
|
188
|
+
!!q && A && /* @__PURE__ */ a(
|
|
189
189
|
c,
|
|
190
190
|
{
|
|
191
191
|
sx: {
|
|
@@ -196,13 +196,13 @@ function K({
|
|
|
196
196
|
},
|
|
197
197
|
children: [
|
|
198
198
|
/* @__PURE__ */ a(c, { sx: { fontWeight: "medium" }, children: [
|
|
199
|
-
|
|
199
|
+
q > 0 ? `${q} ${d("comments")}` : d("comment"),
|
|
200
200
|
" "
|
|
201
201
|
] }),
|
|
202
202
|
/* @__PURE__ */ r(
|
|
203
203
|
fe,
|
|
204
204
|
{
|
|
205
|
-
value:
|
|
205
|
+
value: z,
|
|
206
206
|
options: [
|
|
207
207
|
{ value: "desc", label: d("newest") },
|
|
208
208
|
{ value: "asc", label: d("oldest") }
|
|
@@ -214,10 +214,10 @@ function K({
|
|
|
214
214
|
}
|
|
215
215
|
),
|
|
216
216
|
/* @__PURE__ */ r(he, { className: "comment-list" }),
|
|
217
|
-
|
|
217
|
+
D.user && T && l === "bottom" && /* @__PURE__ */ r(c, { sx: { mt: 6, ...R }, children: E() })
|
|
218
218
|
] });
|
|
219
219
|
}
|
|
220
|
-
|
|
220
|
+
L.propTypes = {
|
|
221
221
|
ref: t.any,
|
|
222
222
|
displayReaction: t.bool,
|
|
223
223
|
object: t.object.isRequired,
|
|
@@ -255,9 +255,10 @@ function Pe({
|
|
|
255
255
|
renderEditorPlugins: m = null,
|
|
256
256
|
enableAutoTranslate: I = !1,
|
|
257
257
|
renderInnerFooter: P = null,
|
|
258
|
-
|
|
258
|
+
profileUrl: $ = null,
|
|
259
|
+
...S
|
|
259
260
|
}) {
|
|
260
|
-
const
|
|
261
|
+
const k = Object.assign(
|
|
261
262
|
{},
|
|
262
263
|
{
|
|
263
264
|
displayReaction: !0,
|
|
@@ -269,11 +270,11 @@ function Pe({
|
|
|
269
270
|
sendComment: null,
|
|
270
271
|
reactionAppend: null
|
|
271
272
|
},
|
|
272
|
-
|
|
273
|
+
S
|
|
273
274
|
);
|
|
274
275
|
if (!e?.id)
|
|
275
276
|
throw new Error("target is required.");
|
|
276
|
-
const { locale:
|
|
277
|
+
const { locale: R = "en" } = K() || {}, p = M(), f = H(
|
|
277
278
|
() => ({
|
|
278
279
|
link: window.location.href,
|
|
279
280
|
blockletName: ve(),
|
|
@@ -284,7 +285,7 @@ function Pe({
|
|
|
284
285
|
), h = re(ye);
|
|
285
286
|
return V(() => (h.connect(), () => {
|
|
286
287
|
h.isConnected();
|
|
287
|
-
}), []), /* @__PURE__ */ r(oe, { FallbackComponent: ge, children: /* @__PURE__ */ r(ne, { translations: we, locale:
|
|
288
|
+
}), []), /* @__PURE__ */ r(oe, { FallbackComponent: ge, children: /* @__PURE__ */ r(ne, { translations: we, locale: R, children: /* @__PURE__ */ r(ie, { children: /* @__PURE__ */ r(se, { children: /* @__PURE__ */ r(ae, { children: /* @__PURE__ */ r(le, { request: i, children: /* @__PURE__ */ r(
|
|
288
289
|
de,
|
|
289
290
|
{
|
|
290
291
|
target: f,
|
|
@@ -303,7 +304,8 @@ function Pe({
|
|
|
303
304
|
enableAutoTranslate: I,
|
|
304
305
|
renderComments: x,
|
|
305
306
|
renderInnerFooter: P,
|
|
306
|
-
|
|
307
|
+
profileUrl: $,
|
|
308
|
+
children: /* @__PURE__ */ r(L, { ...k, object: f, ref: p })
|
|
307
309
|
}
|
|
308
310
|
) }) }) }) }) }) });
|
|
309
311
|
}
|
|
@@ -331,7 +333,8 @@ Pe.propTypes = {
|
|
|
331
333
|
enableAutoTranslate: t.bool,
|
|
332
334
|
renderInnerFooter: t.func,
|
|
333
335
|
sendComment: t.func,
|
|
334
|
-
reactionAppend: t.any
|
|
336
|
+
reactionAppend: t.any,
|
|
337
|
+
profileUrl: t.func
|
|
335
338
|
};
|
|
336
339
|
const $e = Y("div")`
|
|
337
340
|
width: 100%;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/discuss-kit-lite",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.5",
|
|
4
4
|
"description": "A react component for Discuss Kit blocklet.",
|
|
5
5
|
"main": "./lib/cjs/index.js",
|
|
6
6
|
"module": "./lib/es/index.js",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"react-error-boundary": "^3.1.4",
|
|
49
49
|
"rehype-sanitize": "^5.0.1",
|
|
50
50
|
"timeago.js": "^4.0.2",
|
|
51
|
-
"@blocklet/discuss-kit-ux-lite": "2.6.
|
|
52
|
-
"@blocklet/editor-lite": "2.6.
|
|
51
|
+
"@blocklet/discuss-kit-ux-lite": "2.6.5",
|
|
52
|
+
"@blocklet/editor-lite": "2.6.5"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@arcblock/did-connect-react": "^3.1.5",
|