@blocklet/pages-kit-block-studio 0.5.54 → 0.5.56

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.
@@ -205,7 +205,7 @@ router.get('/api/pages', async (req, res) => {
205
205
  return res.status(400).json({ message: 'Either did or projectId is required' });
206
206
  } catch (error) {
207
207
  console.error('Error fetching pages:', error);
208
- return res.status(500).json({ message: 'Internal server error' });
208
+ return res.status(400).json({ message: 'Internal server error' });
209
209
  }
210
210
  });
211
211
 
@@ -115,7 +115,7 @@ initBlockStudioRouter.get('/', async (req, res) => {
115
115
  return res.json(metadata);
116
116
  }
117
117
  catch (error) {
118
- return res.status(500).json({ error: 'Failed to read file' });
118
+ return res.status(400).json({ error: 'Failed to read file' });
119
119
  }
120
120
  });
121
121
  initBlockStudioRouter.post('/', async (req, res) => {
@@ -163,7 +163,7 @@ initBlockStudioRouter.post('/', async (req, res) => {
163
163
  return res.json({ success: true, content: mergedContent, message: 'Updated' });
164
164
  }
165
165
  catch (error) {
166
- return res.status(500).json({ error: 'Failed to write file' });
166
+ return res.status(400).json({ error: 'Failed to write file' });
167
167
  }
168
168
  });
169
169
  initBlockStudioRouter.post('/create', async (req, res) => {
@@ -225,7 +225,7 @@ initBlockStudioRouter.post('/create', async (req, res) => {
225
225
  }
226
226
  catch (error) {
227
227
  console.error('Failed to create block:', error);
228
- return res.status(500).json({ error: 'Failed to create block' });
228
+ return res.status(400).json({ error: 'Failed to create block' });
229
229
  }
230
230
  });
231
231
  initBlockStudioRouter.get('/resources', async (req, res) => {
@@ -319,7 +319,7 @@ initBlockStudioRouter.post('/properties-to-interface', async (req, res) => {
319
319
  }
320
320
  catch (conversionError) {
321
321
  console.error('Failed to convert properties to interface:', conversionError);
322
- return res.status(500).json({
322
+ return res.status(400).json({
323
323
  success: false,
324
324
  error: `Failed to convert properties to interface: ${conversionError.message}`,
325
325
  });
@@ -327,7 +327,7 @@ initBlockStudioRouter.post('/properties-to-interface', async (req, res) => {
327
327
  }
328
328
  catch (error) {
329
329
  console.error('Failed to generate interface:', error);
330
- return res.status(500).json({
330
+ return res.status(400).json({
331
331
  success: false,
332
332
  error: `Failed to generate interface: ${error.message}`,
333
333
  });
@@ -385,7 +385,7 @@ initBlockStudioRouter.post('/interface-to-properties', async (req, res) => {
385
385
  }
386
386
  catch (conversionError) {
387
387
  console.error('Failed to convert interface to properties:', conversionError);
388
- return res.status(500).json({
388
+ return res.status(400).json({
389
389
  success: false,
390
390
  error: `Failed to convert interface to properties: ${conversionError.message}`,
391
391
  });
@@ -393,7 +393,7 @@ initBlockStudioRouter.post('/interface-to-properties', async (req, res) => {
393
393
  }
394
394
  catch (error) {
395
395
  console.error('Failed to generate metadata:', error);
396
- return res.status(500).json({
396
+ return res.status(400).json({
397
397
  success: false,
398
398
  error: `Failed to generate metadata: ${error.message}`,
399
399
  });
@@ -455,7 +455,7 @@ initBlockStudioRouter.delete('/delete', async (req, res) => {
455
455
  }
456
456
  catch (deleteError) {
457
457
  console.error('Failed to delete component directory:', deleteError);
458
- return res.status(500).json({
458
+ return res.status(400).json({
459
459
  success: false,
460
460
  error: `Failed to delete component directory: ${deleteError.message}`,
461
461
  });
@@ -463,7 +463,7 @@ initBlockStudioRouter.delete('/delete', async (req, res) => {
463
463
  }
464
464
  catch (error) {
465
465
  console.error('Failed to delete component:', error);
466
- return res.status(500).json({
466
+ return res.status(400).json({
467
467
  success: false,
468
468
  error: `Failed to delete component: ${error.message}`,
469
469
  });
@@ -250,7 +250,7 @@ initResourceRouter.post('/', async (req, res) => {
250
250
  }
251
251
  catch (error) {
252
252
  console.error('Build failed:', error);
253
- res.status(500).json({ error: 'Build failed' });
253
+ res.status(400).json({ error: 'Build failed' });
254
254
  }
255
255
  });
256
256
  export default initResourceRouter;
@@ -8,12 +8,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
8
  import { createAuthServiceSessionContext } from '@arcblock/did-connect/lib/Session';
9
9
  import { useConfig } from '@arcblock/ux/lib/Config';
10
10
  import { LocaleProvider, useLocaleContext } from '@arcblock/ux/lib/Locale/context';
11
- import { ThemeProvider } from '@arcblock/ux/lib/Theme';
12
11
  import Toast, { ToastProvider } from '@arcblock/ux/lib/Toast';
13
12
  import { createAxios } from '@blocklet/js-sdk';
14
- import {
15
- // PageProvider,
16
- DashboardProvider, } from '@blocklet/pages-kit-inner-components/theme';
13
+ import { PagesKitThemeProvider } from '@blocklet/pages-kit-inner-components/theme';
17
14
  // @ts-ignore
18
15
  import { BasicInfo, ParametersConfig, PropertiesConfig } from '@blocklet/pages-kit-runtime/components';
19
16
  // @ts-ignore
@@ -55,6 +52,14 @@ const api = createAxios({
55
52
  componentDid: PAGES_KIT_BLOCK_STUDIO_BLOCKLET_DID,
56
53
  });
57
54
  const { SessionProvider, SessionContext } = createAuthServiceSessionContext();
55
+ function useIsInsideIframe() {
56
+ const location = useLocation();
57
+ const isInsideIframe = useMemo(() => {
58
+ const url = new URL(window.location.href);
59
+ return url.searchParams.get('simulator') === '1';
60
+ }, [location.href]);
61
+ return isInsideIframe;
62
+ }
58
63
  function useSessionContext() {
59
64
  const info = useContext(SessionContext);
60
65
  return info;
@@ -274,10 +279,7 @@ function Layout({ loadState, loadedData }) {
274
279
  const navigate = useNavigate();
275
280
  const staticData = useStaticData();
276
281
  // 获取当前URL参数判断是否是在iframe内
277
- const isInsideIframe = useMemo(() => {
278
- const url = new URL(window.location.href);
279
- return url.searchParams.get('simulator') === '1';
280
- }, [window.location.href]);
282
+ const isInsideIframe = useIsInsideIframe();
281
283
  useUpdateEffect(() => {
282
284
  const iframe = document.querySelector('#preview-iframe');
283
285
  if (iframe && iframe.contentWindow) {
@@ -639,11 +641,11 @@ function Layout({ loadState, loadedData }) {
639
641
  const url = new URL(window.location.href);
640
642
  const initialComponentId = url.searchParams.get('componentId') || state.metadata.id;
641
643
  const initialLocale = url.searchParams.get('locale') || locale || 'en';
642
- return (_jsx(Box, { className: "custom-component-root", sx: { height: '100vh', width: '100vw', overflow: 'auto' }, children: _jsx(ThemeProvider, { theme: theme, children: _jsx(CustomComponentRenderer, { locale: initialLocale, componentId: initialComponentId || state.metadata.id, dev: {
643
- mode: 'draft',
644
- components: mergedAllBlocks,
645
- defaultLocale,
646
- }, properties: mergedPropertiesValues }, `custom-${renderComponentTrigger}`) }) }));
644
+ return (_jsx(Box, { className: "custom-component-root", sx: { height: '100vh', width: '100vw', overflow: 'auto' }, children: _jsx(CustomComponentRenderer, { locale: initialLocale, componentId: initialComponentId || state.metadata.id, dev: {
645
+ mode: 'draft',
646
+ components: mergedAllBlocks,
647
+ defaultLocale,
648
+ }, properties: mergedPropertiesValues }, `custom-${renderComponentTrigger}`) }));
647
649
  }
648
650
  // 没有匹配到路由,使用欢迎页面
649
651
  if (notSelectedBlock) {
@@ -1128,7 +1130,8 @@ const StyledDashboard = styled(Dashboard) `
1128
1130
  }
1129
1131
  `;
1130
1132
  function LayoutWrapper({ loadState, loadedData, ...rest }) {
1131
- return (_jsx(StyledEngineProvider, { injectFirst: true, children: _jsx(DashboardProvider, { children: _jsx(ToastProvider, { children: _jsx(LocaleProvider, { translations: translations, fallbackLocale: "en", children: _jsx(SessionProvider, { serviceHost: basename, protectedRoutes: [`${basename}/*`], children: _jsx(Layout, { loadState: loadState, loadedData: loadedData }) }) }) }) }) }));
1133
+ const isInsideIframe = useIsInsideIframe();
1134
+ return (_jsx(StyledEngineProvider, { injectFirst: true, children: _jsx(PagesKitThemeProvider, { isDashboard: isInsideIframe, children: _jsx(ToastProvider, { children: _jsx(LocaleProvider, { translations: translations, fallbackLocale: "en", children: _jsx(SessionProvider, { serviceHost: basename, protectedRoutes: [`${basename}/*`], children: _jsx(Layout, { loadState: loadState, loadedData: loadedData }) }) }) }) }) }));
1132
1135
  }
1133
1136
  export default LayoutWrapper;
1134
1137
  function CreateResource({ open, onClose }) {