@blocklet/pages-kit-block-studio 0.6.0 → 0.6.2
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-resource-router.js +35 -0
- package/lib/cjs/middlewares/init-uploader-router.js +0 -3
- package/lib/cjs/plugins/_theme.js +3 -2
- package/lib/cjs/plugins/vite-plugin-block-studio.js +5 -125
- package/lib/cjs/plugins/vite-plugin-code-splitter.js +594 -246
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/helper.js +17 -3
- package/lib/esm/middlewares/init-resource-router.js +36 -1
- package/lib/esm/middlewares/init-uploader-router.js +0 -3
- package/lib/esm/plugins/_theme.js +5 -4
- package/lib/esm/plugins/vite-plugin-block-studio.js +6 -126
- package/lib/esm/plugins/vite-plugin-code-splitter.js +562 -247
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/helper.js +13 -2
- package/lib/types/plugins/vite-plugin-block-studio.d.ts +0 -1
- package/lib/types/plugins/vite-plugin-code-splitter.d.ts +8 -4
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/helper.d.ts +6 -1
- package/package.json +5 -5
|
@@ -186,6 +186,8 @@ exports.initResourceRouter.post('/', async (req, res) => {
|
|
|
186
186
|
// get metadata
|
|
187
187
|
const metadata = _metadata;
|
|
188
188
|
const jsName = `${blockName}.js`;
|
|
189
|
+
// set version to 2
|
|
190
|
+
(0, set_1.default)(metadata, 'version', 2);
|
|
189
191
|
// get code to metadata
|
|
190
192
|
const code = fs_1.default.readFileSync((0, path_1.join)(codeDir, jsName), 'utf8');
|
|
191
193
|
if (code) {
|
|
@@ -207,6 +209,39 @@ exports.initResourceRouter.post('/', async (req, res) => {
|
|
|
207
209
|
catch (error) {
|
|
208
210
|
// ignore error
|
|
209
211
|
}
|
|
212
|
+
// get aigne output value schema
|
|
213
|
+
try {
|
|
214
|
+
const aigneOutputValueSchemaJsName = `${(0, helper_1.getAigneOutputValueSchemaBlockName)(blockName)}.js`;
|
|
215
|
+
const aigneOutputValueSchemaCode = fs_1.default.readFileSync((0, path_1.join)(codeDir, aigneOutputValueSchemaJsName), 'utf8');
|
|
216
|
+
if (aigneOutputValueSchemaCode) {
|
|
217
|
+
(0, set_1.default)(metadata, 'renderer.aigneOutputValueSchema', aigneOutputValueSchemaCode);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
// ignore error
|
|
222
|
+
}
|
|
223
|
+
// get properties schema
|
|
224
|
+
try {
|
|
225
|
+
const propertiesSchemaJsName = `${(0, helper_1.getPropertiesSchemaBlockName)(blockName)}.js`;
|
|
226
|
+
const propertiesSchemaCode = fs_1.default.readFileSync((0, path_1.join)(codeDir, propertiesSchemaJsName), 'utf8');
|
|
227
|
+
if (propertiesSchemaCode) {
|
|
228
|
+
(0, set_1.default)(metadata, 'renderer.PROPERTIES_SCHEMA', propertiesSchemaCode);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
// ignore error
|
|
233
|
+
}
|
|
234
|
+
// get getServerSideProps
|
|
235
|
+
try {
|
|
236
|
+
const getServerSidePropsJsName = `${(0, helper_1.getGetServerSidePropsBlockName)(blockName)}.js`;
|
|
237
|
+
const getServerSidePropsCode = fs_1.default.readFileSync((0, path_1.join)(codeDir, getServerSidePropsJsName), 'utf8');
|
|
238
|
+
if (getServerSidePropsCode) {
|
|
239
|
+
(0, set_1.default)(metadata, 'renderer.getServerSideProps', getServerSidePropsCode);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
// ignore error
|
|
244
|
+
}
|
|
210
245
|
// Handle preview image if exists
|
|
211
246
|
if (metadata.previewImage) {
|
|
212
247
|
const imagePath = path_1.default.join(path_1.default.dirname(fullPath), (0, helper_1.getPreviewImageRelativePath)(metadata.previewImage));
|
|
@@ -106,7 +106,4 @@ exports.initUploaderRouter.use('/uploads', (0, uploader_server_1.initProxyToMedi
|
|
|
106
106
|
exports.initUploaderRouter.use('/chunks', dynamicResourceMiddleware, staticResourceMiddleware, (_req, res) => {
|
|
107
107
|
res.status(404).send('CHUNK NOT FOUND').end();
|
|
108
108
|
});
|
|
109
|
-
exports.initUploaderRouter.use('/.well-known/chunks', dynamicResourceMiddleware, staticResourceMiddleware, (_req, res) => {
|
|
110
|
-
res.status(404).send('CHUNK NOT FOUND').end();
|
|
111
|
-
});
|
|
112
109
|
exports.default = exports.initUploaderRouter;
|
|
@@ -89,7 +89,7 @@ const api = (0, js_sdk_1.createAxios)({
|
|
|
89
89
|
}, {
|
|
90
90
|
componentDid: PAGES_KIT_BLOCK_STUDIO_BLOCKLET_DID,
|
|
91
91
|
});
|
|
92
|
-
const {
|
|
92
|
+
const { SessionContext } = (0, Session_1.createAuthServiceSessionContext)();
|
|
93
93
|
function useIsInsideIframe() {
|
|
94
94
|
const location = (0, react_router_dom_1.useLocation)();
|
|
95
95
|
const isInsideIframe = (0, react_1.useMemo)(() => {
|
|
@@ -229,6 +229,7 @@ const DraggableRouteItem = ({ route, staticDataInRoute, currentPageId, onNavigat
|
|
|
229
229
|
opacity: isHovered ? 0.7 : 0,
|
|
230
230
|
visibility: isHovered ? 'visible' : 'hidden',
|
|
231
231
|
transition: 'opacity 0.2s ease',
|
|
232
|
+
color: currentPageId === route ? 'white' : '',
|
|
232
233
|
'&:hover': {
|
|
233
234
|
bgcolor: 'error.main',
|
|
234
235
|
color: 'error.contrastText',
|
|
@@ -1219,7 +1220,7 @@ const StyledDashboard = (0, material_1.styled)(studio_ui_1.Dashboard) `
|
|
|
1219
1220
|
`;
|
|
1220
1221
|
function LayoutWrapper({ loadState, loadedData, ...rest }) {
|
|
1221
1222
|
const isInsideIframe = useIsInsideIframe();
|
|
1222
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
1223
|
+
return ((0, jsx_runtime_1.jsx)(theme_1.PagesKitThemeProvider, { isDashboard: !isInsideIframe, children: (0, jsx_runtime_1.jsx)(Toast_1.ToastProvider, { children: (0, jsx_runtime_1.jsx)(Layout, { loadState: loadState, loadedData: loadedData }) }) }));
|
|
1223
1224
|
}
|
|
1224
1225
|
exports.default = LayoutWrapper;
|
|
1225
1226
|
function CreateResource({ open, onClose }) {
|
|
@@ -38,18 +38,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.initBlockStudioPlugins = initBlockStudioPlugins;
|
|
40
40
|
// import typescript from '@rollup/plugin-typescript';
|
|
41
|
-
const builtin_module_transformer_1 = require("@blocklet/pages-kit/utils/typescript/builtin-module-transformer");
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
const chunks_analyzer_transformer_1 = require("@blocklet/pages-kit/utils/typescript/chunks-analyzer-transformer");
|
|
44
41
|
const fs_1 = require("fs");
|
|
45
42
|
const camelCase_1 = __importDefault(require("lodash/camelCase"));
|
|
46
43
|
const upperFirst_1 = __importDefault(require("lodash/upperFirst"));
|
|
47
|
-
const p_limit_1 = __importDefault(require("p-limit"));
|
|
48
44
|
const path = __importStar(require("path"));
|
|
49
|
-
const path_1 = require("path");
|
|
50
45
|
const rollup_plugin_external_globals_1 = __importDefault(require("rollup-plugin-external-globals"));
|
|
51
46
|
// import { visualizer } from 'rollup-plugin-visualizer';
|
|
52
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
53
47
|
const ufo_1 = require("ufo");
|
|
54
48
|
const vite_plugin_css_injected_by_js_1 = __importDefault(require("vite-plugin-css-injected-by-js"));
|
|
55
49
|
const vite_plugin_node_polyfills_1 = require("vite-plugin-node-polyfills");
|
|
@@ -74,12 +68,6 @@ const isMatchAfterSlachExternals = (id, externals) => {
|
|
|
74
68
|
return true;
|
|
75
69
|
}
|
|
76
70
|
}
|
|
77
|
-
// 检查其他外部依赖的子路径
|
|
78
|
-
for (const externalModule of Object.keys(externals)) {
|
|
79
|
-
if (id.startsWith(`${externalModule}/`)) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
71
|
return false;
|
|
84
72
|
};
|
|
85
73
|
const defaultBlockExternals = {
|
|
@@ -138,7 +126,6 @@ function initBlockStudioPlugins(options) {
|
|
|
138
126
|
const workingDir = options?.cwd || process.cwd();
|
|
139
127
|
const entryFilesPattern = options?.entryFilesPattern || (0, helper_1.getBlockEntryFilesPattern)();
|
|
140
128
|
const transpileBuiltinModule = options?.transpileBuiltinModule ?? true;
|
|
141
|
-
const ignoreSplitEditComponent = options?.ignoreSplitEditComponent ?? false;
|
|
142
129
|
const watchFilesDir = options?.watchFilesDir || (0, helper_1.getWatchFilesDir)() || workingDir;
|
|
143
130
|
// default fallback to __dirname if _theme.tsx not exists
|
|
144
131
|
let pagesDir = __dirname.replace('cjs', 'esm');
|
|
@@ -362,121 +349,14 @@ function initBlockStudioPlugins(options) {
|
|
|
362
349
|
}),
|
|
363
350
|
// initHtmlPreviewTransformPlugin(),
|
|
364
351
|
(0, vite_plugin_css_injected_by_js_1.default)(),
|
|
365
|
-
|
|
352
|
+
(0, vite_plugin_code_splitter_1.vitePluginCodeSplitter)({
|
|
353
|
+
formats,
|
|
354
|
+
transpileBuiltinModule,
|
|
355
|
+
}),
|
|
366
356
|
{
|
|
367
|
-
name: '
|
|
357
|
+
name: 'vite-plugin-build-exit',
|
|
368
358
|
apply: 'build',
|
|
369
359
|
enforce: 'post',
|
|
370
|
-
async writeBundle(options) {
|
|
371
|
-
// 用于存储每个格式的 chunks 映射
|
|
372
|
-
const allChunksMap = {};
|
|
373
|
-
// 对所有生成的 JavaScript 文件进行 transpileModule 处理
|
|
374
|
-
const transpileBuiltinModuleFn = (dir, format) => {
|
|
375
|
-
const files = (0, fs_1.readdirSync)(dir);
|
|
376
|
-
files.forEach((file) => {
|
|
377
|
-
const filePath = path.join(dir, file);
|
|
378
|
-
const stats = (0, fs_1.statSync)(filePath);
|
|
379
|
-
if (stats.isDirectory()) {
|
|
380
|
-
transpileBuiltinModuleFn(filePath, format); // 递归处理子目录
|
|
381
|
-
}
|
|
382
|
-
else if (file.endsWith('.js')) {
|
|
383
|
-
try {
|
|
384
|
-
const script = (0, fs_1.readFileSync)(filePath, 'utf8');
|
|
385
|
-
// @ts-ignore
|
|
386
|
-
const chunks = (0, chunks_analyzer_transformer_1.analyzeFileChunks)(typescript_1.default, script);
|
|
387
|
-
// ensure chunksMap is with all chunks
|
|
388
|
-
allChunksMap[(0, path_1.basename)(filePath)] = new Set(chunks);
|
|
389
|
-
const moduleMap = {
|
|
390
|
-
es: typescript_1.default.ModuleKind.ESNext,
|
|
391
|
-
cjs: typescript_1.default.ModuleKind.CommonJS,
|
|
392
|
-
umd: typescript_1.default.ModuleKind.ESNext,
|
|
393
|
-
};
|
|
394
|
-
const code = typescript_1.default.transpileModule(script, {
|
|
395
|
-
compilerOptions: {
|
|
396
|
-
jsx: typescript_1.default.JsxEmit.React,
|
|
397
|
-
target: typescript_1.default.ScriptTarget.ES2016,
|
|
398
|
-
module: moduleMap[format],
|
|
399
|
-
},
|
|
400
|
-
transformers: {
|
|
401
|
-
// @ts-ignore
|
|
402
|
-
before: [(0, builtin_module_transformer_1.createBuiltinModuleTransformer)(typescript_1.default)],
|
|
403
|
-
},
|
|
404
|
-
}).outputText;
|
|
405
|
-
(0, fs_1.writeFileSync)(filePath, code);
|
|
406
|
-
helper_1.logger.info(`Transpiled: ${filePath}`);
|
|
407
|
-
// updateStatus(`Transpiled: ${filePath}`);
|
|
408
|
-
}
|
|
409
|
-
catch (error) {
|
|
410
|
-
helper_1.logger.error(`Failed to transpile ${filePath}:`, error);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
// 返回一个 Promise 以便 await
|
|
415
|
-
return new Promise((resolve, reject) => {
|
|
416
|
-
try {
|
|
417
|
-
// ... 处理文件的代码 ...
|
|
418
|
-
resolve();
|
|
419
|
-
}
|
|
420
|
-
catch (error) {
|
|
421
|
-
reject(error);
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
};
|
|
425
|
-
// 获取输出目录
|
|
426
|
-
const outDir = options.dir || 'dist';
|
|
427
|
-
const limit = (0, p_limit_1.default)(20);
|
|
428
|
-
// 使用 Promise.all 等待所有格式处理完成
|
|
429
|
-
await Promise.all(formats.map(async (format) => {
|
|
430
|
-
const formatDir = path.resolve(outDir, `${format}`);
|
|
431
|
-
const chunkDir = path.resolve(formatDir, 'chunks');
|
|
432
|
-
// if not exists, create it
|
|
433
|
-
if (!(0, fs_1.existsSync)(chunkDir)) {
|
|
434
|
-
(0, fs_1.mkdirSync)(chunkDir, { recursive: true });
|
|
435
|
-
}
|
|
436
|
-
if (transpileBuiltinModule) {
|
|
437
|
-
await limit(() => transpileBuiltinModuleFn(formatDir, format));
|
|
438
|
-
}
|
|
439
|
-
}));
|
|
440
|
-
// 现在可以处理完整依赖链
|
|
441
|
-
helper_1.logger.info('all transpile tasks done, start to handle dependency chain...');
|
|
442
|
-
// 在这里处理 allChunksMap 的完整依赖链
|
|
443
|
-
Object.entries(allChunksMap).forEach(([entryFile, directDeps]) => {
|
|
444
|
-
// 收集所有间接依赖
|
|
445
|
-
const allDeps = [...directDeps];
|
|
446
|
-
// 递归寻找间接依赖
|
|
447
|
-
function findTransitiveDeps(chunks) {
|
|
448
|
-
chunks.forEach((chunk) => {
|
|
449
|
-
// 如果该chunk本身也是个入口(有依赖列表)
|
|
450
|
-
if (chunk in allChunksMap) {
|
|
451
|
-
const subDeps = allChunksMap[chunk];
|
|
452
|
-
// 添加未包含的依赖
|
|
453
|
-
if (subDeps) {
|
|
454
|
-
subDeps.forEach((dep) => {
|
|
455
|
-
if (!allDeps.includes(dep)) {
|
|
456
|
-
allDeps.push(dep);
|
|
457
|
-
// 递归寻找这个依赖的依赖
|
|
458
|
-
findTransitiveDeps([dep]);
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
// 开始递归查找
|
|
466
|
-
findTransitiveDeps([...directDeps]);
|
|
467
|
-
// 更新为完整依赖列表
|
|
468
|
-
allChunksMap[entryFile] = new Set(allDeps);
|
|
469
|
-
});
|
|
470
|
-
// 转换 Set 为数组以便正确序列化
|
|
471
|
-
const serializedMap = Object.entries(allChunksMap).reduce((result, [key, deps]) => {
|
|
472
|
-
result[key] = Array.from(deps);
|
|
473
|
-
return result;
|
|
474
|
-
}, {});
|
|
475
|
-
formats.forEach((format) => {
|
|
476
|
-
// 存下来
|
|
477
|
-
(0, fs_1.writeFileSync)(path.join(outDir, `${format}/chunks-map.json`), JSON.stringify(serializedMap, null, 2));
|
|
478
|
-
});
|
|
479
|
-
},
|
|
480
360
|
closeBundle() {
|
|
481
361
|
// ensure vite build exit
|
|
482
362
|
setTimeout(() => {
|