@blocklet/discuss-kit 1.0.17 → 1.0.19

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.
@@ -37,12 +37,20 @@ const getPrefix = () => {
37
37
  const service = (_b = (_a = window.blocklet) == null ? void 0 : _a.componentMountPoints) == null ? void 0 : _b.find((x) => x.name === "did-comments");
38
38
  return service ? joinUrl__default.default(service.mountPoint, "/") : "";
39
39
  };
40
+ const getCurrentBlockletComponentName = () => {
41
+ var _a, _b;
42
+ const ensureTrailingSlash = (str) => str.endsWith("/") ? str : `${str}/`;
43
+ const matched = (_b = (_a = window.blocklet) == null ? void 0 : _a.componentMountPoints) == null ? void 0 : _b.find((x) => {
44
+ var _a2;
45
+ return ensureTrailingSlash(x.mountPoint) === ensureTrailingSlash((_a2 = window.blocklet) == null ? void 0 : _a2.prefix);
46
+ });
47
+ return matched == null ? void 0 : matched.title;
48
+ };
40
49
  const formatComment = (comment) => {
41
50
  var _a;
42
51
  return {
43
52
  ...comment,
44
- rootId: comment.commentId,
45
- author: comment.commenter,
53
+ rootId: comment.rootCommentId,
46
54
  createdAt: comment.createdAt ? new Date(comment.createdAt) : null,
47
55
  updatedAt: comment.updatedAt ? new Date(comment.updatedAt) : null,
48
56
  deletedAt: comment.deletedAt ? new Date(comment.deletedAt) : null,
@@ -110,13 +118,13 @@ const commentAPI = {
110
118
  return formatComment(data);
111
119
  },
112
120
  rate: async (comment, value, ratingType) => {
113
- await api__default.default.post(`/objects/${comment.objectId}/comments/${comment.id}/ratings`, {
121
+ await api__default.default.post(`/topics/${comment.topicId}/comments/${comment.id}/ratings`, {
114
122
  ratingType,
115
123
  value
116
124
  });
117
125
  },
118
126
  unrate: async (comment) => {
119
- await api__default.default.delete(`/objects/${comment.objectId}/comments/${comment.id}/ratings`);
127
+ await api__default.default.delete(`/topics/${comment.topicId}/comments/${comment.id}/ratings`);
120
128
  },
121
129
  fetchRatings: async (id) => {
122
130
  const {
@@ -128,7 +136,8 @@ const commentAPI = {
128
136
  function DiscussKitComments({
129
137
  showConnectBtn,
130
138
  object,
131
- onChange
139
+ onChange,
140
+ commentInputPosition
132
141
  }) {
133
142
  const {
134
143
  session
@@ -189,7 +198,7 @@ function DiscussKitComments({
189
198
  session.login();
190
199
  throw new Error("Unauthenticated.");
191
200
  }
192
- await api__default.default.post(`/objects/${object.id}/ratings`, {
201
+ await api__default.default.post(`/topics/${object.id}/ratings`, {
193
202
  ratingType,
194
203
  value
195
204
  });
@@ -199,7 +208,7 @@ function DiscussKitComments({
199
208
  session.login();
200
209
  throw new Error("Unauthenticated.");
201
210
  }
202
- await api__default.default.delete(`/objects/${object.id}/ratings`);
211
+ await api__default.default.delete(`/topics/${object.id}/ratings`);
203
212
  };
204
213
  return /* @__PURE__ */ jsxRuntime.jsxs(Container, {
205
214
  children: [/* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
@@ -250,8 +259,8 @@ function DiscussKitComments({
250
259
  children: t("installDIDWallet")
251
260
  })]
252
261
  })
253
- }), session.user && /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
254
- mt: 2.5,
262
+ }), session.user && commentInputPosition === "top" && /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
263
+ mt: 2,
255
264
  children: /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.CommentInput, {
256
265
  send: sendComment,
257
266
  draftKey: `object-${object.id}`
@@ -260,7 +269,7 @@ function DiscussKitComments({
260
269
  }), !!total && /* @__PURE__ */ jsxRuntime.jsxs(Box__default.default, {
261
270
  display: "flex",
262
271
  justifyContent: "space-between",
263
- mt: 4,
272
+ mt: 3,
264
273
  children: [/* @__PURE__ */ jsxRuntime.jsxs("span", {
265
274
  children: [total > 0 ? `${total} ${t("comments")}` : t("comment"), " "]
266
275
  }), /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup__default.default, {
@@ -278,18 +287,26 @@ function DiscussKitComments({
278
287
  children: t("newest")
279
288
  })]
280
289
  })]
281
- }), /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.CommentList, {})]
290
+ }), /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.CommentList, {}), session.user && commentInputPosition === "bottom" && /* @__PURE__ */ jsxRuntime.jsx(Box__default.default, {
291
+ mt: 6,
292
+ children: /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.CommentInput, {
293
+ send: sendComment,
294
+ draftKey: `object-${object.id}`
295
+ })
296
+ })]
282
297
  });
283
298
  }
284
299
  DiscussKitComments.propTypes = {
285
300
  showConnectBtn: PropTypes__default.default.bool,
286
301
  object: PropTypes__default.default.object.isRequired,
287
- onChange: PropTypes__default.default.func
302
+ onChange: PropTypes__default.default.func,
303
+ commentInputPosition: PropTypes__default.default.oneOf(["top", "bottom"])
288
304
  };
289
305
  DiscussKitComments.defaultProps = {
290
306
  showConnectBtn: false,
291
307
  onChange: () => {
292
- }
308
+ },
309
+ commentInputPosition: "top"
293
310
  };
294
311
  function Wrapper({
295
312
  target,
@@ -302,8 +319,8 @@ function Wrapper({
302
319
  throw new Error("target is required.");
303
320
  }
304
321
  const {
305
- locale
306
- } = context.useLocaleContext();
322
+ locale = "en"
323
+ } = context.useLocaleContext() || {};
307
324
  const [, setSettings] = discussKitUx.useCommentSettings();
308
325
  react.useEffect(() => {
309
326
  setSettings((prev) => ({
@@ -314,7 +331,8 @@ function Wrapper({
314
331
  const object = react.useMemo(
315
332
  () => ({
316
333
  ...target,
317
- link: window.location.href
334
+ link: window.location.href,
335
+ blockletName: getCurrentBlockletComponentName()
318
336
  }),
319
337
  [target]
320
338
  );
@@ -23,12 +23,20 @@ const getPrefix = () => {
23
23
  const service = (_b = (_a = window.blocklet) == null ? void 0 : _a.componentMountPoints) == null ? void 0 : _b.find((x) => x.name === "did-comments");
24
24
  return service ? joinUrl(service.mountPoint, "/") : "";
25
25
  };
26
+ const getCurrentBlockletComponentName = () => {
27
+ var _a, _b;
28
+ const ensureTrailingSlash = (str) => str.endsWith("/") ? str : `${str}/`;
29
+ const matched = (_b = (_a = window.blocklet) == null ? void 0 : _a.componentMountPoints) == null ? void 0 : _b.find((x) => {
30
+ var _a2;
31
+ return ensureTrailingSlash(x.mountPoint) === ensureTrailingSlash((_a2 = window.blocklet) == null ? void 0 : _a2.prefix);
32
+ });
33
+ return matched == null ? void 0 : matched.title;
34
+ };
26
35
  const formatComment = (comment) => {
27
36
  var _a;
28
37
  return {
29
38
  ...comment,
30
- rootId: comment.commentId,
31
- author: comment.commenter,
39
+ rootId: comment.rootCommentId,
32
40
  createdAt: comment.createdAt ? new Date(comment.createdAt) : null,
33
41
  updatedAt: comment.updatedAt ? new Date(comment.updatedAt) : null,
34
42
  deletedAt: comment.deletedAt ? new Date(comment.deletedAt) : null,
@@ -96,13 +104,13 @@ const commentAPI = {
96
104
  return formatComment(data);
97
105
  },
98
106
  rate: async (comment, value, ratingType) => {
99
- await api.post(`/objects/${comment.objectId}/comments/${comment.id}/ratings`, {
107
+ await api.post(`/topics/${comment.topicId}/comments/${comment.id}/ratings`, {
100
108
  ratingType,
101
109
  value
102
110
  });
103
111
  },
104
112
  unrate: async (comment) => {
105
- await api.delete(`/objects/${comment.objectId}/comments/${comment.id}/ratings`);
113
+ await api.delete(`/topics/${comment.topicId}/comments/${comment.id}/ratings`);
106
114
  },
107
115
  fetchRatings: async (id) => {
108
116
  const {
@@ -114,7 +122,8 @@ const commentAPI = {
114
122
  function DiscussKitComments({
115
123
  showConnectBtn,
116
124
  object,
117
- onChange
125
+ onChange,
126
+ commentInputPosition
118
127
  }) {
119
128
  const {
120
129
  session
@@ -175,7 +184,7 @@ function DiscussKitComments({
175
184
  session.login();
176
185
  throw new Error("Unauthenticated.");
177
186
  }
178
- await api.post(`/objects/${object.id}/ratings`, {
187
+ await api.post(`/topics/${object.id}/ratings`, {
179
188
  ratingType,
180
189
  value
181
190
  });
@@ -185,7 +194,7 @@ function DiscussKitComments({
185
194
  session.login();
186
195
  throw new Error("Unauthenticated.");
187
196
  }
188
- await api.delete(`/objects/${object.id}/ratings`);
197
+ await api.delete(`/topics/${object.id}/ratings`);
189
198
  };
190
199
  return /* @__PURE__ */ jsxs(Container, {
191
200
  children: [/* @__PURE__ */ jsxs(Fragment, {
@@ -236,8 +245,8 @@ function DiscussKitComments({
236
245
  children: t("installDIDWallet")
237
246
  })]
238
247
  })
239
- }), session.user && /* @__PURE__ */ jsx(Box, {
240
- mt: 2.5,
248
+ }), session.user && commentInputPosition === "top" && /* @__PURE__ */ jsx(Box, {
249
+ mt: 2,
241
250
  children: /* @__PURE__ */ jsx(CommentInput, {
242
251
  send: sendComment,
243
252
  draftKey: `object-${object.id}`
@@ -246,7 +255,7 @@ function DiscussKitComments({
246
255
  }), !!total && /* @__PURE__ */ jsxs(Box, {
247
256
  display: "flex",
248
257
  justifyContent: "space-between",
249
- mt: 4,
258
+ mt: 3,
250
259
  children: [/* @__PURE__ */ jsxs("span", {
251
260
  children: [total > 0 ? `${total} ${t("comments")}` : t("comment"), " "]
252
261
  }), /* @__PURE__ */ jsxs(ButtonGroup, {
@@ -264,18 +273,26 @@ function DiscussKitComments({
264
273
  children: t("newest")
265
274
  })]
266
275
  })]
267
- }), /* @__PURE__ */ jsx(CommentList, {})]
276
+ }), /* @__PURE__ */ jsx(CommentList, {}), session.user && commentInputPosition === "bottom" && /* @__PURE__ */ jsx(Box, {
277
+ mt: 6,
278
+ children: /* @__PURE__ */ jsx(CommentInput, {
279
+ send: sendComment,
280
+ draftKey: `object-${object.id}`
281
+ })
282
+ })]
268
283
  });
269
284
  }
270
285
  DiscussKitComments.propTypes = {
271
286
  showConnectBtn: PropTypes.bool,
272
287
  object: PropTypes.object.isRequired,
273
- onChange: PropTypes.func
288
+ onChange: PropTypes.func,
289
+ commentInputPosition: PropTypes.oneOf(["top", "bottom"])
274
290
  };
275
291
  DiscussKitComments.defaultProps = {
276
292
  showConnectBtn: false,
277
293
  onChange: () => {
278
- }
294
+ },
295
+ commentInputPosition: "top"
279
296
  };
280
297
  function Wrapper({
281
298
  target,
@@ -288,8 +305,8 @@ function Wrapper({
288
305
  throw new Error("target is required.");
289
306
  }
290
307
  const {
291
- locale
292
- } = useLocaleContext();
308
+ locale = "en"
309
+ } = useLocaleContext() || {};
293
310
  const [, setSettings] = useCommentSettings();
294
311
  useEffect(() => {
295
312
  setSettings((prev) => ({
@@ -300,7 +317,8 @@ function Wrapper({
300
317
  const object = useMemo(
301
318
  () => ({
302
319
  ...target,
303
- link: window.location.href
320
+ link: window.location.href,
321
+ blockletName: getCurrentBlockletComponentName()
304
322
  }),
305
323
  [target]
306
324
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/discuss-kit",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "A react component for Discuss Kit blocklet.",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/es/index.js",
@@ -37,7 +37,7 @@
37
37
  "@arcblock/did-connect": "^2.4.58",
38
38
  "@arcblock/ux": "^2.4.58",
39
39
  "@arcblock/ws": "^1.18.31",
40
- "@blocklet/discuss-kit-ux": "1.0.17",
40
+ "@blocklet/discuss-kit-ux": "1.0.19",
41
41
  "@blocklet/editor": "0.0.10",
42
42
  "@emotion/react": "^11.10.5",
43
43
  "@emotion/styled": "^11.10.5",
@@ -77,5 +77,5 @@
77
77
  "vite-plugin-build": "^0.6.0",
78
78
  "vite-plugin-svgr": "^2.2.2"
79
79
  },
80
- "gitHead": "355c682168bbc1aaef152240b3107eee90dfec74"
80
+ "gitHead": "9e639c77209dabc2ecdb115545e36936f42f75cd"
81
81
  }