@blocklet/pages-kit-block-studio 0.4.65 → 0.4.67
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/lib/cjs/constants/new-block-template/index.tsx +13 -4
- package/lib/cjs/middlewares/init-block-studio-router.js +201 -0
- package/lib/cjs/plugins/_theme.js +536 -3
- package/lib/cjs/plugins/vite-plugin-block-studio.js +2 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/types/properties.js +2 -0
- package/lib/cjs/utils/block-props-utils.js +151 -0
- package/lib/cjs/utils/generate-wrapper-code.js +127 -345
- package/lib/cjs/utils/ts-morph-utils.js +318 -0
- package/lib/cjs/utils/zod-utils.js +203 -0
- package/lib/esm/constants/new-block-template/index.tsx +13 -4
- package/lib/esm/middlewares/init-block-studio-router.js +168 -0
- package/lib/esm/plugins/_theme.js +501 -3
- package/lib/esm/plugins/vite-plugin-block-studio.js +2 -2
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/types/properties.js +1 -0
- package/lib/esm/utils/block-props-utils.js +114 -0
- package/lib/esm/utils/generate-wrapper-code.js +123 -345
- package/lib/esm/utils/ts-morph-utils.js +276 -0
- package/lib/esm/utils/zod-utils.js +196 -0
- package/lib/types/constants/new-block-template/index.d.ts +13 -6
- package/lib/types/plugins/_theme.d.ts +5 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/types/properties.d.ts +17 -0
- package/lib/types/utils/block-props-utils.d.ts +103 -0
- package/lib/types/utils/generate-wrapper-code.d.ts +24 -0
- package/lib/types/utils/ts-morph-utils.d.ts +33 -0
- package/lib/types/utils/zod-utils.d.ts +51 -0
- package/package.json +19 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type PropertyType = Text | Multiline | Decimal | Boolean | Color | URL | JSON;
|
|
2
|
+
export type Text = string;
|
|
3
|
+
export type Multiline = string;
|
|
4
|
+
export type Decimal = number;
|
|
5
|
+
export type Boolean = boolean;
|
|
6
|
+
export type Color = string;
|
|
7
|
+
export type URL = {
|
|
8
|
+
url: string;
|
|
9
|
+
mediaKitUrl?: string;
|
|
10
|
+
width?: string;
|
|
11
|
+
height?: string;
|
|
12
|
+
};
|
|
13
|
+
export type JSON = {
|
|
14
|
+
[key: string]: PropertyType;
|
|
15
|
+
};
|
|
16
|
+
export type Array = PropertyType[];
|
|
17
|
+
export type YAML = string;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BlockProps 接口处理工具
|
|
3
|
+
* 基于 Zod 重构设计,提供接口解析和转换功能
|
|
4
|
+
*/
|
|
5
|
+
import * as ts from 'typescript';
|
|
6
|
+
/**
|
|
7
|
+
* 基本组件部分类型定义
|
|
8
|
+
* 提供常用组件的TypeScript类型定义
|
|
9
|
+
*/
|
|
10
|
+
export declare const BASIC_COMPONENT_SECTION_TYPES: {
|
|
11
|
+
iframe: string;
|
|
12
|
+
section: string;
|
|
13
|
+
'section-card-list': string;
|
|
14
|
+
toc: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 基本组件部分JSON Schema定义
|
|
18
|
+
* 提供常用组件的JSON Schema定义
|
|
19
|
+
*/
|
|
20
|
+
export declare const BASIC_COMPONENT_SECTION_JSON_SCHEMAS: {
|
|
21
|
+
iframe: {
|
|
22
|
+
src: {
|
|
23
|
+
type: string;
|
|
24
|
+
};
|
|
25
|
+
title: {
|
|
26
|
+
type: string;
|
|
27
|
+
};
|
|
28
|
+
description: {
|
|
29
|
+
type: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
section: {
|
|
33
|
+
title: {
|
|
34
|
+
type: string;
|
|
35
|
+
};
|
|
36
|
+
description: {
|
|
37
|
+
type: string;
|
|
38
|
+
};
|
|
39
|
+
image: {
|
|
40
|
+
type: string;
|
|
41
|
+
};
|
|
42
|
+
imageMeta: {
|
|
43
|
+
type: string;
|
|
44
|
+
properties: {
|
|
45
|
+
naturalWidth: {
|
|
46
|
+
type: string;
|
|
47
|
+
};
|
|
48
|
+
naturalHeight: {
|
|
49
|
+
type: string;
|
|
50
|
+
};
|
|
51
|
+
filename: {
|
|
52
|
+
type: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
'section-card-list': {
|
|
58
|
+
title: {
|
|
59
|
+
type: string;
|
|
60
|
+
};
|
|
61
|
+
description: {
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
list: {
|
|
65
|
+
type: string;
|
|
66
|
+
items: {
|
|
67
|
+
type: string;
|
|
68
|
+
properties: {
|
|
69
|
+
id: {
|
|
70
|
+
type: string;
|
|
71
|
+
};
|
|
72
|
+
title: {
|
|
73
|
+
type: string;
|
|
74
|
+
};
|
|
75
|
+
description: {
|
|
76
|
+
type: string;
|
|
77
|
+
};
|
|
78
|
+
image: {
|
|
79
|
+
type: string;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
toc: {
|
|
86
|
+
title: {
|
|
87
|
+
type: string;
|
|
88
|
+
};
|
|
89
|
+
description: {
|
|
90
|
+
type: string;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* 查找并解析BlockProps接口
|
|
96
|
+
*/
|
|
97
|
+
export declare function findBlockPropsInterface(sourceFile: ts.SourceFile): {
|
|
98
|
+
found: boolean;
|
|
99
|
+
interfaceStart: number;
|
|
100
|
+
interfaceEnd: number;
|
|
101
|
+
interfaceText: string;
|
|
102
|
+
leadingComments: string;
|
|
103
|
+
};
|
|
@@ -1,5 +1,29 @@
|
|
|
1
|
+
import { LLMConfigProperty } from './zod-utils';
|
|
1
2
|
export declare function generateWrapperCode({ project, state, version }: any): Promise<{
|
|
2
3
|
fileName: string;
|
|
3
4
|
content: string;
|
|
4
5
|
}[]>;
|
|
6
|
+
/**
|
|
7
|
+
* 使用Zod生成JSON Schema
|
|
8
|
+
* 替代generatePropertiesJsonSchema
|
|
9
|
+
*/
|
|
10
|
+
export declare function generatePropertiesJsonSchemaWithZod({ properties, llmConfig, }: {
|
|
11
|
+
properties: Record<string, any>;
|
|
12
|
+
llmConfig: Record<string, LLMConfigProperty>;
|
|
13
|
+
}): any;
|
|
14
|
+
/**
|
|
15
|
+
* 使用Zod生成页面数据JSON Schema
|
|
16
|
+
* 替代generatePageDataJsonSchemas
|
|
17
|
+
*/
|
|
18
|
+
export declare function generatePageDataJsonSchemasWithZod(state: any): string;
|
|
19
|
+
/**
|
|
20
|
+
* 使用Zod生成页面数据类型
|
|
21
|
+
* 替代generatePageDataTypes
|
|
22
|
+
*/
|
|
23
|
+
export declare function generatePageDataTypesWithZod(state: any): string;
|
|
24
|
+
/**
|
|
25
|
+
* 使用Zod生成TypeScript类型属性
|
|
26
|
+
* 与现有generatePropertiesTypes函数保持相同签名
|
|
27
|
+
*/
|
|
28
|
+
export declare function generatePropertiesTypesWithZod(properties: Record<string, any>): string;
|
|
5
29
|
export default generateWrapperCode;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Project } from 'ts-morph';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* 创建 ts-morph 项目
|
|
5
|
+
* @param tsConfigFilePath tsconfig.json 文件路径
|
|
6
|
+
*/
|
|
7
|
+
export declare function createTsMorphProject(tsConfigFilePath?: string): Project;
|
|
8
|
+
/**
|
|
9
|
+
* 解析类型定义文件,提取指定类型及其依赖
|
|
10
|
+
* @param sourceFilePath 源文件路径
|
|
11
|
+
* @param typeName 要提取的类型名称
|
|
12
|
+
* @param tsConfigFilePath tsconfig.json 文件路径
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractTypeWithDependencies(sourceFilePath: string, typeName: string, tsConfigFilePath?: string): {
|
|
15
|
+
typeText: string;
|
|
16
|
+
dependencies: Map<string, string>;
|
|
17
|
+
imports: string[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* 组合类型及其依赖为完整的类型定义文本
|
|
21
|
+
* @param typeText 主类型文本
|
|
22
|
+
* @param dependencies 依赖类型集合
|
|
23
|
+
* @param imports 导入语句集合
|
|
24
|
+
*/
|
|
25
|
+
export declare function combineTypeDefinitions(typeText: string, dependencies: Map<string, string>, imports?: string[]): string;
|
|
26
|
+
/**
|
|
27
|
+
* 从TypeScript文件中的类型声明生成Zod schema
|
|
28
|
+
* 支持处理外部引用类型
|
|
29
|
+
* @param sourceFilePath 源文件路径
|
|
30
|
+
* @param typeName 类型名称
|
|
31
|
+
* @param tsConfigFilePath tsconfig.json 路径,默认为项目根目录下的tsconfig.json
|
|
32
|
+
*/
|
|
33
|
+
export declare function tsFileToZodSchema(sourceFilePath: string, typeName: string): Promise<z.ZodTypeAny>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CustomComponentProperty } from '@blocklet/pages-kit/types';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export type LLMConfigProperty = {
|
|
4
|
+
key: string;
|
|
5
|
+
displayName?: string;
|
|
6
|
+
isNeedGenerate: boolean;
|
|
7
|
+
describe: string;
|
|
8
|
+
subProperties?: Record<string, LLMConfigProperty>;
|
|
9
|
+
};
|
|
10
|
+
type PropertyToZodFn = (properties: CustomComponentProperty, { addZodDescribe, propLLMConfig }: {
|
|
11
|
+
addZodDescribe?: boolean;
|
|
12
|
+
propLLMConfig?: LLMConfigProperty;
|
|
13
|
+
}) => z.ZodTypeAny;
|
|
14
|
+
/**
|
|
15
|
+
* Properties 类型与 Schema 类型的映射关系
|
|
16
|
+
* blocklets/pages-kit/src/pages/page-maker/custom-component/setting.tsx
|
|
17
|
+
*/
|
|
18
|
+
export declare const PROPERTIES_TYPE_SCHEMA: {
|
|
19
|
+
propertyToZod: Record<string, PropertyToZodFn>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 从 Properties 对象创建 Zod schema
|
|
23
|
+
*/
|
|
24
|
+
export declare function propertiesToZodSchema(properties: Record<string, any>, { addZodDescribe, isOptional, llmConfig, }?: {
|
|
25
|
+
addZodDescribe?: boolean;
|
|
26
|
+
isOptional?: boolean;
|
|
27
|
+
llmConfig?: Record<string, LLMConfigProperty>;
|
|
28
|
+
}): z.ZodTypeAny;
|
|
29
|
+
/**
|
|
30
|
+
* 从JSON Schema生成Properties对象
|
|
31
|
+
*/
|
|
32
|
+
export declare function jsonSchemaToProperties(jsonSchema: any, { existingProperties, key, isRoot, index, }?: {
|
|
33
|
+
existingProperties?: Record<string, any>;
|
|
34
|
+
key?: string;
|
|
35
|
+
isRoot?: boolean;
|
|
36
|
+
index?: number;
|
|
37
|
+
}): Record<string, any>;
|
|
38
|
+
/**
|
|
39
|
+
* 从Zod schema生成TypeScript类型字符串
|
|
40
|
+
*/
|
|
41
|
+
export declare function zodSchemaToTypeString(schema: z.ZodTypeAny, typeName: string, removeUndefined?: boolean): string;
|
|
42
|
+
/**
|
|
43
|
+
* 从Zod schema生成JSON Schema
|
|
44
|
+
*/
|
|
45
|
+
export declare function zodSchemaToJsonSchema(schema: z.ZodTypeAny): import("zod-to-json-schema").JsonSchema7Type & {
|
|
46
|
+
$schema?: string | undefined;
|
|
47
|
+
definitions?: {
|
|
48
|
+
[key: string]: import("zod-to-json-schema").JsonSchema7Type;
|
|
49
|
+
} | undefined;
|
|
50
|
+
};
|
|
51
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/pages-kit-block-studio",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.67",
|
|
4
4
|
"description": "Pages Kit block studio for blocklet(s)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -43,6 +43,10 @@
|
|
|
43
43
|
"./init-block-studio-router": {
|
|
44
44
|
"import": "./lib/esm/middlewares/init-block-studio-router.js",
|
|
45
45
|
"require": "./lib/cjs/middlewares/init-block-studio-router.js"
|
|
46
|
+
},
|
|
47
|
+
"./frontend": {
|
|
48
|
+
"import": "./lib/esm/plugins/_theme.js",
|
|
49
|
+
"require": "./lib/cjs/plugins/_theme.js"
|
|
46
50
|
}
|
|
47
51
|
},
|
|
48
52
|
"typesVersions": {
|
|
@@ -76,6 +80,10 @@
|
|
|
76
80
|
"init-block-studio-router": [
|
|
77
81
|
"./lib/types/middlewares/init-block-studio-router.d.ts",
|
|
78
82
|
"./lib/types/middlewares/init-block-studio-router.d.ts"
|
|
83
|
+
],
|
|
84
|
+
"frontend": [
|
|
85
|
+
"./lib/types/plugins/_theme.d.ts",
|
|
86
|
+
"./lib/types/plugins/_theme.d.ts"
|
|
79
87
|
]
|
|
80
88
|
}
|
|
81
89
|
},
|
|
@@ -112,6 +120,8 @@
|
|
|
112
120
|
"react-dom": "^18.3.1",
|
|
113
121
|
"react-router-dom": "^6.26.1",
|
|
114
122
|
"rollup-plugin-external-globals": "^0.12.1",
|
|
123
|
+
"ts-morph": "^21.0.1",
|
|
124
|
+
"ts-to-zod": "^3.15.0",
|
|
115
125
|
"typescript": "^5.7.2",
|
|
116
126
|
"ufo": "^1.5.4",
|
|
117
127
|
"vite": "^5.4.11",
|
|
@@ -119,7 +129,10 @@
|
|
|
119
129
|
"vite-plugin-node-polyfills": "^0.23.0",
|
|
120
130
|
"vite-plugin-react-pages": "^5.0.0",
|
|
121
131
|
"yaml": "^2.5.0",
|
|
122
|
-
"
|
|
132
|
+
"zod": "^3.24.2",
|
|
133
|
+
"zod-to-json-schema": "^3.24.4",
|
|
134
|
+
"zod-to-ts": "^1.2.0",
|
|
135
|
+
"@blocklet/pages-kit": "0.4.67"
|
|
123
136
|
},
|
|
124
137
|
"devDependencies": {
|
|
125
138
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
@@ -141,7 +154,10 @@
|
|
|
141
154
|
"react": "^18.3.1",
|
|
142
155
|
"react-dom": "^18.3.1",
|
|
143
156
|
"react-router-dom": "^6.26.1",
|
|
144
|
-
"
|
|
157
|
+
"zod": "^3.24.2",
|
|
158
|
+
"zod-to-json-schema": "^3.24.4",
|
|
159
|
+
"zod-to-ts": "^1.2.0",
|
|
160
|
+
"@blocklet/pages-kit": "0.4.67"
|
|
145
161
|
},
|
|
146
162
|
"scripts": {
|
|
147
163
|
"lint": "eslint src --ext .mjs,.js,.jsx,.ts,.tsx",
|