@blocklet/pages-kit 0.4.117 → 0.4.118

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,2 @@
1
+ export const PAGE_CONTENT_WRITER_AGENT_ID = 'page-content-writer';
2
+ export const AGENT_OPTIONS = [{ id: PAGE_CONTENT_WRITER_AGENT_ID, name: 'Page Content Writer' }];
@@ -48,4 +48,5 @@ export const BuiltinModules = {
48
48
  '@blocklet/pages-kit/builtin/async/ai-runtime': {},
49
49
  '@blocklet/pages-kit/builtin/uploader': {},
50
50
  '@blocklet/pages-kit/builtin/color-picker': {},
51
+ '@blocklet/pages-kit/builtin/markdown/index': {},
51
52
  };
@@ -0,0 +1,67 @@
1
+ import { cloneDeep } from 'lodash';
2
+ export function setPageDataSource(page, state, locale, pageData) {
3
+ try {
4
+ if (!page.locales) {
5
+ page.locales = {};
6
+ }
7
+ page.locales[locale] = cloneDeep(page.locales[locale] || {});
8
+ page.locales[locale].title = pageData.title ?? page.locales[locale].title;
9
+ page.locales[locale].image = pageData.image ?? page.locales[locale].image;
10
+ page.locales[locale].description = pageData.description ?? page.locales[locale].description;
11
+ // 遍历 pageData 的每个 key
12
+ Object.entries(pageData.sectionsData).forEach(([sectionKey, sectionData]) => {
13
+ try {
14
+ // 通过 id 或 name 找到对应的 section
15
+ const section = Object.values(page.sections).find((section) => section.id === sectionKey || section.name === sectionKey);
16
+ if (!section) {
17
+ return;
18
+ }
19
+ if (!section.isTemplateSection) {
20
+ return;
21
+ }
22
+ // 确保 section.locales 存在
23
+ section.locales = cloneDeep(section.locales || {});
24
+ section.locales[locale] = cloneDeep(section.locales[locale] || {});
25
+ if (section.component === 'custom-component') {
26
+ // 处理自定义组件
27
+ const componentId = section.config?.componentId;
28
+ if (!componentId) {
29
+ return;
30
+ }
31
+ // 从 state 中获取组件定义
32
+ const componentDef = state.components[componentId]?.data || state.resources.components?.[componentId]?.component;
33
+ if (!componentDef) {
34
+ return;
35
+ }
36
+ // 确保 properties 存在
37
+ section.locales[locale].properties = cloneDeep(section.locales[locale].properties || {});
38
+ // 遍历 sectionData,设置属性值
39
+ Object.entries(sectionData || {}).forEach(([propKey, propValue]) => {
40
+ // 尝试通过 key 或 id 找到属性定义
41
+ const property = componentDef?.properties?.[propKey] ||
42
+ Object.values(componentDef?.properties || {}).find((prop) => prop.data?.key === propKey);
43
+ if (property) {
44
+ // 设置属性值
45
+ section.locales[locale].properties[property.data?.id] = {
46
+ value: propValue,
47
+ };
48
+ }
49
+ });
50
+ }
51
+ else {
52
+ // 普通组件直接设置 properties
53
+ section.locales[locale] = {
54
+ ...cloneDeep(section.locales[locale]),
55
+ ...(sectionData || {}),
56
+ };
57
+ }
58
+ }
59
+ catch (error) {
60
+ console.error('Failed to set section data source:', error);
61
+ }
62
+ });
63
+ }
64
+ catch (error) {
65
+ console.error('Failed to set page data source:', error);
66
+ }
67
+ }
@@ -13,6 +13,7 @@ import * as emotionCss from '../builtin/emotion/css';
13
13
  import * as iconifyReact from '../builtin/iconify/react';
14
14
  import * as immer from '../builtin/immer';
15
15
  import * as locale from '../builtin/locale';
16
+ import * as markdownRenderer from '../builtin/markdown/index';
16
17
  import * as muiLab from '../builtin/mui/lab';
17
18
  import * as muiMaterial from '../builtin/mui/material';
18
19
  import * as pageHeader from '../builtin/page/header';
@@ -56,6 +57,7 @@ export function injectGlobalComponents() {
56
57
  '@blocklet/pages-kit/builtin/react-dom': reactDOM,
57
58
  '@blocklet/pages-kit/builtin/uploader': uploader,
58
59
  '@blocklet/pages-kit/builtin/color-picker': colorPicker,
60
+ '@blocklet/pages-kit/builtin/markdown/index': markdownRenderer,
59
61
  '@blocklet/pages-kit/builtin/emotion/css': emotionCss,
60
62
  '@blocklet/pages-kit/builtin/mui/material': muiMaterial,
61
63
  '@blocklet/pages-kit/builtin/mui/lab': muiLab,