@blocklet/discuss-kit-ux 2.4.36 → 2.4.37

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.
Files changed (222) hide show
  1. package/dist/axios.d.ts +8 -0
  2. package/dist/blocklets.d.ts +1 -1
  3. package/dist/blocklets.mjs +17 -0
  4. package/dist/components/api-error-handler/api-error-handler.d.ts +1 -1
  5. package/dist/components/api-error-handler/api-error-handler.mjs +25 -0
  6. package/dist/components/api-error-handler/default-handler.mjs +69 -0
  7. package/dist/components/api-error-handler/index.mjs +2 -0
  8. package/dist/components/api-error-handler/json-validation-interceptor.d.ts +1 -1
  9. package/dist/components/api-error-handler/json-validation-interceptor.mjs +9 -0
  10. package/dist/components/arcsphere/index.mjs +51 -0
  11. package/dist/components/authz/access-control.d.ts +15 -1
  12. package/dist/components/authz/access-control.mjs +15 -0
  13. package/dist/components/authz/context.d.ts +2 -1
  14. package/dist/components/authz/context.mjs +30 -0
  15. package/dist/components/authz/index.d.ts +1 -1
  16. package/dist/components/authz/index.mjs +2 -0
  17. package/dist/components/auto-translate/api.d.ts +1 -1
  18. package/dist/components/auto-translate/api.mjs +23 -0
  19. package/dist/components/auto-translate/auto-translate-button.d.ts +2 -1
  20. package/dist/components/auto-translate/auto-translate-button.mjs +47 -0
  21. package/dist/components/auto-translate/editor-store-adaptor.mjs +14 -0
  22. package/dist/components/auto-translate/index.mjs +6 -0
  23. package/dist/components/auto-translate/languages.mjs +61 -0
  24. package/dist/components/auto-translate/post-auto-translate-plugin.d.ts +4 -3
  25. package/dist/components/auto-translate/post-auto-translate-plugin.mjs +32 -0
  26. package/dist/components/auto-translate/store.d.ts +3 -3
  27. package/dist/components/auto-translate/store.mjs +23 -0
  28. package/dist/components/auto-translate/translate.d.ts +3 -2
  29. package/dist/components/auto-translate/translate.mjs +103 -0
  30. package/dist/components/auto-translate/utils.d.ts +1 -1
  31. package/dist/components/auto-translate/utils.mjs +14 -0
  32. package/dist/components/auto-translate/with-availibility-check.d.ts +1 -1
  33. package/dist/components/auto-translate/with-availibility-check.mjs +10 -0
  34. package/dist/components/avatars/author-info.d.ts +3 -2
  35. package/dist/components/avatars/author-info.mjs +184 -0
  36. package/dist/components/avatars/avatar.d.ts +2 -1
  37. package/dist/components/avatars/avatar.mjs +9 -0
  38. package/dist/components/avatars/avatars.d.ts +4 -3
  39. package/dist/components/avatars/avatars.mjs +49 -0
  40. package/dist/components/avatars/badge.d.ts +2 -1
  41. package/dist/components/avatars/badge.mjs +178 -0
  42. package/dist/components/avatars/index.mjs +5 -0
  43. package/dist/components/avatars/system-user.d.ts +1 -1
  44. package/dist/components/avatars/system-user.mjs +58 -0
  45. package/dist/components/back.d.ts +2 -1
  46. package/dist/components/back.mjs +28 -0
  47. package/dist/components/blog/blog-link.mjs +16 -0
  48. package/dist/components/blog/blog-list.d.ts +4 -3
  49. package/dist/components/blog/blog-list.mjs +441 -0
  50. package/dist/components/blog/cover-image.d.ts +4 -3
  51. package/dist/components/blog/cover-image.mjs +160 -0
  52. package/dist/components/blog/index.mjs +4 -0
  53. package/dist/components/blog/permalink.d.ts +3 -2
  54. package/dist/components/blog/permalink.mjs +78 -0
  55. package/dist/components/blog/types.d.ts +1 -1
  56. package/dist/components/blog/types.mjs +0 -0
  57. package/dist/components/button-group/button-group.d.ts +2 -1
  58. package/dist/components/button-group/button-group.mjs +195 -0
  59. package/dist/components/button-group/index.mjs +1 -0
  60. package/dist/components/chat/channel-group.d.ts +3 -2
  61. package/dist/components/chat/channel-group.mjs +41 -0
  62. package/dist/components/chat/chat-client.d.ts +2 -2
  63. package/dist/components/chat/chat-client.mjs +33 -0
  64. package/dist/components/chat/chat-header-addon.d.ts +2 -1
  65. package/dist/components/chat/chat-header-addon.mjs +26 -0
  66. package/dist/components/chat/chat-in-wallet.d.ts +2 -1
  67. package/dist/components/chat/chat-in-wallet.mjs +67 -0
  68. package/dist/components/chat/chat-input.d.ts +3 -2
  69. package/dist/components/chat/chat-input.mjs +295 -0
  70. package/dist/components/chat/chat-list-in-wallet.d.ts +2 -1
  71. package/dist/components/chat/chat-list-in-wallet.mjs +113 -0
  72. package/dist/components/chat/chat-list.d.ts +2 -1
  73. package/dist/components/chat/chat-list.mjs +109 -0
  74. package/dist/components/chat/chat-room.d.ts +3 -2
  75. package/dist/components/chat/chat-room.mjs +225 -0
  76. package/dist/components/chat/chat.d.ts +2 -1
  77. package/dist/components/chat/chat.mjs +163 -0
  78. package/dist/components/chat/context.d.ts +4 -3
  79. package/dist/components/chat/context.mjs +303 -0
  80. package/dist/components/chat/hooks.d.ts +1 -1
  81. package/dist/components/chat/hooks.mjs +59 -0
  82. package/dist/components/chat/index.mjs +7 -0
  83. package/dist/components/chat/message-list.d.ts +3 -2
  84. package/dist/components/chat/message-list.mjs +151 -0
  85. package/dist/components/chat/message.d.ts +4 -3
  86. package/dist/components/chat/message.mjs +312 -0
  87. package/dist/components/chat/participants.d.ts +3 -2
  88. package/dist/components/chat/participants.mjs +60 -0
  89. package/dist/components/chat/time.d.ts +1 -1
  90. package/dist/components/chat/time.mjs +16 -0
  91. package/dist/components/chat/types.d.ts +1 -1
  92. package/dist/components/chat/types.mjs +0 -0
  93. package/dist/components/chat/unread-notification.d.ts +2 -2
  94. package/dist/components/chat/unread-notification.mjs +43 -0
  95. package/dist/components/chat/user-search.d.ts +2 -1
  96. package/dist/components/chat/user-search.mjs +143 -0
  97. package/dist/components/check-mark.d.ts +2 -1
  98. package/dist/components/check-mark.mjs +98 -0
  99. package/dist/components/confirm.d.ts +4 -4
  100. package/dist/components/confirm.mjs +103 -0
  101. package/dist/components/dayjs.d.ts +1 -1
  102. package/dist/components/dayjs.mjs +4 -0
  103. package/dist/components/default-editor-config-provider.d.ts +3 -2
  104. package/dist/components/default-editor-config-provider.mjs +107 -0
  105. package/dist/components/dirty-prompt.d.ts +3 -2
  106. package/dist/components/dirty-prompt.mjs +117 -0
  107. package/dist/components/editor/editor.d.ts +4 -3
  108. package/dist/{editor-BsHdgrDc.mjs → components/editor/editor.mjs} +7 -8
  109. package/dist/components/editor/index.mjs +2 -0
  110. package/dist/components/editor/lazy-editor.d.ts +3 -2
  111. package/dist/components/editor/lazy-editor.mjs +14 -0
  112. package/dist/components/editor/plugins/video-path-fixer-plugin.mjs +29 -0
  113. package/dist/components/editor/preview.d.ts +4 -3
  114. package/dist/components/editor/preview.mjs +32 -0
  115. package/dist/components/emoji-icon.d.ts +2 -1
  116. package/dist/components/emoji-icon.mjs +62 -0
  117. package/dist/components/empty-status/empty-status.d.ts +2 -1
  118. package/dist/components/empty-status/empty-status.mjs +24 -0
  119. package/dist/components/empty-status/index.mjs +1 -0
  120. package/dist/components/hooks/changed.mjs +34 -0
  121. package/dist/components/hooks/index.mjs +6 -0
  122. package/dist/components/hooks/interval.mjs +16 -0
  123. package/dist/components/hooks/locale-context.mjs +12 -0
  124. package/dist/components/hooks/measure.mjs +8 -0
  125. package/dist/components/hooks/now.mjs +10 -0
  126. package/dist/components/hooks/responsive.d.ts +1 -1
  127. package/dist/components/hooks/responsive.mjs +25 -0
  128. package/dist/components/hooks/session.d.ts +1 -0
  129. package/dist/components/hooks/session.mjs +41 -0
  130. package/dist/components/hooks/use-event-callback.mjs +14 -0
  131. package/dist/components/icon-button.d.ts +4 -3
  132. package/dist/components/icon-button.mjs +37 -0
  133. package/dist/components/input/auto-clear-plugin.mjs +26 -0
  134. package/dist/components/input/comment-input.d.ts +2 -1
  135. package/dist/components/input/comment-input.mjs +107 -0
  136. package/dist/components/input/image-path-fixer-plugin.mjs +29 -0
  137. package/dist/components/input/index.mjs +4 -0
  138. package/dist/components/input/input.d.ts +4 -4
  139. package/dist/components/input/input.mjs +152 -0
  140. package/dist/components/input/post-edit.d.ts +2 -1
  141. package/dist/components/input/post-edit.mjs +49 -0
  142. package/dist/components/input/scrollable-editor-wrapper.d.ts +2 -1
  143. package/dist/components/input/scrollable-editor-wrapper.mjs +18 -0
  144. package/dist/components/input/shortcut-plugin.mjs +28 -0
  145. package/dist/components/label-picker.d.ts +2 -1
  146. package/dist/components/label-picker.mjs +41 -0
  147. package/dist/components/lexical.mjs +69 -0
  148. package/dist/components/locale/en.mjs +92 -0
  149. package/dist/components/locale/index.mjs +3 -0
  150. package/dist/components/locale/zh.mjs +94 -0
  151. package/dist/components/pagination.d.ts +3 -2
  152. package/dist/components/pagination.mjs +44 -0
  153. package/dist/components/paywall.d.ts +2 -2
  154. package/dist/components/paywall.mjs +110 -0
  155. package/dist/components/point-up/{box-animation.json.d.ts → box-animation.json} +1 -4
  156. package/dist/components/point-up/index.d.ts +3 -2
  157. package/dist/components/point-up/index.mjs +153 -0
  158. package/dist/components/point-up/lottie-component.d.ts +2 -1
  159. package/dist/components/point-up/lottie-component.mjs +7 -0
  160. package/dist/components/posts/comment-list/comment-list.d.ts +2 -1
  161. package/dist/components/posts/comment-list/comment-list.mjs +163 -0
  162. package/dist/components/posts/comment-list/context.d.ts +4 -4
  163. package/dist/components/posts/comment-list/context.mjs +318 -0
  164. package/dist/components/posts/comment.d.ts +3 -2
  165. package/dist/components/posts/comment.mjs +184 -0
  166. package/dist/components/posts/index.mjs +6 -0
  167. package/dist/components/posts/menu.d.ts +3 -2
  168. package/dist/components/posts/menu.mjs +83 -0
  169. package/dist/components/posts/post-content.d.ts +2 -1
  170. package/dist/components/posts/post-content.mjs +86 -0
  171. package/dist/components/posts/post.d.ts +4 -4
  172. package/dist/components/posts/post.mjs +198 -0
  173. package/dist/components/profile-card/index.mjs +1 -0
  174. package/dist/components/profile-card/profile-card.d.ts +4 -3
  175. package/dist/components/profile-card/profile-card.mjs +162 -0
  176. package/dist/components/rating/binary-thumb.d.ts +4 -3
  177. package/dist/components/rating/binary-thumb.mjs +157 -0
  178. package/dist/components/rating/github-reaction-container.d.ts +2 -1
  179. package/dist/components/rating/github-reaction-container.mjs +46 -0
  180. package/dist/components/rating/github-reaction.d.ts +3 -2
  181. package/dist/components/rating/github-reaction.mjs +173 -0
  182. package/dist/components/rating/index.mjs +3 -0
  183. package/dist/components/rating/rater-list.d.ts +3 -2
  184. package/dist/components/rating/rater-list.mjs +33 -0
  185. package/dist/components/rating/rating.d.ts +1 -1
  186. package/dist/components/rating/rating.mjs +50 -0
  187. package/dist/components/routes.d.ts +1 -1
  188. package/dist/components/routes.mjs +27 -0
  189. package/dist/components/segmented-control.d.ts +3 -2
  190. package/dist/components/segmented-control.mjs +55 -0
  191. package/dist/components/shared/relative-time.d.ts +2 -1
  192. package/dist/components/shared/relative-time.mjs +21 -0
  193. package/dist/components/toast.d.ts +1 -1
  194. package/dist/components/toast.mjs +44 -0
  195. package/dist/components/uploader/index.d.ts +3 -3
  196. package/dist/components/uploader/index.mjs +70 -0
  197. package/dist/components/uploader/utils.mjs +16 -0
  198. package/dist/components/utils.d.ts +4 -4
  199. package/dist/components/utils.mjs +139 -0
  200. package/dist/components/view-more.d.ts +1 -1
  201. package/dist/components/view-more.mjs +50 -0
  202. package/dist/constants.mjs +14 -0
  203. package/dist/global.d.ts +1 -0
  204. package/dist/index.mjs +37 -0
  205. package/dist/preferences.mjs +9 -0
  206. package/dist/theme/index.d.ts +3 -3
  207. package/dist/theme/index.mjs +96 -0
  208. package/dist/theme/typography.d.ts +1 -1
  209. package/dist/theme/typography.mjs +66 -0
  210. package/dist/type-override.d.ts +7 -0
  211. package/dist/types.mjs +0 -0
  212. package/dist/vite-env.d.ts +1 -0
  213. package/dist/ws.d.ts +2 -2
  214. package/dist/ws.mjs +39 -0
  215. package/package.json +10 -17
  216. package/dist/components/avatars/Avatars.stories.d.ts +0 -5
  217. package/dist/components/posts/Post.stories.d.ts +0 -7
  218. package/dist/index-BZDpbkvV.mjs +0 -7631
  219. package/dist/index.es.js +0 -118
  220. package/dist/index.umd.js +0 -7589
  221. package/dist/test/fixtures/index.d.ts +0 -4
  222. package/dist/test/fixtures/mock-session.d.ts +0 -3
@@ -0,0 +1,8 @@
1
+ import { AxiosRequestConfig as OriginalAxiosRequestConfig } from 'axios';
2
+
3
+ // https://github.com/axios/axios/pull/1964#issuecomment-903983962
4
+ declare module 'axios' {
5
+ export interface AxiosRequestConfig extends OriginalAxiosRequestConfig {
6
+ muteError?: boolean;
7
+ }
8
+ }
@@ -1,5 +1,5 @@
1
1
  export declare const blockletMountPointsByDid: {
2
- [k: string]: ComponentMountPoint;
2
+ [k: string]: any;
3
3
  };
4
4
  export declare const isBlockletApp: (did: string) => boolean;
5
5
  export declare const getUsername: (user: {
@@ -0,0 +1,17 @@
1
+ const blockletMountPoints = window.blocklet.componentMountPoints;
2
+ export const blockletMountPointsByDid = Object.fromEntries(blockletMountPoints.map((x) => [x.did, x]));
3
+ export const isBlockletApp = (did) => !!blockletMountPointsByDid[did];
4
+ export const getUsername = (user, fallback) => {
5
+ const username = user?.fullName || fallback;
6
+ if (username) {
7
+ return username;
8
+ }
9
+ return isBlockletApp(user?.did || "") ? "System" : "Unknown";
10
+ };
11
+ export const isValidUser = (user) => {
12
+ return user?.did && user?.fullName && !isBlockletApp(user.did) && user.did !== window.blocklet.appId;
13
+ };
14
+ export function blockletExists(dids) {
15
+ const blockletDids = Array.isArray(dids) ? dids : [dids];
16
+ return blockletDids.every((did) => blockletMountPointsByDid[did]);
17
+ }
@@ -1,4 +1,4 @@
1
- import { AxiosInstance, AxiosError } from 'axios';
1
+ import type { AxiosInstance, AxiosError } from 'axios';
2
2
  export interface ApiError extends AxiosError {
3
3
  markAsHandled: Function;
4
4
  }
@@ -0,0 +1,25 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { jsonValidationInterceptor } from "./json-validation-interceptor.mjs";
3
+ export const useApiErrorHandler = ({ request, errorHandler }) => {
4
+ const errorHandlerRef = useRef(errorHandler);
5
+ useEffect(() => {
6
+ errorHandlerRef.current = errorHandler;
7
+ }, [errorHandler]);
8
+ useEffect(() => {
9
+ const interceptor = request.interceptors.response.use(jsonValidationInterceptor, (error) => {
10
+ let handled = false;
11
+ error.markAsHandled = () => {
12
+ handled = true;
13
+ };
14
+ setTimeout(() => {
15
+ if (!handled && error.config?.muteError !== true) {
16
+ errorHandlerRef.current.handleError(error);
17
+ }
18
+ });
19
+ return Promise.reject(error);
20
+ });
21
+ return () => {
22
+ request.interceptors.response.eject(interceptor);
23
+ };
24
+ }, []);
25
+ };
@@ -0,0 +1,69 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { AxiosError } from "axios";
3
+ import Box from "@mui/material/Box";
4
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
5
+ import { useApiErrorHandler } from "./api-error-handler.mjs";
6
+ import { toast } from "../toast.mjs";
7
+ export const useDefaultApiErrorHandler = (options) => {
8
+ const { request, onError } = options;
9
+ const { t } = useLocaleContext();
10
+ const showError = (msg, toastOptions) => {
11
+ toast.error(msg, toastOptions);
12
+ };
13
+ const showWarning = (msg, toastOptions) => {
14
+ toast.warning(msg, toastOptions);
15
+ };
16
+ const errorHandler = {
17
+ handleError(error) {
18
+ if (onError && onError(error)) {
19
+ return;
20
+ }
21
+ if (error.code === AxiosError.ETIMEDOUT || error.code === AxiosError.ECONNABORTED) {
22
+ showError(t("apiError.timeout"));
23
+ return;
24
+ }
25
+ if (error.response) {
26
+ const { response } = error;
27
+ const statusCode = response.status;
28
+ switch (statusCode) {
29
+ case 400: {
30
+ showError(t("apiError.400"));
31
+ break;
32
+ }
33
+ case 401: {
34
+ showError(t("apiError.401"));
35
+ break;
36
+ }
37
+ case 403: {
38
+ showError(t("apiError.403"));
39
+ break;
40
+ }
41
+ case 409: {
42
+ showWarning(
43
+ /* @__PURE__ */ jsxs(Box, { children: [
44
+ /* @__PURE__ */ jsx(Box, { children: t("apiError.409") }),
45
+ /* @__PURE__ */ jsxs(Box, { children: [
46
+ "(",
47
+ t("apiError.staleTip"),
48
+ ")"
49
+ ] })
50
+ ] }),
51
+ { duration: 1e4, style: { maxWidth: "500px" } }
52
+ );
53
+ break;
54
+ }
55
+ default: {
56
+ console.error("Unhandled error", error);
57
+ }
58
+ }
59
+ } else {
60
+ console.error("Unhandled error", error);
61
+ }
62
+ }
63
+ };
64
+ useApiErrorHandler({ request, errorHandler });
65
+ };
66
+ export const DefaultApiErrorHandler = ({ request }) => {
67
+ useDefaultApiErrorHandler({ request });
68
+ return null;
69
+ };
@@ -0,0 +1,2 @@
1
+ export { useApiErrorHandler } from "./api-error-handler.mjs";
2
+ export * from "./default-handler.mjs";
@@ -1,2 +1,2 @@
1
- import { AxiosResponse } from 'axios';
1
+ import type { AxiosResponse } from 'axios';
2
2
  export declare const jsonValidationInterceptor: (response: AxiosResponse) => AxiosResponse<any, any>;
@@ -0,0 +1,9 @@
1
+ import { AxiosError } from "axios";
2
+ export const jsonValidationInterceptor = (response) => {
3
+ const { responseType } = response.config;
4
+ if ((!responseType || responseType === "json") && response.headers["content-type"] && response.headers["content-type"].indexOf("application/json") === -1) {
5
+ console.error(response);
6
+ throw new AxiosError("Invalid response", AxiosError.ERR_BAD_RESPONSE, response.config, response.request, response);
7
+ }
8
+ return response;
9
+ };
@@ -0,0 +1,51 @@
1
+ import bridge from "@arcblock/bridge";
2
+ import { useCallback } from "react";
3
+ import { joinURL, withQuery, parseQuery } from "ufo";
4
+ import { useSessionContext } from "../hooks/session.mjs";
5
+ export const isInArcSphere = window?.navigator?.userAgent.indexOf("ArcSphere") > -1;
6
+ export const isInArcSphereDialog = !!parseQuery(window.location.search).arcSphereDialog;
7
+ function normalizeUrl(url) {
8
+ if (url.startsWith("/")) {
9
+ return withQuery(joinURL(window.origin, window.blocklet.prefix, url), { arcSphereDialog: 1 });
10
+ }
11
+ return url;
12
+ }
13
+ export const openArcSphereDialog = ({ url, type = "full", onClose }) => {
14
+ bridge.register("closePopupCallback", (arg) => {
15
+ onClose?.(arg);
16
+ });
17
+ bridge.call("arc__openPopup", {
18
+ url: normalizeUrl(url),
19
+ type
20
+ });
21
+ };
22
+ export const closeArcSphereDialog = (reason) => {
23
+ if (isInArcSphereDialog) {
24
+ bridge.call("arc__closePopup", {
25
+ callback: "closePopupCallback",
26
+ args: [reason || ""]
27
+ });
28
+ }
29
+ };
30
+ export const useArcSphereDialog = () => {
31
+ const { session } = useSessionContext();
32
+ const open = useCallback(
33
+ ({ authRequired = true, ...options }) => {
34
+ if (authRequired && !session.user) {
35
+ session.login(() => {
36
+ openArcSphereDialog(options);
37
+ });
38
+ } else {
39
+ openArcSphereDialog(options);
40
+ }
41
+ },
42
+ [session]
43
+ );
44
+ const close = useCallback((reason) => {
45
+ closeArcSphereDialog(reason);
46
+ }, []);
47
+ return {
48
+ open,
49
+ close
50
+ };
51
+ };
@@ -1,4 +1,18 @@
1
1
  /// <reference types="react" />
2
+ interface SessionContextUser {
3
+ did: string;
4
+ fullName: string;
5
+ avatar: string;
6
+ passports: {
7
+ id: string;
8
+ name: string;
9
+ title: string;
10
+ role: string;
11
+ }[];
12
+ permissions: string[];
13
+ role: string;
14
+ locale: string;
15
+ }
2
16
  interface AccessControlProps {
3
17
  authenticated?: boolean;
4
18
  permissions?: string | string[];
@@ -6,5 +20,5 @@ interface AccessControlProps {
6
20
  check?: (user: SessionContextUser) => boolean;
7
21
  children: React.ReactNode;
8
22
  }
9
- export default function AccessControl({ authenticated, permissions, roles, check, children, }: AccessControlProps): import("react/jsx-runtime").JSX.Element | null;
23
+ export declare function AccessControl({ authenticated, permissions, roles, check, children }: AccessControlProps): import("react").JSX.Element | null;
10
24
  export {};
@@ -0,0 +1,15 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { useAuthzContext } from "./context.mjs";
3
+ import { useSessionContext } from "../hooks/index.mjs";
4
+ export function AccessControl({ authenticated = true, permissions, roles, check, children }) {
5
+ const { session } = useSessionContext();
6
+ const { hasPermission, hasAnyPassport } = useAuthzContext();
7
+ if (authenticated && !session?.user) {
8
+ return null;
9
+ }
10
+ const permitted = hasPermission(permissions || "") && hasAnyPassport(roles || "") && (!check || check(session.user));
11
+ if (permitted) {
12
+ return /* @__PURE__ */ jsx(Fragment, { children });
13
+ }
14
+ return null;
15
+ }
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type HasPermission = (perms: string | string[]) => boolean;
2
3
  interface AuthzProviderProps {
3
4
  }
@@ -8,5 +9,5 @@ interface AuthzContextValue {
8
9
  hasAnyPassport: (passports: string | string[]) => boolean;
9
10
  }
10
11
  export declare const useAuthzContext: () => AuthzContextValue;
11
- export declare const AuthzProvider: ({ ...rest }: AuthzProviderProps) => import("react/jsx-runtime").JSX.Element;
12
+ export declare const AuthzProvider: ({ ...rest }: AuthzProviderProps) => import("react").JSX.Element;
12
13
  export {};
@@ -0,0 +1,30 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo, useCallback } from "react";
3
+ import { useSessionContext } from "../hooks/index.mjs";
4
+ const AuthzContext = createContext({
5
+ permissions: [],
6
+ hasPermission: () => false,
7
+ isAdmin: false,
8
+ hasAnyPassport: () => false
9
+ });
10
+ export const useAuthzContext = () => useContext(AuthzContext);
11
+ export const AuthzProvider = ({ ...rest }) => {
12
+ const { session, isAdmin, hasAnyPassport } = useSessionContext();
13
+ const permissions = useMemo(() => session?.user?.permissions || [], [session?.user?.permissions]);
14
+ const permissionSet = useMemo(() => new Set(permissions), [permissions]);
15
+ const hasPermission = useCallback(
16
+ (perms) => {
17
+ if (!perms || perms.length === 0) {
18
+ return true;
19
+ }
20
+ const permsArr = Array.isArray(perms) ? perms : [perms];
21
+ return permsArr.some((item) => permissionSet.has(item));
22
+ },
23
+ [permissionSet]
24
+ );
25
+ const value = useMemo(
26
+ () => ({ permissions, hasPermission, isAdmin, hasAnyPassport }),
27
+ [hasPermission, permissions, isAdmin, hasAnyPassport]
28
+ );
29
+ return /* @__PURE__ */ jsx(AuthzContext.Provider, { ...rest, value });
30
+ };
@@ -1,2 +1,2 @@
1
1
  export * from './context';
2
- export { default as AccessControl } from './access-control';
2
+ export * from './access-control';
@@ -0,0 +1,2 @@
1
+ export * from "./context.mjs";
2
+ export * from "./access-control.mjs";
@@ -1,4 +1,4 @@
1
- export declare const api: import('axios').AxiosInstance;
1
+ export declare const api: import("axios").AxiosInstance;
2
2
  interface TranslateItem {
3
3
  sid: string;
4
4
  text: string;
@@ -0,0 +1,23 @@
1
+ import { createAxios } from "@blocklet/js-sdk";
2
+ import { discussKitApiBaseUrl } from "../utils.mjs";
3
+ export const api = createAxios({
4
+ baseURL: discussKitApiBaseUrl,
5
+ timeout: 2e4
6
+ });
7
+ export const translatePost = async ({
8
+ id,
9
+ sourceItems,
10
+ targetLanguage,
11
+ targetLanguageName,
12
+ contentVersion,
13
+ useCache
14
+ }) => {
15
+ const result = await api.post(`/posts/${id}/translate`, {
16
+ sourceItems,
17
+ targetLanguage,
18
+ targetLanguageName,
19
+ contentVersion,
20
+ useCache
21
+ });
22
+ return result.data;
23
+ };
@@ -1,4 +1,5 @@
1
+ /// <reference types="react" />
1
2
  interface Props {
2
3
  }
3
- export declare const AutoTranslateHeaderAddon: (props: Props) => import("react/jsx-runtime").JSX.Element | null;
4
+ export declare const AutoTranslateHeaderAddon: (props: Props) => import("react").JSX.Element | null;
4
5
  export {};
@@ -0,0 +1,47 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { AddonButton } from "@arcblock/ux/lib/Header/addon-button";
3
+ import LanguageIcon from "virtual:icons/tabler/language";
4
+ import SettingsIcon from "virtual:icons/tabler/settings";
5
+ import { Box, Link, Tooltip, Typography } from "@mui/material";
6
+ import { useAutoTranslateStore, useTargetLanguage } from "./store.mjs";
7
+ import { useEditorStoreAdapter } from "./editor-store-adaptor.mjs";
8
+ import { isInlineTranslationAvailable } from "./utils.mjs";
9
+ import { withAiAvailabilityCheck } from "./with-availibility-check.mjs";
10
+ import { useSessionContext } from "../hooks/session.mjs";
11
+ import { useLocaleContext } from "../hooks/locale-context.mjs";
12
+ function InternalAutoTranslateHeaderAddon({ ...rest }) {
13
+ const { getLanguageName } = useLocaleContext();
14
+ const { autoTranslate, enableAutoTranslate, disableAutoTranslate } = useAutoTranslateStore();
15
+ const targetLanguage = useTargetLanguage();
16
+ const targetLanguageName = getLanguageName(targetLanguage);
17
+ const { session } = useSessionContext();
18
+ useEditorStoreAdapter();
19
+ if (!isInlineTranslationAvailable) {
20
+ return null;
21
+ }
22
+ const tooltipTitle = () => {
23
+ return /* @__PURE__ */ jsx(Box, { sx: { p: 0.25 }, children: /* @__PURE__ */ jsxs(Typography, { variant: "body2", sx: { fontSize: 13 }, children: [
24
+ "Automatic translation is ",
25
+ autoTranslate ? "enabled" : "disabled",
26
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5 }, children: [
27
+ "Target language: ",
28
+ targetLanguageName,
29
+ !!session?.user && /* @__PURE__ */ jsx(Link, { href: "/.well-known/service/user/settings", sx: { lineHeight: 1 }, children: /* @__PURE__ */ jsx(Box, { component: SettingsIcon, sx: { fontSize: 12 } }) })
30
+ ] })
31
+ ] }) });
32
+ };
33
+ return /* @__PURE__ */ jsx(Tooltip, { title: tooltipTitle(), children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
34
+ AddonButton,
35
+ {
36
+ ...autoTranslate && {
37
+ color: "primary",
38
+ variant: "contained",
39
+ sx: { color: "primary.contrastText" }
40
+ },
41
+ icon: /* @__PURE__ */ jsx(LanguageIcon, {}),
42
+ ...rest,
43
+ onClick: () => autoTranslate ? disableAutoTranslate() : enableAutoTranslate()
44
+ }
45
+ ) }) });
46
+ }
47
+ export const AutoTranslateHeaderAddon = withAiAvailabilityCheck(InternalAutoTranslateHeaderAddon);
@@ -0,0 +1,14 @@
1
+ import { useEffect } from "react";
2
+ import { useInlineTranslationStore } from "@blocklet/editor/lib/ext/InlineTranslationPlugin";
3
+ import { useAutoTranslateStore } from "./store.mjs";
4
+ export const useEditorStoreAdapter = () => {
5
+ const { autoTranslate } = useAutoTranslateStore();
6
+ const setAutoTranslate = useInlineTranslationStore((s) => s.setAutoTranslate);
7
+ const showOriginal = useInlineTranslationStore((s) => s.showOriginal);
8
+ useEffect(() => {
9
+ setAutoTranslate(autoTranslate);
10
+ if (!autoTranslate) {
11
+ showOriginal();
12
+ }
13
+ }, [autoTranslate, setAutoTranslate, showOriginal]);
14
+ };
@@ -0,0 +1,6 @@
1
+ export * from "./translate.mjs";
2
+ export * from "./auto-translate-button.mjs";
3
+ export * from "./post-auto-translate-plugin.mjs";
4
+ export * from "./store.mjs";
5
+ export * from "./editor-store-adaptor.mjs";
6
+ export { isInlineTranslationAvailable } from "./utils.mjs";
@@ -0,0 +1,61 @@
1
+ const SUPPORTED_LANGUAGES = [
2
+ {
3
+ name: "English",
4
+ nativeName: "English",
5
+ iso639_1: "en",
6
+ iso639_3: "eng"
7
+ },
8
+ {
9
+ name: "Simplified Chinese",
10
+ nativeName: "\u7B80\u4F53\u4E2D\u6587",
11
+ iso639_1: "zh",
12
+ iso639_3: "cmn"
13
+ },
14
+ {
15
+ name: "Spanish",
16
+ nativeName: "Espa\xF1ol",
17
+ iso639_1: "es",
18
+ iso639_3: "spa"
19
+ },
20
+ {
21
+ name: "Portuguese",
22
+ nativeName: "Portugu\xEAs",
23
+ iso639_1: "pt",
24
+ iso639_3: "por"
25
+ },
26
+ {
27
+ name: "Russian",
28
+ nativeName: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
29
+ iso639_1: "ru",
30
+ iso639_3: "rus"
31
+ },
32
+ {
33
+ name: "Japanese",
34
+ nativeName: "\u65E5\u672C\u8A9E",
35
+ iso639_1: "ja",
36
+ iso639_3: "jpn"
37
+ },
38
+ {
39
+ name: "French",
40
+ nativeName: "Fran\xE7ais",
41
+ iso639_1: "fr",
42
+ iso639_3: "fra"
43
+ },
44
+ {
45
+ name: "German",
46
+ nativeName: "Deutsch",
47
+ iso639_1: "de",
48
+ iso639_3: "deu"
49
+ },
50
+ {
51
+ name: "Korean",
52
+ nativeName: "\uD55C\uAD6D\uC5B4",
53
+ iso639_1: "ko",
54
+ iso639_3: "kor"
55
+ }
56
+ ];
57
+ const languagesByIso6393 = new Map(SUPPORTED_LANGUAGES.map((lang) => [lang.iso639_3, lang]));
58
+ export function getLanguageByIso6393(iso639_3) {
59
+ return languagesByIso6393.get(iso639_3);
60
+ }
61
+ export { SUPPORTED_LANGUAGES };
@@ -1,13 +1,14 @@
1
+ /// <reference types="react" />
1
2
  interface Props {
2
3
  postId: string;
3
4
  updatedAt: Date | string;
4
5
  }
5
- export declare function PostAutoTranslatePlugin({ postId, updatedAt }: Props): import("react/jsx-runtime").JSX.Element | null;
6
+ export declare function PostAutoTranslatePlugin({ postId, updatedAt }: Props): import("react").JSX.Element | null;
6
7
  interface InitialState {
7
8
  postId: string;
8
9
  updatedAt: Date | string;
9
10
  }
10
- export declare const PostAutoTranslationContainer: import('unstated-next').Container<{
11
- plugin: import("react/jsx-runtime").JSX.Element;
11
+ export declare const PostAutoTranslationContainer: import("unstated-next").Container<{
12
+ plugin: import("react").JSX.Element;
12
13
  }, InitialState>;
13
14
  export {};
@@ -0,0 +1,32 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { InlineTranslationPlugin } from "@blocklet/editor/lib/ext/InlineTranslationPlugin";
3
+ import { useMemo } from "react";
4
+ import { createContainer } from "unstated-next";
5
+ import { useLocaleContext } from "../hooks/locale-context.mjs";
6
+ import { detectLanguageIso6391, isInlineTranslationAvailable } from "./utils.mjs";
7
+ import { translatePost } from "./api.mjs";
8
+ export function PostAutoTranslatePlugin({ postId, updatedAt }) {
9
+ const { getLanguageName } = useLocaleContext();
10
+ if (!isInlineTranslationAvailable) {
11
+ return null;
12
+ }
13
+ const version = `${new Date(updatedAt).getTime()}`;
14
+ const translateService = (payload) => {
15
+ return translatePost({
16
+ ...payload,
17
+ targetLanguageName: getLanguageName(payload.targetLanguage),
18
+ id: postId,
19
+ contentVersion: version
20
+ });
21
+ };
22
+ return /* @__PURE__ */ jsx(InlineTranslationPlugin, { translateService, detectLanguage: detectLanguageIso6391 });
23
+ }
24
+ const usePostAutoTranslatePlugin = ({ postId, updatedAt }) => {
25
+ const value = useMemo(() => {
26
+ return {
27
+ plugin: /* @__PURE__ */ jsx(PostAutoTranslatePlugin, { postId, updatedAt })
28
+ };
29
+ }, [postId, updatedAt]);
30
+ return value;
31
+ };
32
+ export const PostAutoTranslationContainer = createContainer(usePostAutoTranslatePlugin);
@@ -6,15 +6,15 @@ interface Action {
6
6
  disableAutoTranslate: () => void;
7
7
  toggleAutoTranslate: (value?: boolean) => void;
8
8
  }
9
- export declare const useAutoTranslateStore: import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<State & Action>, "persist"> & {
9
+ export declare const useAutoTranslateStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<State & Action>, "persist"> & {
10
10
  persist: {
11
- setOptions: (options: Partial<import('zustand/middleware').PersistOptions<State & Action, State & Action>>) => void;
11
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<State & Action, State & Action>>) => void;
12
12
  clearStorage: () => void;
13
13
  rehydrate: () => void | Promise<void>;
14
14
  hasHydrated: () => boolean;
15
15
  onHydrate: (fn: (state: State & Action) => void) => () => void;
16
16
  onFinishHydration: (fn: (state: State & Action) => void) => () => void;
17
- getOptions: () => Partial<import('zustand/middleware').PersistOptions<State & Action, State & Action>>;
17
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<State & Action, State & Action>>;
18
18
  };
19
19
  }>;
20
20
  export declare const useTargetLanguage: () => string;
@@ -0,0 +1,23 @@
1
+ import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
2
+ import { create } from "zustand";
3
+ import { persist } from "zustand/middleware";
4
+ import { useSessionContext } from "../hooks/session.mjs";
5
+ export const useAutoTranslateStore = create()(
6
+ persist(
7
+ (set, get) => ({
8
+ autoTranslate: false,
9
+ enableAutoTranslate: () => set({ autoTranslate: true }),
10
+ disableAutoTranslate: () => set({ autoTranslate: false }),
11
+ toggleAutoTranslate: (value) => set({ autoTranslate: value ?? !get().autoTranslate })
12
+ }),
13
+ {
14
+ name: "auto-translate"
15
+ }
16
+ )
17
+ );
18
+ export const useTargetLanguage = () => {
19
+ const { locale, languages } = useLocaleContext();
20
+ const { session } = useSessionContext();
21
+ const preferredLanguage = languages.find((x) => x.code === session?.user?.locale);
22
+ return preferredLanguage?.code ?? locale;
23
+ };
@@ -1,10 +1,11 @@
1
+ /// <reference types="react" />
1
2
  import { TypographyProps } from '@mui/material';
2
3
  export declare const useTranslate: ({ text, enabled }: {
3
4
  text: string;
4
5
  enabled: boolean;
5
6
  }) => {
6
7
  translation: any;
7
- key: string;
8
+ key: any;
8
9
  loading: boolean;
9
10
  };
10
11
  type Props<C extends React.ElementType> = {
@@ -12,5 +13,5 @@ type Props<C extends React.ElementType> = {
12
13
  } & TypographyProps<C, {
13
14
  component?: C;
14
15
  }>;
15
- export declare function Translate<C extends React.ElementType>({ text, children, sx, ...rest }: Props<C>): import("react/jsx-runtime").JSX.Element;
16
+ export declare function Translate<C extends React.ElementType>({ text, children, sx, ...rest }: Props<C>): import("react").JSX.Element;
16
17
  export {};