@blocklet/discuss-kit 1.0.0
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/LICENSE +13 -0
- package/README.md +15 -0
- package/lib/cjs/api.js +45 -0
- package/lib/cjs/comment-list.js +117 -0
- package/lib/cjs/components/comment.js +335 -0
- package/lib/cjs/components/error-fallback.js +26 -0
- package/lib/cjs/components/menu.js +84 -0
- package/lib/cjs/components/rating/binary-thumb.js +199 -0
- package/lib/cjs/components/rating/emoji-based.js +39 -0
- package/lib/cjs/components/rating/index.js +9 -0
- package/lib/cjs/components/rating/rating.js +93 -0
- package/lib/cjs/context.js +77 -0
- package/lib/cjs/did-comment-with-session.js +25 -0
- package/lib/cjs/did-comment.js +389 -0
- package/lib/cjs/hooks.js +202 -0
- package/lib/cjs/index.js +21 -0
- package/lib/cjs/lib/utils.js +17 -0
- package/lib/cjs/locales/en.js +27 -0
- package/lib/cjs/locales/index.js +10 -0
- package/lib/cjs/locales/zh.js +27 -0
- package/lib/cjs/session.js +14 -0
- package/lib/cjs/theme-provider.js +48 -0
- package/lib/cjs/ws.js +39 -0
- package/lib/es/api.js +43 -0
- package/lib/es/comment-list.js +112 -0
- package/lib/es/components/comment.js +309 -0
- package/lib/es/components/error-fallback.js +23 -0
- package/lib/es/components/menu.js +77 -0
- package/lib/es/components/rating/binary-thumb.js +176 -0
- package/lib/es/components/rating/emoji-based.js +37 -0
- package/lib/es/components/rating/index.js +4 -0
- package/lib/es/components/rating/rating.js +91 -0
- package/lib/es/context.js +74 -0
- package/lib/es/did-comment-with-session.js +24 -0
- package/lib/es/did-comment.js +377 -0
- package/lib/es/hooks.js +197 -0
- package/lib/es/index.js +8 -0
- package/lib/es/lib/utils.js +17 -0
- package/lib/es/locales/en.js +26 -0
- package/lib/es/locales/index.js +7 -0
- package/lib/es/locales/zh.js +26 -0
- package/lib/es/session.js +14 -0
- package/lib/es/theme-provider.js +46 -0
- package/lib/es/ws.js +37 -0
- package/package.json +79 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createContext, useState, useEffect, useContext } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import { ThemeProvider as ThemeProvider$2 } from "@emotion/react";
|
|
4
|
+
import { createTheme, ThemeProvider as ThemeProvider$1 } from "@mui/material/styles";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
const defaultTheme = createTheme({});
|
|
7
|
+
const ThemeContext = createContext({});
|
|
8
|
+
function ThemeProvider({
|
|
9
|
+
children,
|
|
10
|
+
theme: _theme
|
|
11
|
+
} = {}) {
|
|
12
|
+
const [theme, setTheme] = useState(defaultTheme);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (_theme && typeof _theme === "object")
|
|
15
|
+
setTheme(_theme);
|
|
16
|
+
}, [_theme]);
|
|
17
|
+
if (theme) {
|
|
18
|
+
return /* @__PURE__ */ jsx(ThemeContext.Provider, {
|
|
19
|
+
value: theme,
|
|
20
|
+
children: /* @__PURE__ */ jsx(ThemeContext.Consumer, {
|
|
21
|
+
children: (themeValue) => {
|
|
22
|
+
return /* @__PURE__ */ jsx(ThemeProvider$1, {
|
|
23
|
+
theme: themeValue,
|
|
24
|
+
children: /* @__PURE__ */ jsx(ThemeProvider$2, {
|
|
25
|
+
theme: themeValue,
|
|
26
|
+
children
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return children;
|
|
34
|
+
}
|
|
35
|
+
ThemeProvider.propTypes = {
|
|
36
|
+
children: PropTypes.any.isRequired,
|
|
37
|
+
theme: PropTypes.object.isRequired
|
|
38
|
+
};
|
|
39
|
+
function useThemeContext() {
|
|
40
|
+
return useContext(ThemeContext);
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
ThemeProvider,
|
|
44
|
+
ThemeProvider as default,
|
|
45
|
+
useThemeContext
|
|
46
|
+
};
|
package/lib/es/ws.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import Cookie from "js-cookie";
|
|
3
|
+
import { WsClient } from "@arcblock/ws";
|
|
4
|
+
let client;
|
|
5
|
+
function create(prefix) {
|
|
6
|
+
const pathPrefix = prefix;
|
|
7
|
+
const url = `//${window.location.host}${pathPrefix.replace(/\/$/, "")}`;
|
|
8
|
+
return new WsClient(url, {
|
|
9
|
+
heartbeatIntervalMs: 10 * 1e3,
|
|
10
|
+
params: () => ({
|
|
11
|
+
token: Cookie.get("login_token")
|
|
12
|
+
})
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function getWsClient(prefix) {
|
|
16
|
+
if (!client) {
|
|
17
|
+
client = create(prefix);
|
|
18
|
+
}
|
|
19
|
+
return client;
|
|
20
|
+
}
|
|
21
|
+
const useSubscription = (event, cb = () => {
|
|
22
|
+
}, deps = [], prefix = "") => {
|
|
23
|
+
if (!client) {
|
|
24
|
+
client = getWsClient(prefix);
|
|
25
|
+
}
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
client.on(event, cb);
|
|
28
|
+
return () => {
|
|
29
|
+
client.off(event, cb);
|
|
30
|
+
};
|
|
31
|
+
}, deps);
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
create,
|
|
35
|
+
getWsClient as default,
|
|
36
|
+
useSubscription
|
|
37
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blocklet/discuss-kit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A react component for DID Comments blocklet.",
|
|
5
|
+
"main": "./lib/cjs/index.js",
|
|
6
|
+
"module": "./lib/es/index.js",
|
|
7
|
+
"typings": "./lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./lib/es/index.js",
|
|
11
|
+
"require": "./lib/cjs/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./components/": {
|
|
14
|
+
"import": "./lib/es/components/",
|
|
15
|
+
"require": "./lib/cjs/components/"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"lint": "eslint src --ext .mjs,.js,.jsx,.ts,.tsx",
|
|
20
|
+
"lint:fix": "eslint src --ext .mjs,.js,.jsx,.ts,.tsx --fix",
|
|
21
|
+
"build": "vite build",
|
|
22
|
+
"watch": "vite build --watch",
|
|
23
|
+
"prepublish": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"did"
|
|
27
|
+
],
|
|
28
|
+
"files": [
|
|
29
|
+
"lib",
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"package.json",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"author": "Nate <nate@arcblock.io> (http://github.com/NateRobinson)",
|
|
35
|
+
"license": "MIT",
|
|
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.0",
|
|
41
|
+
"@emotion/react": "^11.10.5",
|
|
42
|
+
"@emotion/styled": "^11.10.5",
|
|
43
|
+
"@mui/icons-material": "^5.10.9",
|
|
44
|
+
"@mui/lab": "^5.0.0-alpha.109",
|
|
45
|
+
"@mui/material": "^5.10.13",
|
|
46
|
+
"@uiw/react-md-editor": "^3.19.7",
|
|
47
|
+
"axios": "^0.27.2",
|
|
48
|
+
"clsx": "^1.2.1",
|
|
49
|
+
"flat": "^5.0.2",
|
|
50
|
+
"js-cookie": "^3.0.1",
|
|
51
|
+
"lodash": "^4.17.21",
|
|
52
|
+
"prop-types": "^15.8.1",
|
|
53
|
+
"react-error-boundary": "^3.1.4",
|
|
54
|
+
"react-use": "^17.4.0",
|
|
55
|
+
"rehype-sanitize": "^5.0.1",
|
|
56
|
+
"timeago.js": "^4.0.2",
|
|
57
|
+
"url-join": "^4.0.1"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"react": ">=18.0.0",
|
|
61
|
+
"react-dom": ">=18.0.0"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@babel/cli": "^7.19.3",
|
|
68
|
+
"@babel/core": "^7.20.2",
|
|
69
|
+
"@babel/preset-env": "^7.20.2",
|
|
70
|
+
"@babel/preset-react": "^7.18.6",
|
|
71
|
+
"@vitejs/plugin-react": "^2.2.0",
|
|
72
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
73
|
+
"jest": "^24.9.0",
|
|
74
|
+
"vite": "3.1.8",
|
|
75
|
+
"vite-plugin-build": "^0.6.0",
|
|
76
|
+
"vite-plugin-svgr": "^2.2.2"
|
|
77
|
+
},
|
|
78
|
+
"gitHead": "232712ad4d77f9d70e1cc136ef002b1e76b4211f"
|
|
79
|
+
}
|