@blocklet/discuss-kit-ux 2.3.83 → 2.3.85
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/dist/blocklets.d.ts +1 -0
- package/dist/components/auto-translate/api.d.ts +14 -0
- package/dist/components/auto-translate/auto-translate-button.d.ts +4 -0
- package/dist/components/auto-translate/editor-store-adaptor.d.ts +1 -0
- package/dist/components/auto-translate/index.d.ts +6 -0
- package/dist/components/auto-translate/languages.d.ts +13 -0
- package/dist/components/auto-translate/post-auto-translate-plugin.d.ts +13 -0
- package/dist/components/auto-translate/store.d.ts +21 -0
- package/dist/components/auto-translate/translate.d.ts +16 -0
- package/dist/components/auto-translate/utils.d.ts +9 -0
- package/dist/components/auto-translate/with-availibility-check.d.ts +2 -0
- package/dist/components/hooks/locale-context.d.ts +10 -0
- package/dist/components/hooks/session.d.ts +1 -0
- package/dist/components/posts/comment-list/context.d.ts +3 -1
- package/dist/components/posts/comment.d.ts +2 -1
- package/dist/components/posts/post.d.ts +2 -1
- package/dist/constants.d.ts +3 -0
- package/dist/{editor-gidK4SQd.mjs → editor-CdK8tIVK.mjs} +1 -1
- package/dist/{index-h097ecr7.mjs → index-CIb6-P8d.mjs} +403 -60
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +11 -1
- package/dist/index.umd.js +369 -32
- package/package.json +9 -6
|
@@ -7,7 +7,7 @@ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
|
7
7
|
import { useTheme, ThemeProvider, styled as styled$2 } from "@mui/material/styles";
|
|
8
8
|
import { create as create$1, styled } from "@arcblock/ux/lib/Theme";
|
|
9
9
|
import { useEffect, useRef, useState, createElement, useContext, useMemo, useLayoutEffect, useCallback, isValidElement, Suspense, createContext, Fragment as Fragment$1, forwardRef, useImperativeHandle } from "react";
|
|
10
|
-
import { Box, useTheme as useTheme$1, useMediaQuery, styled as styled$1, Button as Button$1, Stack as Stack$1, Dialog, DialogTitle, DialogContent, DialogActions, DialogContentText, IconButton as IconButton$3, Tooltip as Tooltip$1, Chip as Chip$1, alpha, ClickAwayListener, Divider, Skeleton, InputBase, Badge as Badge$1, tooltipClasses as tooltipClasses$1, CircularProgress, Backdrop, Autocomplete, Typography as Typography$1, TextField, InputAdornment, SwipeableDrawer, ToggleButtonGroup, ToggleButton } from "@mui/material";
|
|
10
|
+
import { Box, useTheme as useTheme$1, useMediaQuery, styled as styled$1, Button as Button$1, Stack as Stack$1, Dialog, DialogTitle, DialogContent, DialogActions, DialogContentText, IconButton as IconButton$3, Tooltip as Tooltip$1, Chip as Chip$1, alpha, ClickAwayListener, Divider, Skeleton, InputBase, Badge as Badge$1, tooltipClasses as tooltipClasses$1, CircularProgress, Backdrop, Autocomplete, Typography as Typography$1, TextField, InputAdornment, SwipeableDrawer, ToggleButtonGroup, ToggleButton, Link as Link$1 } from "@mui/material";
|
|
11
11
|
import isNil from "lodash/isNil";
|
|
12
12
|
import { useEditorConfig, EditorConfigProvider } from "@blocklet/editor/lib/config";
|
|
13
13
|
import { lazyWithPreload } from "react-lazy-with-preload";
|
|
@@ -18,7 +18,7 @@ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext
|
|
|
18
18
|
import { ImageNode } from "@blocklet/editor/lib/main/nodes/ImageNode";
|
|
19
19
|
import { VideoNode } from "@blocklet/editor/lib/ext/VideoPlugin/VideoNode";
|
|
20
20
|
import { useSize, useUpdate, useInViewport, useSetState, useCreation, useRequest, useLocalStorageState, useGetState, useReactive } from "ahooks";
|
|
21
|
-
import { LocaleContext, useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
21
|
+
import { LocaleContext, useLocaleContext as useLocaleContext$1 } from "@arcblock/ux/lib/Locale/context";
|
|
22
22
|
import { Send, Save, ChatBubbleOutlineOutlined, MoreVert, NavigateNext, DeleteOutlineOutlined, ContentCopy, ArrowUpward, ArrowDownward, ArrowBackIos, Add, BorderColorOutlined } from "@mui/icons-material";
|
|
23
23
|
import LoadingButton from "@mui/lab/LoadingButton";
|
|
24
24
|
import Alert from "@mui/material/Alert";
|
|
@@ -56,6 +56,11 @@ import MuiMenuItem from "@mui/material/MenuItem";
|
|
|
56
56
|
import clsx from "clsx";
|
|
57
57
|
import IconButton$2 from "@mui/material/IconButton";
|
|
58
58
|
import MuiMenu from "@mui/material/Menu";
|
|
59
|
+
import { InlineTranslationPlugin, useInlineTranslationStore } from "@blocklet/editor/lib/ext/InlineTranslationPlugin";
|
|
60
|
+
import { createContainer } from "unstated-next";
|
|
61
|
+
import murmurhash from "murmurhash";
|
|
62
|
+
import { franc } from "franc-min";
|
|
63
|
+
import { createAxios } from "@blocklet/js-sdk";
|
|
59
64
|
import { EditorHolderProvider } from "@blocklet/editor/lib/ext/EditorHolderPlugin";
|
|
60
65
|
import red from "@mui/material/colors/red";
|
|
61
66
|
import Dialog$1 from "@arcblock/ux/lib/Dialog";
|
|
@@ -80,10 +85,11 @@ import { BusyPlugin } from "@blocklet/editor/lib/ext/BusyPlugin";
|
|
|
80
85
|
import { AddonButton } from "@arcblock/ux/lib/Header/addon-button";
|
|
81
86
|
import hotToast from "react-hot-toast";
|
|
82
87
|
import MuiPagination from "@mui/material/Pagination";
|
|
83
|
-
import { createContainer } from "unstated-next";
|
|
84
88
|
import Cookie from "js-cookie";
|
|
85
89
|
import { WsClient } from "@arcblock/ws";
|
|
86
90
|
import { css } from "@emotion/css";
|
|
91
|
+
import { create as create$2 } from "zustand";
|
|
92
|
+
import { persist } from "zustand/middleware";
|
|
87
93
|
const typography = {
|
|
88
94
|
h1: {
|
|
89
95
|
fontSize: "1.875rem",
|
|
@@ -319,7 +325,7 @@ const getBlockletMountPointInfo = (name) => {
|
|
|
319
325
|
var _a2, _b2;
|
|
320
326
|
return (_b2 = (_a2 = window.blocklet) == null ? void 0 : _a2.componentMountPoints) == null ? void 0 : _b2.find((x) => x.name === name);
|
|
321
327
|
};
|
|
322
|
-
const blockletExists = (name) => {
|
|
328
|
+
const blockletExists$1 = (name) => {
|
|
323
329
|
const info = getBlockletMountPointInfo(name);
|
|
324
330
|
return (info == null ? void 0 : info.status) === "running";
|
|
325
331
|
};
|
|
@@ -389,7 +395,7 @@ const getPaymentKitMountPoint = () => {
|
|
|
389
395
|
};
|
|
390
396
|
const utils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
391
397
|
__proto__: null,
|
|
392
|
-
blockletExists,
|
|
398
|
+
blockletExists: blockletExists$1,
|
|
393
399
|
copy,
|
|
394
400
|
discussKitApiBaseUrl,
|
|
395
401
|
discussKitMountPoint,
|
|
@@ -901,7 +907,7 @@ function RelativeTime({ value, autoUpdate, ...rest }) {
|
|
|
901
907
|
return /* @__PURE__ */ jsx(UxRelativeTime, { value: v2, ...rest });
|
|
902
908
|
}
|
|
903
909
|
function EmptyStatus({ sx }) {
|
|
904
|
-
const { t } = useLocaleContext();
|
|
910
|
+
const { t } = useLocaleContext$1();
|
|
905
911
|
return /* @__PURE__ */ jsx(
|
|
906
912
|
Box$1,
|
|
907
913
|
{
|
|
@@ -1244,7 +1250,7 @@ const useChatInWallet = () => {
|
|
|
1244
1250
|
function ProfileCard({ user, click, ...rest }) {
|
|
1245
1251
|
var _a2, _b2, _c2;
|
|
1246
1252
|
const { session } = useSessionContext();
|
|
1247
|
-
const { t } = useLocaleContext();
|
|
1253
|
+
const { t } = useLocaleContext$1();
|
|
1248
1254
|
let chatUrl = (user == null ? void 0 : user.did) && `/chat/dm/${user == null ? void 0 : user.did}`;
|
|
1249
1255
|
if (chatUrl && ((_a2 = window.location.pathname) == null ? void 0 : _a2.includes(user == null ? void 0 : user.did))) {
|
|
1250
1256
|
chatUrl = "";
|
|
@@ -1402,6 +1408,10 @@ const getUsername = (user, fallback2) => {
|
|
|
1402
1408
|
const isValidUser = (user) => {
|
|
1403
1409
|
return (user == null ? void 0 : user.did) && (user == null ? void 0 : user.fullName) && !isBlockletApp(user.did) && user.did !== window.blocklet.appId;
|
|
1404
1410
|
};
|
|
1411
|
+
function blockletExists(dids) {
|
|
1412
|
+
const blockletDids = Array.isArray(dids) ? dids : [dids];
|
|
1413
|
+
return blockletDids.every((did) => blockletMountPointsByDid[did]);
|
|
1414
|
+
}
|
|
1405
1415
|
function AuthorInfo({
|
|
1406
1416
|
user,
|
|
1407
1417
|
createdAt,
|
|
@@ -1600,7 +1610,7 @@ const Root$2 = styled("div")`
|
|
|
1600
1610
|
}
|
|
1601
1611
|
`;
|
|
1602
1612
|
function ViewMore({ children, ...rest }) {
|
|
1603
|
-
const { t } = useLocaleContext();
|
|
1613
|
+
const { t } = useLocaleContext$1();
|
|
1604
1614
|
const [collapsed, setCollapsed] = useState(true);
|
|
1605
1615
|
const [ref, { height }] = useMeasure();
|
|
1606
1616
|
const _collapsed = collapsed && height > MAX_HEIGHT;
|
|
@@ -1762,6 +1772,139 @@ function Menu({ items = [], ...rest }) {
|
|
|
1762
1772
|
] });
|
|
1763
1773
|
}
|
|
1764
1774
|
Menu.Item = MuiMenuItem;
|
|
1775
|
+
const useLocaleContext = () => {
|
|
1776
|
+
const { languages, ...rest } = useLocaleContext$1();
|
|
1777
|
+
function getLanguageName(code) {
|
|
1778
|
+
var _a2;
|
|
1779
|
+
return ((_a2 = languages.find((x) => x.code === code)) == null ? void 0 : _a2.name) || code;
|
|
1780
|
+
}
|
|
1781
|
+
return {
|
|
1782
|
+
languages,
|
|
1783
|
+
getLanguageName,
|
|
1784
|
+
...rest
|
|
1785
|
+
};
|
|
1786
|
+
};
|
|
1787
|
+
const AIGNE_RUNTIME_DID = "z2qaBP9SahqU2L2YA3ip7NecwKACMByTFuiJ2";
|
|
1788
|
+
const AIGNE_STUDIO_DID = "z8iZpog7mcgcgBZzTiXJCWESvmnRrQmnd3XBB";
|
|
1789
|
+
const DISCUSS_KIT_DID = "z8ia1WEiBZ7hxURf6LwH21Wpg99vophFwSJdu";
|
|
1790
|
+
const SUPPORTED_LANGUAGES = [
|
|
1791
|
+
{
|
|
1792
|
+
name: "English",
|
|
1793
|
+
nativeName: "English",
|
|
1794
|
+
iso639_1: "en",
|
|
1795
|
+
iso639_3: "eng"
|
|
1796
|
+
},
|
|
1797
|
+
{
|
|
1798
|
+
name: "Simplified Chinese",
|
|
1799
|
+
nativeName: "简体中文",
|
|
1800
|
+
iso639_1: "zh",
|
|
1801
|
+
iso639_3: "cmn"
|
|
1802
|
+
},
|
|
1803
|
+
{
|
|
1804
|
+
name: "Spanish",
|
|
1805
|
+
nativeName: "Español",
|
|
1806
|
+
iso639_1: "es",
|
|
1807
|
+
iso639_3: "spa"
|
|
1808
|
+
},
|
|
1809
|
+
{
|
|
1810
|
+
name: "Portuguese",
|
|
1811
|
+
nativeName: "Português",
|
|
1812
|
+
iso639_1: "pt",
|
|
1813
|
+
iso639_3: "por"
|
|
1814
|
+
},
|
|
1815
|
+
{
|
|
1816
|
+
name: "Russian",
|
|
1817
|
+
nativeName: "Русский",
|
|
1818
|
+
iso639_1: "ru",
|
|
1819
|
+
iso639_3: "rus"
|
|
1820
|
+
},
|
|
1821
|
+
{
|
|
1822
|
+
name: "Japanese",
|
|
1823
|
+
nativeName: "日本語",
|
|
1824
|
+
iso639_1: "ja",
|
|
1825
|
+
iso639_3: "jpn"
|
|
1826
|
+
},
|
|
1827
|
+
{
|
|
1828
|
+
name: "French",
|
|
1829
|
+
nativeName: "Français",
|
|
1830
|
+
iso639_1: "fr",
|
|
1831
|
+
iso639_3: "fra"
|
|
1832
|
+
},
|
|
1833
|
+
{
|
|
1834
|
+
name: "German",
|
|
1835
|
+
nativeName: "Deutsch",
|
|
1836
|
+
iso639_1: "de",
|
|
1837
|
+
iso639_3: "deu"
|
|
1838
|
+
},
|
|
1839
|
+
{
|
|
1840
|
+
name: "Korean",
|
|
1841
|
+
nativeName: "한국어",
|
|
1842
|
+
iso639_1: "ko",
|
|
1843
|
+
iso639_3: "kor"
|
|
1844
|
+
}
|
|
1845
|
+
];
|
|
1846
|
+
const languagesByIso6393 = new Map(SUPPORTED_LANGUAGES.map((lang) => [lang.iso639_3, lang]));
|
|
1847
|
+
function getLanguageByIso6393(iso639_3) {
|
|
1848
|
+
return languagesByIso6393.get(iso639_3);
|
|
1849
|
+
}
|
|
1850
|
+
function hashText(text = "") {
|
|
1851
|
+
return murmurhash.v3(text).toString(16);
|
|
1852
|
+
}
|
|
1853
|
+
const isInlineTranslationAvailable = blockletExists([AIGNE_RUNTIME_DID, AIGNE_STUDIO_DID, DISCUSS_KIT_DID]) && !!window.blocklet.preferences.inlineTranslatorAgentAid;
|
|
1854
|
+
function detectLanguage(src) {
|
|
1855
|
+
const lang = franc(src, { only: SUPPORTED_LANGUAGES.map((x) => x.iso639_3), minLength: 2 });
|
|
1856
|
+
return getLanguageByIso6393(lang) || null;
|
|
1857
|
+
}
|
|
1858
|
+
function detectLanguageIso6391(src) {
|
|
1859
|
+
var _a2;
|
|
1860
|
+
return ((_a2 = detectLanguage(src)) == null ? void 0 : _a2.iso639_1) || null;
|
|
1861
|
+
}
|
|
1862
|
+
const api = createAxios({
|
|
1863
|
+
baseURL: discussKitApiBaseUrl,
|
|
1864
|
+
timeout: 2e4
|
|
1865
|
+
});
|
|
1866
|
+
const translatePost = async ({
|
|
1867
|
+
id: id2,
|
|
1868
|
+
sourceItems,
|
|
1869
|
+
targetLanguage,
|
|
1870
|
+
targetLanguageName,
|
|
1871
|
+
contentVersion,
|
|
1872
|
+
useCache
|
|
1873
|
+
}) => {
|
|
1874
|
+
const result = await api.post(`/posts/${id2}/translate`, {
|
|
1875
|
+
sourceItems,
|
|
1876
|
+
targetLanguage,
|
|
1877
|
+
targetLanguageName,
|
|
1878
|
+
contentVersion,
|
|
1879
|
+
useCache
|
|
1880
|
+
});
|
|
1881
|
+
return result.data;
|
|
1882
|
+
};
|
|
1883
|
+
function PostAutoTranslatePlugin({ postId, updatedAt }) {
|
|
1884
|
+
const { getLanguageName } = useLocaleContext();
|
|
1885
|
+
if (!isInlineTranslationAvailable) {
|
|
1886
|
+
return null;
|
|
1887
|
+
}
|
|
1888
|
+
const version = `${new Date(updatedAt).getTime()}`;
|
|
1889
|
+
const translateService = (payload) => {
|
|
1890
|
+
return translatePost({
|
|
1891
|
+
...payload,
|
|
1892
|
+
targetLanguageName: getLanguageName(payload.targetLanguage),
|
|
1893
|
+
id: postId,
|
|
1894
|
+
contentVersion: version
|
|
1895
|
+
});
|
|
1896
|
+
};
|
|
1897
|
+
return /* @__PURE__ */ jsx(InlineTranslationPlugin, { translateService, detectLanguage: detectLanguageIso6391 });
|
|
1898
|
+
}
|
|
1899
|
+
const usePostAutoTranslatePlugin = ({ postId, updatedAt }) => {
|
|
1900
|
+
const value = useMemo(() => {
|
|
1901
|
+
return {
|
|
1902
|
+
plugin: /* @__PURE__ */ jsx(PostAutoTranslatePlugin, { postId, updatedAt })
|
|
1903
|
+
};
|
|
1904
|
+
}, [postId, updatedAt]);
|
|
1905
|
+
return value;
|
|
1906
|
+
};
|
|
1907
|
+
const PostAutoTranslationContainer = createContainer(usePostAutoTranslatePlugin);
|
|
1765
1908
|
const Root$1 = styled$2(Box$1)`
|
|
1766
1909
|
.post-highlighted {
|
|
1767
1910
|
animation: highlighted-post-fade 3s;
|
|
@@ -1796,13 +1939,14 @@ function PostComponent({
|
|
|
1796
1939
|
showProfileCard,
|
|
1797
1940
|
resolveAuthorInfoAppend = () => void 0,
|
|
1798
1941
|
editorPlugins,
|
|
1942
|
+
enableAutoTranslate,
|
|
1799
1943
|
...rest
|
|
1800
1944
|
}) {
|
|
1801
1945
|
var _a2;
|
|
1802
1946
|
const { session, isAdmin } = useSessionContext();
|
|
1803
1947
|
const isAuthor = post.author.did === ((_a2 = session == null ? void 0 : session.user) == null ? void 0 : _a2.did);
|
|
1804
1948
|
const commentUrl = window.location.hash.substring(1);
|
|
1805
|
-
const { t } = useLocaleContext();
|
|
1949
|
+
const { t } = useLocaleContext$1();
|
|
1806
1950
|
const [editing, setEditing] = useState(false);
|
|
1807
1951
|
const postContext = { isAdmin, isAuthor, interactive, post };
|
|
1808
1952
|
const [inViewport] = useInViewport(() => document == null ? void 0 : document.getElementById(post.id));
|
|
@@ -1907,7 +2051,10 @@ function PostComponent({
|
|
|
1907
2051
|
onExitEditing: () => setEditing(false),
|
|
1908
2052
|
onSubmit: (content) => onContentUpdate(post, content),
|
|
1909
2053
|
autoCollapse,
|
|
1910
|
-
editorPrepend:
|
|
2054
|
+
editorPrepend: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2055
|
+
editorPlugins,
|
|
2056
|
+
enableAutoTranslate && /* @__PURE__ */ jsx(PostAutoTranslatePlugin, { postId: post.id, updatedAt: post.updatedAt || "" })
|
|
2057
|
+
] })
|
|
1911
2058
|
},
|
|
1912
2059
|
editing ? "comment-content" : post.synced || 0
|
|
1913
2060
|
) }),
|
|
@@ -1943,7 +2090,7 @@ function Confirm({
|
|
|
1943
2090
|
}) {
|
|
1944
2091
|
const theme = useTheme();
|
|
1945
2092
|
const fullScreen = useMediaQuery(theme.breakpoints.down("md"));
|
|
1946
|
-
const { t } = useLocaleContext();
|
|
2093
|
+
const { t } = useLocaleContext$1();
|
|
1947
2094
|
const renderDesc = () => {
|
|
1948
2095
|
if (isValidElement(description)) {
|
|
1949
2096
|
return description;
|
|
@@ -2484,8 +2631,8 @@ const createApi = (request) => {
|
|
|
2484
2631
|
};
|
|
2485
2632
|
function GithubReactionContainer({ id: id2, request, ...rest }) {
|
|
2486
2633
|
const { session } = useSessionContext();
|
|
2487
|
-
const
|
|
2488
|
-
const { data, loading, error } = useRequest(() =>
|
|
2634
|
+
const api2 = useCreation(() => createApi(request || axios.create({})), [request]);
|
|
2635
|
+
const { data, loading, error } = useRequest(() => api2.fetchRatings(id2), {
|
|
2489
2636
|
refreshDeps: [id2]
|
|
2490
2637
|
});
|
|
2491
2638
|
const handleRate = async ({ ratingType, value }) => {
|
|
@@ -2493,14 +2640,14 @@ function GithubReactionContainer({ id: id2, request, ...rest }) {
|
|
|
2493
2640
|
session.login();
|
|
2494
2641
|
throw new Error("Unauthenticated.");
|
|
2495
2642
|
}
|
|
2496
|
-
await
|
|
2643
|
+
await api2.rate({ id: id2, ratingType, value });
|
|
2497
2644
|
};
|
|
2498
2645
|
const handleUnrate = async () => {
|
|
2499
2646
|
if (!session.user) {
|
|
2500
2647
|
session.login();
|
|
2501
2648
|
throw new Error("Unauthenticated.");
|
|
2502
2649
|
}
|
|
2503
|
-
await
|
|
2650
|
+
await api2.unrate({ id: id2 });
|
|
2504
2651
|
};
|
|
2505
2652
|
if (loading || error) {
|
|
2506
2653
|
return null;
|
|
@@ -2518,10 +2665,11 @@ function Comment({
|
|
|
2518
2665
|
renderDonation,
|
|
2519
2666
|
renderActions,
|
|
2520
2667
|
renderEditorPlugins,
|
|
2668
|
+
enableAutoTranslate,
|
|
2521
2669
|
...rest
|
|
2522
2670
|
}) {
|
|
2523
2671
|
const { session } = useSessionContext();
|
|
2524
|
-
const { t } = useLocaleContext();
|
|
2672
|
+
const { t } = useLocaleContext$1();
|
|
2525
2673
|
const [inputVisible, setInputVisible] = useState(false);
|
|
2526
2674
|
const { confirm } = useConfirm();
|
|
2527
2675
|
const handleDelete = async (...args) => {
|
|
@@ -2621,7 +2769,8 @@ function Comment({
|
|
|
2621
2769
|
resolveAuthorInfoAppend: rest.resolveAuthorInfoAppend,
|
|
2622
2770
|
renderDonation,
|
|
2623
2771
|
renderActions,
|
|
2624
|
-
renderEditorPlugins
|
|
2772
|
+
renderEditorPlugins,
|
|
2773
|
+
enableAutoTranslate
|
|
2625
2774
|
},
|
|
2626
2775
|
item.id
|
|
2627
2776
|
);
|
|
@@ -2657,7 +2806,8 @@ function Comment({
|
|
|
2657
2806
|
customMenu,
|
|
2658
2807
|
render,
|
|
2659
2808
|
renderExtraContent,
|
|
2660
|
-
editorPlugins: renderEditorPlugins == null ? void 0 : renderEditorPlugins(rest.post)
|
|
2809
|
+
editorPlugins: renderEditorPlugins == null ? void 0 : renderEditorPlugins(rest.post),
|
|
2810
|
+
enableAutoTranslate
|
|
2661
2811
|
}
|
|
2662
2812
|
) });
|
|
2663
2813
|
}
|
|
@@ -2730,7 +2880,7 @@ const CommentsContext = createContext({});
|
|
|
2730
2880
|
const useCommentsContext = () => useContext(CommentsContext);
|
|
2731
2881
|
function CommentsProvider({
|
|
2732
2882
|
target,
|
|
2733
|
-
api,
|
|
2883
|
+
api: api2,
|
|
2734
2884
|
flatView,
|
|
2735
2885
|
children,
|
|
2736
2886
|
order,
|
|
@@ -2744,6 +2894,7 @@ function CommentsProvider({
|
|
|
2744
2894
|
renderDonation,
|
|
2745
2895
|
renderActions,
|
|
2746
2896
|
renderEditorPlugins,
|
|
2897
|
+
enableAutoTranslate,
|
|
2747
2898
|
renderInnerFooter
|
|
2748
2899
|
}) {
|
|
2749
2900
|
var _a2;
|
|
@@ -2779,14 +2930,14 @@ function CommentsProvider({
|
|
|
2779
2930
|
return;
|
|
2780
2931
|
}
|
|
2781
2932
|
setState({ ...getInitialState(), order: state.order, initialized: false });
|
|
2782
|
-
const fetchCommentPosition = () =>
|
|
2933
|
+
const fetchCommentPosition = () => api2.fetchCommentPosition({
|
|
2783
2934
|
id: highlightedRef.current,
|
|
2784
2935
|
objectId: target.id,
|
|
2785
2936
|
order: state.order,
|
|
2786
2937
|
includeReplies: flatView ? 1 : null
|
|
2787
2938
|
});
|
|
2788
2939
|
const [{ data, total, nextCursor }, positionRes, pinnedComments] = await Promise.all([
|
|
2789
|
-
|
|
2940
|
+
api2.fetchComments({
|
|
2790
2941
|
objectId: target.id,
|
|
2791
2942
|
limit,
|
|
2792
2943
|
order: state.order,
|
|
@@ -2794,7 +2945,7 @@ function CommentsProvider({
|
|
|
2794
2945
|
initialRepliesLimit
|
|
2795
2946
|
}),
|
|
2796
2947
|
highlightedRef.current ? fetchCommentPosition() : -1,
|
|
2797
|
-
|
|
2948
|
+
api2.fetchPinnedComments(target.id)
|
|
2798
2949
|
]);
|
|
2799
2950
|
let position = -1;
|
|
2800
2951
|
let cursor = highlightedRef.current;
|
|
@@ -2805,7 +2956,7 @@ function CommentsProvider({
|
|
|
2805
2956
|
position = positionRes;
|
|
2806
2957
|
}
|
|
2807
2958
|
if (position > data.length - 1) {
|
|
2808
|
-
const result = await
|
|
2959
|
+
const result = await api2.fetchComments({
|
|
2809
2960
|
objectId: target.id,
|
|
2810
2961
|
limit,
|
|
2811
2962
|
order: state.order,
|
|
@@ -2852,7 +3003,7 @@ function CommentsProvider({
|
|
|
2852
3003
|
}
|
|
2853
3004
|
};
|
|
2854
3005
|
const loadMore = async (cursor) => {
|
|
2855
|
-
const { data, total, nextCursor } = await
|
|
3006
|
+
const { data, total, nextCursor } = await api2.fetchComments({
|
|
2856
3007
|
objectId: target.id,
|
|
2857
3008
|
limit,
|
|
2858
3009
|
order: state.order,
|
|
@@ -2867,7 +3018,7 @@ function CommentsProvider({
|
|
|
2867
3018
|
if (!state.highlighted) {
|
|
2868
3019
|
return;
|
|
2869
3020
|
}
|
|
2870
|
-
const { data, total, nextCursor } = await
|
|
3021
|
+
const { data, total, nextCursor } = await api2.fetchComments({
|
|
2871
3022
|
objectId: target.id,
|
|
2872
3023
|
limit,
|
|
2873
3024
|
order: state.order,
|
|
@@ -2883,7 +3034,7 @@ function CommentsProvider({
|
|
|
2883
3034
|
const root = commentsKeyById[rootId];
|
|
2884
3035
|
if (root.replies) {
|
|
2885
3036
|
const cursor = state.replyCursors[root.id] || ((_a3 = getLastItem(root.replies)) == null ? void 0 : _a3.id);
|
|
2886
|
-
const { data, total, nextCursor } = await
|
|
3037
|
+
const { data, total, nextCursor } = await api2.fetchComments({
|
|
2887
3038
|
objectId: target.id,
|
|
2888
3039
|
rootId,
|
|
2889
3040
|
limit,
|
|
@@ -2927,19 +3078,19 @@ function CommentsProvider({
|
|
|
2927
3078
|
};
|
|
2928
3079
|
const updateComment = async (post, content) => {
|
|
2929
3080
|
updateCommentState(post.id, (current) => ({ ...current, content }));
|
|
2930
|
-
const { updatedAt } = await
|
|
3081
|
+
const { updatedAt } = await api2.updateComment(post, content);
|
|
2931
3082
|
updateCommentState(post.id, (current) => ({ ...current, content, updatedAt }));
|
|
2932
3083
|
};
|
|
2933
3084
|
const deleteComment = async (post) => {
|
|
2934
|
-
await
|
|
3085
|
+
await api2.deleteComment(post);
|
|
2935
3086
|
updateCommentState(post.id, (current) => ({ ...current, deletedAt: /* @__PURE__ */ new Date() }));
|
|
2936
3087
|
};
|
|
2937
3088
|
const reply = async (post, content) => {
|
|
2938
|
-
const result = await
|
|
3089
|
+
const result = await api2.reply(post, content);
|
|
2939
3090
|
setTimeout(() => add(result), 800);
|
|
2940
3091
|
};
|
|
2941
3092
|
const togglePin = async ({ post, value: value2 }) => {
|
|
2942
|
-
await
|
|
3093
|
+
await api2.togglePin({ post, value: value2 });
|
|
2943
3094
|
updateCommentState(post.id, (current) => ({ ...current, pinnedAt: value2 ? /* @__PURE__ */ new Date() : null }));
|
|
2944
3095
|
};
|
|
2945
3096
|
const findById = (id2) => commentsKeyById[id2];
|
|
@@ -2959,7 +3110,7 @@ function CommentsProvider({
|
|
|
2959
3110
|
loadMoreForTailSection,
|
|
2960
3111
|
sort,
|
|
2961
3112
|
add,
|
|
2962
|
-
api,
|
|
3113
|
+
api: api2,
|
|
2963
3114
|
updateComment,
|
|
2964
3115
|
deleteComment,
|
|
2965
3116
|
reply,
|
|
@@ -2970,6 +3121,7 @@ function CommentsProvider({
|
|
|
2970
3121
|
renderDonation,
|
|
2971
3122
|
renderActions,
|
|
2972
3123
|
renderEditorPlugins,
|
|
3124
|
+
enableAutoTranslate,
|
|
2973
3125
|
renderInnerFooter
|
|
2974
3126
|
}),
|
|
2975
3127
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -2983,7 +3135,7 @@ const LoadMoreButtonWrapper = styled$2(Box$1)`
|
|
|
2983
3135
|
background-position: center;
|
|
2984
3136
|
`;
|
|
2985
3137
|
function SegmentalList({ ...rest }) {
|
|
2986
|
-
const { t } = useLocaleContext();
|
|
3138
|
+
const { t } = useLocaleContext$1();
|
|
2987
3139
|
const {
|
|
2988
3140
|
state: { comments, nextCursor, highlighted },
|
|
2989
3141
|
autoCollapse,
|
|
@@ -2997,7 +3149,7 @@ function SegmentalList({ ...rest }) {
|
|
|
2997
3149
|
reply,
|
|
2998
3150
|
togglePin,
|
|
2999
3151
|
loadMoreReplies,
|
|
3000
|
-
api
|
|
3152
|
+
api: api2
|
|
3001
3153
|
} = useCommentsContext();
|
|
3002
3154
|
if (!highlighted) {
|
|
3003
3155
|
return null;
|
|
@@ -3038,8 +3190,8 @@ function SegmentalList({ ...rest }) {
|
|
|
3038
3190
|
post: comment,
|
|
3039
3191
|
onDelete: deleteComment,
|
|
3040
3192
|
onContentUpdate: updateComment,
|
|
3041
|
-
onRate:
|
|
3042
|
-
onUnrate:
|
|
3193
|
+
onRate: api2.rate,
|
|
3194
|
+
onUnrate: api2.unrate,
|
|
3043
3195
|
onReply: reply,
|
|
3044
3196
|
onTogglePin: togglePin,
|
|
3045
3197
|
onLoadMoreReplies: loadMoreReplies,
|
|
@@ -3065,7 +3217,7 @@ function SegmentalList({ ...rest }) {
|
|
|
3065
3217
|
] });
|
|
3066
3218
|
}
|
|
3067
3219
|
function CommentList(props) {
|
|
3068
|
-
const { t } = useLocaleContext();
|
|
3220
|
+
const { t } = useLocaleContext$1();
|
|
3069
3221
|
const {
|
|
3070
3222
|
state: { order, nextCursor, highlighted },
|
|
3071
3223
|
comments,
|
|
@@ -3080,11 +3232,12 @@ function CommentList(props) {
|
|
|
3080
3232
|
reply,
|
|
3081
3233
|
togglePin,
|
|
3082
3234
|
loadMoreReplies,
|
|
3083
|
-
api,
|
|
3235
|
+
api: api2,
|
|
3084
3236
|
renderComments,
|
|
3085
3237
|
renderDonation,
|
|
3086
3238
|
renderActions,
|
|
3087
|
-
renderEditorPlugins
|
|
3239
|
+
renderEditorPlugins,
|
|
3240
|
+
enableAutoTranslate
|
|
3088
3241
|
} = useCommentsContext();
|
|
3089
3242
|
if (highlighted) {
|
|
3090
3243
|
return /* @__PURE__ */ jsx(SegmentalList, { ...props });
|
|
@@ -3095,8 +3248,8 @@ function CommentList(props) {
|
|
|
3095
3248
|
post: comment,
|
|
3096
3249
|
onDelete: deleteComment,
|
|
3097
3250
|
onContentUpdate: updateComment,
|
|
3098
|
-
onRate:
|
|
3099
|
-
onUnrate:
|
|
3251
|
+
onRate: api2.rate,
|
|
3252
|
+
onUnrate: api2.unrate,
|
|
3100
3253
|
onReply: reply,
|
|
3101
3254
|
onTogglePin: togglePin,
|
|
3102
3255
|
onLoadMoreReplies: loadMoreReplies,
|
|
@@ -3107,6 +3260,7 @@ function CommentList(props) {
|
|
|
3107
3260
|
renderDonation,
|
|
3108
3261
|
renderActions,
|
|
3109
3262
|
renderEditorPlugins,
|
|
3263
|
+
enableAutoTranslate,
|
|
3110
3264
|
...restProps
|
|
3111
3265
|
},
|
|
3112
3266
|
comment.id
|
|
@@ -3186,7 +3340,7 @@ function UploaderTrigger({ onChange, children }) {
|
|
|
3186
3340
|
}
|
|
3187
3341
|
function UploaderProvider({ children }) {
|
|
3188
3342
|
const uploaderRef = useRef(null);
|
|
3189
|
-
const { locale } = useLocaleContext();
|
|
3343
|
+
const { locale } = useLocaleContext$1();
|
|
3190
3344
|
window.uploaderRef = uploaderRef;
|
|
3191
3345
|
return /* @__PURE__ */ jsxs(UploaderContext.Provider, { value: uploaderRef, children: [
|
|
3192
3346
|
children,
|
|
@@ -3439,7 +3593,7 @@ function BlogItem({
|
|
|
3439
3593
|
var _a2;
|
|
3440
3594
|
const theme = useTheme();
|
|
3441
3595
|
const downMd = useMediaQuery$1(theme.breakpoints.down("md"));
|
|
3442
|
-
const { locale } = useLocaleContext();
|
|
3596
|
+
const { locale } = useLocaleContext$1();
|
|
3443
3597
|
const navigate = useNavigate();
|
|
3444
3598
|
const coverImgWidths = { xs: 84, md: 180, lg: 200 };
|
|
3445
3599
|
const coverImgWidth = useResponsiveValue(coverImgWidths);
|
|
@@ -4321,7 +4475,7 @@ function ChannelGroup({ size = "normal", chat, children, ...rest }) {
|
|
|
4321
4475
|
] });
|
|
4322
4476
|
}
|
|
4323
4477
|
function ChatList({ inWallet, ...rest }) {
|
|
4324
|
-
const { t } = useLocaleContext();
|
|
4478
|
+
const { t } = useLocaleContext$1();
|
|
4325
4479
|
const { orderedChats, activeChatId, setActiveChat, getOppositeUser, getLastMessageText } = useChatContext();
|
|
4326
4480
|
const { chatUnreadCounts } = useUnreadNotification();
|
|
4327
4481
|
const { navigateToChat } = useChatInWallet();
|
|
@@ -4439,7 +4593,7 @@ const baseItemSx = {
|
|
|
4439
4593
|
};
|
|
4440
4594
|
function Message({ message, prevMessage, showTime = true, ...rest }) {
|
|
4441
4595
|
var _a2, _b2;
|
|
4442
|
-
const { t } = useLocaleContext();
|
|
4596
|
+
const { t } = useLocaleContext$1();
|
|
4443
4597
|
const { session, isAdmin } = useSessionContext();
|
|
4444
4598
|
const { confirm } = useConfirm();
|
|
4445
4599
|
const { activeChatId, deleteMessage, isInWallet, renderMessage } = useChatContext();
|
|
@@ -4551,7 +4705,7 @@ function Message({ message, prevMessage, showTime = true, ...rest }) {
|
|
|
4551
4705
|
}
|
|
4552
4706
|
function NotificationMessage({ chat, message, prevMessage }) {
|
|
4553
4707
|
const { session } = useSessionContext();
|
|
4554
|
-
const { t } = useLocaleContext();
|
|
4708
|
+
const { t } = useLocaleContext$1();
|
|
4555
4709
|
const renderQuote = ({ title, cover }) => {
|
|
4556
4710
|
if ("post" in message) {
|
|
4557
4711
|
return /* @__PURE__ */ jsxs(Box$1, { sx: { color: 14, mt: 1 }, children: [
|
|
@@ -4740,7 +4894,7 @@ const checkIsAtBottom = (element) => {
|
|
|
4740
4894
|
const MessageList = forwardRef(({ chat, ...rest }, ref) => {
|
|
4741
4895
|
var _a2, _b2, _c2;
|
|
4742
4896
|
const { isActiveChat, loadMessages } = useChatContext();
|
|
4743
|
-
const { t } = useLocaleContext();
|
|
4897
|
+
const { t } = useLocaleContext$1();
|
|
4744
4898
|
const isActive = isActiveChat(chat.id);
|
|
4745
4899
|
const containerRef = useRef(null);
|
|
4746
4900
|
const [isAtBottom, setIsAtBottom] = useState(true);
|
|
@@ -5004,7 +5158,7 @@ function Back({ url, fallbackUrl, iconOnly, sx, icon, ...rest }) {
|
|
|
5004
5158
|
}
|
|
5005
5159
|
const tablerSend = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M10 14L21 3m0 0l-6.5 18a.55.55 0 0 1-1 0L10 14l-7-3.5a.55.55 0 0 1 0-1z" }) });
|
|
5006
5160
|
const tablerLetterCase = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M14 15.5a3.5 3.5 0 1 0 7 0a3.5 3.5 0 1 0-7 0M3 19V8.5a3.5 3.5 0 0 1 7 0V19m-7-6h7m11-1v7" }) });
|
|
5007
|
-
const Editor = lazyRetry(() => import("./editor-
|
|
5161
|
+
const Editor = lazyRetry(() => import("./editor-CdK8tIVK.mjs"));
|
|
5008
5162
|
function LazyEditor(props) {
|
|
5009
5163
|
const fallback2 = /* @__PURE__ */ jsxs(Box, { sx: { px: 3 }, children: [
|
|
5010
5164
|
/* @__PURE__ */ jsx(Skeleton, {}),
|
|
@@ -5143,7 +5297,7 @@ function ShortcutPlugin({ callback }) {
|
|
|
5143
5297
|
return null;
|
|
5144
5298
|
}
|
|
5145
5299
|
function ChatInput({ initialContent, send, onContentChange, onFocusChange }) {
|
|
5146
|
-
const { t } = useLocaleContext();
|
|
5300
|
+
const { t } = useLocaleContext$1();
|
|
5147
5301
|
const [content, setContent] = useState("");
|
|
5148
5302
|
const [lastSent, setLastSent] = useState(0);
|
|
5149
5303
|
const [toolbarVisible, setToolbarVisible] = useLocalStorageState("chat-input-toolbar-visible", {
|
|
@@ -5322,7 +5476,7 @@ function RoomTitle({ title }) {
|
|
|
5322
5476
|
function ChatRoom({ chat, inWallet, ...rest }) {
|
|
5323
5477
|
var _a2;
|
|
5324
5478
|
const { isChatInWalletV2 } = useChatInWallet();
|
|
5325
|
-
const { t } = useLocaleContext();
|
|
5479
|
+
const { t } = useLocaleContext$1();
|
|
5326
5480
|
const theme = useTheme();
|
|
5327
5481
|
const downSm = useMediaQuery((currentTheme) => currentTheme.breakpoints.down("sm"));
|
|
5328
5482
|
const {
|
|
@@ -5635,7 +5789,7 @@ function UserSearch({ sx, inputSx, ...rest }) {
|
|
|
5635
5789
|
] });
|
|
5636
5790
|
}
|
|
5637
5791
|
function Empty$2({ sx }) {
|
|
5638
|
-
const { t } = useLocaleContext();
|
|
5792
|
+
const { t } = useLocaleContext$1();
|
|
5639
5793
|
const mergedSx = [
|
|
5640
5794
|
{
|
|
5641
5795
|
display: "flex",
|
|
@@ -5667,7 +5821,7 @@ function Chat({ sx, ChannelEditComponent, ...rest }) {
|
|
|
5667
5821
|
setEditingChannel
|
|
5668
5822
|
} = useChatContext();
|
|
5669
5823
|
const downMd = useMediaQuery((theme) => theme.breakpoints.down("sm"));
|
|
5670
|
-
const { t } = useLocaleContext();
|
|
5824
|
+
const { t } = useLocaleContext$1();
|
|
5671
5825
|
const activeChat = (_a2 = chats == null ? void 0 : chats.filter((chat) => (chat == null ? void 0 : chat.id) === activeChatId)) == null ? void 0 : _a2[0];
|
|
5672
5826
|
const webTitleMap = {
|
|
5673
5827
|
dm: () => {
|
|
@@ -5787,7 +5941,7 @@ function Chat({ sx, ChannelEditComponent, ...rest }) {
|
|
|
5787
5941
|
] });
|
|
5788
5942
|
}
|
|
5789
5943
|
function Empty$1({ sx }) {
|
|
5790
|
-
const { t } = useLocaleContext();
|
|
5944
|
+
const { t } = useLocaleContext$1();
|
|
5791
5945
|
const mergedSx = [
|
|
5792
5946
|
{
|
|
5793
5947
|
display: "flex",
|
|
@@ -5835,7 +5989,7 @@ function ChatInWallet({ sx, ...rest }) {
|
|
|
5835
5989
|
] }) });
|
|
5836
5990
|
}
|
|
5837
5991
|
function Empty({ sx }) {
|
|
5838
|
-
const { t } = useLocaleContext();
|
|
5992
|
+
const { t } = useLocaleContext$1();
|
|
5839
5993
|
const mergedSx = [
|
|
5840
5994
|
{
|
|
5841
5995
|
display: "flex",
|
|
@@ -6108,7 +6262,7 @@ if (isInArcSphere) {
|
|
|
6108
6262
|
}
|
|
6109
6263
|
const useDefaultApiErrorHandler = (options) => {
|
|
6110
6264
|
const { request, onError } = options;
|
|
6111
|
-
const { t } = useLocaleContext();
|
|
6265
|
+
const { t } = useLocaleContext$1();
|
|
6112
6266
|
const showError = (msg, toastOptions) => {
|
|
6113
6267
|
toast.error(msg, toastOptions);
|
|
6114
6268
|
};
|
|
@@ -6195,7 +6349,7 @@ function DefaultEditorConfigProvider({
|
|
|
6195
6349
|
const AI = {
|
|
6196
6350
|
checkAvailable: async () => {
|
|
6197
6351
|
var _a3;
|
|
6198
|
-
if (downMd || !blockletExists("ai-kit")) {
|
|
6352
|
+
if (downMd || !blockletExists$1("ai-kit")) {
|
|
6199
6353
|
return false;
|
|
6200
6354
|
}
|
|
6201
6355
|
try {
|
|
@@ -6357,7 +6511,7 @@ const useDirtySources = () => {
|
|
|
6357
6511
|
return { dirty };
|
|
6358
6512
|
};
|
|
6359
6513
|
const useDirtyPrompt = () => {
|
|
6360
|
-
const { t } = useLocaleContext();
|
|
6514
|
+
const { t } = useLocaleContext$1();
|
|
6361
6515
|
const [dirty, setDirty, getDirty] = useGetState(false);
|
|
6362
6516
|
const { confirm } = useConfirm();
|
|
6363
6517
|
const resetCallbackRef = useRef(null);
|
|
@@ -6398,7 +6552,7 @@ const useDirtyPrompt = () => {
|
|
|
6398
6552
|
};
|
|
6399
6553
|
const DirtyPromptContainer = createContainer(useDirtyPrompt);
|
|
6400
6554
|
function ConfirmNavigation() {
|
|
6401
|
-
const { t } = useLocaleContext();
|
|
6555
|
+
const { t } = useLocaleContext$1();
|
|
6402
6556
|
const { dirty, reset } = DirtyPromptContainer.useContainer();
|
|
6403
6557
|
const blocker = useBlocker(dirty);
|
|
6404
6558
|
useEffect(() => {
|
|
@@ -12153,7 +12307,7 @@ const WsEvents = Object.freeze({
|
|
|
12153
12307
|
});
|
|
12154
12308
|
const usePointUpContext = () => useContext(PointUpContext);
|
|
12155
12309
|
function PointUp({ points }) {
|
|
12156
|
-
const { t } = useLocaleContext();
|
|
12310
|
+
const { t } = useLocaleContext$1();
|
|
12157
12311
|
return /* @__PURE__ */ jsxs(
|
|
12158
12312
|
Box$1,
|
|
12159
12313
|
{
|
|
@@ -12300,7 +12454,7 @@ function ButtonGroup({
|
|
|
12300
12454
|
type,
|
|
12301
12455
|
...rest
|
|
12302
12456
|
}) {
|
|
12303
|
-
const { t } = useLocaleContext();
|
|
12457
|
+
const { t } = useLocaleContext$1();
|
|
12304
12458
|
const downSm = useMediaQuery$1((mainTheme) => mainTheme.breakpoints.down("sm"));
|
|
12305
12459
|
const navigate = useNavigate();
|
|
12306
12460
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
@@ -12571,7 +12725,7 @@ function Paywall({ children, cta, ...rest }) {
|
|
|
12571
12725
|
}
|
|
12572
12726
|
function SubscriptionPaywall({ type, fetchPaymentLink, ...rest }) {
|
|
12573
12727
|
const { session } = useSessionContext();
|
|
12574
|
-
const { t } = useLocaleContext();
|
|
12728
|
+
const { t } = useLocaleContext$1();
|
|
12575
12729
|
const { data, loading } = useRequest(() => fetchPaymentLink({ type, redirect: window.location.href }));
|
|
12576
12730
|
const paymentLink = paymentKitMountPoint && (data == null ? void 0 : data.link) ? joinURL(paymentKitMountPoint, data.link) : null;
|
|
12577
12731
|
const loginAndReloadPage = () => {
|
|
@@ -12617,6 +12771,185 @@ function SubscriptionPaywall({ type, fetchPaymentLink, ...rest }) {
|
|
|
12617
12771
|
}
|
|
12618
12772
|
);
|
|
12619
12773
|
}
|
|
12774
|
+
const useAutoTranslateStore = create$2()(
|
|
12775
|
+
persist(
|
|
12776
|
+
(set, get) => ({
|
|
12777
|
+
autoTranslate: false,
|
|
12778
|
+
enableAutoTranslate: () => set({ autoTranslate: true }),
|
|
12779
|
+
disableAutoTranslate: () => set({ autoTranslate: false }),
|
|
12780
|
+
toggleAutoTranslate: (value) => set({ autoTranslate: value ?? !get().autoTranslate })
|
|
12781
|
+
}),
|
|
12782
|
+
{
|
|
12783
|
+
name: "auto-translate"
|
|
12784
|
+
}
|
|
12785
|
+
)
|
|
12786
|
+
);
|
|
12787
|
+
const useTargetLanguage = () => {
|
|
12788
|
+
const { locale, languages } = useLocaleContext$1();
|
|
12789
|
+
const { session } = useSessionContext();
|
|
12790
|
+
const preferredLanguage = languages.find((x) => {
|
|
12791
|
+
var _a2;
|
|
12792
|
+
return x.code === ((_a2 = session == null ? void 0 : session.user) == null ? void 0 : _a2.locale);
|
|
12793
|
+
});
|
|
12794
|
+
return (preferredLanguage == null ? void 0 : preferredLanguage.code) ?? locale;
|
|
12795
|
+
};
|
|
12796
|
+
const useTranslate = ({ text, enabled }) => {
|
|
12797
|
+
const { getLanguageName } = useLocaleContext();
|
|
12798
|
+
const targetLanguage = useTargetLanguage();
|
|
12799
|
+
const targetLanguageName = getLanguageName(targetLanguage);
|
|
12800
|
+
const key = useMemo(() => hashText(text), [text]);
|
|
12801
|
+
const isTranslatedRef = useRef({});
|
|
12802
|
+
const { data, loading, run } = useRequest(
|
|
12803
|
+
async () => {
|
|
12804
|
+
var _a2;
|
|
12805
|
+
if (!text || !enabled) {
|
|
12806
|
+
return "";
|
|
12807
|
+
}
|
|
12808
|
+
if (detectLanguageIso6391(text) === targetLanguage) {
|
|
12809
|
+
return text;
|
|
12810
|
+
}
|
|
12811
|
+
try {
|
|
12812
|
+
const { data: translations2 } = await minDelay(
|
|
12813
|
+
api.post("/translate", {
|
|
12814
|
+
pieces: [{ key, text }],
|
|
12815
|
+
targetLanguage,
|
|
12816
|
+
targetLanguageName
|
|
12817
|
+
}),
|
|
12818
|
+
500
|
|
12819
|
+
);
|
|
12820
|
+
return ((_a2 = translations2[0]) == null ? void 0 : _a2.translation) || text;
|
|
12821
|
+
} catch (error) {
|
|
12822
|
+
return text;
|
|
12823
|
+
}
|
|
12824
|
+
},
|
|
12825
|
+
{
|
|
12826
|
+
refreshDeps: [text, targetLanguage, key, enabled],
|
|
12827
|
+
manual: true
|
|
12828
|
+
}
|
|
12829
|
+
);
|
|
12830
|
+
useEffect(() => {
|
|
12831
|
+
if (enabled && !isTranslatedRef.current[targetLanguage]) {
|
|
12832
|
+
isTranslatedRef.current[targetLanguage] = true;
|
|
12833
|
+
run();
|
|
12834
|
+
}
|
|
12835
|
+
}, [enabled, run, targetLanguage]);
|
|
12836
|
+
return {
|
|
12837
|
+
translation: data,
|
|
12838
|
+
key,
|
|
12839
|
+
loading
|
|
12840
|
+
};
|
|
12841
|
+
};
|
|
12842
|
+
function Translate({ text, children, sx, ...rest }) {
|
|
12843
|
+
if (typeof children === "string" && !text) {
|
|
12844
|
+
text = children;
|
|
12845
|
+
}
|
|
12846
|
+
const ref = useRef(null);
|
|
12847
|
+
const [inViewport] = useInViewport(ref);
|
|
12848
|
+
const autoTranslate = useAutoTranslateStore((s) => s.autoTranslate);
|
|
12849
|
+
const enabled = !!inViewport && autoTranslate && isInlineTranslationAvailable;
|
|
12850
|
+
const { translation, loading } = useTranslate({ text, enabled });
|
|
12851
|
+
const mergedSx = [
|
|
12852
|
+
{
|
|
12853
|
+
"& .translate-loader": {
|
|
12854
|
+
boxSizing: "border-box",
|
|
12855
|
+
display: "inline-block",
|
|
12856
|
+
width: 13,
|
|
12857
|
+
height: 13,
|
|
12858
|
+
ml: 0.5,
|
|
12859
|
+
border: (theme) => `2px solid ${theme.palette.divider}`,
|
|
12860
|
+
borderBottomColor: "transparent",
|
|
12861
|
+
verticalAlign: "middle",
|
|
12862
|
+
borderRadius: "50%",
|
|
12863
|
+
animation: "rotation 1s linear infinite"
|
|
12864
|
+
},
|
|
12865
|
+
"@keyframes rotation": {
|
|
12866
|
+
"0%": {
|
|
12867
|
+
transform: "rotate(0deg)"
|
|
12868
|
+
},
|
|
12869
|
+
"100%": {
|
|
12870
|
+
transform: "rotate(360deg)"
|
|
12871
|
+
}
|
|
12872
|
+
}
|
|
12873
|
+
},
|
|
12874
|
+
...Array.isArray(sx) ? sx : [sx]
|
|
12875
|
+
];
|
|
12876
|
+
const render = () => {
|
|
12877
|
+
if (!enabled) {
|
|
12878
|
+
return text;
|
|
12879
|
+
}
|
|
12880
|
+
if (loading) {
|
|
12881
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
12882
|
+
text,
|
|
12883
|
+
/* @__PURE__ */ jsx(Box, { component: "span", className: "translate-loader" })
|
|
12884
|
+
] });
|
|
12885
|
+
}
|
|
12886
|
+
return translation;
|
|
12887
|
+
};
|
|
12888
|
+
return /* @__PURE__ */ jsx(Typography$1, { ref, sx: mergedSx, component: "span", ...rest, children: render() });
|
|
12889
|
+
}
|
|
12890
|
+
const tablerLanguage = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsxs("g", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, children: [
|
|
12891
|
+
/* @__PURE__ */ jsx("path", { d: "M4 5h7M9 3v2c0 4.418-2.239 8-5 8" }),
|
|
12892
|
+
/* @__PURE__ */ jsx("path", { d: "M5 9c0 2.144 2.952 3.908 6.7 4m.3 7l4-9l4 9m-.9-2h-6.2" })
|
|
12893
|
+
] }) });
|
|
12894
|
+
const tablerSettings = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsxs("g", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, children: [
|
|
12895
|
+
/* @__PURE__ */ jsx("path", { d: "M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 0 0-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 0 0-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 0 0-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 0 0-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 0 0 1.066-2.573c-.94-1.543.826-3.31 2.37-2.37c1 .608 2.296.07 2.572-1.065" }),
|
|
12896
|
+
/* @__PURE__ */ jsx("path", { d: "M9 12a3 3 0 1 0 6 0a3 3 0 0 0-6 0" })
|
|
12897
|
+
] }) });
|
|
12898
|
+
const useEditorStoreAdapter = () => {
|
|
12899
|
+
const { autoTranslate } = useAutoTranslateStore();
|
|
12900
|
+
const setAutoTranslate = useInlineTranslationStore((s) => s.setAutoTranslate);
|
|
12901
|
+
const showOriginal = useInlineTranslationStore((s) => s.showOriginal);
|
|
12902
|
+
useEffect(() => {
|
|
12903
|
+
setAutoTranslate(autoTranslate);
|
|
12904
|
+
if (!autoTranslate) {
|
|
12905
|
+
showOriginal();
|
|
12906
|
+
}
|
|
12907
|
+
}, [autoTranslate, setAutoTranslate, showOriginal]);
|
|
12908
|
+
};
|
|
12909
|
+
function withAiAvailabilityCheck(Component) {
|
|
12910
|
+
return (props) => {
|
|
12911
|
+
if (!isInlineTranslationAvailable) {
|
|
12912
|
+
return null;
|
|
12913
|
+
}
|
|
12914
|
+
return /* @__PURE__ */ jsx(Component, { ...props });
|
|
12915
|
+
};
|
|
12916
|
+
}
|
|
12917
|
+
function InternalAutoTranslateHeaderAddon({ ...rest }) {
|
|
12918
|
+
const { getLanguageName } = useLocaleContext();
|
|
12919
|
+
const { autoTranslate, enableAutoTranslate, disableAutoTranslate } = useAutoTranslateStore();
|
|
12920
|
+
const targetLanguage = useTargetLanguage();
|
|
12921
|
+
const targetLanguageName = getLanguageName(targetLanguage);
|
|
12922
|
+
const { session } = useSessionContext();
|
|
12923
|
+
useEditorStoreAdapter();
|
|
12924
|
+
if (!isInlineTranslationAvailable) {
|
|
12925
|
+
return null;
|
|
12926
|
+
}
|
|
12927
|
+
const tooltipTitle = () => {
|
|
12928
|
+
return /* @__PURE__ */ jsx(Box, { sx: { p: 0.25 }, children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body2", sx: { fontSize: 13 }, children: [
|
|
12929
|
+
"Automatic translation is ",
|
|
12930
|
+
autoTranslate ? "enabled" : "disabled",
|
|
12931
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5 }, children: [
|
|
12932
|
+
"Target language: ",
|
|
12933
|
+
targetLanguageName,
|
|
12934
|
+
!!(session == null ? void 0 : session.user) && /* @__PURE__ */ jsx(Link$1, { href: "/.well-known/service/user/settings", sx: { lineHeight: 1 }, children: /* @__PURE__ */ jsx(Box, { component: tablerSettings, sx: { fontSize: 12 } }) })
|
|
12935
|
+
] })
|
|
12936
|
+
] }) });
|
|
12937
|
+
};
|
|
12938
|
+
return /* @__PURE__ */ jsx(Tooltip$1, { title: tooltipTitle(), children: /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
12939
|
+
AddonButton,
|
|
12940
|
+
{
|
|
12941
|
+
...autoTranslate && {
|
|
12942
|
+
color: "primary",
|
|
12943
|
+
variant: "contained",
|
|
12944
|
+
sx: { color: "primary.contrastText" }
|
|
12945
|
+
},
|
|
12946
|
+
icon: /* @__PURE__ */ jsx(tablerLanguage, {}),
|
|
12947
|
+
...rest,
|
|
12948
|
+
onClick: () => autoTranslate ? disableAutoTranslate() : enableAutoTranslate()
|
|
12949
|
+
}
|
|
12950
|
+
) }) });
|
|
12951
|
+
}
|
|
12952
|
+
const AutoTranslateHeaderAddon = withAiAvailabilityCheck(InternalAutoTranslateHeaderAddon);
|
|
12620
12953
|
export {
|
|
12621
12954
|
ChatInWallet as $,
|
|
12622
12955
|
Avatar as A,
|
|
@@ -12669,6 +13002,16 @@ export {
|
|
|
12669
13002
|
isBlockletApp as aJ,
|
|
12670
13003
|
getUsername as aK,
|
|
12671
13004
|
isValidUser as aL,
|
|
13005
|
+
blockletExists as aM,
|
|
13006
|
+
isInlineTranslationAvailable as aN,
|
|
13007
|
+
useTranslate as aO,
|
|
13008
|
+
Translate as aP,
|
|
13009
|
+
AutoTranslateHeaderAddon as aQ,
|
|
13010
|
+
PostAutoTranslatePlugin as aR,
|
|
13011
|
+
PostAutoTranslationContainer as aS,
|
|
13012
|
+
useAutoTranslateStore as aT,
|
|
13013
|
+
useTargetLanguage as aU,
|
|
13014
|
+
useEditorStoreAdapter as aV,
|
|
12672
13015
|
ConfirmProvider as aa,
|
|
12673
13016
|
SecureLabelPicker as ab,
|
|
12674
13017
|
useApiErrorHandler as ac,
|