@blocklet/pages-kit-block-studio 0.4.61 → 0.4.62

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.
@@ -125,17 +125,25 @@ initPackResourceStates(({ states }: any) => {
125
125
  });
126
126
 
127
127
  router.get('/api/pages', async (req, res) => {
128
- const { did, projectId, siteFrom } = req.query;
128
+ const { did, projectId } = req.query;
129
129
 
130
- console.log('get state data', StateData);
131
- return res.json(StateData.state);
130
+ if (process.env.USE_ONLINE_STATE !== 'true') {
131
+ console.log('get state data', StateData);
132
+ return res.json(StateData.state);
133
+ }
134
+
135
+ // use online state
132
136
  try {
133
137
  // Case 1: Using did
134
138
  if (did) {
135
139
  const data = tempStates.find((state) => state.blockletId === did);
140
+ console.log('get state data from did', did, data);
136
141
  return res.json(data);
137
142
  }
138
143
 
144
+ // Get siteFrom from environment variable
145
+ const siteFrom = process.env.PAGES_KIT_SITE_FROM;
146
+
139
147
  // Case 2: Using projectId
140
148
  const tmpProjectId = projectId || PROJECT_ID;
141
149
  if (tmpProjectId) {
@@ -158,10 +166,12 @@ router.get('/api/pages', async (req, res) => {
158
166
  // 使用 axios 发起请求
159
167
  const { data } = await axios.get(apiUrl, {
160
168
  params: {
161
- secret: 'chunchunchunchun',
169
+ secret: '${project.npmSecret}',
162
170
  },
163
171
  });
164
172
 
173
+ console.log('get state data from projectId', data);
174
+
165
175
  return res.json(data);
166
176
  }
167
177
 
@@ -320,7 +330,7 @@ function getCustomComponentPropertyType(type) {
320
330
  return 'any';
321
331
  return 'any';
322
332
  }
323
- const ALLOWED_PROPERTY_TYPES = ['string', 'multiline', 'url', 'json', 'yaml'];
333
+ const ALLOWED_PROPERTY_TYPES = ['string', 'multiline', 'url', 'json', 'yaml', 'array'];
324
334
  function generatePageDataTypes(state) {
325
335
  // 递归生成TypeScript类型属性
326
336
  function generateTsTypeProperties(properties) {
@@ -353,6 +363,15 @@ function generatePageDataTypes(state) {
353
363
  typeStr = 'any';
354
364
  }
355
365
  }
366
+ else if (prop.data.type === 'array') {
367
+ if (prop.data.subProperties && Object.keys(prop.data.subProperties).length > 0) {
368
+ const subProps = generateTsTypeProperties(prop.data.subProperties).filter(Boolean).join('\n ');
369
+ typeStr = `{\n ${subProps}\n }[];`;
370
+ }
371
+ else {
372
+ typeStr = 'any[]';
373
+ }
374
+ }
356
375
  else {
357
376
  typeStr = 'any';
358
377
  }
@@ -403,6 +422,14 @@ function generatePageDataTypes(state) {
403
422
  const subProps = generateTsTypeProperties(prop.data.subProperties).filter(Boolean).join('\n ');
404
423
  return ` "${key}"?: {\n ${subProps}\n };`;
405
424
  }
425
+ // 处理数组类型
426
+ if (prop.data?.type === 'array') {
427
+ if (prop.data?.subProperties && Object.keys(prop.data.subProperties).length > 0) {
428
+ const subProps = generateTsTypeProperties(prop.data.subProperties).filter(Boolean).join('\n ');
429
+ return ` "${key}"?: {\n ${subProps}\n }[];`;
430
+ }
431
+ return ` "${key}"?: any[];`;
432
+ }
406
433
  return ` "${key}"?: ${getCustomComponentPropertyType(prop.data?.type)};`;
407
434
  })
408
435
  .filter(Boolean)
@@ -493,6 +520,16 @@ function generatePageDataJsonSchemas(state) {
493
520
  schemaProperties[key] = {};
494
521
  }
495
522
  }
523
+ else if (prop.data.type === 'array') {
524
+ // 处理数组类型 - 数组元素始终是对象
525
+ schemaProperties[key] = {
526
+ type: 'array',
527
+ items: {
528
+ type: 'object',
529
+ properties: prop.data.subProperties ? generateJsonSchemaProperties(prop.data.subProperties) : {},
530
+ },
531
+ };
532
+ }
496
533
  else {
497
534
  schemaProperties[key] = { type: 'string' };
498
535
  }
@@ -560,6 +597,16 @@ function generatePageDataJsonSchemas(state) {
560
597
  properties[key] = {};
561
598
  }
562
599
  }
600
+ else if (prop.data?.type === 'array') {
601
+ // 处理数组类型 - 数组元素始终是对象
602
+ properties[key] = {
603
+ type: 'array',
604
+ items: {
605
+ type: 'object',
606
+ properties: prop.data?.subProperties ? generateJsonSchemaProperties(prop.data.subProperties) : {},
607
+ },
608
+ };
609
+ }
563
610
  else {
564
611
  properties[key] = { type: 'string' };
565
612
  }