@mybricks/to-code-taro 1.1.5 → 1.1.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 (126) hide show
  1. package/dist/cjs/core/mybricks/Subject.js +9 -5
  2. package/dist/cjs/core/mybricks/createJSHandle.js +43 -3
  3. package/dist/cjs/core/utils/comRefResolver.js +112 -0
  4. package/dist/cjs/core/utils/event.js +53 -0
  5. package/dist/cjs/core/utils/hooks.js +71 -29
  6. package/dist/cjs/core/utils/index.js +3 -0
  7. package/dist/cjs/core/utils/pageRouter.js +34 -11
  8. package/dist/cjs/core/utils/slots.js +55 -9
  9. package/dist/cjs/core/utils/tabbar.js +56 -0
  10. package/dist/cjs/core/utils/useContext.js +42 -2
  11. package/dist/cjs/core/utils/with.js +9 -34
  12. package/dist/cjs/generate/generateTaroProjectJson.js +3 -18
  13. package/dist/cjs/generate/utils/appConfig.d.ts +1 -1
  14. package/dist/cjs/generate/utils/appConfig.js +22 -12
  15. package/dist/cjs/generate/utils/commonDir.js +9 -0
  16. package/dist/cjs/generate/utils/customTabBar.d.ts +11 -0
  17. package/dist/cjs/generate/utils/customTabBar.js +73 -0
  18. package/dist/cjs/generate/utils/fileNode.d.ts +4 -0
  19. package/dist/cjs/generate/utils/fileNode.js +12 -2
  20. package/dist/cjs/handleCom.js +15 -16
  21. package/dist/cjs/handleGlobal.d.ts +1 -1
  22. package/dist/cjs/handleGlobal.js +6 -0
  23. package/dist/cjs/handleSlot.js +5 -10
  24. package/dist/cjs/processors/processScene.js +13 -1
  25. package/dist/cjs/processors/processSceneLogic.js +2 -6
  26. package/dist/cjs/taro-template.json +364 -66
  27. package/dist/cjs/toCodeTaro.d.ts +1 -2
  28. package/dist/cjs/utils/builder/buildResult.js +1 -2
  29. package/dist/cjs/utils/common/ImportManager.d.ts +7 -0
  30. package/dist/cjs/utils/common/ImportManager.js +19 -1
  31. package/dist/cjs/utils/logic/genJSModules.js +2 -2
  32. package/dist/cjs/utils/logic/handleProcess.js +59 -13
  33. package/dist/cjs/utils/templates/index.js +1 -1
  34. package/dist/cjs/utils/templates/renderManager.js +5 -5
  35. package/dist/cjs/utils/templates/scene.js +4 -4
  36. package/dist/esm/core/mybricks/Subject.js +11 -5
  37. package/dist/esm/core/mybricks/createJSHandle.js +55 -5
  38. package/dist/esm/core/utils/comRefResolver.js +134 -0
  39. package/dist/esm/core/utils/event.js +32 -0
  40. package/dist/esm/core/utils/hooks.js +109 -39
  41. package/dist/esm/core/utils/index.js +1 -0
  42. package/dist/esm/core/utils/pageRouter.js +56 -13
  43. package/dist/esm/core/utils/slots.js +78 -12
  44. package/dist/esm/core/utils/tabbar.js +47 -0
  45. package/dist/esm/core/utils/useContext.js +42 -2
  46. package/dist/esm/core/utils/with.js +19 -53
  47. package/dist/esm/generate/generateTaroProjectJson.js +2 -20
  48. package/dist/esm/generate/utils/appConfig.d.ts +1 -1
  49. package/dist/esm/generate/utils/appConfig.js +28 -9
  50. package/dist/esm/generate/utils/commonDir.js +13 -0
  51. package/dist/esm/generate/utils/customTabBar.d.ts +11 -0
  52. package/dist/esm/generate/utils/customTabBar.js +52 -0
  53. package/dist/esm/generate/utils/fileNode.d.ts +4 -0
  54. package/dist/esm/generate/utils/fileNode.js +13 -0
  55. package/dist/esm/handleCom.js +24 -21
  56. package/dist/esm/handleGlobal.d.ts +1 -1
  57. package/dist/esm/handleGlobal.js +6 -1
  58. package/dist/esm/handleSlot.js +7 -12
  59. package/dist/esm/processors/processScene.js +23 -3
  60. package/dist/esm/processors/processSceneLogic.js +3 -5
  61. package/dist/esm/taro-template.json +364 -66
  62. package/dist/esm/toCodeTaro.d.ts +1 -2
  63. package/dist/esm/toCodeTaro.js +1 -1
  64. package/dist/esm/utils/builder/buildResult.js +1 -2
  65. package/dist/esm/utils/common/ImportManager.d.ts +7 -0
  66. package/dist/esm/utils/common/ImportManager.js +42 -14
  67. package/dist/esm/utils/logic/genJSModules.js +2 -2
  68. package/dist/esm/utils/logic/handleProcess.js +73 -12
  69. package/dist/esm/utils/templates/index.js +1 -1
  70. package/dist/esm/utils/templates/renderManager.js +4 -7
  71. package/dist/esm/utils/templates/scene.js +2 -2
  72. package/package.json +1 -1
  73. package/dist/cjs/core/comlib/Index.js +0 -114
  74. package/dist/cjs/core/comlib/_AesEncode.js +0 -115
  75. package/dist/cjs/core/comlib/_BackTo.js +0 -80
  76. package/dist/cjs/core/comlib/_CallPhone.js +0 -58
  77. package/dist/cjs/core/comlib/_ChooseFile.js +0 -103
  78. package/dist/cjs/core/comlib/_ChooseMedia.js +0 -70
  79. package/dist/cjs/core/comlib/_Connector.js +0 -79
  80. package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +0 -79
  81. package/dist/cjs/core/comlib/_Format.js +0 -123
  82. package/dist/cjs/core/comlib/_GetLocation.js +0 -60
  83. package/dist/cjs/core/comlib/_GetStorage.js +0 -68
  84. package/dist/cjs/core/comlib/_GetSystemInfo.js +0 -62
  85. package/dist/cjs/core/comlib/_Modal.js +0 -68
  86. package/dist/cjs/core/comlib/_OpenCamera.js +0 -73
  87. package/dist/cjs/core/comlib/_OpenPetalMap.js +0 -49
  88. package/dist/cjs/core/comlib/_OpenUrl.js +0 -62
  89. package/dist/cjs/core/comlib/_RemoveStorage.js +0 -68
  90. package/dist/cjs/core/comlib/_Router.js +0 -100
  91. package/dist/cjs/core/comlib/_ScanQrcode.js +0 -59
  92. package/dist/cjs/core/comlib/_SetStorage.js +0 -67
  93. package/dist/cjs/core/comlib/_Share.js +0 -58
  94. package/dist/cjs/core/comlib/_ShowToast.js +0 -69
  95. package/dist/cjs/core/comlib/_TextToSpeech.js +0 -120
  96. package/dist/cjs/core/comlib/_TimerDebounce.js +0 -72
  97. package/dist/cjs/core/comlib/_TimerDelay.js +0 -88
  98. package/dist/cjs/core/comlib/_TimerThrottle.js +0 -75
  99. package/dist/cjs/core/comlib/_Vibrate.js +0 -60
  100. package/dist/esm/core/comlib/Index.js +0 -39
  101. package/dist/esm/core/comlib/_AesEncode.js +0 -85
  102. package/dist/esm/core/comlib/_BackTo.js +0 -66
  103. package/dist/esm/core/comlib/_CallPhone.js +0 -30
  104. package/dist/esm/core/comlib/_ChooseFile.js +0 -81
  105. package/dist/esm/core/comlib/_ChooseMedia.js +0 -38
  106. package/dist/esm/core/comlib/_Connector.js +0 -77
  107. package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +0 -56
  108. package/dist/esm/core/comlib/_Format.js +0 -102
  109. package/dist/esm/core/comlib/_GetLocation.js +0 -26
  110. package/dist/esm/core/comlib/_GetStorage.js +0 -44
  111. package/dist/esm/core/comlib/_GetSystemInfo.js +0 -32
  112. package/dist/esm/core/comlib/_Modal.js +0 -51
  113. package/dist/esm/core/comlib/_OpenCamera.js +0 -44
  114. package/dist/esm/core/comlib/_OpenPetalMap.js +0 -28
  115. package/dist/esm/core/comlib/_OpenUrl.js +0 -36
  116. package/dist/esm/core/comlib/_RemoveStorage.js +0 -42
  117. package/dist/esm/core/comlib/_Router.js +0 -113
  118. package/dist/esm/core/comlib/_ScanQrcode.js +0 -26
  119. package/dist/esm/core/comlib/_SetStorage.js +0 -40
  120. package/dist/esm/core/comlib/_Share.js +0 -28
  121. package/dist/esm/core/comlib/_ShowToast.js +0 -45
  122. package/dist/esm/core/comlib/_TextToSpeech.js +0 -117
  123. package/dist/esm/core/comlib/_TimerDebounce.js +0 -66
  124. package/dist/esm/core/comlib/_TimerDelay.js +0 -79
  125. package/dist/esm/core/comlib/_TimerThrottle.js +0 -69
  126. package/dist/esm/core/comlib/_Vibrate.js +0 -34
@@ -64,10 +64,9 @@ 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" | "connector-api" | "extension-event" | "jsModulesRuntime" | "tabBarConfig" | "customTabBar";
67
+ type: "normal" | "popup" | "module" | "global" | "extension-config" | "extension-api" | "extension-bus" | "abstractEventTypeDef" | "fx" | "api" | "rootConfig" | "connector-api" | "extension-event" | "jsModulesRuntime" | "tabBarConfig" | "customTabBar";
68
68
  meta?: ReturnType<typeof toCode>["scenes"][0]["scene"];
69
69
  name: string;
70
- tabBarConfig?: string;
71
70
  }
72
71
  /** 统一的生成结果结构 */
73
72
  export interface GenerationResult {
@@ -79,7 +79,7 @@ var getCode = function getCode(params, config) {
79
79
  var globalVarTypeDef = buildGlobalVarTypeDef(tojson.global.comsReg);
80
80
  var defaultFxsMap = buildDefaultFxsMap(tojson.global.fxFrames || []);
81
81
 
82
- // ========== 第四步:处理全局变量和 FX ==========
82
+ // ========== 第四步:处理全局变量、FX、其他全局配置 ==========
83
83
  files.push.apply(files, _toConsumableArray(handleGlobal({
84
84
  tojson: tojson,
85
85
  globalFxs: globalFxs,
@@ -74,8 +74,7 @@ export var buildFinalResults = function buildFinalResults(params) {
74
74
  type: "tabBarConfig",
75
75
  content: globalTabBarConfig,
76
76
  importManager: new ImportManager(config),
77
- name: "tabBarConfig",
78
- tabBarConfig: globalTabBarConfig
77
+ name: "tabBarConfig"
79
78
  });
80
79
  files.push({
81
80
  type: "customTabBar",
@@ -14,6 +14,13 @@ export declare class ImportManager {
14
14
  dependencyNames: string[];
15
15
  importType: ImportType;
16
16
  }): void;
17
+ /**
18
+ * 获取 import 排序优先级
19
+ * 1. 第三方包(react, @tarojs 等)
20
+ * 2. 绝对路径别名(@/xxx)
21
+ * 3. 相对路径(./xxx, ../xxx)
22
+ */
23
+ private getImportPriority;
17
24
  /** 依赖解析为code */
18
25
  toCode(): string;
19
26
  }
@@ -40,24 +40,52 @@ export var ImportManager = /*#__PURE__*/function () {
40
40
  }
41
41
  }
42
42
 
43
+ /**
44
+ * 获取 import 排序优先级
45
+ * 1. 第三方包(react, @tarojs 等)
46
+ * 2. 绝对路径别名(@/xxx)
47
+ * 3. 相对路径(./xxx, ../xxx)
48
+ */
49
+ }, {
50
+ key: "getImportPriority",
51
+ value: function getImportPriority(packageName) {
52
+ if (packageName.startsWith('./') || packageName.startsWith('../')) {
53
+ return 3; // 相对路径
54
+ }
55
+ if (packageName.startsWith('@/')) {
56
+ return 2; // 绝对路径别名
57
+ }
58
+ return 1; // 第三方包
59
+ }
60
+
43
61
  /** 依赖解析为code */
44
62
  }, {
45
63
  key: "toCode",
46
64
  value: function toCode() {
65
+ var _this = this;
47
66
  var indent = indentation(this._config.codeStyle.indent);
48
- return Object.entries(this._imports).reduce(function (pre, _ref2) {
67
+
68
+ // 对 imports 按优先级排序
69
+ var sortedEntries = Object.entries(this._imports).sort(function (_ref2, _ref3) {
70
+ var _ref4 = _slicedToArray(_ref2, 1),
71
+ a = _ref4[0];
72
+ var _ref5 = _slicedToArray(_ref3, 1),
73
+ b = _ref5[0];
74
+ return _this.getImportPriority(a) - _this.getImportPriority(b);
75
+ });
76
+ return sortedEntries.reduce(function (pre, _ref6) {
49
77
  var _dependencies$__modul;
50
- var _ref3 = _slicedToArray(_ref2, 2),
51
- packageName = _ref3[0],
52
- dependencies = _ref3[1];
78
+ var _ref7 = _slicedToArray(_ref6, 2),
79
+ packageName = _ref7[0],
80
+ dependencies = _ref7[1];
53
81
  var defaultDependency = "";
54
82
  var namedDependencies = "";
55
83
  var dependencyEntries = Object.entries(dependencies);
56
84
 
57
85
  // 检查是否有 module 类型的导入(如 import './index.less')
58
- var hasModuleType = ((_dependencies$__modul = dependencies["__module__"]) === null || _dependencies$__modul === void 0 ? void 0 : _dependencies$__modul.importType) === "module" || dependencyEntries.some(function (_ref4) {
59
- var _ref5 = _slicedToArray(_ref4, 2),
60
- importType = _ref5[1].importType;
86
+ var hasModuleType = ((_dependencies$__modul = dependencies["__module__"]) === null || _dependencies$__modul === void 0 ? void 0 : _dependencies$__modul.importType) === "module" || dependencyEntries.some(function (_ref8) {
87
+ var _ref9 = _slicedToArray(_ref8, 2),
88
+ importType = _ref9[1].importType;
61
89
  return importType === "module";
62
90
  });
63
91
  if (hasModuleType) {
@@ -65,16 +93,16 @@ export var ImportManager = /*#__PURE__*/function () {
65
93
  }
66
94
 
67
95
  /** 超过三项换行 */
68
- var validEntries = dependencyEntries.filter(function (_ref6) {
69
- var _ref7 = _slicedToArray(_ref6, 1),
70
- key = _ref7[0];
96
+ var validEntries = dependencyEntries.filter(function (_ref10) {
97
+ var _ref11 = _slicedToArray(_ref10, 1),
98
+ key = _ref11[0];
71
99
  return key !== "__module__";
72
100
  });
73
101
  var wrap = validEntries.length > 3;
74
- validEntries.forEach(function (_ref8, index) {
75
- var _ref9 = _slicedToArray(_ref8, 2),
76
- dependencyName = _ref9[0],
77
- importType = _ref9[1].importType;
102
+ validEntries.forEach(function (_ref12, index) {
103
+ var _ref13 = _slicedToArray(_ref12, 2),
104
+ dependencyName = _ref13[0],
105
+ importType = _ref13[1].importType;
78
106
  if (importType === "default") {
79
107
  defaultDependency = dependencyName;
80
108
  } else if (importType === "named") {
@@ -12,7 +12,7 @@ export var genJSModulesRuntime = function genJSModulesRuntime() {
12
12
  * 输出:export const jsModules = { u_xxx: (props, appContext) => createJSHandle(...) }
13
13
  */
14
14
  export var genScopedJSModules = function genScopedJSModules(jsModules, importCreateJSHandleFrom, importRuntimeFrom) {
15
- var code = "/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { createJSHandle } from \"".concat(importCreateJSHandleFrom, "\";\nimport { _execJs } from \"").concat(importRuntimeFrom, "\";\n\nexport const jsModules: Record<string, (props: any, appContext: any) => any> = {};\n");
15
+ var code = "/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { createJSHandle } from \"".concat(importCreateJSHandleFrom, "\";\nimport { _execJs } from \"").concat(importRuntimeFrom, "\";\n\nexport const jsModules: Record<string, (props: any, appContext: any, handleKey?: string) => any> = {};\n");
16
16
  jsModules.forEach(function (module) {
17
17
  var id = module.id,
18
18
  title = module.title,
@@ -26,7 +26,7 @@ export var genScopedJSModules = function genScopedJSModules(jsModules, importCre
26
26
  code += "\n// ".concat(title, "\n");
27
27
  code += "const js_".concat(id, " = ").concat(decodedCode, ";\n");
28
28
  code += "const _execJs_".concat(id, " = _execJs(js_").concat(id, ");\n");
29
- code += "jsModules.".concat(id, " = (props, appContext) => createJSHandle(_execJs_").concat(id, ", { props, appContext });\n");
29
+ code += "jsModules.".concat(id, " = (props, appContext, handleKey) => createJSHandle(_execJs_").concat(id, ", { props, appContext }, handleKey);\n");
30
30
  });
31
31
  code += "\n";
32
32
  return code;
@@ -16,7 +16,10 @@ var isJsCalculationComponent = function isJsCalculationComponent(namespace) {
16
16
  * 判断是否是 JS API 组件
17
17
  */
18
18
  var isJsApiComponent = function isJsApiComponent(namespace, rtType) {
19
- return namespace.startsWith("mybricks.taro._") && (rtType === null || rtType === void 0 ? void 0 : rtType.match(/^js/gi)) !== null;
19
+ var jsCompNamespace = ['mybricks.taro.', 'mybricks.normal-pc.'];
20
+ return jsCompNamespace.some(function (_namespace) {
21
+ return namespace.startsWith(_namespace);
22
+ }) && (rtType === null || rtType === void 0 ? void 0 : rtType.match(/^js/gi)) !== null;
20
23
  };
21
24
  export var handleProcess = function handleProcess(event, config) {
22
25
  var code = "";
@@ -109,14 +112,22 @@ export var handleProcess = function handleProcess(event, config) {
109
112
  });
110
113
 
111
114
  // 处理节点调用
115
+ // 边遍历边构建映射:确保引用时只能看到已声明的变量
116
+ var outputToInputPinMap = new Map();
112
117
  process.nodesInvocation.forEach(function (props) {
113
- var _config$getCallTempla, _props$meta$model;
118
+ var _props$nextParam, _config$getCallTempla, _props$meta$model;
114
119
  var componentType = props.componentType,
115
120
  category = props.category,
116
121
  runType = props.runType;
117
- var nextValue = getNextValue(props, config, event);
122
+ var nextValue = getNextValue(props, config, event, outputToInputPinMap);
118
123
  var isSameScope = checkIsSameScope(event, props);
119
124
  var nextCode = getNextCode(props, config, isSameScope, event);
125
+
126
+ // 声明后记录映射,供后续引用
127
+ var inputPinId = props.id.replace(/[^a-zA-Z0-9_]/g, '_');
128
+ (_props$nextParam = props.nextParam) === null || _props$nextParam === void 0 || _props$nextParam.forEach(function (np) {
129
+ outputToInputPinMap.set("".concat(props.meta.id, "_").concat(np.id), inputPinId);
130
+ });
120
131
  if (code) {
121
132
  code += "\n";
122
133
  }
@@ -189,7 +200,22 @@ export var handleProcess = function handleProcess(event, config) {
189
200
  }
190
201
  } else {
191
202
  // UI 组件处理
192
- code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " \u7684 ").concat(props.title, " */") + "\n".concat(indent).concat(nextCode, "this.").concat(props.meta.id, ".").concat(props.id, "(").concat(nextValue, ")");
203
+ if (props.type === "frameOutput") {
204
+ var _event$meta, _currentScene$coms;
205
+ // 帧输出:找到拥有该帧的组件,通过 $outputs 调用
206
+ var _currentScene = config.getCurrentScene();
207
+ var parentComId = event.comId || ((_event$meta = event.meta) === null || _event$meta === void 0 ? void 0 : _event$meta.parentComId);
208
+ var frameConEntry = Object.values(_currentScene.cons || {}).flat().find(function (con) {
209
+ if (con.type !== "frame" || con.pinId !== props.id) return false;
210
+ if (parentComId && con.comId) return con.comId === parentComId;
211
+ return true;
212
+ });
213
+ var comId = (frameConEntry === null || frameConEntry === void 0 ? void 0 : frameConEntry.comId) || props.meta.id;
214
+ var comTitle = ((_currentScene$coms = _currentScene.coms) === null || _currentScene$coms === void 0 || (_currentScene$coms = _currentScene$coms[comId]) === null || _currentScene$coms === void 0 ? void 0 : _currentScene$coms.title) || props.meta.title || comId;
215
+ code += "".concat(indent, "/** \u8C03\u7528 ").concat(comTitle, " \u7684 ").concat(props.title, " */") + "\n".concat(indent).concat(nextCode, "$outputs['").concat(comId, "'].").concat(props.id, "(").concat(nextValue, ")");
216
+ } else {
217
+ code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " \u7684 ").concat(props.title, " */") + "\n".concat(indent).concat(nextCode, "this.").concat(props.meta.id, ".").concat(props.id, "(").concat(nextValue, ")");
218
+ }
193
219
  }
194
220
  });
195
221
  if (["fx", "extension-api", "extension-bus"].includes(event.type)) {
@@ -263,7 +289,11 @@ var getNextCode = function getNextCode(props, config, isSameScope, event) {
263
289
  return "";
264
290
  }
265
291
  var componentNameWithId = getComponentNameWithId(props, config, event);
266
- return "const ".concat(componentNameWithId, "_result = ");
292
+ // 使用输入端口ID(props.id)来区分同一组件的不同调用
293
+ // 这样可以确保 trigger 和 cancel 两个输入端口生成不同的变量名
294
+ var pinId = props.id;
295
+ var sanitizedPinId = pinId.replace(/[^a-zA-Z0-9_]/g, '_');
296
+ return "const ".concat(componentNameWithId, "_").concat(sanitizedPinId, "_result: any = ");
267
297
  };
268
298
 
269
299
  /**
@@ -282,13 +312,20 @@ function getFrameInputValueExpr(meta, config, event) {
282
312
  var pinProxy = scene === null || scene === void 0 || (_pinValueProxies = scene.pinValueProxies) === null || _pinValueProxies === void 0 ? void 0 : _pinValueProxies[proxyKey];
283
313
  var pinId = pinProxy === null || pinProxy === void 0 ? void 0 : pinProxy.pinId;
284
314
  if (typeof pinId === "string" && pinId) {
315
+ var _config$getParams;
316
+ // 优先使用 getParams 映射(场景级输入:回调参数名如 data)
317
+ var paramsMap = (_config$getParams = config.getParams) === null || _config$getParams === void 0 ? void 0 : _config$getParams.call(config);
318
+ if (paramsMap !== null && paramsMap !== void 0 && paramsMap[pinId]) {
319
+ return paramsMap[pinId];
320
+ }
321
+ // fallback:插槽场景使用 params.inputValues
285
322
  return "params?.inputValues?.[".concat(JSON.stringify(pinId), "]");
286
323
  }
287
324
  }
288
- var getNextValue = function getNextValue(props, config, event) {
325
+ var getNextValue = function getNextValue(props, config, event, outputToInputPinMap) {
289
326
  var paramSource = props.paramSource;
290
327
  var nextValue = paramSource.map(function (param) {
291
- var _param$meta, _param$meta2;
328
+ var _param$meta, _param$meta2, _param$meta4;
292
329
  if (param.type === "params") {
293
330
  var params = config.getParams();
294
331
  return params[param.id];
@@ -303,28 +340,52 @@ var getNextValue = function getNextValue(props, config, event) {
303
340
  var componentNameWithId = getComponentNameWithId(param, config, event);
304
341
  // 变量组件直接返回 Subject,不加 .id 后缀
305
342
  if ((_param$meta2 = param.meta) !== null && _param$meta2 !== void 0 && (_param$meta2 = _param$meta2.def) !== null && _param$meta2 !== void 0 && (_param$meta2 = _param$meta2.namespace) !== null && _param$meta2 !== void 0 && _param$meta2.includes(".var")) {
343
+ var _param$meta3;
344
+ // 从 outputToInputPinMap 中查找对应的输入端口ID
345
+ var _key = "".concat((_param$meta3 = param.meta) === null || _param$meta3 === void 0 ? void 0 : _param$meta3.id, "_").concat(param.id);
346
+ var _inputPinId = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(_key);
347
+ if (_inputPinId) {
348
+ return "".concat(componentNameWithId, "_").concat(_inputPinId, "_result");
349
+ }
306
350
  return "".concat(componentNameWithId, "_result");
307
351
  }
352
+
353
+ // 从 outputToInputPinMap 中查找对应的输入端口ID
354
+ // key = `${componentId}_${outputPinId}`
355
+ var key = "".concat((_param$meta4 = param.meta) === null || _param$meta4 === void 0 ? void 0 : _param$meta4.id, "_").concat(param.id);
356
+ var inputPinId = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(key);
357
+ if (inputPinId) {
358
+ return "".concat(componentNameWithId, "_").concat(inputPinId, "_result.").concat(param.id);
359
+ }
308
360
  return "".concat(componentNameWithId, "_result.").concat(param.id);
309
361
  });
310
362
  return nextValue.join(", ");
311
363
  };
312
364
  var getNextValueWithParam = function getNextValueWithParam(param, config, event) {
313
- var _param$meta3, _param$meta4;
365
+ var _param$meta5, _param$meta6;
314
366
  if (param.type === "params") {
315
367
  var params = config.getParams();
316
368
  return params[param.id];
317
369
  }
318
370
 
319
371
  // frame-input:直接从 slot params 读取(不生成 frameInput_xxx_result 临时变量)
320
- if (((_param$meta3 = param.meta) === null || _param$meta3 === void 0 || (_param$meta3 = _param$meta3.def) === null || _param$meta3 === void 0 ? void 0 : _param$meta3.namespace) === "mybricks.core-comlib.frame-input" && param.id === "return") {
372
+ if (((_param$meta5 = param.meta) === null || _param$meta5 === void 0 || (_param$meta5 = _param$meta5.def) === null || _param$meta5 === void 0 ? void 0 : _param$meta5.namespace) === "mybricks.core-comlib.frame-input" && param.id === "return") {
321
373
  return getFrameInputValueExpr(param.meta, config, event);
322
374
  }
323
375
  var componentNameWithId = getComponentNameWithId(param, config, event);
324
376
  // 变量组件直接返回 Subject
325
- if ((_param$meta4 = param.meta) !== null && _param$meta4 !== void 0 && (_param$meta4 = _param$meta4.def) !== null && _param$meta4 !== void 0 && (_param$meta4 = _param$meta4.namespace) !== null && _param$meta4 !== void 0 && _param$meta4.includes(".var")) {
377
+ if ((_param$meta6 = param.meta) !== null && _param$meta6 !== void 0 && (_param$meta6 = _param$meta6.def) !== null && _param$meta6 !== void 0 && (_param$meta6 = _param$meta6.namespace) !== null && _param$meta6 !== void 0 && _param$meta6.includes(".var")) {
378
+ var _connectId = param.connectId;
379
+ if (_connectId) {
380
+ return "".concat(componentNameWithId, "_").concat(_connectId, "_result");
381
+ }
326
382
  return "".concat(componentNameWithId, "_result");
327
383
  }
384
+ // 使用 connectId(连接ID)来引用对应的 result 变量
385
+ var connectId = param.connectId;
386
+ if (connectId) {
387
+ return "".concat(componentNameWithId, "_").concat(connectId, "_result.").concat(param.id);
388
+ }
328
389
  return "".concat(componentNameWithId, "_result.").concat(param.id);
329
390
  };
330
391
  var getCurrentProvider = function getCurrentProvider(params, config) {
@@ -381,7 +442,7 @@ var generateJsCalculationComponentCode = function generateJsCalculationComponent
381
442
  return "\"".concat(input, "\"");
382
443
  }).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, "outputs: [").concat(props.outputs.map(function (output) {
383
444
  return "\"".concat(output, "\"");
384
- }).join(", "), "],") : "") + "\n".concat(indent, "}, appContext)\n");
445
+ }).join(", "), "],") : "") + "\n".concat(indent, "}, appContext, '").concat(meta.id, "')\n");
385
446
  };
386
447
 
387
448
  /**
@@ -430,5 +491,5 @@ var generateJsApiComponentCode = function generateJsApiComponentCode(params) {
430
491
  return "\"".concat(input, "\"");
431
492
  }).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, " outputs: [").concat(props.outputs.map(function (output) {
432
493
  return "\"".concat(output, "\"");
433
- }).join(", "), "],") : "") + "\n".concat(indent2, "},") + "\n".concat(indent2, "appContext") + "\n".concat(indent, "})\n");
494
+ }).join(", "), "],") : "") + "\n".concat(indent2, "},") + "\n".concat(indent2, "appContext") + "\n".concat(indent, "}, '").concat(meta.id, "')\n");
434
495
  };
@@ -54,7 +54,7 @@ export var getUiComponentCode = function getUiComponentCode(params, config) {
54
54
  var ui = "".concat(indent, "<WithCom");
55
55
  ui += "\n".concat(indent2, "component={").concat(componentName, "}");
56
56
  ui += "\n".concat(indent2, "id='").concat(meta.id, "'");
57
- ui += "\n".concat(indent2, "className='").concat(meta.id, " mybricks_com'");
57
+ ui += "\n".concat(indent2, "className='mybricks_com ").concat(meta.id, "'");
58
58
  if (meta.name) {
59
59
  ui += "\n".concat(indent2, "name='").concat(meta.name, "'");
60
60
  }
@@ -55,11 +55,10 @@ export var RenderManager = /*#__PURE__*/function () {
55
55
  code += "".concat(indent, "/** ").concat(description, " */\n");
56
56
  }
57
57
  code += "".concat(indent, "function ").concat(renderFunctionName, "(params: any) {\n");
58
- // render 函数内的事件处理代码可能会用到 appContext(例如 jsModules.xxx(..., appContext))
59
- // outputs 统一从 comRefs.current.$outputs 读取(不再通过 context.outputs 透出)
60
58
  code += "".concat(indent).concat(indent2, "const { comRefs, $vars, $fxs, appContext } = useAppContext();\n");
61
- // code += `${indent}${indent2}const outputs = comRefs.current.$outputs;\n`;
62
-
59
+ if (logicCode !== null && logicCode !== void 0 && logicCode.includes('$outputs')) {
60
+ code += "".concat(indent).concat(indent2, "const $outputs = comRefs.current.$outputs;\n");
61
+ }
63
62
  if (logicCode) {
64
63
  code += logicCode.split("\n").map(function (line) {
65
64
  return "".concat(indent).concat(line);
@@ -101,7 +100,7 @@ export var RenderManager = /*#__PURE__*/function () {
101
100
  code += "".concat(indent).concat(indent4, "name: ").concat(child.name !== undefined ? "'".concat(child.name, "'") : 'undefined', ",\n");
102
101
  code += "".concat(indent).concat(indent4, "style: ").concat(childStyle, ",\n");
103
102
  code += "".concat(indent).concat(indent4, "get inputs() { return comRefs.current['").concat(child.id, "'] },\n");
104
- code += "".concat(indent).concat(indent4, "get outputs() { return outputs['").concat(child.id, "'] },\n");
103
+ code += "".concat(indent).concat(indent4, "get outputs() { return comRefs.current.$outputs['").concat(child.id, "'] },\n");
105
104
  code += "".concat(indent).concat(indent4, "jsx: ").concat(varName, ",\n");
106
105
  code += "".concat(indent).concat(indent3, "},\n");
107
106
  }
@@ -115,11 +114,9 @@ export var RenderManager = /*#__PURE__*/function () {
115
114
  // 如果是容器协议插槽,直接调用 wrap
116
115
  code += "".concat(indent).concat(indent3, "params?.wrap?.(descriptors)\n");
117
116
  } else {
118
- code += "".concat(indent).concat(indent3, "<>\n");
119
117
  code += modifiedRenderCode.split("\n").map(function (line) {
120
118
  return "".concat(indent).concat(indent2).concat(line);
121
119
  }).join("\n") + "\n";
122
- code += "".concat(indent).concat(indent3, "</>\n");
123
120
  }
124
121
  code += "".concat(indent).concat(indent2, ");\n");
125
122
  code += "".concat(indent, "}\n\n");
@@ -48,9 +48,9 @@ export var genComponentTemplate = function genComponentTemplate(_ref) {
48
48
  var pageScopeCode = "const PageScopeContext = createContext<any>(null);\n" + "function usePageScope<T = any>() {\n" + " return useContext(PageScopeContext) as T;\n" + "}\n\n";
49
49
 
50
50
  // 渲染定义放在组件外部,保持引用稳定
51
- var code = "".concat(pageScopeCode).concat(renderDefinitions, "\n") + "function ".concat(componentName, "() {\n") + " // \u9875\u9762\u7EA7 scope\uFF1A\u4F60\u53EF\u4EE5\u628A useState/useMemo \u7684\u7ED3\u679C\u653E\u5230\u8FD9\u4E2A ref \u4E0A\uFF0C\u8BA9\u63D2\u69FD\u8BFB\u53D6\n" + " const pageScopeRef = useRef<any>({});\n" + "".concat(combinedJsCode, "\n") + " return (\n" + " <PageScopeContext.Provider value={pageScopeRef}>\n" + " <>\n" + "".concat(uiResult.split('\n').map(function (line) {
51
+ var code = "".concat(pageScopeCode).concat(renderDefinitions, "\n") + "function ".concat(componentName, "() {\n") + " // \u9875\u9762\u7EA7 scope\uFF1A\u4F60\u53EF\u4EE5\u628A useState/useMemo \u7684\u7ED3\u679C\u653E\u5230\u8FD9\u4E2A ref \u4E0A\uFF0C\u8BA9\u63D2\u69FD\u8BFB\u53D6\n" + " const pageScopeRef = useRef<any>({});\n" + "".concat(combinedJsCode, "\n") + " return (\n" + " <PageScopeContext.Provider value={pageScopeRef}>\n" + (hasPopups ? " <>\n" : "") + "".concat(uiResult.split('\n').map(function (line) {
52
52
  return " ".concat(line);
53
- }).join('\n'), "\n") + (hasPopups ? " <PopupRenderer popupMap={POPUP_MAP} />\n" : "") + " </>\n" + " </PageScopeContext.Provider>\n" + " );\n" + "}\n\n";
53
+ }).join('\n'), "\n") + (hasPopups ? " <PopupRenderer popupMap={POPUP_MAP} />\n" : "") + (hasPopups ? " </>\n" : "") + " </PageScopeContext.Provider>\n" + " );\n" + "}\n\n";
54
54
  if (isPopup) {
55
55
  code += "(".concat(componentName, " as any).isPopup = true;\n\n");
56
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mybricks/to-code-taro",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "To code for Taro",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,114 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/core/comlib/Index.ts
30
- var Index_exports = {};
31
- __export(Index_exports, {
32
- mybricks_taro_aesEncode: () => import_AesEncode.default,
33
- mybricks_taro_callPhone: () => import_CallPhone.default,
34
- mybricks_taro_chooseFile: () => import_ChooseFile.default,
35
- mybricks_taro_chooseMedia: () => import_ChooseMedia.default,
36
- mybricks_taro_connector: () => import_Connector.default,
37
- mybricks_taro_connectorGlobalHeaders: () => import_ConnectorGlobalHeaders.default,
38
- mybricks_taro_format: () => import_Format.default,
39
- mybricks_taro_getLocation: () => import_GetLocation.default,
40
- mybricks_taro_getStorage: () => import_GetStorage.default,
41
- mybricks_taro_getSystemInfo: () => import_GetSystemInfo.default,
42
- mybricks_taro_modal: () => import_Modal.default,
43
- mybricks_taro_navigateBack: () => import_BackTo.default,
44
- mybricks_taro_openCamera: () => import_OpenCamera.default,
45
- mybricks_taro_openPetalMap: () => import_OpenPetalMap.default,
46
- mybricks_taro_openUrl: () => import_OpenUrl.default,
47
- mybricks_taro_removeStorage: () => import_RemoveStorage.default,
48
- mybricks_taro_router: () => import_Router.default,
49
- mybricks_taro_scanQrcode: () => import_ScanQrcode.default,
50
- mybricks_taro_setStorage: () => import_SetStorage.default,
51
- mybricks_taro_share: () => import_Share.default,
52
- mybricks_taro_showToast: () => import_ShowToast.default,
53
- mybricks_taro_textToSpeech: () => import_TextToSpeech.default,
54
- mybricks_taro_timerDebounce: () => import_TimerDebounce.default,
55
- mybricks_taro_timerDelay: () => import_TimerDelay.default,
56
- mybricks_taro_timerThrottle: () => import_TimerThrottle.default,
57
- mybricks_taro_vibrate: () => import_Vibrate.default
58
- });
59
- module.exports = __toCommonJS(Index_exports);
60
- var import_ShowToast = __toESM(require("./_ShowToast"));
61
- var import_ScanQrcode = __toESM(require("./_ScanQrcode"));
62
- var import_SetStorage = __toESM(require("./_SetStorage"));
63
- var import_GetStorage = __toESM(require("./_GetStorage"));
64
- var import_RemoveStorage = __toESM(require("./_RemoveStorage"));
65
- var import_GetLocation = __toESM(require("./_GetLocation"));
66
- var import_Vibrate = __toESM(require("./_Vibrate"));
67
- var import_CallPhone = __toESM(require("./_CallPhone"));
68
- var import_OpenCamera = __toESM(require("./_OpenCamera"));
69
- var import_OpenUrl = __toESM(require("./_OpenUrl"));
70
- var import_Share = __toESM(require("./_Share"));
71
- var import_GetSystemInfo = __toESM(require("./_GetSystemInfo"));
72
- var import_AesEncode = __toESM(require("./_AesEncode"));
73
- var import_Modal = __toESM(require("./_Modal"));
74
- var import_Format = __toESM(require("./_Format"));
75
- var import_ChooseFile = __toESM(require("./_ChooseFile"));
76
- var import_ChooseMedia = __toESM(require("./_ChooseMedia"));
77
- var import_Connector = __toESM(require("./_Connector"));
78
- var import_ConnectorGlobalHeaders = __toESM(require("./_ConnectorGlobalHeaders"));
79
- var import_BackTo = __toESM(require("./_BackTo"));
80
- var import_Router = __toESM(require("./_Router"));
81
- var import_OpenPetalMap = __toESM(require("./_OpenPetalMap"));
82
- var import_TextToSpeech = __toESM(require("./_TextToSpeech"));
83
- var import_TimerDebounce = __toESM(require("./_TimerDebounce"));
84
- var import_TimerDelay = __toESM(require("./_TimerDelay"));
85
- var import_TimerThrottle = __toESM(require("./_TimerThrottle"));
86
- // Annotate the CommonJS export names for ESM import in node:
87
- 0 && (module.exports = {
88
- mybricks_taro_aesEncode,
89
- mybricks_taro_callPhone,
90
- mybricks_taro_chooseFile,
91
- mybricks_taro_chooseMedia,
92
- mybricks_taro_connector,
93
- mybricks_taro_connectorGlobalHeaders,
94
- mybricks_taro_format,
95
- mybricks_taro_getLocation,
96
- mybricks_taro_getStorage,
97
- mybricks_taro_getSystemInfo,
98
- mybricks_taro_modal,
99
- mybricks_taro_navigateBack,
100
- mybricks_taro_openCamera,
101
- mybricks_taro_openPetalMap,
102
- mybricks_taro_openUrl,
103
- mybricks_taro_removeStorage,
104
- mybricks_taro_router,
105
- mybricks_taro_scanQrcode,
106
- mybricks_taro_setStorage,
107
- mybricks_taro_share,
108
- mybricks_taro_showToast,
109
- mybricks_taro_textToSpeech,
110
- mybricks_taro_timerDebounce,
111
- mybricks_taro_timerDelay,
112
- mybricks_taro_timerThrottle,
113
- mybricks_taro_vibrate
114
- });
@@ -1,115 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/core/comlib/_AesEncode.ts
30
- var AesEncode_exports = {};
31
- __export(AesEncode_exports, {
32
- default: () => AesEncode_default
33
- });
34
- module.exports = __toCommonJS(AesEncode_exports);
35
- var import_crypto_js = __toESM(require("crypto-js"));
36
- var AesEncode_default = (context) => {
37
- var _a, _b;
38
- const data = context.data;
39
- const inputs = context.inputs;
40
- const outputs = context.outputs;
41
- const modeMap = {
42
- CBC: import_crypto_js.default.mode.CBC,
43
- ECB: import_crypto_js.default.mode.ECB,
44
- CFB: import_crypto_js.default.mode.CFB,
45
- OFB: import_crypto_js.default.mode.OFB,
46
- CTR: import_crypto_js.default.mode.CTR
47
- };
48
- const paddingMap = {
49
- Pkcs7: import_crypto_js.default.pad.Pkcs7,
50
- Iso97971: import_crypto_js.default.pad.Iso97971,
51
- AnsiX923: import_crypto_js.default.pad.AnsiX923,
52
- Iso10126: import_crypto_js.default.pad.Iso10126,
53
- ZeroPadding: import_crypto_js.default.pad.ZeroPadding,
54
- NoPadding: import_crypto_js.default.pad.NoPadding
55
- };
56
- (_a = inputs.encrypt) == null ? void 0 : _a.call(inputs, (val) => {
57
- try {
58
- const text = val.text || "";
59
- const key = val.key || data.key || "defaultKey1234567890123456";
60
- const iv = val.iv || data.iv;
61
- const mode = modeMap[val.mode || data.mode || "CBC"];
62
- const padding = paddingMap[val.padding || data.padding || "Pkcs7"];
63
- if (!text) {
64
- outputs.onFail("待加密文本不能为空");
65
- return;
66
- }
67
- const keyBytes = import_crypto_js.default.enc.Utf8.parse(key);
68
- const ivBytes = iv ? import_crypto_js.default.enc.Utf8.parse(iv) : void 0;
69
- const encrypted = import_crypto_js.default.AES.encrypt(text, keyBytes, {
70
- mode,
71
- padding,
72
- iv: ivBytes
73
- });
74
- outputs.onEncryptSuccess({
75
- encryptedText: encrypted.toString(),
76
- originalText: text
77
- });
78
- } catch (error) {
79
- console.error("AES加密失败:", error);
80
- outputs.onFail((error == null ? void 0 : error.message) || "AES加密失败");
81
- }
82
- });
83
- (_b = inputs.decrypt) == null ? void 0 : _b.call(inputs, (val) => {
84
- try {
85
- const encryptedText = val.encryptedText || "";
86
- const key = val.key || data.key || "defaultKey1234567890123456";
87
- const iv = val.iv || data.iv;
88
- const mode = modeMap[val.mode || data.mode || "CBC"];
89
- const padding = paddingMap[val.padding || data.padding || "Pkcs7"];
90
- if (!encryptedText) {
91
- outputs.onFail("待解密文本不能为空");
92
- return;
93
- }
94
- const keyBytes = import_crypto_js.default.enc.Utf8.parse(key);
95
- const ivBytes = iv ? import_crypto_js.default.enc.Utf8.parse(iv) : void 0;
96
- const decrypted = import_crypto_js.default.AES.decrypt(encryptedText, keyBytes, {
97
- mode,
98
- padding,
99
- iv: ivBytes
100
- });
101
- const decryptedText = decrypted.toString(import_crypto_js.default.enc.Utf8);
102
- if (!decryptedText) {
103
- outputs.onFail("解密失败,可能密钥或参数不正确");
104
- return;
105
- }
106
- outputs.onDecryptSuccess({
107
- decryptedText,
108
- encryptedText
109
- });
110
- } catch (error) {
111
- console.error("AES解密失败:", error);
112
- outputs.onFail((error == null ? void 0 : error.message) || "AES解密失败");
113
- }
114
- });
115
- };