@blocklet/pages-kit-block-studio 0.4.89 → 0.4.91

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.
@@ -38,8 +38,10 @@ exports.generatePropertiesJsonSchemaWithZod = generatePropertiesJsonSchemaWithZo
38
38
  exports.generatePageDataJsonSchemasWithZod = generatePageDataJsonSchemasWithZod;
39
39
  exports.generatePageDataTypesWithZod = generatePageDataTypesWithZod;
40
40
  exports.generatePropertiesTypesWithZod = generatePropertiesTypesWithZod;
41
+ exports.generatePageSectionsDataZod = generatePageSectionsDataZod;
41
42
  // 导入 Zod 工具集
42
43
  const property_1 = require("@blocklet/pages-kit/utils/property");
44
+ const zod_1 = require("zod");
43
45
  const block_props_utils_1 = require("./block-props-utils");
44
46
  const zod_utils_1 = require("./zod-utils");
45
47
  async function generateWrapperCode({ project, state, version }) {
@@ -501,4 +503,74 @@ function generatePropertiesTypesWithZod(properties) {
501
503
  const typeString = (0, zod_utils_1.zodSchemaToTypeString)(zodSchema, 'Props');
502
504
  return typeString;
503
505
  }
506
+ /**
507
+ * 生成特定页面所有 section 数据的 Zod 类型定义
508
+ * @param state 应用状态
509
+ * @param pageId 目标页面ID
510
+ * @returns 包含所有 section 数据类型的 Zod schema
511
+ */
512
+ function generatePageSectionsDataZod(state, pageId) {
513
+ const page = state.pages[pageId];
514
+ if (!page) {
515
+ return zod_1.z.object({}).describe('Empty page data');
516
+ }
517
+ const sectionSchemas = {};
518
+ // 收集页面所有section的配置信息
519
+ page.sectionIds.forEach((sectionId) => {
520
+ const section = page.sections[sectionId];
521
+ if (!section || !section.isTemplateSection)
522
+ return;
523
+ const sectionName = section.name || section.id;
524
+ if (section.component === 'custom-component') {
525
+ const componentId = section.config?.componentId;
526
+ if (!componentId)
527
+ return;
528
+ const component = state.components[componentId]?.data || state.resources.components?.[componentId]?.component;
529
+ if (!component)
530
+ return;
531
+ // 使用propertiesToZodSchema生成Zod Schema,并包含llmConfig配置
532
+ const zodSchema = (0, zod_utils_1.propertiesToZodSchema)(component.properties || {}, {
533
+ addZodDescribe: false,
534
+ llmConfig: section.llmConfig?.properties || {},
535
+ });
536
+ // 添加section描述
537
+ sectionSchemas[sectionName] = zodSchema.describe(section.templateDescription || '');
538
+ }
539
+ else if (block_props_utils_1.BASIC_COMPONENT_SECTION_TYPES[section.component]) {
540
+ // 处理基本组件类型
541
+ const componentType = section.component;
542
+ const schemaProperties = block_props_utils_1.BASIC_COMPONENT_SECTION_JSON_SCHEMAS[componentType];
543
+ // 将JSON Schema转换为Zod Schema
544
+ const zodProperties = Object.entries(schemaProperties || {}).reduce((acc, [key, value]) => {
545
+ // 简单处理常见类型
546
+ if (value.type === 'string') {
547
+ acc[key] = zod_1.z.string().optional();
548
+ }
549
+ else if (value.type === 'number') {
550
+ acc[key] = zod_1.z.number().optional();
551
+ }
552
+ else if (value.type === 'boolean') {
553
+ acc[key] = zod_1.z.boolean().optional();
554
+ }
555
+ else if (value.type === 'array') {
556
+ acc[key] = zod_1.z.array(zod_1.z.any()).optional();
557
+ }
558
+ else if (value.type === 'object') {
559
+ acc[key] = zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional();
560
+ }
561
+ else {
562
+ acc[key] = zod_1.z.any().optional();
563
+ }
564
+ return acc;
565
+ }, {});
566
+ sectionSchemas[sectionName] = zod_1.z.object(zodProperties).describe(section.templateDescription || '');
567
+ }
568
+ else {
569
+ // 其他类型的section,使用默认对象
570
+ sectionSchemas[sectionName] = zod_1.z.object({}).describe(section.templateDescription || '');
571
+ }
572
+ });
573
+ // 创建包含所有section的schema
574
+ return zod_1.z.object(sectionSchemas).describe(`Page ${page.title || pageId} sections data`);
575
+ }
504
576
  exports.default = generateWrapperCode;
@@ -456,7 +456,13 @@ function Layout({ loadState, loadedData }) {
456
456
  Toast.error('生成接口预览失败');
457
457
  }
458
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']);
459
+ const realPath = [...path, 'data'];
460
+ const property = get(state.metadata, realPath);
461
+ // ensure property exist
462
+ if (!property) {
463
+ Toast.warning(`无法找到属性,请检查在 @metadata.json 中,是否存在该属性: ${realPath.join('.')}`);
464
+ return;
465
+ }
460
466
  const realValue = parsePropertyValue(property, value.value, {
461
467
  locale,
462
468
  defaultLocale,