@blocklet/pages-kit-block-studio 0.4.73 → 0.4.74

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.
@@ -79,12 +79,9 @@ exports.PROPERTIES_TYPE_SCHEMA = {
79
79
  const { subProperties } = properties;
80
80
  if (subProperties && Object.keys(subProperties)?.length > 0) {
81
81
  // 使用联合类型:字符串或结构化对象
82
- return zod_1.z.union([
83
- zod_1.z.string(),
84
- propertiesToZodSchema(subProperties, { addZodDescribe, llmConfig: propLLMConfig?.subProperties }),
85
- ]);
82
+ return propertiesToZodSchema(subProperties, { addZodDescribe, llmConfig: propLLMConfig?.subProperties });
86
83
  }
87
- return zod_1.z.string();
84
+ return zod_1.z.object({});
88
85
  },
89
86
  array: (properties, { addZodDescribe, propLLMConfig }) => {
90
87
  const { subProperties } = properties;
@@ -15,6 +15,7 @@ import { BasicInfo, ParametersConfig, PropertiesConfig } from '@blocklet/pages-k
15
15
  // @ts-ignore
16
16
  import { translations } from '@blocklet/pages-kit-runtime/locales';
17
17
  import { CustomComponentRenderer } from '@blocklet/pages-kit/components';
18
+ import { parsePropertyValue } from '@blocklet/pages-kit/utils/property';
18
19
  // @ts-ignore
19
20
  import { Dashboard } from '@blocklet/studio-ui';
20
21
  import { BlockletStudio } from '@blocklet/ui-react';
@@ -22,6 +23,7 @@ import AddIcon from '@mui/icons-material/Add';
22
23
  import { Alert, Box, Button, CircularProgress, Dialog, DialogContent, DialogTitle, Drawer, List, ListItem, ListItemButton, Stack, StyledEngineProvider, TextField, ThemeProvider, Tooltip, Typography, backdropClasses, circularProgressClasses, styled, } from '@mui/material';
23
24
  import { useDebounceFn, useReactive } from 'ahooks';
24
25
  import cloneDeep from 'lodash/cloneDeep';
26
+ import get from 'lodash/get';
25
27
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
28
  import { Suspense, useCallback, useContext, useEffect, useMemo } from 'react';
27
29
  import { DndProvider } from 'react-dnd';
@@ -45,6 +47,7 @@ function useSessionContext() {
45
47
  }
46
48
  const LEFT_DRAWER_WIDTH = 200;
47
49
  const RIGHT_DRAWER_WIDTH = 300;
50
+ const defaultLocale = 'en';
48
51
  const ComparisonPreviewDialog = ({ open, title, leftTitle, leftContent, rightTitle, rightContent, description = '确认后将更新配置。', loading, onConfirm, onClose, }) => {
49
52
  const handleConfirm = async () => {
50
53
  try {
@@ -83,7 +86,6 @@ function Layout({ loadState, loadedData }) {
83
86
  createdAt: '',
84
87
  updatedAt: '',
85
88
  },
86
- data: {},
87
89
  allResources: {},
88
90
  searchValue: '',
89
91
  newBlockParams: {
@@ -103,6 +105,7 @@ function Layout({ loadState, loadedData }) {
103
105
  },
104
106
  init: false,
105
107
  allComponents: [],
108
+ propertiesValue: {},
106
109
  });
107
110
  const { locale } = useLocaleContext();
108
111
  const { session } = useSessionContext();
@@ -232,6 +235,18 @@ function Layout({ loadState, loadedData }) {
232
235
  description: '',
233
236
  };
234
237
  };
238
+ let mergedPropertiesValues = Object.fromEntries(Object.values(state.metadata.properties ?? {}).map(({ data }) => {
239
+ return [
240
+ data.id,
241
+ {
242
+ value: state.propertiesValue[data.id]?.value ??
243
+ parsePropertyValue(data, data.locales?.[locale]?.defaultValue ?? data.locales?.[defaultLocale]?.defaultValue, {
244
+ locale,
245
+ defaultLocale,
246
+ }),
247
+ },
248
+ ];
249
+ }));
235
250
  const getRenderContent = useCallback(() => {
236
251
  if (loadState.type === '404') {
237
252
  return null;
@@ -241,12 +256,12 @@ function Layout({ loadState, loadedData }) {
241
256
  }
242
257
  // const pageData = loadedData[loadState.routePath];
243
258
  // const Component = pageData.main.default;
244
- // return <Component {...state.data} />;
259
+ // return <Component />;
245
260
  return [
246
- _jsx(CustomComponentRenderer, { locale: locale, componentId: state.metadata.id, dev: { mode: 'draft', components: mergedAllBlocks, defaultLocale: 'en' }, props: state.data }, "custom"),
247
- // <Component key="original" {...state.data} />,
261
+ _jsx(CustomComponentRenderer, { locale: locale, componentId: state.metadata.id, dev: { mode: 'draft', components: mergedAllBlocks, defaultLocale }, properties: mergedPropertiesValues }, "custom"),
262
+ // <Component key="original" />,
248
263
  ];
249
- }, [loadedData, loadState, locale, state.injectBlocks, state.metadata, mergedAllBlocks]);
264
+ }, [loadedData, loadState, locale, state.injectBlocks, state.metadata, mergedAllBlocks, mergedPropertiesValues]);
250
265
  // add auto redirect to first route
251
266
  if (loadState.type === '404' &&
252
267
  !routes.includes(location.pathname) &&
@@ -331,7 +346,7 @@ function Layout({ loadState, loadedData }) {
331
346
  position: 'relative',
332
347
  height: '100%',
333
348
  },
334
- }, children: _jsxs(List, { sx: { display: 'flex', flexDirection: 'column', gap: 1 }, children: [_jsx(ListItem, { children: _jsx(Box, { sx: { width: '100%' }, children: _jsx(BasicInfo, { config: state.metadata }) }) }), _jsx(ListItem, { children: _jsxs(Box, { sx: { width: '100%' }, children: [_jsx(PropertiesConfig, { config: state.metadata, currentLocale: locale, defaultLocale: "en", allComponents: mergedAllBlocks, onUpdateConfig: (updater) => {
349
+ }, children: _jsxs(List, { sx: { display: 'flex', flexDirection: 'column', gap: 1 }, children: [_jsx(ListItem, { children: _jsx(Box, { sx: { width: '100%' }, children: _jsx(BasicInfo, { config: state.metadata }) }) }), _jsx(ListItem, { children: _jsxs(Box, { sx: { width: '100%' }, children: [_jsx(PropertiesConfig, { config: state.metadata, currentLocale: locale, defaultLocale: defaultLocale, allComponents: mergedAllBlocks, onUpdateConfig: (updater) => {
335
350
  updater(state.metadata);
336
351
  }, useI18nEditor: false }), _jsxs(Stack, { direction: "column", spacing: 1, sx: { mt: 1 }, children: [_jsx(Button, { variant: "contained", size: "small", color: "primary", onClick: async () => {
337
352
  try {
@@ -440,16 +455,15 @@ function Layout({ loadState, loadedData }) {
440
455
  console.error('生成接口预览失败:', error);
441
456
  Toast.error('生成接口预览失败');
442
457
  }
443
- }, children: "Properties \u2192 Interface" })] })] }) }), state.metadata.id && (_jsx(ListItem, { children: _jsx(Box, { sx: { width: '100%' }, children: _jsx(ParametersConfig, { config: state.metadata, allComponents: mergedAllBlocks, defaultLocale: "en", locale: locale,
444
- // 不需要 propertiesValue
445
- // propertiesValue={{}}
446
- onChange: ({ key, value }) => {
447
- state.data = {
448
- ...state.data,
449
- [key]: value.value,
458
+ }, children: "Properties \u2192 Interface" })] })] }) }), state.metadata.id && (_jsx(ListItem, { children: _jsx(Box, { sx: { width: '100%' }, children: _jsx(ParametersConfig, { config: state.metadata, allComponents: mergedAllBlocks, defaultLocale: defaultLocale, locale: locale, propertiesValue: mergedPropertiesValues, onChange: ({ key, value, id, path, ...rest }) => {
459
+ const property = get(state.metadata, [...path, 'data']);
460
+ const realValue = parsePropertyValue(property, value.value, {
461
+ locale,
462
+ defaultLocale,
463
+ });
464
+ state.propertiesValue[id] = {
465
+ value: realValue,
450
466
  };
451
- }, props: {
452
- ...state.data,
453
467
  } }) }) }))] }) }), _jsx(CreateResource, { open: state.createResourceOpen, onClose: () => {
454
468
  state.createResourceOpen = false;
455
469
  } }), _jsxs(Dialog, { open: state.createBlockOpen, onClose: onCloseCreateBlock, children: [_jsx(DialogTitle, { children: "Create New Block" }), _jsx(DialogContent, { children: _jsxs(Stack, { spacing: 2, sx: { pt: 1, minWidth: 300 }, children: [_jsx(TextField, { autoFocus: true, required: true, label: "Name", fullWidth: true, value: state.newBlockParams.name, onChange: (e) => {