@blocklet/discuss-kit 2.0.44 → 2.0.46

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/api.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
3
  const jsSdk = require("@blocklet/js-sdk");
4
- const request = jsSdk.createAxios({ baseURL: "/", timeout: 2e4 });
4
+ const utils = require("./lib/utils");
5
+ const request = jsSdk.createAxios({ baseURL: utils.discussKitApiPrefix, timeout: 2e4 });
5
6
  request.interceptors.request.use(
6
7
  (config) => {
7
8
  return config;
@@ -2,7 +2,7 @@
2
2
  const jsxRuntime = require("react/jsx-runtime");
3
3
  const react = require("react");
4
4
  const Theme = require("@arcblock/ux/lib/Theme");
5
- const joinUrl = require("url-join");
5
+ require("url-join");
6
6
  const PropTypes = require("prop-types");
7
7
  const SessionManager = require("@arcblock/did-connect/lib/SessionManager");
8
8
  const Session = require("@arcblock/did-connect/lib/Session");
@@ -14,16 +14,12 @@ const discussKitUx = require("@blocklet/discuss-kit-ux");
14
14
  const ahooks = require("ahooks");
15
15
  const ErrorFallback = require("./components/error-fallback");
16
16
  const locales = require("./locales");
17
+ const utils = require("./lib/utils");
17
18
  const api = require("./api");
18
19
  const useAsyncRetry = (fn, deps = []) => {
19
20
  const state = ahooks.useRequest(fn, { refreshDeps: deps });
20
21
  return { ...state, value: state == null ? void 0 : state.data, retry: state == null ? void 0 : state.run };
21
22
  };
22
- const getPrefix = () => {
23
- var _a, _b;
24
- const service = (_b = (_a = window.blocklet) == null ? void 0 : _a.componentMountPoints) == null ? void 0 : _b.find((x) => x.name === "did-comments");
25
- return service ? joinUrl(service.mountPoint, "/") : "";
26
- };
27
23
  const getCurrentBlockletComponentName = () => {
28
24
  var _a, _b;
29
25
  const ensureTrailingSlash = (str) => str.endsWith("/") ? str : `${str}/`;
@@ -104,7 +100,7 @@ const DiscussKitComments = react.forwardRef(
104
100
  sendIcon,
105
101
  showTopbar
106
102
  }, ref) => {
107
- const [apiAvailable, setApiAvailable] = react.useState(true);
103
+ const [apiAvailable, setApiAvailable] = react.useState(utils.isDiscussKitRunning);
108
104
  discussKitUx.useDefaultApiErrorHandler({
109
105
  request: api,
110
106
  onError: (e) => {
@@ -153,6 +149,12 @@ const DiscussKitComments = react.forwardRef(
153
149
  },
154
150
  [object.id, state]
155
151
  );
152
+ if (!apiAvailable) {
153
+ return /* @__PURE__ */ jsxRuntime.jsxs(material.Alert, { severity: "info", children: [
154
+ /* @__PURE__ */ jsxRuntime.jsx(material.AlertTitle, { children: t("apiUnavailable.title") }),
155
+ t("apiUnavailable.desc")
156
+ ] });
157
+ }
156
158
  if (!initialized) {
157
159
  return /* @__PURE__ */ jsxRuntime.jsx(material.Box, { width: "100%", display: "flex", justifyContent: "center", children: /* @__PURE__ */ jsxRuntime.jsx(material.CircularProgress, {}) });
158
160
  }
@@ -189,12 +191,6 @@ const DiscussKitComments = react.forwardRef(
189
191
  }
190
192
  );
191
193
  };
192
- if (!apiAvailable) {
193
- return /* @__PURE__ */ jsxRuntime.jsxs(material.Alert, { severity: "info", children: [
194
- /* @__PURE__ */ jsxRuntime.jsx(material.AlertTitle, { children: t("apiUnavailable.title") }),
195
- t("apiUnavailable.desc")
196
- ] });
197
- }
198
194
  return /* @__PURE__ */ jsxRuntime.jsxs(Container, { ref, children: [
199
195
  /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
200
196
  /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", justifyContent: "space-between", alignItems: "end", children: [
@@ -269,7 +265,6 @@ DiscussKitComments.defaultProps = {
269
265
  };
270
266
  function Wrapper({
271
267
  target,
272
- prefix,
273
268
  flatView,
274
269
  autoCollapse,
275
270
  autoLoadComments,
@@ -278,6 +273,7 @@ function Wrapper({
278
273
  showProfileCard,
279
274
  interactive,
280
275
  renderComments,
276
+ renderDonation,
281
277
  ...rest
282
278
  }) {
283
279
  if (!(target == null ? void 0 : target.id)) {
@@ -294,11 +290,7 @@ function Wrapper({
294
290
  // eslint-disable-next-line react-hooks/exhaustive-deps
295
291
  [target]
296
292
  );
297
- const _prefix = prefix || getPrefix();
298
- if (!_prefix) {
299
- throw new Error("prefix is required.");
300
- }
301
- const wsClient = discussKitUx.getWsClient(_prefix);
293
+ const wsClient = discussKitUx.getWsClient(utils.discussKitPrefix);
302
294
  react.useEffect(() => {
303
295
  wsClient.connect();
304
296
  return () => {
@@ -306,7 +298,6 @@ function Wrapper({
306
298
  ;
307
299
  };
308
300
  }, []);
309
- api.defaults.baseURL = joinUrl(_prefix, "/api/");
310
301
  return /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.UploaderProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary, { FallbackComponent: ErrorFallback, children: /* @__PURE__ */ jsxRuntime.jsx(context.LocaleProvider, { translations: locales.translations, locale, children: /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.InternalThemeProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.ConfirmProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(discussKitUx.DefaultEditorConfigProvider, { request: api, children: /* @__PURE__ */ jsxRuntime.jsx(
311
302
  discussKitUx.CommentsProvider,
312
303
  {
@@ -320,6 +311,7 @@ function Wrapper({
320
311
  showProfileCard,
321
312
  interactive,
322
313
  containerRef,
314
+ renderDonation,
323
315
  renderComments,
324
316
  children: /* @__PURE__ */ jsxRuntime.jsx(DiscussKitComments, { ...rest, object, ref: containerRef })
325
317
  }
@@ -335,7 +327,6 @@ Wrapper.propTypes = {
335
327
  displayConnectButton: PropTypes.bool,
336
328
  displayReaction: PropTypes.bool,
337
329
  onChange: PropTypes.func,
338
- prefix: PropTypes.string,
339
330
  flatView: PropTypes.bool,
340
331
  autoCollapse: PropTypes.bool,
341
332
  autoLoadComments: PropTypes.bool,
@@ -351,7 +342,6 @@ Wrapper.defaultProps = {
351
342
  displayReaction: true,
352
343
  onChange: () => {
353
344
  },
354
- prefix: "",
355
345
  flatView: false,
356
346
  autoCollapse: false,
357
347
  autoLoadComments: true,
@@ -360,7 +350,8 @@ Wrapper.defaultProps = {
360
350
  showProfileCard: false,
361
351
  order: void 0,
362
352
  interactive: true,
363
- renderComments: null
353
+ renderComments: null,
354
+ renderDonation: null
364
355
  };
365
356
  const Container = Theme.styled("div")`
366
357
  width: 100%;
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
+ var _a, _b;
2
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
+ const joinUrl = require("url-join");
3
5
  const protectLogin = (session, action) => {
4
6
  if (session.user) {
5
7
  return action();
@@ -12,6 +14,16 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
12
14
  const minDelay = (promise, ms) => {
13
15
  return Promise.all([promise, sleep(ms)]).then(([result]) => result);
14
16
  };
17
+ const discussKitService = (_b = (_a = window.blocklet) == null ? void 0 : _a.componentMountPoints) == null ? void 0 : _b.find(
18
+ (x) => x.did === "z8ia1WEiBZ7hxURf6LwH21Wpg99vophFwSJdu"
19
+ );
20
+ const discussKitPrefix = discussKitService ? joinUrl(discussKitService.mountPoint, "/") : "";
21
+ const discussKitApiPrefix = joinUrl(discussKitPrefix, "/api/");
22
+ const isDiscussKitRunning = (discussKitService == null ? void 0 : discussKitService.status) === "running";
23
+ exports.discussKitApiPrefix = discussKitApiPrefix;
24
+ exports.discussKitPrefix = discussKitPrefix;
25
+ exports.discussKitService = discussKitService;
26
+ exports.isDiscussKitRunning = isDiscussKitRunning;
15
27
  exports.minDelay = minDelay;
16
28
  exports.protectLogin = protectLogin;
17
29
  exports.sleep = sleep;
package/lib/es/api.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createAxios } from "@blocklet/js-sdk";
2
- const request = createAxios({ baseURL: "/", timeout: 2e4 });
2
+ import { discussKitApiPrefix } from "./lib/utils";
3
+ const request = createAxios({ baseURL: discussKitApiPrefix, timeout: 2e4 });
3
4
  request.interceptors.request.use(
4
5
  (config) => {
5
6
  return config;
@@ -1,28 +1,24 @@
1
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
1
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { forwardRef, useState, useContext, useRef, useMemo, useEffect } from "react";
3
3
  import { styled } from "@arcblock/ux/lib/Theme";
4
- import joinUrl from "url-join";
4
+ import "url-join";
5
5
  import PropTypes from "prop-types";
6
6
  import SessionManager from "@arcblock/did-connect/lib/SessionManager";
7
7
  import { SessionContext } from "@arcblock/did-connect/lib/Session";
8
8
  import Button from "@arcblock/ux/lib/Button";
9
- import { Box, CircularProgress, Alert, AlertTitle } from "@mui/material";
9
+ import { Alert, AlertTitle, Box, CircularProgress } from "@mui/material";
10
10
  import { useLocaleContext, LocaleProvider } from "@arcblock/ux/lib/Locale/context";
11
11
  import { ErrorBoundary } from "react-error-boundary";
12
12
  import { useDefaultApiErrorHandler, useCommentsContext, useSubscription, GithubReaction, SegmentedControl, CommentList, getWsClient, UploaderProvider, InternalThemeProvider, ConfirmProvider, DefaultEditorConfigProvider, CommentsProvider, CommentInput } from "@blocklet/discuss-kit-ux";
13
13
  import { useRequest } from "ahooks";
14
14
  import ErrorFallback from "./components/error-fallback";
15
15
  import { translations } from "./locales";
16
+ import { isDiscussKitRunning, discussKitPrefix } from "./lib/utils";
16
17
  import api, { fetchRatings } from "./api";
17
18
  const useAsyncRetry = (fn, deps = []) => {
18
19
  const state = useRequest(fn, { refreshDeps: deps });
19
20
  return { ...state, value: state == null ? void 0 : state.data, retry: state == null ? void 0 : state.run };
20
21
  };
21
- const getPrefix = () => {
22
- var _a, _b;
23
- const service = (_b = (_a = window.blocklet) == null ? void 0 : _a.componentMountPoints) == null ? void 0 : _b.find((x) => x.name === "did-comments");
24
- return service ? joinUrl(service.mountPoint, "/") : "";
25
- };
26
22
  const getCurrentBlockletComponentName = () => {
27
23
  var _a, _b;
28
24
  const ensureTrailingSlash = (str) => str.endsWith("/") ? str : `${str}/`;
@@ -103,7 +99,7 @@ const DiscussKitComments = forwardRef(
103
99
  sendIcon,
104
100
  showTopbar
105
101
  }, ref) => {
106
- const [apiAvailable, setApiAvailable] = useState(true);
102
+ const [apiAvailable, setApiAvailable] = useState(isDiscussKitRunning);
107
103
  useDefaultApiErrorHandler({
108
104
  request: api,
109
105
  onError: (e) => {
@@ -152,6 +148,12 @@ const DiscussKitComments = forwardRef(
152
148
  },
153
149
  [object.id, state]
154
150
  );
151
+ if (!apiAvailable) {
152
+ return /* @__PURE__ */ jsxs(Alert, { severity: "info", children: [
153
+ /* @__PURE__ */ jsx(AlertTitle, { children: t("apiUnavailable.title") }),
154
+ t("apiUnavailable.desc")
155
+ ] });
156
+ }
155
157
  if (!initialized) {
156
158
  return /* @__PURE__ */ jsx(Box, { width: "100%", display: "flex", justifyContent: "center", children: /* @__PURE__ */ jsx(CircularProgress, {}) });
157
159
  }
@@ -188,12 +190,6 @@ const DiscussKitComments = forwardRef(
188
190
  }
189
191
  );
190
192
  };
191
- if (!apiAvailable) {
192
- return /* @__PURE__ */ jsxs(Alert, { severity: "info", children: [
193
- /* @__PURE__ */ jsx(AlertTitle, { children: t("apiUnavailable.title") }),
194
- t("apiUnavailable.desc")
195
- ] });
196
- }
197
193
  return /* @__PURE__ */ jsxs(Container, { ref, children: [
198
194
  /* @__PURE__ */ jsxs(Fragment, { children: [
199
195
  /* @__PURE__ */ jsxs(Box, { display: "flex", justifyContent: "space-between", alignItems: "end", children: [
@@ -268,7 +264,6 @@ DiscussKitComments.defaultProps = {
268
264
  };
269
265
  function Wrapper({
270
266
  target,
271
- prefix,
272
267
  flatView,
273
268
  autoCollapse,
274
269
  autoLoadComments,
@@ -277,6 +272,7 @@ function Wrapper({
277
272
  showProfileCard,
278
273
  interactive,
279
274
  renderComments,
275
+ renderDonation,
280
276
  ...rest
281
277
  }) {
282
278
  if (!(target == null ? void 0 : target.id)) {
@@ -293,11 +289,7 @@ function Wrapper({
293
289
  // eslint-disable-next-line react-hooks/exhaustive-deps
294
290
  [target]
295
291
  );
296
- const _prefix = prefix || getPrefix();
297
- if (!_prefix) {
298
- throw new Error("prefix is required.");
299
- }
300
- const wsClient = getWsClient(_prefix);
292
+ const wsClient = getWsClient(discussKitPrefix);
301
293
  useEffect(() => {
302
294
  wsClient.connect();
303
295
  return () => {
@@ -305,7 +297,6 @@ function Wrapper({
305
297
  ;
306
298
  };
307
299
  }, []);
308
- api.defaults.baseURL = joinUrl(_prefix, "/api/");
309
300
  return /* @__PURE__ */ jsx(UploaderProvider, { children: /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent: ErrorFallback, children: /* @__PURE__ */ jsx(LocaleProvider, { translations, locale, children: /* @__PURE__ */ jsx(InternalThemeProvider, { children: /* @__PURE__ */ jsx(ConfirmProvider, { children: /* @__PURE__ */ jsx(DefaultEditorConfigProvider, { request: api, children: /* @__PURE__ */ jsx(
310
301
  CommentsProvider,
311
302
  {
@@ -319,6 +310,7 @@ function Wrapper({
319
310
  showProfileCard,
320
311
  interactive,
321
312
  containerRef,
313
+ renderDonation,
322
314
  renderComments,
323
315
  children: /* @__PURE__ */ jsx(DiscussKitComments, { ...rest, object, ref: containerRef })
324
316
  }
@@ -334,7 +326,6 @@ Wrapper.propTypes = {
334
326
  displayConnectButton: PropTypes.bool,
335
327
  displayReaction: PropTypes.bool,
336
328
  onChange: PropTypes.func,
337
- prefix: PropTypes.string,
338
329
  flatView: PropTypes.bool,
339
330
  autoCollapse: PropTypes.bool,
340
331
  autoLoadComments: PropTypes.bool,
@@ -350,7 +341,6 @@ Wrapper.defaultProps = {
350
341
  displayReaction: true,
351
342
  onChange: () => {
352
343
  },
353
- prefix: "",
354
344
  flatView: false,
355
345
  autoCollapse: false,
356
346
  autoLoadComments: true,
@@ -359,7 +349,8 @@ Wrapper.defaultProps = {
359
349
  showProfileCard: false,
360
350
  order: void 0,
361
351
  interactive: true,
362
- renderComments: null
352
+ renderComments: null,
353
+ renderDonation: null
363
354
  };
364
355
  const Container = styled("div")`
365
356
  width: 100%;
@@ -1,3 +1,5 @@
1
+ var _a, _b;
2
+ import joinUrl from "url-join";
1
3
  const protectLogin = (session, action) => {
2
4
  if (session.user) {
3
5
  return action();
@@ -10,7 +12,17 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
10
12
  const minDelay = (promise, ms) => {
11
13
  return Promise.all([promise, sleep(ms)]).then(([result]) => result);
12
14
  };
15
+ const discussKitService = (_b = (_a = window.blocklet) == null ? void 0 : _a.componentMountPoints) == null ? void 0 : _b.find(
16
+ (x) => x.did === "z8ia1WEiBZ7hxURf6LwH21Wpg99vophFwSJdu"
17
+ );
18
+ const discussKitPrefix = discussKitService ? joinUrl(discussKitService.mountPoint, "/") : "";
19
+ const discussKitApiPrefix = joinUrl(discussKitPrefix, "/api/");
20
+ const isDiscussKitRunning = (discussKitService == null ? void 0 : discussKitService.status) === "running";
13
21
  export {
22
+ discussKitApiPrefix,
23
+ discussKitPrefix,
24
+ discussKitService,
25
+ isDiscussKitRunning,
14
26
  minDelay,
15
27
  protectLogin,
16
28
  sleep
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/discuss-kit",
3
- "version": "2.0.44",
3
+ "version": "2.0.46",
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,8 +37,8 @@
37
37
  "@arcblock/did-connect": "^2.10.1",
38
38
  "@arcblock/ux": "^2.10.1",
39
39
  "@arcblock/ws": "^1.18.123",
40
- "@blocklet/discuss-kit-ux": "2.0.44",
41
- "@blocklet/editor": "2.0.44",
40
+ "@blocklet/discuss-kit-ux": "2.0.46",
41
+ "@blocklet/editor": "2.0.46",
42
42
  "@blocklet/js-sdk": "^1.16.28",
43
43
  "@blocklet/ui-react": "^2.10.1",
44
44
  "@emotion/react": "^11.10.5",
@@ -78,5 +78,5 @@
78
78
  "vite-plugin-build": "^0.10.0",
79
79
  "vite-plugin-svgr": "^4.2.0"
80
80
  },
81
- "gitHead": "4d037d20b283699d419250f1336000768638ae89"
81
+ "gitHead": "aacdd3922f539000ddae02530aebd49641af17ef"
82
82
  }