@blocklet/discuss-kit-ux-lite 2.6.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.
Files changed (186) hide show
  1. package/LICENSE +13 -0
  2. package/dist/axios.d.ts +8 -0
  3. package/dist/blocklets.d.ts +13 -0
  4. package/dist/blocklets.mjs +17 -0
  5. package/dist/components/api-error-handler/api-error-handler.d.ts +13 -0
  6. package/dist/components/api-error-handler/api-error-handler.mjs +25 -0
  7. package/dist/components/api-error-handler/default-handler.d.ts +8 -0
  8. package/dist/components/api-error-handler/default-handler.mjs +69 -0
  9. package/dist/components/api-error-handler/index.d.ts +2 -0
  10. package/dist/components/api-error-handler/index.mjs +2 -0
  11. package/dist/components/api-error-handler/json-validation-interceptor.d.ts +2 -0
  12. package/dist/components/api-error-handler/json-validation-interceptor.mjs +9 -0
  13. package/dist/components/arcsphere/index.d.ts +16 -0
  14. package/dist/components/arcsphere/index.mjs +52 -0
  15. package/dist/components/authz/access-control.d.ts +24 -0
  16. package/dist/components/authz/access-control.mjs +15 -0
  17. package/dist/components/authz/context.d.ts +13 -0
  18. package/dist/components/authz/context.mjs +30 -0
  19. package/dist/components/authz/index.d.ts +2 -0
  20. package/dist/components/authz/index.mjs +2 -0
  21. package/dist/components/auto-translate/api.d.ts +14 -0
  22. package/dist/components/auto-translate/api.mjs +23 -0
  23. package/dist/components/auto-translate/auto-translate-button.d.ts +5 -0
  24. package/dist/components/auto-translate/auto-translate-button.mjs +48 -0
  25. package/dist/components/auto-translate/editor-store-adaptor.d.ts +1 -0
  26. package/dist/components/auto-translate/editor-store-adaptor.mjs +14 -0
  27. package/dist/components/auto-translate/index.d.ts +6 -0
  28. package/dist/components/auto-translate/index.mjs +6 -0
  29. package/dist/components/auto-translate/languages.d.ts +13 -0
  30. package/dist/components/auto-translate/languages.mjs +61 -0
  31. package/dist/components/auto-translate/post-auto-translate-plugin.d.ts +14 -0
  32. package/dist/components/auto-translate/post-auto-translate-plugin.mjs +32 -0
  33. package/dist/components/auto-translate/store.d.ts +21 -0
  34. package/dist/components/auto-translate/store.mjs +23 -0
  35. package/dist/components/auto-translate/translate.d.ts +17 -0
  36. package/dist/components/auto-translate/translate.mjs +103 -0
  37. package/dist/components/auto-translate/utils.d.ts +4 -0
  38. package/dist/components/auto-translate/utils.mjs +14 -0
  39. package/dist/components/auto-translate/with-availibility-check.d.ts +2 -0
  40. package/dist/components/auto-translate/with-availibility-check.mjs +10 -0
  41. package/dist/components/avatars/author-info.d.ts +23 -0
  42. package/dist/components/avatars/author-info.mjs +178 -0
  43. package/dist/components/avatars/avatar.d.ts +7 -0
  44. package/dist/components/avatars/avatar.mjs +9 -0
  45. package/dist/components/avatars/avatars.d.ts +10 -0
  46. package/dist/components/avatars/avatars.mjs +49 -0
  47. package/dist/components/avatars/badge.d.ts +14 -0
  48. package/dist/components/avatars/badge.mjs +178 -0
  49. package/dist/components/avatars/index.d.ts +5 -0
  50. package/dist/components/avatars/index.mjs +5 -0
  51. package/dist/components/avatars/system-user.d.ts +10 -0
  52. package/dist/components/avatars/system-user.mjs +58 -0
  53. package/dist/components/button-group/button-group.d.ts +18 -0
  54. package/dist/components/button-group/button-group.mjs +195 -0
  55. package/dist/components/button-group/index.d.ts +1 -0
  56. package/dist/components/button-group/index.mjs +1 -0
  57. package/dist/components/confirm.d.ts +29 -0
  58. package/dist/components/confirm.mjs +103 -0
  59. package/dist/components/dayjs.d.ts +3 -0
  60. package/dist/components/dayjs.mjs +5 -0
  61. package/dist/components/default-editor-config-provider.d.ts +8 -0
  62. package/dist/components/default-editor-config-provider.mjs +108 -0
  63. package/dist/components/dirty-prompt.d.ts +8 -0
  64. package/dist/components/dirty-prompt.mjs +117 -0
  65. package/dist/components/editor/blocklet-editor.d.ts +1 -0
  66. package/dist/components/editor/blocklet-editor.mjs +1 -0
  67. package/dist/components/editor/editor.d.ts +17 -0
  68. package/dist/components/editor/editor.mjs +35 -0
  69. package/dist/components/editor/index.d.ts +4 -0
  70. package/dist/components/editor/index.mjs +3 -0
  71. package/dist/components/editor/lazy-editor.d.ts +3 -0
  72. package/dist/components/editor/lazy-editor.mjs +14 -0
  73. package/dist/components/editor/viewer.d.ts +10 -0
  74. package/dist/components/editor/viewer.mjs +18 -0
  75. package/dist/components/emoji-icon.d.ts +11 -0
  76. package/dist/components/emoji-icon.mjs +62 -0
  77. package/dist/components/empty-status/empty-status.d.ts +7 -0
  78. package/dist/components/empty-status/empty-status.mjs +24 -0
  79. package/dist/components/empty-status/index.d.ts +1 -0
  80. package/dist/components/empty-status/index.mjs +1 -0
  81. package/dist/components/hooks/changed.d.ts +10 -0
  82. package/dist/components/hooks/changed.mjs +34 -0
  83. package/dist/components/hooks/index.d.ts +6 -0
  84. package/dist/components/hooks/index.mjs +6 -0
  85. package/dist/components/hooks/interval.d.ts +6 -0
  86. package/dist/components/hooks/interval.mjs +16 -0
  87. package/dist/components/hooks/locale-context.d.ts +10 -0
  88. package/dist/components/hooks/locale-context.mjs +12 -0
  89. package/dist/components/hooks/measure.d.ts +5 -0
  90. package/dist/components/hooks/measure.mjs +8 -0
  91. package/dist/components/hooks/now.d.ts +1 -0
  92. package/dist/components/hooks/now.mjs +10 -0
  93. package/dist/components/hooks/responsive.d.ts +17 -0
  94. package/dist/components/hooks/responsive.mjs +25 -0
  95. package/dist/components/hooks/session.d.ts +12 -0
  96. package/dist/components/hooks/session.mjs +48 -0
  97. package/dist/components/hooks/use-event-callback.d.ts +1 -0
  98. package/dist/components/hooks/use-event-callback.mjs +14 -0
  99. package/dist/components/icon-button.d.ts +6 -0
  100. package/dist/components/icon-button.mjs +37 -0
  101. package/dist/components/input/auto-clear-plugin.d.ts +3 -0
  102. package/dist/components/input/auto-clear-plugin.mjs +20 -0
  103. package/dist/components/input/comment-input.d.ts +11 -0
  104. package/dist/components/input/comment-input.mjs +108 -0
  105. package/dist/components/input/index.d.ts +4 -0
  106. package/dist/components/input/index.mjs +4 -0
  107. package/dist/components/input/input.d.ts +29 -0
  108. package/dist/components/input/input.mjs +149 -0
  109. package/dist/components/input/post-edit.d.ts +10 -0
  110. package/dist/components/input/post-edit.mjs +49 -0
  111. package/dist/components/input/scrollable-editor-wrapper.d.ts +9 -0
  112. package/dist/components/input/scrollable-editor-wrapper.mjs +18 -0
  113. package/dist/components/input/shortcut-plugin.d.ts +7 -0
  114. package/dist/components/input/shortcut-plugin.mjs +28 -0
  115. package/dist/components/lexical.d.ts +10 -0
  116. package/dist/components/lexical.mjs +56 -0
  117. package/dist/components/locale/en.d.ts +117 -0
  118. package/dist/components/locale/en.mjs +116 -0
  119. package/dist/components/locale/index.d.ts +236 -0
  120. package/dist/components/locale/index.mjs +3 -0
  121. package/dist/components/locale/zh.d.ts +119 -0
  122. package/dist/components/locale/zh.mjs +118 -0
  123. package/dist/components/pagination.d.ts +12 -0
  124. package/dist/components/pagination.mjs +44 -0
  125. package/dist/components/posts/comment-list/comment-list.d.ts +5 -0
  126. package/dist/components/posts/comment-list/comment-list.mjs +163 -0
  127. package/dist/components/posts/comment-list/context.d.ts +76 -0
  128. package/dist/components/posts/comment-list/context.mjs +318 -0
  129. package/dist/components/posts/comment.d.ts +16 -0
  130. package/dist/components/posts/comment.mjs +184 -0
  131. package/dist/components/posts/index.d.ts +6 -0
  132. package/dist/components/posts/index.mjs +6 -0
  133. package/dist/components/posts/menu.d.ts +14 -0
  134. package/dist/components/posts/menu.mjs +83 -0
  135. package/dist/components/posts/post-content.d.ts +16 -0
  136. package/dist/components/posts/post-content.mjs +63 -0
  137. package/dist/components/posts/post.d.ts +26 -0
  138. package/dist/components/posts/post.mjs +198 -0
  139. package/dist/components/profile-card/index.d.ts +1 -0
  140. package/dist/components/profile-card/index.mjs +1 -0
  141. package/dist/components/profile-card/profile-card.d.ts +15 -0
  142. package/dist/components/profile-card/profile-card.mjs +140 -0
  143. package/dist/components/rating/binary-thumb.d.ts +9 -0
  144. package/dist/components/rating/binary-thumb.mjs +162 -0
  145. package/dist/components/rating/github-reaction-container.d.ts +9 -0
  146. package/dist/components/rating/github-reaction-container.mjs +46 -0
  147. package/dist/components/rating/github-reaction.d.ts +18 -0
  148. package/dist/components/rating/github-reaction.mjs +174 -0
  149. package/dist/components/rating/index.d.ts +3 -0
  150. package/dist/components/rating/index.mjs +3 -0
  151. package/dist/components/rating/rater-list.d.ts +10 -0
  152. package/dist/components/rating/rater-list.mjs +33 -0
  153. package/dist/components/rating/rating.d.ts +27 -0
  154. package/dist/components/rating/rating.mjs +50 -0
  155. package/dist/components/segmented-control.d.ts +14 -0
  156. package/dist/components/segmented-control.mjs +55 -0
  157. package/dist/components/shared/relative-time.d.ts +8 -0
  158. package/dist/components/shared/relative-time.mjs +21 -0
  159. package/dist/components/toast.d.ts +8 -0
  160. package/dist/components/toast.mjs +44 -0
  161. package/dist/components/uploader/index.d.ts +13 -0
  162. package/dist/components/uploader/index.mjs +70 -0
  163. package/dist/components/uploader/utils.d.ts +1 -0
  164. package/dist/components/uploader/utils.mjs +16 -0
  165. package/dist/components/utils.d.ts +22 -0
  166. package/dist/components/utils.mjs +103 -0
  167. package/dist/components/view-more.d.ts +4 -0
  168. package/dist/components/view-more.mjs +50 -0
  169. package/dist/constants.d.ts +5 -0
  170. package/dist/constants.mjs +14 -0
  171. package/dist/global.d.ts +1 -0
  172. package/dist/index.d.ts +29 -0
  173. package/dist/index.mjs +29 -0
  174. package/dist/preferences.d.ts +2 -0
  175. package/dist/preferences.mjs +9 -0
  176. package/dist/theme/index.d.ts +8 -0
  177. package/dist/theme/index.mjs +96 -0
  178. package/dist/theme/typography.d.ts +2 -0
  179. package/dist/theme/typography.mjs +66 -0
  180. package/dist/type-override.d.ts +7 -0
  181. package/dist/types.d.ts +84 -0
  182. package/dist/types.mjs +0 -0
  183. package/dist/vite-env.d.ts +1 -0
  184. package/dist/ws.d.ts +3 -0
  185. package/dist/ws.mjs +39 -0
  186. package/package.json +81 -0
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2018-2020 ArcBlock
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -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
+ }
@@ -0,0 +1,13 @@
1
+ export declare const blockletMountPointsByDid: {
2
+ [k: string]: any;
3
+ };
4
+ export declare const isBlockletApp: (did: string) => boolean;
5
+ export declare const getUsername: (user: {
6
+ did: string;
7
+ fullName?: string;
8
+ } | null | undefined, fallback?: string) => string;
9
+ export declare const isValidUser: (user: {
10
+ did?: string;
11
+ fullName?: string;
12
+ } | null | undefined) => boolean | "" | undefined;
13
+ export declare function blockletExists(dids: string[] | string): boolean;
@@ -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] || did === window.blocklet.appId;
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
+ }
@@ -0,0 +1,13 @@
1
+ import type { AxiosInstance, AxiosError } from 'axios';
2
+ export interface ApiError extends AxiosError {
3
+ markAsHandled: Function;
4
+ }
5
+ interface ErrorHandler {
6
+ handleError: (error: AxiosError) => void;
7
+ }
8
+ interface Options {
9
+ request: AxiosInstance;
10
+ errorHandler: ErrorHandler;
11
+ }
12
+ export declare const useApiErrorHandler: ({ request, errorHandler }: Options) => void;
13
+ export {};
@@ -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,8 @@
1
+ import { AxiosError, AxiosInstance } from 'axios';
2
+ interface Options {
3
+ request: AxiosInstance;
4
+ onError?: (error: AxiosError) => boolean;
5
+ }
6
+ export declare const useDefaultApiErrorHandler: (options: Options) => void;
7
+ export declare const DefaultApiErrorHandler: ({ request }: Options) => null;
8
+ export {};
@@ -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';
2
+ export * from './default-handler';
@@ -0,0 +1,2 @@
1
+ export { useApiErrorHandler } from "./api-error-handler.mjs";
2
+ export * from "./default-handler.mjs";
@@ -0,0 +1,2 @@
1
+ import type { AxiosResponse } from 'axios';
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,16 @@
1
+ export declare const isInArcSphere: boolean;
2
+ export declare const isInArcSphereDialog: boolean;
3
+ interface OpenDialogOptions {
4
+ url: string;
5
+ type?: 'full' | 'half';
6
+ onClose?: (reason: string) => void;
7
+ }
8
+ export declare const openArcSphereDialog: ({ url, type, onClose }: OpenDialogOptions) => void;
9
+ export declare const closeArcSphereDialog: (reason?: string) => void;
10
+ export declare const useArcSphereDialog: () => {
11
+ open: ({ authRequired, ...options }: OpenDialogOptions & {
12
+ authRequired?: boolean | undefined;
13
+ }) => void;
14
+ close: (reason?: string) => void;
15
+ };
16
+ export {};
@@ -0,0 +1,52 @@
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
+ const ARC_SPHERE_TAG = "ArcSphere";
6
+ export const isInArcSphere = window?.navigator?.userAgent.indexOf(ARC_SPHERE_TAG) > -1;
7
+ export const isInArcSphereDialog = !!parseQuery(window.location.search).arcSphereDialog;
8
+ function normalizeUrl(url) {
9
+ if (url.startsWith("/")) {
10
+ return withQuery(joinURL(window.origin, window.blocklet.prefix, url), { arcSphereDialog: 1 });
11
+ }
12
+ return url;
13
+ }
14
+ export const openArcSphereDialog = ({ url, type = "full", onClose }) => {
15
+ bridge.register("closePopupCallback", (arg) => {
16
+ onClose?.(arg);
17
+ });
18
+ bridge.call("arc__openPopup", {
19
+ url: normalizeUrl(url),
20
+ type
21
+ });
22
+ };
23
+ export const closeArcSphereDialog = (reason) => {
24
+ if (isInArcSphereDialog) {
25
+ bridge.call("arc__closePopup", {
26
+ callback: "closePopupCallback",
27
+ args: [reason || ""]
28
+ });
29
+ }
30
+ };
31
+ export const useArcSphereDialog = () => {
32
+ const { session } = useSessionContext();
33
+ const open = useCallback(
34
+ ({ authRequired = true, ...options }) => {
35
+ if (authRequired && !session.user) {
36
+ session.login(() => {
37
+ openArcSphereDialog(options);
38
+ });
39
+ } else {
40
+ openArcSphereDialog(options);
41
+ }
42
+ },
43
+ [session]
44
+ );
45
+ const close = useCallback((reason) => {
46
+ closeArcSphereDialog(reason);
47
+ }, []);
48
+ return {
49
+ open,
50
+ close
51
+ };
52
+ };
@@ -0,0 +1,24 @@
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
+ }
16
+ interface AccessControlProps {
17
+ authenticated?: boolean;
18
+ permissions?: string | string[];
19
+ roles?: string | string[];
20
+ check?: (user: SessionContextUser) => boolean;
21
+ children: React.ReactNode;
22
+ }
23
+ export declare function AccessControl({ authenticated, permissions, roles, check, children }: AccessControlProps): import("react").JSX.Element | null;
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
+ }
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ type HasPermission = (perms: string | string[]) => boolean;
3
+ interface AuthzProviderProps {
4
+ }
5
+ interface AuthzContextValue {
6
+ permissions: string[];
7
+ hasPermission: HasPermission;
8
+ isAdmin: boolean;
9
+ hasAnyPassport: (passports: string | string[]) => boolean;
10
+ }
11
+ export declare const useAuthzContext: () => AuthzContextValue;
12
+ export declare const AuthzProvider: ({ ...rest }: AuthzProviderProps) => import("react").JSX.Element;
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
+ };
@@ -0,0 +1,2 @@
1
+ export * from './context';
2
+ export * from './access-control';
@@ -0,0 +1,2 @@
1
+ export * from "./context.mjs";
2
+ export * from "./access-control.mjs";
@@ -0,0 +1,14 @@
1
+ export declare const api: import("axios").AxiosInstance;
2
+ interface TranslateItem {
3
+ sid: string;
4
+ text: string;
5
+ }
6
+ export declare const translatePost: ({ id, sourceItems, targetLanguage, targetLanguageName, contentVersion, useCache, }: {
7
+ id: string;
8
+ sourceItems: TranslateItem[];
9
+ targetLanguage: string;
10
+ targetLanguageName?: string | undefined;
11
+ contentVersion: string;
12
+ useCache?: boolean | undefined;
13
+ }) => Promise<any>;
14
+ export {};
@@ -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
+ };
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ interface Props {
3
+ }
4
+ export declare const AutoTranslateHeaderAddon: (props: Props) => import("react").JSX.Element | null;
5
+ export {};
@@ -0,0 +1,48 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { AddonButton } from "@arcblock/ux/lib/Header/addon-button";
3
+ import { Icon } from "@iconify/react";
4
+ import LanguageIcon from "@iconify/icons-tabler/language";
5
+ import SettingsIcon from "@iconify/icons-tabler/settings";
6
+ import { Box, Link, Tooltip, Typography } from "@mui/material";
7
+ import { useAutoTranslateStore, useTargetLanguage } from "./store.mjs";
8
+ import { useEditorStoreAdapter } from "./editor-store-adaptor.mjs";
9
+ import { isInlineTranslationAvailable } from "./utils.mjs";
10
+ import { withAiAvailabilityCheck } from "./with-availibility-check.mjs";
11
+ import { useSessionContext } from "../hooks/session.mjs";
12
+ import { useLocaleContext } from "../hooks/locale-context.mjs";
13
+ function InternalAutoTranslateHeaderAddon({ ...rest }) {
14
+ const { getLanguageName } = useLocaleContext();
15
+ const { autoTranslate, enableAutoTranslate, disableAutoTranslate } = useAutoTranslateStore();
16
+ const targetLanguage = useTargetLanguage();
17
+ const targetLanguageName = getLanguageName(targetLanguage);
18
+ const { session } = useSessionContext();
19
+ useEditorStoreAdapter();
20
+ if (!isInlineTranslationAvailable) {
21
+ return null;
22
+ }
23
+ const tooltipTitle = () => {
24
+ return /* @__PURE__ */ jsx(Box, { sx: { p: 0.25 }, children: /* @__PURE__ */ jsxs(Typography, { variant: "body2", sx: { fontSize: 13 }, children: [
25
+ "Automatic translation is ",
26
+ autoTranslate ? "enabled" : "disabled",
27
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5 }, children: [
28
+ "Target language: ",
29
+ targetLanguageName,
30
+ !!session?.user && /* @__PURE__ */ jsx(Link, { href: "/.well-known/service/user/settings", sx: { lineHeight: 1 }, children: /* @__PURE__ */ jsx(Box, { component: Icon, icon: SettingsIcon, sx: { fontSize: 12 } }) })
31
+ ] })
32
+ ] }) });
33
+ };
34
+ return /* @__PURE__ */ jsx(Tooltip, { title: tooltipTitle(), children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
35
+ AddonButton,
36
+ {
37
+ ...autoTranslate && {
38
+ color: "primary",
39
+ variant: "contained",
40
+ sx: { color: "primary.contrastText" }
41
+ },
42
+ icon: /* @__PURE__ */ jsx(Icon, { icon: LanguageIcon }),
43
+ ...rest,
44
+ onClick: () => autoTranslate ? disableAutoTranslate() : enableAutoTranslate()
45
+ }
46
+ ) }) });
47
+ }
48
+ export const AutoTranslateHeaderAddon = withAiAvailabilityCheck(InternalAutoTranslateHeaderAddon);
@@ -0,0 +1 @@
1
+ export declare const useEditorStoreAdapter: () => void;
@@ -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';
2
+ export * from './auto-translate-button';
3
+ export * from './post-auto-translate-plugin';
4
+ export * from './store';
5
+ export * from './editor-store-adaptor';
6
+ export { isInlineTranslationAvailable } from './utils';
@@ -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,13 @@
1
+ declare const SUPPORTED_LANGUAGES: {
2
+ name: string;
3
+ nativeName: string;
4
+ iso639_1: string;
5
+ iso639_3: string;
6
+ }[];
7
+ export declare function getLanguageByIso6393(iso639_3: string): {
8
+ name: string;
9
+ nativeName: string;
10
+ iso639_1: string;
11
+ iso639_3: string;
12
+ } | undefined;
13
+ export { SUPPORTED_LANGUAGES };
@@ -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 };
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ interface Props {
3
+ postId: string;
4
+ updatedAt: Date | string;
5
+ }
6
+ export declare function PostAutoTranslatePlugin({ postId, updatedAt }: Props): import("react").JSX.Element | null;
7
+ interface InitialState {
8
+ postId: string;
9
+ updatedAt: Date | string;
10
+ }
11
+ export declare const PostAutoTranslationContainer: import("unstated-next").Container<{
12
+ plugin: import("react").JSX.Element;
13
+ }, InitialState>;
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);
@@ -0,0 +1,21 @@
1
+ interface State {
2
+ autoTranslate: boolean;
3
+ }
4
+ interface Action {
5
+ enableAutoTranslate: () => void;
6
+ disableAutoTranslate: () => void;
7
+ toggleAutoTranslate: (value?: boolean) => void;
8
+ }
9
+ export declare const useAutoTranslateStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<State & Action>, "persist"> & {
10
+ persist: {
11
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<State & Action, State & Action>>) => void;
12
+ clearStorage: () => void;
13
+ rehydrate: () => void | Promise<void>;
14
+ hasHydrated: () => boolean;
15
+ onHydrate: (fn: (state: State & Action) => void) => () => void;
16
+ onFinishHydration: (fn: (state: State & Action) => void) => () => void;
17
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<State & Action, State & Action>>;
18
+ };
19
+ }>;
20
+ export declare const useTargetLanguage: () => string;
21
+ export {};