@mybricks/to-code-taro 1.1.2 → 1.1.5

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.
Files changed (129) hide show
  1. package/dist/cjs/core/comlib/_Connector.js +49 -62
  2. package/dist/cjs/core/mybricks/createJSHandle.js +2 -1
  3. package/dist/cjs/core/utils/PopupRenderer.js +1 -1
  4. package/dist/cjs/core/utils/hooks.js +97 -38
  5. package/dist/cjs/core/utils/index.js +3 -0
  6. package/dist/cjs/core/utils/pool.js +63 -0
  7. package/dist/cjs/core/utils/slots.js +12 -5
  8. package/dist/cjs/core/utils/useContext.js +10 -6
  9. package/dist/cjs/core/utils/with.js +3 -3
  10. package/dist/cjs/generate/generateTaroProjectJson.js +15 -4
  11. package/dist/cjs/generate/utils/commonDir.js +12 -1
  12. package/dist/cjs/generate/utils/pageImages.d.ts +14 -0
  13. package/dist/cjs/generate/utils/pageImages.js +36 -0
  14. package/dist/cjs/handleCom.js +37 -14
  15. package/dist/cjs/handleDom.d.ts +2 -0
  16. package/dist/cjs/handleDom.js +5 -2
  17. package/dist/cjs/handleGlobal.js +4 -2
  18. package/dist/cjs/handleSlot.d.ts +3 -0
  19. package/dist/cjs/handleSlot.js +31 -7
  20. package/dist/cjs/taro-template.json +1258 -946
  21. package/dist/cjs/toCodeTaro.d.ts +2 -1
  22. package/dist/cjs/toCodeTaro.js +82 -1
  23. package/dist/cjs/utils/builder/buildResult.d.ts +1 -0
  24. package/dist/cjs/utils/builder/buildResult.js +53 -0
  25. package/dist/cjs/utils/config/content/converter.js +2 -2
  26. package/dist/cjs/utils/config/content/pageConfig.js +4 -1
  27. package/dist/cjs/utils/config/content/saveBase64Image.d.ts +10 -0
  28. package/dist/cjs/utils/config/content/saveBase64Image.js +44 -3
  29. package/dist/cjs/utils/config/content/tabBarConfig.js +8 -2
  30. package/dist/cjs/utils/context/buildContext.d.ts +7 -0
  31. package/dist/cjs/utils/context/buildContext.js +11 -0
  32. package/dist/cjs/utils/logic/handleProcess.js +3 -3
  33. package/dist/cjs/utils/logic/processChildren.d.ts +14 -1
  34. package/dist/cjs/utils/logic/processChildren.js +30 -6
  35. package/dist/cjs/utils/style/converter.js +34 -72
  36. package/dist/cjs/utils/templates/index.d.ts +1 -0
  37. package/dist/cjs/utils/templates/index.js +11 -2
  38. package/dist/cjs/utils/templates/renderManager.d.ts +4 -0
  39. package/dist/cjs/utils/templates/renderManager.js +10 -5
  40. package/dist/cjs/utils/templates/scene.js +2 -0
  41. package/dist/esm/core/comlib/_Connector.js +71 -54
  42. package/dist/esm/core/mybricks/createJSHandle.js +2 -1
  43. package/dist/esm/core/utils/PopupRenderer.js +1 -1
  44. package/dist/esm/core/utils/hooks.js +130 -53
  45. package/dist/esm/core/utils/index.js +1 -0
  46. package/dist/esm/core/utils/pool.js +52 -0
  47. package/dist/esm/core/utils/popupRouter.js +2 -1
  48. package/dist/esm/core/utils/slots.js +25 -23
  49. package/dist/esm/core/utils/useContext.js +19 -12
  50. package/dist/esm/core/utils/with.js +3 -3
  51. package/dist/esm/generate/generateTaroProjectJson.js +19 -2
  52. package/dist/esm/generate/utils/commonDir.js +15 -0
  53. package/dist/esm/generate/utils/pageImages.d.ts +14 -0
  54. package/dist/esm/generate/utils/pageImages.js +15 -0
  55. package/dist/esm/handleCom.js +44 -17
  56. package/dist/esm/handleDom.d.ts +2 -0
  57. package/dist/esm/handleDom.js +6 -4
  58. package/dist/esm/handleGlobal.js +4 -2
  59. package/dist/esm/handleSlot.d.ts +3 -0
  60. package/dist/esm/handleSlot.js +52 -10
  61. package/dist/esm/taro-template.json +1258 -946
  62. package/dist/esm/toCodeTaro.d.ts +2 -1
  63. package/dist/esm/toCodeTaro.js +92 -5
  64. package/dist/esm/utils/builder/buildResult.d.ts +1 -0
  65. package/dist/esm/utils/builder/buildResult.js +41 -1
  66. package/dist/esm/utils/config/content/converter.js +2 -2
  67. package/dist/esm/utils/config/content/pageConfig.js +4 -1
  68. package/dist/esm/utils/config/content/saveBase64Image.d.ts +10 -0
  69. package/dist/esm/utils/config/content/saveBase64Image.js +42 -1
  70. package/dist/esm/utils/config/content/tabBarConfig.js +7 -2
  71. package/dist/esm/utils/context/buildContext.d.ts +7 -0
  72. package/dist/esm/utils/context/buildContext.js +12 -0
  73. package/dist/esm/utils/logic/handleProcess.js +3 -3
  74. package/dist/esm/utils/logic/processChildren.d.ts +14 -1
  75. package/dist/esm/utils/logic/processChildren.js +45 -8
  76. package/dist/esm/utils/style/converter.js +57 -106
  77. package/dist/esm/utils/templates/index.d.ts +1 -0
  78. package/dist/esm/utils/templates/index.js +9 -2
  79. package/dist/esm/utils/templates/renderManager.d.ts +4 -0
  80. package/dist/esm/utils/templates/renderManager.js +19 -5
  81. package/dist/esm/utils/templates/scene.js +1 -0
  82. package/package.json +1 -1
  83. package/dist/esm/abstractEventTypeDef.d.ts.map +0 -1
  84. package/dist/esm/generate/generateTaroTempalteJson.d.ts.map +0 -1
  85. package/dist/esm/generate/utils/appConfig.d.ts.map +0 -1
  86. package/dist/esm/generate/utils/commonDir.d.ts.map +0 -1
  87. package/dist/esm/generate/utils/fileNode.d.ts.map +0 -1
  88. package/dist/esm/generate/utils/index.d.ts.map +0 -1
  89. package/dist/esm/generate/utils/tabBarImages.d.ts.map +0 -1
  90. package/dist/esm/handleCom.d.ts.map +0 -1
  91. package/dist/esm/handleDom.d.ts.map +0 -1
  92. package/dist/esm/handleExtension.d.ts.map +0 -1
  93. package/dist/esm/handleGlobal.d.ts.map +0 -1
  94. package/dist/esm/handleModule.d.ts.map +0 -1
  95. package/dist/esm/index.d.ts.map +0 -1
  96. package/dist/esm/processors/processComEvents.d.ts.map +0 -1
  97. package/dist/esm/processors/processModule.d.ts.map +0 -1
  98. package/dist/esm/processors/processScene.d.ts.map +0 -1
  99. package/dist/esm/processors/processSceneLogic.d.ts.map +0 -1
  100. package/dist/esm/toCodeTaro.d.ts.map +0 -1
  101. package/dist/esm/utils/builder/buildResult.d.ts.map +0 -1
  102. package/dist/esm/utils/common/ImportManager.d.ts.map +0 -1
  103. package/dist/esm/utils/common/helper.d.ts.map +0 -1
  104. package/dist/esm/utils/common/object.d.ts.map +0 -1
  105. package/dist/esm/utils/common/string.d.ts.map +0 -1
  106. package/dist/esm/utils/config/content/converter.d.ts.map +0 -1
  107. package/dist/esm/utils/config/content/index.d.ts.map +0 -1
  108. package/dist/esm/utils/config/content/pageConfig.d.ts.map +0 -1
  109. package/dist/esm/utils/config/content/saveBase64Image.d.ts.map +0 -1
  110. package/dist/esm/utils/config/content/tabBarConfig.d.ts.map +0 -1
  111. package/dist/esm/utils/config/content/types.d.ts.map +0 -1
  112. package/dist/esm/utils/config/content/validator.d.ts.map +0 -1
  113. package/dist/esm/utils/context/buildContext.d.ts.map +0 -1
  114. package/dist/esm/utils/context/buildFrameMap.d.ts.map +0 -1
  115. package/dist/esm/utils/context/buildGlobalData.d.ts.map +0 -1
  116. package/dist/esm/utils/context/collectJSModules.d.ts.map +0 -1
  117. package/dist/esm/utils/context/createEventQueries.d.ts.map +0 -1
  118. package/dist/esm/utils/context/createProvider.d.ts.map +0 -1
  119. package/dist/esm/utils/index.d.ts.map +0 -1
  120. package/dist/esm/utils/logic/convertNamespace.d.ts.map +0 -1
  121. package/dist/esm/utils/logic/handleProcess.d.ts.map +0 -1
  122. package/dist/esm/utils/logic/processChildren.d.ts.map +0 -1
  123. package/dist/esm/utils/style/color.d.ts.map +0 -1
  124. package/dist/esm/utils/style/getComponentClassName.d.ts.map +0 -1
  125. package/dist/esm/utils/style/pxtransform.d.ts.map +0 -1
  126. package/dist/esm/utils/style/types.d.ts.map +0 -1
  127. package/dist/esm/utils/templates/component.d.ts.map +0 -1
  128. package/dist/esm/utils/templates/index.d.ts.map +0 -1
  129. package/dist/esm/utils/templates/renderManager.d.ts.map +0 -1
@@ -64,7 +64,7 @@ export interface GeneratedFile {
64
64
  /** 当前页面/弹窗内用到的 JS 计算组件(用于生成 index.jsModules.ts) */
65
65
  jsModules?: import("./utils/context/collectJSModules").JSModule[];
66
66
  importManager: ImportManager;
67
- type: "normal" | "popup" | "module" | "global" | "extension-config" | "extension-api" | "extension-bus" | "abstractEventTypeDef" | "fx" | "api" | "extension-event" | "jsModulesRuntime" | "tabBarConfig" | "customTabBar";
67
+ type: "normal" | "popup" | "module" | "global" | "extension-config" | "extension-api" | "extension-bus" | "abstractEventTypeDef" | "fx" | "api" | "connector-api" | "extension-event" | "jsModulesRuntime" | "tabBarConfig" | "customTabBar";
68
68
  meta?: ReturnType<typeof toCode>["scenes"][0]["scene"];
69
69
  name: string;
70
70
  tabBarConfig?: string;
@@ -74,6 +74,7 @@ export interface GenerationResult {
74
74
  files: GeneratedFile[];
75
75
  assets?: {
76
76
  tabBarImages?: any[];
77
+ pageImages?: any[];
77
78
  };
78
79
  }
79
80
  /**
@@ -1,3 +1,5 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
1
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
4
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
5
  /**
@@ -9,10 +11,11 @@ import toCode from "@mybricks/to-code-react/dist/cjs/toCode";
9
11
  import handleGlobal from "./handleGlobal";
10
12
  import handleExtension from "./handleExtension";
11
13
  import { HandlePageConfig } from "./utils/config/handlePageConfig";
14
+ import { replaceBase64InText } from "./utils/config/content";
12
15
 
13
16
  // 工具函数
14
17
  import { buildFrameMap } from "./utils/context/buildFrameMap";
15
- import { buildSceneMap, buildEventsMap, createGetSceneById, createGetExtensionEventById, createGetFrameById } from "./utils/context/buildContext";
18
+ import { buildSceneMap, buildEventsMap, buildConnectorMap, createGetSceneById, createGetExtensionEventById, createGetFrameById } from "./utils/context/buildContext";
16
19
  import { createJSModulesCollector } from "./utils/context/collectJSModules";
17
20
  import { buildGlobalVarTypeDef, buildDefaultFxsMap } from "./utils/context/buildGlobalData";
18
21
  import { buildFinalResults } from "./utils/builder/buildResult";
@@ -60,6 +63,7 @@ var getCode = function getCode(params, config) {
60
63
  var eventsMap = buildEventsMap(tojson.frames);
61
64
  var getSceneById = createGetSceneById(sceneMap);
62
65
  var getExtensionEventById = createGetExtensionEventById(eventsMap);
66
+ var connectorMap = buildConnectorMap(tojson.plugins);
63
67
 
64
68
  // ========== 第二步:处理扩展事件 ==========
65
69
  files.push.apply(files, _toConsumableArray(handleExtension({
@@ -90,6 +94,33 @@ var getCode = function getCode(params, config) {
90
94
  var abstractEventTypeDefMap = {};
91
95
  var jsModulesCollector = createJSModulesCollector();
92
96
  var pageConfigHandler = new HandlePageConfig();
97
+ var pageBase64Images = [];
98
+ var pageImageIndex = new Map();
99
+ var nextImageIndex = function nextImageIndex(pageId, nameHint) {
100
+ var key = "".concat(pageId, "::").concat(nameHint);
101
+ var next = (pageImageIndex.get(key) || 0) + 1;
102
+ pageImageIndex.set(key, next);
103
+ return next;
104
+ };
105
+ var replaceBase64InObject = function replaceBase64InObject(value, pageId, nameHint) {
106
+ if (typeof value === "string") {
107
+ return replaceBase64InText(value, pageId, pageBase64Images, nameHint, function () {
108
+ return nextImageIndex(pageId, nameHint);
109
+ });
110
+ }
111
+ if (Array.isArray(value)) {
112
+ return value.map(function (item) {
113
+ return replaceBase64InObject(item, pageId, nameHint);
114
+ });
115
+ }
116
+ if (value && _typeof(value) === "object") {
117
+ Object.keys(value).forEach(function (key) {
118
+ value[key] = replaceBase64InObject(value[key], pageId, nameHint);
119
+ });
120
+ return value;
121
+ }
122
+ return value;
123
+ };
93
124
 
94
125
  // 提前识别所有弹窗场景
95
126
  var popupIds = new Set();
@@ -102,7 +133,29 @@ var getCode = function getCode(params, config) {
102
133
  }
103
134
  });
104
135
 
105
- // ========== 第六步:处理场景 ==========
136
+ // ========== 第六步:预处理 base64 图片(替换 data 中的 base64 为本地资源路径) ==========
137
+ scenes.forEach(function (_ref) {
138
+ var scene = _ref.scene;
139
+ var pageId = scene === null || scene === void 0 ? void 0 : scene.id;
140
+ if (!pageId) return;
141
+ Object.entries(scene.coms || {}).forEach(function (_ref2) {
142
+ var _com$model, _com$props, _com$props2;
143
+ var _ref3 = _slicedToArray(_ref2, 2),
144
+ comId = _ref3[0],
145
+ com = _ref3[1];
146
+ if (com !== null && com !== void 0 && (_com$model = com.model) !== null && _com$model !== void 0 && _com$model.data) {
147
+ com.model.data = replaceBase64InObject(com.model.data, pageId, "".concat(comId));
148
+ }
149
+ if (com !== null && com !== void 0 && (_com$props = com.props) !== null && _com$props !== void 0 && _com$props.data) {
150
+ com.props.data = replaceBase64InObject(com.props.data, pageId, "".concat(comId));
151
+ }
152
+ if (com !== null && com !== void 0 && (_com$props2 = com.props) !== null && _com$props2 !== void 0 && _com$props2.style) {
153
+ com.props.style = replaceBase64InObject(com.props.style, pageId, "".concat(comId));
154
+ }
155
+ });
156
+ });
157
+
158
+ // ========== 第七步:处理场景 ==========
106
159
  processScenes(scenes, {
107
160
  config: _objectSpread(_objectSpread({}, config), {}, {
108
161
  // @ts-ignore
@@ -121,7 +174,7 @@ var getCode = function getCode(params, config) {
121
174
  }
122
175
  });
123
176
 
124
- // ========== 第七步:处理模块 ==========
177
+ // ========== 第八步:处理模块 ==========
125
178
  processModules(modules, {
126
179
  config: config,
127
180
  globalVarTypeDef: globalVarTypeDef,
@@ -136,10 +189,43 @@ var getCode = function getCode(params, config) {
136
189
  }
137
190
  });
138
191
 
139
- // ========== 第八步:构建最终结果 ==========
192
+ // ========== 第九步:构建最终结果 ==========
193
+ // 为页面产物中的图片路径补充 import,并用变量名替换字符串
194
+ files.forEach(function (file) {
195
+ var _file$meta;
196
+ if (!file.content || !file.importManager || !((_file$meta = file.meta) !== null && _file$meta !== void 0 && _file$meta.id)) return;
197
+ var pageId = file.meta.id;
198
+ var regex = new RegExp("@/assets/".concat(pageId, "/([a-zA-Z0-9_\\-\\.]+\\.(?:png|jpg|jpeg|gif|webp|svg))"), "g");
199
+ var seen = new Map();
200
+ var updated = file.content;
201
+ var match;
202
+ while ((match = regex.exec(file.content)) !== null) {
203
+ var fileName = match[1];
204
+ if (!seen.has(fileName)) {
205
+ var base = fileName.replace(/\.[^.]+$/, "");
206
+ var varName = "".concat(base, "Img").replace(/[^a-zA-Z0-9_]/g, "_");
207
+ if (/^[0-9]/.test(varName)) {
208
+ varName = "img_".concat(varName);
209
+ }
210
+ seen.set(fileName, varName);
211
+ file.importManager.addImport({
212
+ packageName: "@/assets/".concat(pageId, "/").concat(fileName),
213
+ dependencyNames: [varName],
214
+ importType: "default"
215
+ });
216
+ }
217
+ }
218
+ seen.forEach(function (varName, fileName) {
219
+ var literal = "@/assets/".concat(pageId, "/").concat(fileName);
220
+ // 替换字符串字面量为变量(去掉引号)
221
+ updated = updated.split("\"".concat(literal, "\"")).join(varName).split("'".concat(literal, "'")).join(varName).split(literal).join(varName);
222
+ });
223
+ file.content = updated;
224
+ });
140
225
  var finalResultData = buildFinalResults({
141
226
  abstractEventTypeDefMap: abstractEventTypeDefMap,
142
227
  jsModulesMap: jsModulesCollector.getMap(),
228
+ connectorMap: connectorMap,
143
229
  globalTabBarConfig: pageConfigHandler.getTabBarConfig(),
144
230
  tabBarImageFiles: pageConfigHandler.getTabBarImageFiles(),
145
231
  customTabBarFileContent: pageConfigHandler.getCustomTabBarFileContent(),
@@ -150,7 +236,8 @@ var getCode = function getCode(params, config) {
150
236
  return {
151
237
  files: files,
152
238
  assets: {
153
- tabBarImages: finalResultData.tabBarImageFiles
239
+ tabBarImages: finalResultData.tabBarImageFiles,
240
+ pageImages: pageBase64Images
154
241
  }
155
242
  };
156
243
  };
@@ -7,6 +7,7 @@ import type { JSModulesMap } from "../context/collectJSModules";
7
7
  interface BuildResultParams {
8
8
  abstractEventTypeDefMap: Record<string, any>;
9
9
  jsModulesMap: JSModulesMap;
10
+ connectorMap: any;
10
11
  globalTabBarConfig: string | null;
11
12
  tabBarImageFiles: any[];
12
13
  popupIds: string[];
@@ -12,6 +12,7 @@ import { genJSModulesRuntime } from "../logic/genJSModules";
12
12
  export var buildFinalResults = function buildFinalResults(params) {
13
13
  var abstractEventTypeDefMap = params.abstractEventTypeDefMap,
14
14
  jsModulesMap = params.jsModulesMap,
15
+ connectorMap = params.connectorMap,
15
16
  globalTabBarConfig = params.globalTabBarConfig,
16
17
  tabBarImageFiles = params.tabBarImageFiles,
17
18
  popupIds = params.popupIds,
@@ -37,6 +38,16 @@ export var buildFinalResults = function buildFinalResults(params) {
37
38
  });
38
39
  }
39
40
 
41
+ // 生成 API 定义
42
+ if (connectorMap) {
43
+ files.push({
44
+ type: "connector-api",
45
+ content: generateApi(connectorMap),
46
+ importManager: new ImportManager(config),
47
+ name: "api"
48
+ });
49
+ }
50
+
40
51
  // 生成弹窗汇总文件 (popup.ts)
41
52
  if (popupIds.length > 0) {
42
53
  var registryContent = "";
@@ -77,4 +88,33 @@ export var buildFinalResults = function buildFinalResults(params) {
77
88
  files: files,
78
89
  tabBarImageFiles: tabBarImageFiles
79
90
  };
80
- };
91
+ };
92
+
93
+ /**
94
+ * 生成 API 定义代码
95
+ */
96
+ function generateApi(connectorMap) {
97
+ var connectors = connectorMap.connectors,
98
+ config = connectorMap.config;
99
+ var code = "/* eslint-disable @typescript-eslint/no-explicit-any */\n\n";
100
+ code += "export const api: Record<string, any> = {\n";
101
+ connectors.forEach(function (conn) {
102
+ code += " '".concat(conn.id, "': {\n");
103
+ code += " type: '".concat(conn.type, "',\n");
104
+ code += " input: ".concat(conn.input || 'function _RT_(params) { return params; }', ",\n");
105
+ code += " output: ".concat(conn.output || 'function _RT_(result) { return result; }', ",\n");
106
+ code += " method: '".concat(conn.method, "',\n");
107
+ code += " path: '".concat(conn.path, "',\n");
108
+ code += " globalMock: ".concat(conn.globalMock || false, ",\n");
109
+ code += " markList: ".concat(JSON.stringify(conn.markList || []), "\n");
110
+ code += " },\n";
111
+ });
112
+ code += "};\n\n";
113
+ code += "export const baseConfig = {\n";
114
+ code += " globalParamsFn: ".concat(config.paramsFn || 'function _RT_(params) { return params; }', ",\n");
115
+ code += " globalResultFn: ".concat(config.resultFn || 'function _RT_(response) { return response; }', ",\n");
116
+ code += " globalErrorResultFn: ".concat(config.errorResultFn || 'function _RT_(error) { throw error; }', ",\n");
117
+ code += " globalMock: ".concat(config.globalMock || false, "\n");
118
+ code += "};\n";
119
+ return code;
120
+ }
@@ -26,10 +26,10 @@ function convertTabBarItem(item, pageIdToPath) {
26
26
 
27
27
  // 添加图标路径(如果存在)
28
28
  if (item.normalIconPath) {
29
- taroItem.iconPath = processIcon ? processIcon(item.normalIconPath, index, 'normal') : item.normalIconPath;
29
+ taroItem.iconPath = processIcon ? processIcon(item.normalIconPath, index, 'normal') : item.normalIconPath.replace(/^\/?@\//, "");
30
30
  }
31
31
  if (item.selectedIconPath) {
32
- taroItem.selectedIconPath = processIcon ? processIcon(item.selectedIconPath, index, 'selected') : item.selectedIconPath;
32
+ taroItem.selectedIconPath = processIcon ? processIcon(item.selectedIconPath, index, 'selected') : item.selectedIconPath.replace(/^\/?@\//, "");
33
33
  }
34
34
  return taroItem;
35
35
  }
@@ -13,7 +13,10 @@ var TARO_PAGE_CONFIG_TEMPLATE_PROPERTIES = ['navigationBarBackgroundColor', 'nav
13
13
  * @returns definePageConfig 配置字符串
14
14
  */
15
15
  export function generatePageConfigContent(systemPageData) {
16
- var pageConfig = {};
16
+ var pageConfig = {
17
+ enableShareAppMessage: true,
18
+ enableShareTimeline: true
19
+ };
17
20
  if (systemPageData) {
18
21
  // 1. 处理导航栏隐藏逻辑:如果是 none,强制设置 navigationStyle 为 custom 以隐藏默认导航栏
19
22
  if (systemPageData.useNavigationStyle === "none") {
@@ -12,3 +12,13 @@ import type { ImageFileInfo } from './types';
12
12
  * @returns 处理后的图标路径(用于 app.config.ts),如果不是 base64 则返回原路径
13
13
  */
14
14
  export declare function processTabBarIcon(iconPath: string | undefined, tabBarIndex: number, type: "normal" | "selected", imageFiles?: ImageFileInfo[]): string | undefined;
15
+ /**
16
+ * 处理页面/组件 data 中的 base64 图片
17
+ * - 图片文件保存到 src/assets/<pageId>/ 目录(与 tabbar 同级)
18
+ * - data 中替换为 "@/assets/<pageId>/<fileName>"
19
+ */
20
+ export declare function processPageBase64Image(value: string, pageId: string, imageFiles: ImageFileInfo[], nameHint: string, index: number): string;
21
+ /**
22
+ * 替换字符串中的 base64 图片(支持 url(data:image/...) 形式)
23
+ */
24
+ export declare function replaceBase64InText(value: string, pageId: string, imageFiles: ImageFileInfo[], nameHint: string, getIndex: () => number): string;
@@ -43,6 +43,9 @@ var getFileExtension = function getFileExtension(mimeType) {
43
43
  var _MIME_TO_EXT$mimeType;
44
44
  return (_MIME_TO_EXT$mimeType = MIME_TO_EXT[mimeType.toLowerCase()]) !== null && _MIME_TO_EXT$mimeType !== void 0 ? _MIME_TO_EXT$mimeType : "png";
45
45
  };
46
+ var sanitizeName = function sanitizeName(name) {
47
+ return name.replace(/[^a-zA-Z0-9_]/g, "_").slice(0, 64) || "img";
48
+ };
46
49
 
47
50
  /**
48
51
  * 生成唯一的文件名
@@ -66,7 +69,7 @@ var generateFileName = function generateFileName(index, type, extension) {
66
69
  export function processTabBarIcon(iconPath, tabBarIndex, type, imageFiles) {
67
70
  if (!iconPath) return undefined;
68
71
  var parsed = parseBase64Image(iconPath);
69
- if (!parsed) return iconPath;
72
+ if (!parsed) return iconPath.replace(/^\/?@\//, "");
70
73
  var extension = getFileExtension(parsed.mimeType);
71
74
  var fileName = generateFileName(tabBarIndex, type, extension);
72
75
  var fileSystemPath = "src/assets/tabbar/".concat(fileName);
@@ -83,4 +86,42 @@ export function processTabBarIcon(iconPath, tabBarIndex, type, imageFiles) {
83
86
  }
84
87
  }
85
88
  return configPath;
89
+ }
90
+
91
+ /**
92
+ * 处理页面/组件 data 中的 base64 图片
93
+ * - 图片文件保存到 src/assets/<pageId>/ 目录(与 tabbar 同级)
94
+ * - data 中替换为 "@/assets/<pageId>/<fileName>"
95
+ */
96
+ export function processPageBase64Image(value, pageId, imageFiles, nameHint, index) {
97
+ var parsed = parseBase64Image(value);
98
+ if (!parsed) return value;
99
+ var extension = getFileExtension(parsed.mimeType);
100
+ var safeName = sanitizeName(nameHint);
101
+ var finalName = index > 1 ? "".concat(safeName, "_").concat(index) : safeName;
102
+ var fileName = "".concat(finalName, ".").concat(extension);
103
+ var fileSystemPath = "src/assets/".concat(pageId, "/").concat(fileName);
104
+ var aliasPath = "@/assets/".concat(pageId, "/").concat(fileName);
105
+ imageFiles.push({
106
+ filePath: fileSystemPath,
107
+ fileContent: Buffer.from(parsed.base64Data, "base64")
108
+ });
109
+ return aliasPath;
110
+ }
111
+
112
+ /**
113
+ * 替换字符串中的 base64 图片(支持 url(data:image/...) 形式)
114
+ */
115
+ export function replaceBase64InText(value, pageId, imageFiles, nameHint, getIndex) {
116
+ if (typeof value !== "string") return value;
117
+ var result = value;
118
+ // 支持一个字符串中多处 base64
119
+ while (true) {
120
+ var match = result.match(/data:image\/[^;]+;base64,[a-zA-Z0-9+/=]+/);
121
+ if (!match) break;
122
+ var currentIndex = getIndex();
123
+ var replaced = processPageBase64Image(match[0], pageId, imageFiles, nameHint, currentIndex);
124
+ result = result.replace(match[0], replaced);
125
+ }
126
+ return result;
86
127
  }
@@ -73,10 +73,15 @@ export function generateCustomTabBarFileContent(tabBar, config) {
73
73
  var _config$list$index = config.list[index],
74
74
  iconPath = _config$list$index.iconPath,
75
75
  selectedIconPath = _config$list$index.selectedIconPath;
76
+ var cleanPath = function cleanPath(p) {
77
+ if (!p) return undefined;
78
+ var cleaned = p.replace(/^\/?@\//, "").replace(/^\//, "");
79
+ return "/".concat(cleaned);
80
+ };
76
81
  return _objectSpread(_objectSpread({}, item), {}, {
77
82
  pagePath: config.list[index].pagePath,
78
- normalIconPath: iconPath ? "/".concat(iconPath) : undefined,
79
- selectedIconPath: selectedIconPath ? "/".concat(selectedIconPath) : undefined
83
+ normalIconPath: cleanPath(iconPath),
84
+ selectedIconPath: cleanPath(selectedIconPath)
80
85
  });
81
86
  });
82
87
  var tabBarJson = JSON.stringify(customTabbarConfig, null, 2);
@@ -10,6 +10,13 @@ export declare const buildSceneMap: (scenes: any[]) => any;
10
10
  * 构建扩展事件映射表
11
11
  */
12
12
  export declare const buildEventsMap: (frames: any[]) => any;
13
+ /**
14
+ * 构建连接器映射表
15
+ */
16
+ export declare const buildConnectorMap: (plugins: any) => {
17
+ connectors: any;
18
+ config: any;
19
+ };
13
20
  /**
14
21
  * 创建场景查询函数
15
22
  */
@@ -25,6 +25,18 @@ export var buildEventsMap = function buildEventsMap(frames) {
25
25
  }, {});
26
26
  };
27
27
 
28
+ /**
29
+ * 构建连接器映射表
30
+ */
31
+ export var buildConnectorMap = function buildConnectorMap(plugins) {
32
+ var servicePlugin = plugins === null || plugins === void 0 ? void 0 : plugins["@mybricks/plugins/service"];
33
+ if (!servicePlugin) return null;
34
+ return {
35
+ connectors: servicePlugin.connectors || [],
36
+ config: servicePlugin.config || {}
37
+ };
38
+ };
39
+
28
40
  /**
29
41
  * 创建场景查询函数
30
42
  */
@@ -159,7 +159,7 @@ export var handleProcess = function handleProcess(event, config) {
159
159
  var varKey = getSafeVarName(props.meta);
160
160
  if (props.meta.global) {
161
161
  config.addParentDependencyImport({
162
- packageName: config.getComponentPackageName(),
162
+ packageName: "../../common/global",
163
163
  dependencyNames: ["globalVars"],
164
164
  importType: "named"
165
165
  });
@@ -174,7 +174,7 @@ export var handleProcess = function handleProcess(event, config) {
174
174
  } else if (category === "fx") {
175
175
  if (props.meta.global) {
176
176
  config.addParentDependencyImport({
177
- packageName: config.getComponentPackageName(),
177
+ packageName: "../../common/global",
178
178
  dependencyNames: ["globalFxs"],
179
179
  importType: "named"
180
180
  });
@@ -401,7 +401,7 @@ var generateJsApiComponentCode = function generateJsApiComponentCode(params) {
401
401
 
402
402
  // 导入 createJSHandle
403
403
  config.addParentDependencyImport({
404
- packageName: "../../core/mybricks/index",
404
+ packageName: "@/core/mybricks/index",
405
405
  dependencyNames: ["createJSHandle"],
406
406
  importType: "named"
407
407
  });
@@ -5,9 +5,22 @@ export type ChildResult = {
5
5
  cssContent: string;
6
6
  slots: string[];
7
7
  scopeSlots: string[];
8
+ /** 所有层级的后代组件结果 */
8
9
  childrenResults?: any[];
10
+ /** 仅当前层级的直接子组件结果 */
11
+ directChildren?: any[];
9
12
  };
10
13
  /**
11
14
  * 统一处理子节点(com, dom, module)
12
15
  */
13
- export declare const processChildren: (children: UI["children"], config: any) => ChildResult;
16
+ export declare const processChildren: (children: UI["children"] | any[], config: any) => ChildResult;
17
+ /**
18
+ * 归一化子节点提取逻辑
19
+ * 兼容不同版本的 DSL 结构:
20
+ * 1. 数组直接返回
21
+ * 2. 包含 elements 的 DOM 包装层
22
+ * 3. 包含 layoutTemplate 的插槽
23
+ * 4. 包含 comAry 的传统插槽
24
+ * 5. 包含 children 的 Slot/Dom/Com 对象
25
+ */
26
+ export declare function normalizeChildren(input: any): any[];
@@ -13,9 +13,14 @@ export var processChildren = function processChildren(children, config) {
13
13
  var slots = [];
14
14
  var scopeSlots = [];
15
15
  var allChildrenResults = [];
16
- children.forEach(function (child) {
16
+ var directChildren = [];
17
+
18
+ // 归一化处理子节点:兼容 comAry, children, elements, layoutTemplate
19
+ var normalizedChildren = normalizeChildren(children);
20
+ normalizedChildren.forEach(function (child) {
17
21
  var result;
18
- if (child.type === "com") {
22
+ // 增加对 child.def 的判断,兼容 layoutTemplate 中的组件
23
+ if (child.type === "com" || child.def) {
19
24
  result = handleCom(child, config);
20
25
  } else if (child.type === "module") {
21
26
  result = handleModule(child, config);
@@ -23,18 +28,30 @@ export var processChildren = function processChildren(children, config) {
23
28
  result = handleDom(child, config);
24
29
  }
25
30
  if (result) {
26
- // 收集组件元数据(用于 RenderManager 的 wrap/itemWrap)
27
- if (child.type === "com") {
31
+ // 收集组件元数据
32
+ if (child.type === "com" || child.def) {
28
33
  var _meta, _props, _meta2;
29
34
  var comId = child.id || ((_meta = child.meta) === null || _meta === void 0 ? void 0 : _meta.id);
30
- allChildrenResults.push(_objectSpread(_objectSpread({}, result), {}, {
35
+ var childInfo = _objectSpread(_objectSpread({}, result), {}, {
31
36
  id: comId,
32
37
  // 优先使用 handleCom 解析出的稳定名称 (如 comName 别名)
33
38
  name: result.name || child.name || ((_props = child.props) === null || _props === void 0 || (_props = _props.data) === null || _props === void 0 ? void 0 : _props.name) || ((_meta2 = child.meta) === null || _meta2 === void 0 ? void 0 : _meta2.title) || comId,
34
- type: child.type,
39
+ type: child.type || "com",
35
40
  meta: child.meta,
36
41
  props: child.props
37
- }));
42
+ });
43
+ directChildren.push(childInfo);
44
+ allChildrenResults.push(childInfo);
45
+
46
+ // 递归收集所有后代
47
+ if (result.childrenResults) {
48
+ allChildrenResults.push.apply(allChildrenResults, _toConsumableArray(result.childrenResults));
49
+ }
50
+ } else {
51
+ // 如果是 DOM 或 Module,也要收集它们内部可能包含的组件
52
+ if (result.childrenResults) {
53
+ allChildrenResults.push.apply(allChildrenResults, _toConsumableArray(result.childrenResults));
54
+ }
38
55
  }
39
56
  if (result.ui) {
40
57
  uiCode += (uiCode ? "\n" : "") + result.ui;
@@ -59,6 +76,26 @@ export var processChildren = function processChildren(children, config) {
59
76
  cssContent: cssContent,
60
77
  slots: slots,
61
78
  scopeSlots: scopeSlots,
79
+ directChildren: directChildren,
62
80
  childrenResults: allChildrenResults
63
81
  };
64
- };
82
+ };
83
+
84
+ /**
85
+ * 归一化子节点提取逻辑
86
+ * 兼容不同版本的 DSL 结构:
87
+ * 1. 数组直接返回
88
+ * 2. 包含 elements 的 DOM 包装层
89
+ * 3. 包含 layoutTemplate 的插槽
90
+ * 4. 包含 comAry 的传统插槽
91
+ * 5. 包含 children 的 Slot/Dom/Com 对象
92
+ */
93
+ export function normalizeChildren(input) {
94
+ if (!input) return [];
95
+ if (Array.isArray(input)) return input;
96
+
97
+ // 优先级顺序:elements -> layoutTemplate -> comAry -> children
98
+ var list = input.elements || input.layoutTemplate || input.comAry || input.children;
99
+ if (Array.isArray(list)) return list;
100
+ return [];
101
+ }