@mybricks/to-code-taro 1.0.5 → 1.0.7

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 (57) hide show
  1. package/dist/cjs/core/utils/ComContext.js +11 -2
  2. package/dist/cjs/core/utils/hooks.js +13 -4
  3. package/dist/cjs/core/utils/index.js +9 -2
  4. package/dist/cjs/core/utils/slots.js +124 -0
  5. package/dist/cjs/core/utils/useContext.js +10 -6
  6. package/dist/cjs/core/utils/with.js +32 -5
  7. package/dist/cjs/generate/generateTaroProjectJson.js +2 -2
  8. package/dist/cjs/handleCom.d.ts +7 -30
  9. package/dist/cjs/handleCom.js +171 -61
  10. package/dist/cjs/handleSlot.d.ts +3 -0
  11. package/dist/cjs/handleSlot.js +27 -10
  12. package/dist/cjs/processors/processScene.js +34 -1
  13. package/dist/cjs/processors/processSceneLogic.js +1 -1
  14. package/dist/cjs/taro-template.json +16 -12
  15. package/dist/cjs/toCodeTaro.d.ts +2 -0
  16. package/dist/cjs/utils/logic/handleProcess.js +8 -13
  17. package/dist/cjs/utils/logic/processChildren.d.ts +1 -0
  18. package/dist/cjs/utils/logic/processChildren.js +16 -1
  19. package/dist/cjs/utils/style/converter.js +43 -15
  20. package/dist/cjs/utils/style/pxtransform.d.ts +2 -26
  21. package/dist/cjs/utils/style/pxtransform.js +27 -67
  22. package/dist/cjs/utils/templates/component.js +4 -3
  23. package/dist/cjs/utils/templates/index.d.ts +10 -0
  24. package/dist/cjs/utils/templates/index.js +31 -7
  25. package/dist/cjs/utils/templates/renderManager.d.ts +3 -11
  26. package/dist/cjs/utils/templates/renderManager.js +86 -21
  27. package/dist/cjs/utils/templates/scene.d.ts +2 -1
  28. package/dist/cjs/utils/templates/scene.js +4 -1
  29. package/dist/esm/core/utils/ComContext.js +5 -0
  30. package/dist/esm/core/utils/hooks.js +14 -5
  31. package/dist/esm/core/utils/index.js +4 -2
  32. package/dist/esm/core/utils/slots.js +108 -0
  33. package/dist/esm/core/utils/useContext.js +21 -11
  34. package/dist/esm/core/utils/with.js +50 -7
  35. package/dist/esm/generate/generateTaroProjectJson.js +2 -2
  36. package/dist/esm/handleCom.d.ts +7 -30
  37. package/dist/esm/handleCom.js +224 -81
  38. package/dist/esm/handleSlot.d.ts +3 -0
  39. package/dist/esm/handleSlot.js +34 -11
  40. package/dist/esm/processors/processScene.js +36 -1
  41. package/dist/esm/processors/processSceneLogic.js +3 -1
  42. package/dist/esm/taro-template.json +16 -12
  43. package/dist/esm/toCodeTaro.d.ts +2 -0
  44. package/dist/esm/utils/logic/handleProcess.js +12 -16
  45. package/dist/esm/utils/logic/processChildren.d.ts +1 -0
  46. package/dist/esm/utils/logic/processChildren.js +17 -1
  47. package/dist/esm/utils/style/converter.js +66 -31
  48. package/dist/esm/utils/style/pxtransform.d.ts +2 -26
  49. package/dist/esm/utils/style/pxtransform.js +31 -98
  50. package/dist/esm/utils/templates/component.js +3 -2
  51. package/dist/esm/utils/templates/index.d.ts +10 -0
  52. package/dist/esm/utils/templates/index.js +33 -9
  53. package/dist/esm/utils/templates/renderManager.d.ts +3 -11
  54. package/dist/esm/utils/templates/renderManager.js +92 -23
  55. package/dist/esm/utils/templates/scene.d.ts +2 -1
  56. package/dist/esm/utils/templates/scene.js +4 -2
  57. package/package.json +1 -1
@@ -2,21 +2,27 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- var _excluded = ["component", "id", "data", "className", "style"];
5
+ var _excluded = ["component", "id", "data", "className", "style", "inputValues", "inputValuesMapping"],
6
+ _excluded2 = ["slots", "parentSlot"];
6
7
  import React, { useState, useEffect } from 'react';
8
+ // @ts-ignore 运行时由宿主项目提供 @tarojs/components
7
9
  import { View } from '@tarojs/components';
8
10
  import { useModel, useBindInputs, useBindEvents, subscribePopupRouter, closeActivePopupRouter } from "./index";
9
11
  import { useAppCreateContext } from "./useContext";
10
12
  import ComContext, { useAppContext } from "./ComContext";
13
+ import { useEnhancedSlots, useResolvedParentSlot } from "./slots";
11
14
  // @ts-ignore 运行时由宿主项目提供 @tarojs/taro
12
15
  import { useTabItemTap } from '@tarojs/taro';
13
16
  export var WithCom = function WithCom(props) {
17
+ var _parentSlot$params;
14
18
  var Component = props.component,
15
19
  _props$id = props.id,
16
20
  id = _props$id === void 0 ? '' : _props$id,
17
21
  data = props.data,
18
22
  className = props.className,
19
23
  style = props.style,
24
+ inputValues = props.inputValues,
25
+ inputValuesMapping = props.inputValuesMapping,
20
26
  rest = _objectWithoutProperties(props, _excluded);
21
27
  var _useAppContext = useAppContext(),
22
28
  comRefs = _useAppContext.comRefs,
@@ -71,19 +77,56 @@ export var WithCom = function WithCom(props) {
71
77
 
72
78
  // 绑定输入,传入初始 handlers
73
79
  var inputProxy = useBindInputs(comRefs, id, handlers);
74
- var eventProxy = useBindEvents(rest);
80
+ var _ref = rest,
81
+ rawSlots = _ref.slots,
82
+ parentSlotProp = _ref.parentSlot,
83
+ restProps = _objectWithoutProperties(_ref, _excluded2);
84
+ var _useAppContext2 = useAppContext(),
85
+ globalOutputs = _useAppContext2.outputs;
86
+ var parentSlot = useResolvedParentSlot(parentSlotProp);
87
+
88
+ // 绑定事件,带上上下文(用于事件流自动封装 id/name)
89
+ var eventProxy = useBindEvents(restProps, {
90
+ id: id,
91
+ name: props.name || id,
92
+ parentSlot: parentSlot
93
+ });
94
+
95
+ // 注册到全局 IO 管理
96
+ if (globalOutputs && globalOutputs.current) {
97
+ globalOutputs.current[id] = eventProxy;
98
+ }
99
+
100
+ // 鸿蒙规范:确保 comRefs 中挂载的是最新的 inputProxy
75
101
  comRefs.current[id] = inputProxy;
76
- return show || isPopup ? /*#__PURE__*/React.createElement(View, {
77
- className: className,
78
- style: _objectSpread(_objectSpread({}, style), dynamicStyle)
79
- }, /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
102
+ var enhancedSlots = useEnhancedSlots(rawSlots, id);
103
+ var jsx = /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {
80
104
  inputs: inputProxy,
81
105
  outputs: eventProxy,
106
+ slots: enhancedSlots,
107
+ parentSlot: parentSlot,
82
108
  data: _data,
83
109
  env: env,
84
110
  id: id,
85
111
  style: style
86
- }))) : null;
112
+ }));
113
+
114
+ // 鸿蒙化处理:支持 itemWrap 协议
115
+ if (parentSlot !== null && parentSlot !== void 0 && (_parentSlot$params = parentSlot.params) !== null && _parentSlot$params !== void 0 && _parentSlot$params.itemWrap) {
116
+ return parentSlot.params.itemWrap({
117
+ id: id,
118
+ name: props.name || id,
119
+ jsx: jsx,
120
+ def: Component.def,
121
+ inputs: inputProxy,
122
+ outputs: eventProxy,
123
+ style: style
124
+ });
125
+ }
126
+ return show || isPopup ? /*#__PURE__*/React.createElement(View, {
127
+ className: className,
128
+ style: _objectSpread(_objectSpread({}, style), dynamicStyle)
129
+ }, jsx) : null;
87
130
  };
88
131
  export var WithWrapper = function WithWrapper(Component) {
89
132
  return function WrappedComponent(props) {
@@ -70,7 +70,7 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
70
70
  path: "src/pages/".concat(pageName, "/index.config.ts"),
71
71
  content: configContent
72
72
  }, {
73
- path: "src/pages/".concat(pageName, "/index.less"),
73
+ path: "src/pages/".concat(pageName, "/index.global.less"),
74
74
  content: item.cssContent || ""
75
75
  }, {
76
76
  path: "src/pages/".concat(pageName, "/index.tsx"),
@@ -105,7 +105,7 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
105
105
  path: "src/popupComponents/".concat(popupId, "/index.tsx"),
106
106
  content: fullContent
107
107
  }, {
108
- path: "src/popupComponents/".concat(popupId, "/index.less"),
108
+ path: "src/popupComponents/".concat(popupId, "/index.global.less"),
109
109
  content: item.cssContent || ""
110
110
  }]
111
111
  });
@@ -1,31 +1,8 @@
1
- import { ImportManager } from "./utils";
2
- import { RenderManager } from "./utils/templates/renderManager";
3
- import type { UI, BaseConfig } from "./toCodeTaro";
4
- export type Com = Extract<UI["children"][0], {
5
- type: "com";
6
- }>;
7
- type HandleComResult = {
8
- ui: string;
9
- js: string;
10
- slots: string[];
11
- scopeSlots: string[];
12
- cssContent: string;
13
- renderCode?: string;
14
- outputsConfig?: Record<string, any>;
15
- };
16
- export interface HandleComConfig extends BaseConfig {
17
- addParentDependencyImport: (typeof ImportManager)["prototype"]["addImport"];
18
- addConsumer: (provider: ReturnType<BaseConfig["getCurrentProvider"]>) => void;
19
- addComId: (comId: string) => void;
20
- renderManager?: RenderManager;
21
- addJSModule?: (module: {
22
- id: string;
23
- title: string;
24
- transformCode: string;
25
- inputs: string[];
26
- outputs: string[];
27
- data: any;
28
- }) => void;
29
- }
30
- declare const handleCom: (com: Com, config: HandleComConfig) => HandleComResult;
1
+ export type Com = any;
2
+ export type HandleComConfig = any;
3
+ export type HandleComResult = any;
4
+ /**
5
+ * 处理组件
6
+ */
7
+ export declare const handleCom: (com: Com, config: HandleComConfig) => HandleComResult;
31
8
  export default handleCom;
@@ -2,39 +2,64 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
- import { convertComponentStyle, firstCharToUpperCase, convertStyleAryToCss, indentation } from "./utils";
6
- import { getUiComponentCode } from "./utils/templates";
7
- import handleSlot from "./handleSlot";
5
+ import { convertComponentStyle, convertStyleAryToCss } from "./utils/style/converter";
6
+ import { indentation, firstCharToUpperCase, formatSlotContent, getUiComponentCode } from "./utils/templates/index";
7
+ import { genSlotRenderRef } from "./utils/templates/component";
8
8
  import { RenderManager } from "./utils/templates/renderManager";
9
+ import handleSlot from "./handleSlot";
9
10
  import { processComEvents } from "./processors/processComEvents";
10
- import { genSlotRenderRef, formatSlotContent } from "./utils/templates/component";
11
- var handleCom = function handleCom(com, config) {
11
+ /**
12
+ * 组件协议配置(参考鸿蒙规范)
13
+ * - useWrap: 是否支持容器协议(如 Form 容器需要 metadata 包装)
14
+ */
15
+ var COM_PROTOCOL = {
16
+ "mybricks.taro.formContainer": {
17
+ useWrap: true
18
+ },
19
+ "mybricks.taro.formAdditionContainer": {
20
+ useWrap: true
21
+ }
22
+ };
23
+
24
+ /**
25
+ * 处理组件
26
+ */
27
+ export var handleCom = function handleCom(com, config) {
12
28
  var meta = com.meta,
13
29
  props = com.props;
30
+ var namespace = meta.def.namespace;
14
31
 
15
- // 1. 处理 JS 计算组件
16
- if (isJsCalculation(meta)) {
32
+ // 鸿蒙规范:确保组件具有稳定的 DSL 名称(用于容器识别)
33
+ if (!meta.name && config.getDslComNameById) {
34
+ meta.name = config.getDslComNameById(meta.id);
35
+ }
36
+
37
+ // 1. 如果是 JS 计算组件
38
+ if (namespace === "mybricks.core-comlib.js-calculation") {
17
39
  return handleJsCalculation(com, config);
18
40
  }
19
41
 
20
- // 2. 注册到 Provider 并获取元信息
42
+ // 2. 准备组件元数据
21
43
  var _prepareComponent = prepareComponent(com, config),
22
44
  componentName = _prepareComponent.componentName,
23
45
  eventHandlers = _prepareComponent.eventHandlers,
24
46
  comEventCode = _prepareComponent.comEventCode;
25
47
 
26
- // 3. 处理样式
48
+ // 3. 准备样式
27
49
  var _prepareStyles = prepareStyles(com),
28
50
  cssContent = _prepareStyles.cssContent,
29
51
  rootStyle = _prepareStyles.rootStyle;
52
+ var accumulatedCssContent = cssContent;
30
53
 
31
54
  // 4. 处理插槽
32
- var _processComSlots = processComSlots(com, config, cssContent),
55
+ var _processComSlots = processComSlots(com, config, accumulatedCssContent),
33
56
  slotsCode = _processComSlots.slotsCode,
34
- accumulatedCssContent = _processComSlots.accumulatedCssContent,
35
- eventCode = _processComSlots.eventCode;
57
+ slotCss = _processComSlots.accumulatedCssContent,
58
+ eventCode = _processComSlots.eventCode,
59
+ childrenResults = _processComSlots.childrenResults;
60
+ accumulatedCssContent = slotCss;
36
61
 
37
- // 5. 生成组件 UI 代码
62
+ // 5. 生成 UI 代码
38
63
  var ui = generateUiCode(com, config, componentName, rootStyle, comEventCode, slotsCode, eventHandlers);
39
64
  return {
40
65
  slots: [],
@@ -42,12 +67,16 @@ var handleCom = function handleCom(com, config) {
42
67
  ui: ui,
43
68
  js: eventCode,
44
69
  cssContent: accumulatedCssContent,
45
- outputsConfig: Object.keys(eventHandlers).length > 0 ? _defineProperty({}, meta.id, eventHandlers) : undefined
70
+ outputsConfig: Object.keys(eventHandlers).length > 0 ? _defineProperty({}, meta.id, eventHandlers) : undefined,
71
+ childrenResults: childrenResults,
72
+ name: meta.name,
73
+ // 返回解析后的稳定名称
74
+ rootStyle: rootStyle // 返回转换后的根样式
46
75
  };
47
76
  };
48
77
 
49
78
  /**
50
- * 准备组件信息
79
+ * 准备组件注册与事件
51
80
  */
52
81
  var prepareComponent = function prepareComponent(com, config) {
53
82
  var meta = com.meta;
@@ -75,7 +104,7 @@ var prepareComponent = function prepareComponent(com, config) {
75
104
  };
76
105
 
77
106
  /**
78
- * 准备样式
107
+ * 准备样式转换
79
108
  */
80
109
  var prepareStyles = function prepareStyles(com) {
81
110
  var _props$style;
@@ -89,17 +118,140 @@ var prepareStyles = function prepareStyles(com) {
89
118
  };
90
119
  };
91
120
 
121
+ /**
122
+ * 处理组件内的所有插槽
123
+ */
124
+ var processComSlots = function processComSlots(com, config, initialCss) {
125
+ var meta = com.meta,
126
+ props = com.props,
127
+ slots = com.slots;
128
+ var slotsCode = "";
129
+ var accumulatedCssContent = initialCss;
130
+ var eventCode = "";
131
+ var allChildrenResults = [];
132
+ if (!slots) return {
133
+ slotsCode: slotsCode,
134
+ accumulatedCssContent: accumulatedCssContent,
135
+ eventCode: eventCode,
136
+ childrenResults: []
137
+ };
138
+ var renderManager = config.renderManager || new RenderManager();
139
+ var slotEntries = Object.entries(slots);
140
+ slotEntries.forEach(function (_ref2, index) {
141
+ var _props$data, _COM_PROTOCOL$meta$de;
142
+ var _ref3 = _slicedToArray(_ref2, 2),
143
+ slotId = _ref3[0],
144
+ slot = _ref3[1];
145
+ // 鸿蒙规范:如果插槽内没有组件,跳过渲染
146
+ var children = slot.comAry || slot.children || [];
147
+ if (children.length === 0) {
148
+ return;
149
+ }
150
+ var result = handleSlot(slot, _objectSpread(_objectSpread({}, config), {}, {
151
+ checkIsRoot: function checkIsRoot() {
152
+ return false;
153
+ },
154
+ depth: 1,
155
+ renderManager: renderManager,
156
+ slotKey: slotId
157
+ }));
158
+ eventCode += result.js;
159
+ if (result.cssContent) {
160
+ accumulatedCssContent += (accumulatedCssContent ? "\n" : "") + result.cssContent;
161
+ }
162
+ var renderId = "".concat(meta.id, "_").concat(slotId);
163
+ var baseIndentSize = config.codeStyle.indent;
164
+ var renderBodyIndent = indentation(config.codeStyle.indent * 2);
165
+ var formattedContent = formatSlotContent(result.ui, baseIndentSize, renderBodyIndent);
166
+
167
+ // 鸿蒙化处理:针对表单容器进行别名对齐
168
+ if (meta.def.namespace === "mybricks.taro.formContainer" && Array.isArray((_props$data = props.data) === null || _props$data === void 0 ? void 0 : _props$data.items) && result.childrenResults) {
169
+ var _props$data2;
170
+ var items = (_props$data2 = props.data) === null || _props$data2 === void 0 ? void 0 : _props$data2.items;
171
+ result.childrenResults.forEach(function (childRes) {
172
+ var itemConfig = items.find(function (it) {
173
+ return it.id === childRes.id;
174
+ });
175
+ if (itemConfig !== null && itemConfig !== void 0 && itemConfig.comName) {
176
+ childRes.name = itemConfig.comName;
177
+ }
178
+ });
179
+ }
180
+
181
+ // 生成插槽内的驱动逻辑 (jsModules 驱动输入)
182
+ var logicCode = buildSlotLogicCode(slotId, result.childrenResults, config);
183
+
184
+ // 生成插槽描述注释内容
185
+ var description = "".concat(meta.title || meta.id, "\u7684").concat(slot.title || slotId, "\u63D2\u69FD");
186
+ renderManager.register(renderId, formattedContent, result.childrenResults, logicCode, slot.type, slot.wrap || slot.itemWrap || ((_COM_PROTOCOL$meta$de = COM_PROTOCOL[meta.def.namespace]) === null || _COM_PROTOCOL$meta$de === void 0 ? void 0 : _COM_PROTOCOL$meta$de.useWrap), description);
187
+ if (result.childrenResults) {
188
+ allChildrenResults = allChildrenResults.concat(result.childrenResults);
189
+ }
190
+ var slotIndent = indentation(config.codeStyle.indent * (config.depth + 2));
191
+ slotsCode += genSlotRenderRef({
192
+ slotId: slotId,
193
+ renderId: renderId,
194
+ indent: slotIndent,
195
+ isLast: index === slotEntries.length - 1
196
+ });
197
+ });
198
+ return {
199
+ slotsCode: slotsCode,
200
+ accumulatedCssContent: accumulatedCssContent,
201
+ eventCode: eventCode,
202
+ childrenResults: allChildrenResults
203
+ };
204
+ };
205
+
206
+ /**
207
+ * 生成插槽内部的驱动逻辑 (useEffect 监听 inputValues 并调用子组件 inputs)
208
+ */
209
+ var buildSlotLogicCode = function buildSlotLogicCode(slotId, children, config) {
210
+ var scene = config.getCurrentScene();
211
+ var indent = indentation(2);
212
+ var indent2 = indentation(4);
213
+ var indent3 = indentation(6);
214
+ var bodyCode = "";
215
+ children === null || children === void 0 || children.forEach(function (child) {
216
+ if (child.type !== 'com') return;
217
+
218
+ // 寻找连线:frame-input -> child.id
219
+ var mapping = collectSlotInputMappingForCom({
220
+ slotFrameId: slotId,
221
+ scene: scene,
222
+ targetComId: child.id
223
+ });
224
+ Object.entries(mapping).forEach(function (_ref4) {
225
+ var _ref5 = _slicedToArray(_ref4, 2),
226
+ pinId = _ref5[0],
227
+ slotKey = _ref5[1];
228
+ bodyCode += "".concat(indent3, "const val_").concat(child.id, "_").concat(pinId, " = params.inputValues['").concat(slotKey, "'];\n");
229
+ bodyCode += "".concat(indent3, "if (val_").concat(child.id, "_").concat(pinId, " !== undefined) {\n");
230
+ // 生成调用代码:comRefs.current['u_TXC0P']?.['value']?.(val)
231
+ bodyCode += "".concat(indent3).concat(indent, "comRefs.current['").concat(child.id, "']?.['").concat(pinId, "']?.(val_").concat(child.id, "_").concat(pinId, ");\n");
232
+ bodyCode += "".concat(indent3, "}\n");
233
+ });
234
+ });
235
+ if (!bodyCode) {
236
+ return "";
237
+ }
238
+ var code = "".concat(indent, "useEffect(() => {\n");
239
+ code += "".concat(indent2, "if (params?.inputValues) {\n");
240
+ code += bodyCode;
241
+ code += "".concat(indent2, "}\n");
242
+ code += "".concat(indent, "}, [params?.inputValues]);\n");
243
+ return code;
244
+ };
245
+
92
246
  /**
93
247
  * 生成 UI 代码
94
248
  */
95
249
  var generateUiCode = function generateUiCode(com, config, componentName, rootStyle, comEventCode, slotsCode, eventHandlers) {
96
- var _scene$coms;
250
+ var _scene$coms, _sceneCom$inputs, _sceneCom$outputs, _meta$outputs;
97
251
  var meta = com.meta,
98
252
  props = com.props;
99
253
  var scene = config.getCurrentScene();
100
254
  var sceneCom = (_scene$coms = scene.coms) === null || _scene$coms === void 0 ? void 0 : _scene$coms[meta.id];
101
- var componentInputs = (sceneCom === null || sceneCom === void 0 ? void 0 : sceneCom.inputs) || [];
102
- var componentOutputs = (sceneCom === null || sceneCom === void 0 ? void 0 : sceneCom.outputs) || meta.outputs || [];
103
255
  return getUiComponentCode({
104
256
  componentName: componentName,
105
257
  meta: meta,
@@ -107,8 +259,8 @@ var generateUiCode = function generateUiCode(com, config, componentName, rootSty
107
259
  resultStyle: {
108
260
  root: rootStyle
109
261
  },
110
- componentInputs: componentInputs.length > 0 ? componentInputs : undefined,
111
- componentOutputs: componentOutputs.length > 0 ? componentOutputs : undefined,
262
+ componentInputs: ((sceneCom === null || sceneCom === void 0 || (_sceneCom$inputs = sceneCom.inputs) === null || _sceneCom$inputs === void 0 ? void 0 : _sceneCom$inputs.length) || 0) > 0 ? sceneCom.inputs : undefined,
263
+ componentOutputs: ((sceneCom === null || sceneCom === void 0 || (_sceneCom$outputs = sceneCom.outputs) === null || _sceneCom$outputs === void 0 ? void 0 : _sceneCom$outputs.length) || 0) > 0 ? sceneCom.outputs : (((_meta$outputs = meta.outputs) === null || _meta$outputs === void 0 ? void 0 : _meta$outputs.length) || 0) > 0 ? meta.outputs : undefined,
112
264
  comEventCode: comEventCode,
113
265
  slotsCode: slotsCode,
114
266
  eventHandlers: eventHandlers
@@ -118,18 +270,15 @@ var generateUiCode = function generateUiCode(com, config, componentName, rootSty
118
270
  verbose: config.verbose
119
271
  });
120
272
  };
121
- var isJsCalculation = function isJsCalculation(meta) {
122
- return meta.def.namespace === "mybricks.taro._muilt-inputJs" || meta.def.namespace === "mybricks.core-comlib.js-ai";
123
- };
124
273
 
125
274
  /**
126
- * 处理 JS 计算组件
275
+ * JS 计算组件专用处理
127
276
  */
128
277
  var handleJsCalculation = function handleJsCalculation(com, config) {
129
- var _props$data, _props$data2, _props$data3;
278
+ var _props$data3, _props$data4, _props$data5;
130
279
  var meta = com.meta,
131
280
  props = com.props;
132
- var transformCode = ((_props$data = props.data) === null || _props$data === void 0 || (_props$data = _props$data.fns) === null || _props$data === void 0 ? void 0 : _props$data.code) || ((_props$data2 = props.data) === null || _props$data2 === void 0 || (_props$data2 = _props$data2.fns) === null || _props$data2 === void 0 ? void 0 : _props$data2.transformCode) || ((_props$data3 = props.data) === null || _props$data3 === void 0 ? void 0 : _props$data3.fns);
281
+ var transformCode = ((_props$data3 = props.data) === null || _props$data3 === void 0 || (_props$data3 = _props$data3.fns) === null || _props$data3 === void 0 ? void 0 : _props$data3.code) || ((_props$data4 = props.data) === null || _props$data4 === void 0 || (_props$data4 = _props$data4.fns) === null || _props$data4 === void 0 ? void 0 : _props$data4.transformCode) || ((_props$data5 = props.data) === null || _props$data5 === void 0 ? void 0 : _props$data5.fns);
133
282
  if (transformCode && config.addJSModule) {
134
283
  var _meta$model, _meta$model2;
135
284
  config.addJSModule({
@@ -152,61 +301,55 @@ var handleJsCalculation = function handleJsCalculation(com, config) {
152
301
  };
153
302
 
154
303
  /**
155
- * 处理组件插槽
304
+ * 鸿蒙化解析逻辑:通过连线关系(cons)和 作用域代理(pinValueProxies)推导数据源映射
156
305
  */
157
- var processComSlots = function processComSlots(com, config, initialCss) {
158
- var meta = com.meta,
159
- props = com.props,
160
- slots = com.slots;
161
- var slotsCode = "";
162
- var accumulatedCssContent = initialCss;
163
- var eventCode = "";
164
- if (slots) {
165
- var renderManager = config.renderManager || new RenderManager();
166
- var slotEntries = Object.entries(slots);
167
- slotEntries.forEach(function (_ref2, index) {
168
- var _props$style2;
169
- var _ref3 = _slicedToArray(_ref2, 2),
170
- slotId = _ref3[0],
171
- slot = _ref3[1];
172
- var rawSlotInfo = (_props$style2 = props.style) === null || _props$style2 === void 0 || (_props$style2 = _props$style2.slots) === null || _props$style2 === void 0 ? void 0 : _props$style2[slotId];
173
- if (rawSlotInfo !== null && rawSlotInfo !== void 0 && rawSlotInfo.layout) {
174
- slot.layout = rawSlotInfo.layout;
175
- }
176
- var result = handleSlot(slot, _objectSpread(_objectSpread({}, config), {}, {
177
- checkIsRoot: function checkIsRoot() {
178
- return false;
179
- },
180
- depth: 1,
181
- renderManager: renderManager
182
- }));
183
- eventCode += result.js;
184
- if (result.cssContent) {
185
- accumulatedCssContent += (accumulatedCssContent ? "\n" : "") + result.cssContent;
306
+ function collectSlotInputMappingForCom(params) {
307
+ var slotFrameId = params.slotFrameId,
308
+ scene = params.scene,
309
+ targetComId = params.targetComId;
310
+ var mapping = {};
311
+ var cons = (scene === null || scene === void 0 ? void 0 : scene.cons) || {};
312
+ var pinValueProxies = (scene === null || scene === void 0 ? void 0 : scene.pinValueProxies) || {};
313
+ var coms = (scene === null || scene === void 0 ? void 0 : scene.coms) || {};
314
+
315
+ // 1. 识别属于当前插槽的 frame-input
316
+ var frameInputComIdToKey = {};
317
+ Object.entries(pinValueProxies).forEach(function (_ref6) {
318
+ var _ref7 = _slicedToArray(_ref6, 2),
319
+ key = _ref7[0],
320
+ proxy = _ref7[1];
321
+ if ((proxy === null || proxy === void 0 ? void 0 : proxy.type) === "frame" && proxy.frameId === slotFrameId && proxy.pinId) {
322
+ var _coms$comId;
323
+ var _String$split = String(key).split("-"),
324
+ _String$split2 = _slicedToArray(_String$split, 1),
325
+ comId = _String$split2[0];
326
+ if (comId && ((_coms$comId = coms[comId]) === null || _coms$comId === void 0 || (_coms$comId = _coms$comId.def) === null || _coms$comId === void 0 ? void 0 : _coms$comId.namespace) === "mybricks.core-comlib.frame-input") {
327
+ frameInputComIdToKey[comId] = proxy.pinId;
186
328
  }
187
- var renderId = "".concat(meta.id, "_").concat(slotId);
188
- var baseIndentSize = config.codeStyle.indent;
189
- var rootIndent = config.codeStyle.indent;
190
- var renderBodyIndent = indentation(rootIndent + config.codeStyle.indent);
191
- var formattedContent = formatSlotContent({
192
- uiContent: result.ui,
193
- baseIndentSize: baseIndentSize,
194
- renderBodyIndent: renderBodyIndent
195
- });
196
- renderManager.register(renderId, formattedContent);
197
- var slotIndent = indentation(config.codeStyle.indent * (config.depth + 2));
198
- slotsCode += genSlotRenderRef({
199
- slotId: slotId,
200
- renderId: renderId,
201
- indent: slotIndent,
202
- isLast: index === slotEntries.length - 1
329
+ }
330
+ });
331
+ if (Object.keys(frameInputComIdToKey).length === 0) return mapping;
332
+
333
+ // 2. 推导连线:frame-input -> targetCom
334
+ Object.entries(cons).forEach(function (_ref8) {
335
+ var _ref9 = _slicedToArray(_ref8, 2),
336
+ sourceKey = _ref9[0],
337
+ targets = _ref9[1];
338
+ if (!Array.isArray(targets)) return;
339
+ var _String$split3 = String(sourceKey).split("-"),
340
+ _String$split4 = _slicedToArray(_String$split3, 1),
341
+ sourceComId = _String$split4[0];
342
+ var slotInputKey = frameInputComIdToKey[sourceComId];
343
+ if (slotInputKey) {
344
+ targets.forEach(function (t) {
345
+ var targetId = typeof t === 'string' ? t.split('-')[0] : t.comId;
346
+ var targetPin = typeof t === 'string' ? t.split('-')[1] : t.pinId;
347
+ if (targetId === targetComId && targetPin) {
348
+ mapping[targetPin] = slotInputKey;
349
+ }
203
350
  });
204
- });
205
- }
206
- return {
207
- slotsCode: slotsCode,
208
- accumulatedCssContent: accumulatedCssContent,
209
- eventCode: eventCode
210
- };
211
- };
351
+ }
352
+ });
353
+ return mapping;
354
+ }
212
355
  export default handleCom;
@@ -10,6 +10,8 @@ interface HandleSlotConfig extends BaseConfig {
10
10
  addJSModule?: (module: any) => void;
11
11
  isPopup?: boolean;
12
12
  hasPopups?: boolean;
13
+ /** handleCom 处理 slots 时的 slot key(如 item/content),用于识别 scope 入参 */
14
+ slotKey?: string;
13
15
  }
14
16
  declare const handleSlot: (ui: UI, config: HandleSlotConfig) => {
15
17
  js: string;
@@ -18,5 +20,6 @@ declare const handleSlot: (ui: UI, config: HandleSlotConfig) => {
18
20
  cssContent: string;
19
21
  slots: any[];
20
22
  scopeSlots: any[];
23
+ childrenResults: any[];
21
24
  };
22
25
  export default handleSlot;