@blocklet/pages-kit 0.2.356 → 0.2.358

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.
@@ -15,23 +15,14 @@ import { CircularProgress, CssBaseline, GlobalStyles, ThemeProvider as MuiThemeP
15
15
  import { Suspense, useMemo } from 'react';
16
16
  import { Helmet } from 'react-helmet';
17
17
  import { useRuntimeState } from '../state/runtime';
18
+ import { chineseFonts } from '../utils/fonts';
18
19
  import GlobalLoading from './GlobalLoading';
19
- const getFontUrl = (fontList) => {
20
- var _a;
21
- if (!fontList.length)
22
- return;
23
- const BASE_URL = 'https://fonts.googleapis.com/css?family=';
24
- const newFontList = (_a = fontList
25
- .filter((font) => typeof font === 'string')) === null || _a === void 0 ? void 0 : _a.map((font) => font.replace(/ /g, '+')).join('|');
26
- // eslint-disable-next-line consistent-return
27
- return `${BASE_URL}${newFontList}`;
28
- };
29
20
  export default function ThemeProvider({ children }) {
30
21
  var _a, _b, _c;
31
22
  const { appearance } = useRuntimeState().agent.project;
32
23
  const theme = useTheme();
33
- const titleFont = (_a = appearance === null || appearance === void 0 ? void 0 : appearance.typography) === null || _a === void 0 ? void 0 : _a.fontFamily;
34
- const headFont = (_c = (_b = appearance === null || appearance === void 0 ? void 0 : appearance.typography) === null || _b === void 0 ? void 0 : _b.heading) === null || _c === void 0 ? void 0 : _c.fontFamily;
24
+ const bodyFontFamily = (_a = appearance === null || appearance === void 0 ? void 0 : appearance.typography) === null || _a === void 0 ? void 0 : _a.fontFamily;
25
+ const headingFontFamily = (_c = (_b = appearance === null || appearance === void 0 ? void 0 : appearance.typography) === null || _b === void 0 ? void 0 : _b.heading) === null || _c === void 0 ? void 0 : _c.fontFamily;
35
26
  const newTheme = useMemo(() => {
36
27
  var _a, _b, _c, _d, _e, _f;
37
28
  let { primary } = theme.palette;
@@ -158,7 +149,17 @@ export default function ThemeProvider({ children }) {
158
149
  ],
159
150
  });
160
151
  }, [theme]);
161
- return (_jsxs(MuiThemeProvider, { theme: newTheme, children: [_jsx(Helmet, { children: _jsx("link", { rel: "stylesheet", href: getFontUrl([titleFont, headFont]) }) }), _jsxs(CssBaseline, { children: [_jsx(GlobalStyles, { styles: (theme) => theme.unstable_sx({
152
+ const fontUrls = useMemo(() => {
153
+ const urls = [bodyFontFamily, headingFontFamily]
154
+ .filter((i) => !!i)
155
+ .map((font) => {
156
+ var _a;
157
+ return ((_a = chineseFonts.find((i) => i.value === font)) === null || _a === void 0 ? void 0 : _a.link) ||
158
+ `https://fonts.googleapis.com/css?family=${font.replace(/ /g, '+')}`;
159
+ });
160
+ return [...new Set(urls)];
161
+ }, [bodyFontFamily, headingFontFamily]);
162
+ return (_jsxs(MuiThemeProvider, { theme: newTheme, children: [_jsx(Helmet, { children: fontUrls.map((url) => (_jsx("link", { rel: "stylesheet", href: url }, url))) }), _jsxs(CssBaseline, { children: [_jsx(GlobalStyles, { styles: (theme) => theme.unstable_sx({
162
163
  'h1,h2,h3,h4,h5': {
163
164
  fontFamily: `${theme.typography.h1.fontFamily} !important`,
164
165
  },
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
14
14
  import { Icon } from '@iconify/react';
15
- import { Alert, Box, Button, Dialog, DialogContent, DialogTitle, Stack, Typography, alpha, } from '@mui/material';
15
+ import { Box, Button, Dialog, DialogContent, DialogTitle, Stack, Typography, alpha } from '@mui/material';
16
16
  import { useMemo, useState } from 'react';
17
17
  import { RelativeTime } from '../../../../arcblock/ux';
18
18
  import { useLocaleContext } from '../../../../locale';
@@ -37,16 +37,9 @@ export default function PhotoGalleryItem() {
37
37
  const { message } = useCurrentMessage();
38
38
  const [openDialog, setOpenDialog] = useState(false);
39
39
  const objects = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) !== null && _b !== void 0 ? _b : [];
40
- const images = objects.flatMap((i) => { var _a, _b; return (_b = (_a = i.data) === null || _a === void 0 ? void 0 : _a[RuntimeOutputVariable.images]) !== null && _b !== void 0 ? _b : []; });
41
- if (!images.length && message.error) {
42
- return (_jsx(Stack, { alignItems: "center", justifyContent: "center", sx: {
43
- aspectRatio: 1,
44
- bgcolor: 'grey.50',
45
- borderRadius: 1,
46
- overflow: 'hidden',
47
- wordBreak: 'break-word',
48
- }, children: _jsx(Alert, { severity: "error", sx: { bgcolor: 'transparent' }, children: message.error.message }) }));
49
- }
40
+ const images = objects.flatMap((i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) !== null && _a !== void 0 ? _a : []; });
41
+ if (!images.length && message.error)
42
+ throw message.error;
50
43
  return images.map(({ url }, index) => {
51
44
  var _a;
52
45
  return (_jsxs(Box, { sx: {
@@ -19,11 +19,13 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  return t;
20
20
  };
21
21
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
22
+ import { SubscriptionErrorType } from '@blocklet/ai-kit/api';
22
23
  import { Icon } from '@iconify/react';
23
24
  import { Box, Typography } from '@mui/material';
24
25
  import { memo, useCallback, useState } from 'react';
25
26
  import CustomComponentRenderer from '../../../../../../components/CustomComponentRenderer';
26
27
  import { useLocaleContext } from '../../../../../locale';
28
+ import { AgentErrorView } from '../../../components/AgentErrorBoundary';
27
29
  import LoadingButton from '../../../components/LoadingButton';
28
30
  import { useCurrentAgent } from '../../../contexts/CurrentAgent';
29
31
  import { useRuntimeState } from '../../../state/runtime';
@@ -33,6 +35,7 @@ import { AIRunningLoading } from './Loading';
33
35
  import TransparentTooltip from './TransparentTooltip';
34
36
  const codeField = 'code';
35
37
  function RetryComponent({ message, tip }) {
38
+ var _a;
36
39
  const { t } = useLocaleContext();
37
40
  const { execute } = useRuntimeState();
38
41
  const { aid } = useCurrentAgent();
@@ -50,14 +53,14 @@ function RetryComponent({ message, tip }) {
50
53
  }, children: [_jsx(Box, { component: Icon, icon: "unjs:automd", sx: {
51
54
  mt: 6,
52
55
  fontSize: 120,
53
- } }), _jsxs(Typography, { variant: "h6", sx: {
56
+ } }), ((_a = message === null || message === void 0 ? void 0 : message.error) === null || _a === void 0 ? void 0 : _a.type) === SubscriptionErrorType.UNSUBSCRIBED ? (_jsx(Box, { width: "100%", children: _jsx(AgentErrorView, { error: message.error }) })) : (_jsxs(Typography, { variant: "h6", sx: {
54
57
  display: 'flex',
55
58
  alignItems: 'center',
56
59
  }, children: [tip || t('v0.retryTip'), _jsx(TransparentTooltip, { arrow: true, placement: "top", title: _jsx(MessageErrorView, { error: (message === null || message === void 0 ? void 0 : message.error) || new Error('Code syntax errors'), sx: {
57
60
  mr: 0,
58
61
  } }), children: _jsx(Box, { component: Icon, icon: "akar-icons:info", sx: {
59
62
  ml: 1,
60
- } }) })] }), _jsx(LoadingButton, { variant: "contained", loading: loading, color: "primary", onClick: () => __awaiter(this, void 0, void 0, function* () {
63
+ } }) })] })), _jsx(LoadingButton, { variant: "contained", loading: loading, color: "primary", onClick: () => __awaiter(this, void 0, void 0, function* () {
61
64
  setLoading(true);
62
65
  try {
63
66
  const { inputs } = message || {};
@@ -0,0 +1,32 @@
1
+ export const chineseFonts = [
2
+ {
3
+ key: '东方大楷',
4
+ value: 'Alimama DongFangDaKai',
5
+ link: 'https://cdn.jsdelivr.net/npm/cn-fontsource-alimama-dong-fang-da-kai-regular/font.css',
6
+ },
7
+ {
8
+ key: '鸿雷行书',
9
+ value: 'hongleixingshu',
10
+ link: 'https://cdn.jsdelivr.net/npm/cn-fontsource-hongleixingshu-regular/font.css',
11
+ },
12
+ {
13
+ key: '方正楷体',
14
+ value: 'FZKai-Z03',
15
+ link: 'https://cdn.jsdelivr.net/npm/cn-fontsource-fz-kai-z-03-regular/font.css',
16
+ },
17
+ {
18
+ key: '方正宋体',
19
+ value: 'FZShuSong-Z01',
20
+ link: 'https://cdn.jsdelivr.net/npm/cn-fontsource-fz-shu-song-z-01-regular/font.css',
21
+ },
22
+ {
23
+ key: '方正黑体',
24
+ value: 'FZHei-B01',
25
+ link: 'https://cdn.jsdelivr.net/npm/cn-fontsource-fz-hei-b-01-regular/font.css',
26
+ },
27
+ {
28
+ key: '方正仿宋',
29
+ value: 'FZFangSong-Z02S',
30
+ link: 'https://cdn.jsdelivr.net/npm/cn-fontsource-fz-fang-song-z-02-s-regular/font.css',
31
+ },
32
+ ];