@blocklet/pages-kit-block-studio 0.1.26 → 0.1.28

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.
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.EditComponent = void 0;
15
+ exports.default = HelloWorld;
16
+ const jsx_runtime_1 = require("react/jsx-runtime");
17
+ // default export
18
+ function HelloWorld({ title = 'Hello World', logo, description, copyright }) {
19
+ return ((0, jsx_runtime_1.jsxs)("div", { style: {
20
+ display: 'flex',
21
+ flexDirection: 'column',
22
+ alignItems: 'center',
23
+ padding: '16px 0',
24
+ }, children: [title && (0, jsx_runtime_1.jsx)("h1", { children: title }), logo && ((0, jsx_runtime_1.jsx)("img", { src: typeof logo === 'object' ? logo.url : logo, alt: "logo", style: {
25
+ margin: '16px 0',
26
+ maxWidth: '200px',
27
+ } })), description && ((0, jsx_runtime_1.jsx)("div", { style: {
28
+ color: '#666',
29
+ marginTop: '8px',
30
+ }, children: description })), copyright && ((0, jsx_runtime_1.jsx)("div", { style: {
31
+ color: '#999',
32
+ fontSize: '12px',
33
+ marginTop: '16px',
34
+ }, children: copyright }))] }));
35
+ }
36
+ // export edit component
37
+ const EditComponent = (_a) => {
38
+ var { onChange } = _a, props = __rest(_a, ["onChange"]);
39
+ return ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', gap: '16px' }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
40
+ fontSize: '14px',
41
+ fontWeight: 500,
42
+ color: '#333',
43
+ padding: '8px 0',
44
+ borderBottom: '1px solid #eee',
45
+ }, children: "Footer Parameters" }), (0, jsx_runtime_1.jsx)("input", { id: "copyright-input", type: "text", style: {
46
+ width: '100%',
47
+ padding: '8px 12px',
48
+ border: '1px solid #ddd',
49
+ borderRadius: '4px',
50
+ fontSize: '14px',
51
+ transition: 'border-color 0.3s',
52
+ outline: 'none',
53
+ }, value: props.copyright || '', onChange: (e) => onChange === null || onChange === void 0 ? void 0 : onChange({ copyright: e.target.value }), placeholder: "Please Input Copyright" })] }));
54
+ };
55
+ exports.EditComponent = EditComponent;
@@ -59,6 +59,8 @@ const helper_1 = require("../utils/helper");
59
59
  const DID = 'z2qa7rr3eUyVnWp2PCxEVARuUfLFh6cE5V2xV';
60
60
  const RESOURCE_TYPE = 'page';
61
61
  const allTag = '@ALL_COMPONENTS';
62
+ // use for tracking build process
63
+ let currentBuildProcess = null;
62
64
  function copyFile(src, dest) {
63
65
  return new Promise((resolve, reject) => {
64
66
  const readStream = fs_1.default.createReadStream(src);
@@ -136,12 +138,19 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
136
138
  // ignore all tag
137
139
  const componentIds = resources.filter((resource) => resource.id !== allTag);
138
140
  try {
141
+ // if current build process exists, kill it
142
+ if (currentBuildProcess) {
143
+ currentBuildProcess.kill();
144
+ currentBuildProcess = null;
145
+ }
139
146
  // Execute build command with filtered components
140
147
  const buildProcess = (0, child_process_1.spawn)('pnpm', ['run', 'build-lib'], {
141
148
  stdio: 'inherit',
142
149
  shell: true,
143
- env: Object.assign(Object.assign({}, process.env), { FORCE_COLOR: '1', BLOCK_FILTER: componentIds.join(',') }),
150
+ env: Object.assign(Object.assign({}, process.env), { FORCE_COLOR: '1', BLOCK_FILTER: componentIds.join(','), NODE_OPTIONS: '--max_old_space_size=16384' }),
144
151
  });
152
+ // save current build process
153
+ currentBuildProcess = buildProcess;
145
154
  yield new Promise((resolve, reject) => {
146
155
  buildProcess.on('close', (code) => {
147
156
  if (code === 0)
@@ -149,18 +158,25 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
149
158
  else
150
159
  reject(new Error(`Build process exited with code ${code}`));
151
160
  });
161
+ buildProcess.on('error', (error) => {
162
+ console.error('Build process error:', error);
163
+ reject(error);
164
+ });
152
165
  });
153
166
  const dir = getExportDir(projectId, releaseId);
154
167
  fs_1.default.rmSync(dir, { recursive: true, force: true });
155
168
  fs_1.default.mkdirSync(dir, { recursive: true });
156
169
  const rootDir = process.cwd();
157
170
  const distDir = (0, path_1.join)(rootDir, helper_1.libDir);
171
+ const codeDir = (0, path_1.join)(distDir, 'es');
158
172
  const tmpPackage = (0, path_1.join)(distDir, 'resource-blocklet');
159
173
  fs_1.default.mkdirSync(tmpPackage, { recursive: true });
160
174
  const pagesDir = (0, path_1.join)(tmpPackage, 'pages');
161
175
  fs_1.default.mkdirSync(pagesDir, { recursive: true });
162
176
  const componentsDir = (0, path_1.join)(tmpPackage, 'components');
163
177
  fs_1.default.mkdirSync(componentsDir, { recursive: true });
178
+ const chunksDir = (0, path_1.join)(tmpPackage, 'chunks');
179
+ fs_1.default.mkdirSync(chunksDir, { recursive: true });
164
180
  // get @metadata.json by glob
165
181
  const canUseComponents = (0, helper_1.findComponentFiles)({ cwd: rootDir, filter: componentIds });
166
182
  // Filter and process metadata files
@@ -168,7 +184,7 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
168
184
  // get metadata
169
185
  const metadata = _metadata;
170
186
  // get code to metadata
171
- const code = fs_1.default.readFileSync((0, path_1.join)(distDir, 'es', `${blockName}.js`), 'utf8');
187
+ const code = fs_1.default.readFileSync((0, path_1.join)(codeDir, `${blockName}.js`), 'utf8');
172
188
  if (code) {
173
189
  (0, set_1.default)(metadata, 'renderer.script', code);
174
190
  (0, set_1.default)(metadata, 'renderer.type', 'react-component');
@@ -186,10 +202,13 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
186
202
  }
187
203
  return metadata;
188
204
  });
205
+ // cp _chunks dir
206
+ yield copyRecursive((0, path_1.join)(codeDir, '_chunks'), chunksDir);
189
207
  // write pages.config.yml
190
208
  const pagesConfigPath = path_1.default.join(tmpPackage, '.blocklet/pages/pages.config.yml');
191
209
  fs_1.default.mkdirSync(path_1.default.dirname(pagesConfigPath), { recursive: true });
192
210
  const pagesConfig = {
211
+ version: 2,
193
212
  pages: [],
194
213
  components: metadataList.map((metadata) => ({
195
214
  id: metadata.id,
@@ -21,6 +21,7 @@ exports.RESOLVED_VIRTUAL_MODULE_ID = `\0${exports.VIRTUAL_MODULE_ID}`;
21
21
  const isRelativePath = (path) => {
22
22
  return path.startsWith('./') || path.startsWith('../') || (!path.startsWith('http') && !path.startsWith('//'));
23
23
  };
24
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
24
25
  function extractExternalResources(html, _dirPath) {
25
26
  const external = {
26
27
  js: [],
@@ -204,6 +205,7 @@ ${content.trim()}`;
204
205
  name: (0, path_1.basename)(dirPath),
205
206
  };
206
207
  }
208
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
207
209
  function generateComponent(content, _isDev = true) {
208
210
  const htmlContent = content.html;
209
211
  const { name } = content;