@blocklet/pages-kit-block-studio 0.4.66 → 0.4.68
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/middlewares/init-block-studio-router.js +14 -3
- package/lib/cjs/plugins/_theme.js +279 -241
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/ts-morph-utils.js +63 -0
- package/lib/cjs/utils/zod-utils.js +0 -111
- package/lib/esm/middlewares/init-block-studio-router.js +15 -4
- package/lib/esm/plugins/_theme.js +280 -242
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/ts-morph-utils.js +59 -0
- package/lib/esm/utils/zod-utils.js +0 -73
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/ts-morph-utils.d.ts +9 -0
- package/lib/types/utils/zod-utils.d.ts +0 -16
- package/package.json +4 -4
|
@@ -47,6 +47,7 @@ const constants_1 = require("../constants");
|
|
|
47
47
|
// 导入Zod相关工具
|
|
48
48
|
const block_props_utils_1 = require("../utils/block-props-utils");
|
|
49
49
|
const helper_1 = require("../utils/helper");
|
|
50
|
+
const ts_morph_utils_1 = require("../utils/ts-morph-utils");
|
|
50
51
|
const zod_utils_1 = require("../utils/zod-utils");
|
|
51
52
|
exports.initBlockStudioRouter = (0, express_1.Router)();
|
|
52
53
|
const BINARY_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.ico', '.svg'];
|
|
@@ -121,7 +122,7 @@ exports.initBlockStudioRouter.post('/', async (req, res) => {
|
|
|
121
122
|
try {
|
|
122
123
|
const dir = path_1.default.dirname(filePath);
|
|
123
124
|
if (!fs_1.default.existsSync(dir)) {
|
|
124
|
-
|
|
125
|
+
throw new Error('Directory not found');
|
|
125
126
|
}
|
|
126
127
|
const currentMetadata = (0, helper_1.initializeMetadata)(filePath);
|
|
127
128
|
const mergedContent = { ...currentMetadata, ...content };
|
|
@@ -191,7 +192,7 @@ exports.initBlockStudioRouter.post('/create', async (req, res) => {
|
|
|
191
192
|
return res.status(500).json({ error: 'Failed to create block' });
|
|
192
193
|
}
|
|
193
194
|
});
|
|
194
|
-
exports.initBlockStudioRouter.get('/
|
|
195
|
+
exports.initBlockStudioRouter.get('/resources', async (req, res) => {
|
|
195
196
|
const { withBlockletData = true } = req.query;
|
|
196
197
|
const allBlocks = await (0, helper_1.findComponentFiles)();
|
|
197
198
|
// get code to metadata
|
|
@@ -220,6 +221,10 @@ exports.initBlockStudioRouter.get('/all', async (req, res) => {
|
|
|
220
221
|
}
|
|
221
222
|
return res.json((0, lodash_1.keyBy)(allBlocksWithCode, 'id'));
|
|
222
223
|
});
|
|
224
|
+
exports.initBlockStudioRouter.get('/components', async (_req, res) => {
|
|
225
|
+
const allBlocks = await (0, helper_1.findComponentFiles)();
|
|
226
|
+
return res.json(allBlocks);
|
|
227
|
+
});
|
|
223
228
|
// 统一的属性到接口转换端点 - 可以预览或生成
|
|
224
229
|
exports.initBlockStudioRouter.post('/properties-to-interface', async (req, res) => {
|
|
225
230
|
const write = req.body.write === true;
|
|
@@ -308,7 +313,13 @@ exports.initBlockStudioRouter.post('/interface-to-properties', async (req, res)
|
|
|
308
313
|
return res.status(404).json({ success: false, error: 'BlockProps interface not found or could not be parsed' });
|
|
309
314
|
}
|
|
310
315
|
try {
|
|
311
|
-
const
|
|
316
|
+
const zodSchema = await (0, ts_morph_utils_1.tsFileToZodSchema)(componentPath, 'BlockProps');
|
|
317
|
+
const jsonSchema = (0, zod_utils_1.zodSchemaToJsonSchema)(zodSchema);
|
|
318
|
+
const newProperties = (0, zod_utils_1.jsonSchemaToProperties)(jsonSchema, {
|
|
319
|
+
existingProperties: currentMetadata.properties || {},
|
|
320
|
+
key: '',
|
|
321
|
+
isRoot: true,
|
|
322
|
+
});
|
|
312
323
|
// 如果请求要求写入文件
|
|
313
324
|
if (write) {
|
|
314
325
|
// 更新元数据
|