@blocklet/pages-kit-block-studio 0.0.17 → 0.0.18
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 +12 -13
- package/lib/cjs/plugins/vite-plugin-block-studio.js +1 -0
- package/lib/cjs/plugins/vite-plugin-html-transform.js +5 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/helper.js +20 -1
- package/lib/esm/middlewares/init-block-studio-router.js +9 -10
- package/lib/esm/plugins/vite-plugin-block-studio.js +2 -1
- package/lib/esm/plugins/vite-plugin-html-transform.js +5 -2
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/helper.js +18 -0
- package/lib/types/plugins/vite-plugin-html-transform.d.ts +14 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/helper.d.ts +1 -0
- package/package.json +1 -1
|
@@ -16,8 +16,6 @@ exports.initBlockStudioRouter = void 0;
|
|
|
16
16
|
const express_1 = require("express");
|
|
17
17
|
const fs_1 = __importDefault(require("fs"));
|
|
18
18
|
const lodash_1 = require("lodash");
|
|
19
|
-
const lodash_2 = require("lodash");
|
|
20
|
-
const lodash_3 = require("lodash");
|
|
21
19
|
const path_1 = __importDefault(require("path"));
|
|
22
20
|
const helper_1 = require("../utils/helper");
|
|
23
21
|
exports.initBlockStudioRouter = (0, express_1.Router)();
|
|
@@ -45,10 +43,10 @@ exports.initBlockStudioRouter.get('/', (req, res) => __awaiter(void 0, void 0, v
|
|
|
45
43
|
return fs_1.default.createReadStream(filePath).pipe(res);
|
|
46
44
|
}
|
|
47
45
|
const metadata = (0, helper_1.initializeMetadata)(filePath);
|
|
48
|
-
const code =
|
|
46
|
+
const code = (0, helper_1.getBlockCode)(filePath);
|
|
49
47
|
if (code) {
|
|
50
|
-
(0,
|
|
51
|
-
(0,
|
|
48
|
+
(0, lodash_1.set)(metadata, 'renderer.script', code);
|
|
49
|
+
(0, lodash_1.set)(metadata, 'renderer.type', 'react-component');
|
|
52
50
|
}
|
|
53
51
|
return res.json(metadata);
|
|
54
52
|
}
|
|
@@ -74,8 +72,6 @@ exports.initBlockStudioRouter.post('/', (req, res) => __awaiter(void 0, void 0,
|
|
|
74
72
|
}
|
|
75
73
|
const currentMetadata = (0, helper_1.initializeMetadata)(filePath);
|
|
76
74
|
const mergedContent = Object.assign(Object.assign({}, currentMetadata), content);
|
|
77
|
-
// remove renderer
|
|
78
|
-
delete mergedContent.renderer;
|
|
79
75
|
if ((0, lodash_1.isEqual)(currentMetadata, mergedContent)) {
|
|
80
76
|
return res.json({ success: true, content: mergedContent, message: 'No changes' });
|
|
81
77
|
}
|
|
@@ -91,8 +87,11 @@ exports.initBlockStudioRouter.post('/', (req, res) => __awaiter(void 0, void 0,
|
|
|
91
87
|
});
|
|
92
88
|
}
|
|
93
89
|
}
|
|
90
|
+
res.json({ success: true, content: mergedContent, message: 'Updated' });
|
|
91
|
+
// save metadata without renderer after response
|
|
92
|
+
delete mergedContent.renderer;
|
|
94
93
|
fs_1.default.writeFileSync(filePath, JSON.stringify(mergedContent, null, 2));
|
|
95
|
-
return
|
|
94
|
+
return null;
|
|
96
95
|
}
|
|
97
96
|
catch (error) {
|
|
98
97
|
return res.status(500).json({ error: 'Failed to write file' });
|
|
@@ -103,10 +102,10 @@ exports.initBlockStudioRouter.get('/all', (req, res) => __awaiter(void 0, void 0
|
|
|
103
102
|
const allBlocks = yield (0, helper_1.findComponentFiles)();
|
|
104
103
|
// get code to metadata
|
|
105
104
|
const allBlocksWithCode = allBlocks.map((block) => {
|
|
106
|
-
const code =
|
|
105
|
+
const code = (0, helper_1.getBlockCode)(block.fullPath);
|
|
107
106
|
if (code) {
|
|
108
|
-
(0,
|
|
109
|
-
(0,
|
|
107
|
+
(0, lodash_1.set)(block.metadata, 'renderer.script', code);
|
|
108
|
+
(0, lodash_1.set)(block.metadata, 'renderer.type', 'react-component');
|
|
110
109
|
}
|
|
111
110
|
return block;
|
|
112
111
|
});
|
|
@@ -123,8 +122,8 @@ exports.initBlockStudioRouter.get('/all', (req, res) => __awaiter(void 0, void 0
|
|
|
123
122
|
};
|
|
124
123
|
return item;
|
|
125
124
|
});
|
|
126
|
-
return res.json((0,
|
|
125
|
+
return res.json((0, lodash_1.keyBy)(allBlocksWithBlockletData, 'data.id'));
|
|
127
126
|
}
|
|
128
|
-
res.json((0,
|
|
127
|
+
return res.json((0, lodash_1.keyBy)(allBlocksWithCode, 'id'));
|
|
129
128
|
}));
|
|
130
129
|
exports.default = exports.initBlockStudioRouter;
|
|
@@ -169,6 +169,7 @@ function initBlockStudioPlugins(options) {
|
|
|
169
169
|
? {
|
|
170
170
|
isHtmlPreview: true,
|
|
171
171
|
dataPath: filePath,
|
|
172
|
+
code: (0, vite_plugin_html_transform_1.generateComponent)((0, vite_plugin_html_transform_1.readHtmlFiles)(dirPath.split('?dir=')[1] || '')),
|
|
172
173
|
blockName,
|
|
173
174
|
dirPath,
|
|
174
175
|
metadataPath,
|
|
@@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RESOLVED_VIRTUAL_MODULE_ID = exports.VIRTUAL_MODULE_ID = void 0;
|
|
13
|
+
exports.readHtmlFiles = readHtmlFiles;
|
|
14
|
+
exports.generateComponent = generateComponent;
|
|
13
15
|
exports.initHtmlPreviewTransformPlugin = initHtmlPreviewTransformPlugin;
|
|
14
16
|
const fs_1 = require("fs");
|
|
15
17
|
const path_1 = require("path");
|
|
@@ -191,6 +193,9 @@ ${content.trim()}`;
|
|
|
191
193
|
function generateComponent(content, _isDev = true) {
|
|
192
194
|
const htmlContent = content.html;
|
|
193
195
|
const { name } = content;
|
|
196
|
+
if (_isDev) {
|
|
197
|
+
// do something
|
|
198
|
+
}
|
|
194
199
|
return `import { createElement } from 'react';
|
|
195
200
|
|
|
196
201
|
export default function HtmlPreview() {
|