@blocklet/discuss-kit 1.0.9 → 1.0.11

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.
@@ -0,0 +1,39 @@
1
+ import joinUrl from "url-join";
2
+ import { xhrUploader, Uppload, en, Local, Camera, Screenshot, URL, Twitter, Facebook, Preview, Rotate, Crop, Blur, Contrast, Grayscale, Saturate } from "uppload";
3
+ const uppload = "";
4
+ const light = "";
5
+ const getEndpoint = () => {
6
+ const obj = new window.URL(window.location.origin);
7
+ obj.pathname = joinUrl(window.blocklet.prefix, "/api/uploads");
8
+ return obj.href;
9
+ };
10
+ const upload = xhrUploader({
11
+ endpoint: getEndpoint(),
12
+ fileKeyName: "image",
13
+ responseFunction: (text) => {
14
+ try {
15
+ const json = JSON.parse(text);
16
+ return json.url;
17
+ } catch (error) {
18
+ return Promise.reject(error);
19
+ }
20
+ }
21
+ });
22
+ const uploader = new Uppload({
23
+ lang: en,
24
+ defaultService: "local",
25
+ maxWidth: 1440,
26
+ maxHeight: 900,
27
+ uploader: xhrUploader({
28
+ endpoint: getEndpoint(),
29
+ fileKeyName: "image"
30
+ })
31
+ });
32
+ uploader.use([new Local({
33
+ mimeTypes: ["image/png", "image/jpeg", "image/gif"]
34
+ }), new Camera(), new Screenshot(), new URL(), new Twitter(), new Facebook()]);
35
+ uploader.use([new Preview(), new Rotate(), new Crop(), new Blur(), new Contrast(), new Grayscale(), new Saturate()]);
36
+ export {
37
+ uploader as default,
38
+ upload
39
+ };
@@ -9,12 +9,14 @@ import Button from "@arcblock/ux/lib/Button";
9
9
  import Box from "@mui/material/Box";
10
10
  import CircularProgress from "@mui/material/CircularProgress";
11
11
  import ButtonGroup from "@mui/material/ButtonGroup";
12
+ import { EditorConfigProvider } from "@blocklet/editor";
12
13
  import { useLocaleContext, LocaleProvider } from "@arcblock/ux/lib/Locale/context";
13
14
  import { ErrorBoundary } from "react-error-boundary";
14
15
  import { useCommentSettings, InternalThemeProvider, CommentsProvider, useCommentsContext, BinaryThumb, CommentInput, CommentList } from "@blocklet/discuss-kit-ux";
15
16
  import ErrorFallback from "./components/error-fallback";
16
17
  import { translations } from "./locales";
17
18
  import getWsClient, { useSubscription } from "./ws";
19
+ import { upload } from "./components/uploader";
18
20
  import api, { fetchRatingStats } from "./api";
19
21
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
20
22
  const getPrefix = () => {
@@ -102,6 +104,12 @@ const commentAPI = {
102
104
  },
103
105
  unrate: async (comment) => {
104
106
  await api.delete(`/objects/${comment.objectId}/comments/${comment.id}/ratings`);
107
+ },
108
+ fetchRatings: async (id) => {
109
+ const {
110
+ data
111
+ } = await api.get(`/ratings/${id}`);
112
+ return data;
105
113
  }
106
114
  };
107
115
  function DIDComment({
@@ -194,7 +202,8 @@ function DIDComment({
194
202
  onRate: handleOnRate,
195
203
  onUnrate: handleOnUnrate,
196
204
  variant: "inverse",
197
- size: "lg"
205
+ size: "lg",
206
+ fetchRatings: () => commentAPI.fetchRatings(object.id)
198
207
  })
199
208
  }), showConnectBtn && (session.user ? /* @__PURE__ */ jsx(SessionManager, {
200
209
  style: {
@@ -315,13 +324,22 @@ function Wrapper({
315
324
  translations,
316
325
  locale,
317
326
  children: /* @__PURE__ */ jsx(InternalThemeProvider, {
318
- children: /* @__PURE__ */ jsx(CommentsProvider, {
319
- target: object,
320
- api: commentAPI,
321
- flatView,
322
- children: /* @__PURE__ */ jsx(DIDComment, {
323
- ...rest,
324
- object
327
+ children: /* @__PURE__ */ jsx(EditorConfigProvider, {
328
+ value: {
329
+ uploader: {
330
+ upload: (file) => upload(file).then((url) => ({
331
+ url
332
+ }))
333
+ }
334
+ },
335
+ children: /* @__PURE__ */ jsx(CommentsProvider, {
336
+ target: object,
337
+ api: commentAPI,
338
+ flatView,
339
+ children: /* @__PURE__ */ jsx(DIDComment, {
340
+ ...rest,
341
+ object
342
+ })
325
343
  })
326
344
  })
327
345
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/discuss-kit",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "A react component for DID Comments blocklet.",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/es/index.js",
@@ -34,10 +34,11 @@
34
34
  "author": "Nate <nate@arcblock.io> (http://github.com/NateRobinson)",
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
- "@arcblock/did-connect": "^2.4.52",
38
- "@arcblock/ux": "^2.4.52",
39
- "@arcblock/ws": "^1.18.15",
40
- "@blocklet/discuss-kit-ux": "1.0.9",
37
+ "@arcblock/did-connect": "^2.4.57",
38
+ "@arcblock/ux": "^2.4.57",
39
+ "@arcblock/ws": "^1.18.30",
40
+ "@blocklet/discuss-kit-ux": "1.0.11",
41
+ "@blocklet/editor": "^0.0.10",
41
42
  "@emotion/react": "^11.10.5",
42
43
  "@emotion/styled": "^11.10.5",
43
44
  "@mui/icons-material": "^5.10.9",
@@ -54,6 +55,7 @@
54
55
  "react-use": "^17.4.0",
55
56
  "rehype-sanitize": "^5.0.1",
56
57
  "timeago.js": "^4.0.2",
58
+ "uppload": "^3.2.1",
57
59
  "url-join": "^4.0.1"
58
60
  },
59
61
  "peerDependencies": {
@@ -75,5 +77,5 @@
75
77
  "vite-plugin-build": "^0.6.0",
76
78
  "vite-plugin-svgr": "^2.2.2"
77
79
  },
78
- "gitHead": "45f92bb9b0462212eb468f78056784e1bc44a184"
80
+ "gitHead": "490359cef22ea8000b532752f47b7a5a500048c9"
79
81
  }