@mybricks/to-code-taro 1.1.5 → 1.1.6

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 (122) 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 +23 -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 +4 -9
  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 +1312 -1018
  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 +54 -12
  33. package/dist/cjs/utils/templates/renderManager.js +5 -1
  34. package/dist/esm/core/mybricks/Subject.js +11 -5
  35. package/dist/esm/core/mybricks/createJSHandle.js +55 -5
  36. package/dist/esm/core/utils/comRefResolver.js +134 -0
  37. package/dist/esm/core/utils/event.js +32 -0
  38. package/dist/esm/core/utils/hooks.js +109 -39
  39. package/dist/esm/core/utils/index.js +1 -0
  40. package/dist/esm/core/utils/pageRouter.js +56 -13
  41. package/dist/esm/core/utils/slots.js +78 -12
  42. package/dist/esm/core/utils/tabbar.js +47 -0
  43. package/dist/esm/core/utils/useContext.js +42 -2
  44. package/dist/esm/core/utils/with.js +19 -53
  45. package/dist/esm/generate/generateTaroProjectJson.js +2 -20
  46. package/dist/esm/generate/utils/appConfig.d.ts +1 -1
  47. package/dist/esm/generate/utils/appConfig.js +29 -9
  48. package/dist/esm/generate/utils/commonDir.js +13 -0
  49. package/dist/esm/generate/utils/customTabBar.d.ts +11 -0
  50. package/dist/esm/generate/utils/customTabBar.js +52 -0
  51. package/dist/esm/generate/utils/fileNode.d.ts +4 -0
  52. package/dist/esm/generate/utils/fileNode.js +13 -0
  53. package/dist/esm/handleCom.js +24 -21
  54. package/dist/esm/handleGlobal.d.ts +1 -1
  55. package/dist/esm/handleGlobal.js +6 -1
  56. package/dist/esm/handleSlot.js +6 -11
  57. package/dist/esm/processors/processScene.js +23 -3
  58. package/dist/esm/processors/processSceneLogic.js +3 -5
  59. package/dist/esm/taro-template.json +1312 -1018
  60. package/dist/esm/toCodeTaro.d.ts +1 -2
  61. package/dist/esm/toCodeTaro.js +1 -1
  62. package/dist/esm/utils/builder/buildResult.js +1 -2
  63. package/dist/esm/utils/common/ImportManager.d.ts +7 -0
  64. package/dist/esm/utils/common/ImportManager.js +42 -14
  65. package/dist/esm/utils/logic/genJSModules.js +2 -2
  66. package/dist/esm/utils/logic/handleProcess.js +66 -12
  67. package/dist/esm/utils/templates/renderManager.js +4 -5
  68. package/package.json +1 -1
  69. package/dist/cjs/core/comlib/Index.js +0 -114
  70. package/dist/cjs/core/comlib/_AesEncode.js +0 -115
  71. package/dist/cjs/core/comlib/_BackTo.js +0 -80
  72. package/dist/cjs/core/comlib/_CallPhone.js +0 -58
  73. package/dist/cjs/core/comlib/_ChooseFile.js +0 -103
  74. package/dist/cjs/core/comlib/_ChooseMedia.js +0 -70
  75. package/dist/cjs/core/comlib/_Connector.js +0 -79
  76. package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +0 -79
  77. package/dist/cjs/core/comlib/_Format.js +0 -123
  78. package/dist/cjs/core/comlib/_GetLocation.js +0 -60
  79. package/dist/cjs/core/comlib/_GetStorage.js +0 -68
  80. package/dist/cjs/core/comlib/_GetSystemInfo.js +0 -62
  81. package/dist/cjs/core/comlib/_Modal.js +0 -68
  82. package/dist/cjs/core/comlib/_OpenCamera.js +0 -73
  83. package/dist/cjs/core/comlib/_OpenPetalMap.js +0 -49
  84. package/dist/cjs/core/comlib/_OpenUrl.js +0 -62
  85. package/dist/cjs/core/comlib/_RemoveStorage.js +0 -68
  86. package/dist/cjs/core/comlib/_Router.js +0 -100
  87. package/dist/cjs/core/comlib/_ScanQrcode.js +0 -59
  88. package/dist/cjs/core/comlib/_SetStorage.js +0 -67
  89. package/dist/cjs/core/comlib/_Share.js +0 -58
  90. package/dist/cjs/core/comlib/_ShowToast.js +0 -69
  91. package/dist/cjs/core/comlib/_TextToSpeech.js +0 -120
  92. package/dist/cjs/core/comlib/_TimerDebounce.js +0 -72
  93. package/dist/cjs/core/comlib/_TimerDelay.js +0 -88
  94. package/dist/cjs/core/comlib/_TimerThrottle.js +0 -75
  95. package/dist/cjs/core/comlib/_Vibrate.js +0 -60
  96. package/dist/esm/core/comlib/Index.js +0 -39
  97. package/dist/esm/core/comlib/_AesEncode.js +0 -85
  98. package/dist/esm/core/comlib/_BackTo.js +0 -66
  99. package/dist/esm/core/comlib/_CallPhone.js +0 -30
  100. package/dist/esm/core/comlib/_ChooseFile.js +0 -81
  101. package/dist/esm/core/comlib/_ChooseMedia.js +0 -38
  102. package/dist/esm/core/comlib/_Connector.js +0 -77
  103. package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +0 -56
  104. package/dist/esm/core/comlib/_Format.js +0 -102
  105. package/dist/esm/core/comlib/_GetLocation.js +0 -26
  106. package/dist/esm/core/comlib/_GetStorage.js +0 -44
  107. package/dist/esm/core/comlib/_GetSystemInfo.js +0 -32
  108. package/dist/esm/core/comlib/_Modal.js +0 -51
  109. package/dist/esm/core/comlib/_OpenCamera.js +0 -44
  110. package/dist/esm/core/comlib/_OpenPetalMap.js +0 -28
  111. package/dist/esm/core/comlib/_OpenUrl.js +0 -36
  112. package/dist/esm/core/comlib/_RemoveStorage.js +0 -42
  113. package/dist/esm/core/comlib/_Router.js +0 -113
  114. package/dist/esm/core/comlib/_ScanQrcode.js +0 -26
  115. package/dist/esm/core/comlib/_SetStorage.js +0 -40
  116. package/dist/esm/core/comlib/_Share.js +0 -28
  117. package/dist/esm/core/comlib/_ShowToast.js +0 -45
  118. package/dist/esm/core/comlib/_TextToSpeech.js +0 -117
  119. package/dist/esm/core/comlib/_TimerDebounce.js +0 -66
  120. package/dist/esm/core/comlib/_TimerDelay.js +0 -79
  121. package/dist/esm/core/comlib/_TimerThrottle.js +0 -69
  122. 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
  /**
@@ -285,10 +315,10 @@ function getFrameInputValueExpr(meta, config, event) {
285
315
  return "params?.inputValues?.[".concat(JSON.stringify(pinId), "]");
286
316
  }
287
317
  }
288
- var getNextValue = function getNextValue(props, config, event) {
318
+ var getNextValue = function getNextValue(props, config, event, outputToInputPinMap) {
289
319
  var paramSource = props.paramSource;
290
320
  var nextValue = paramSource.map(function (param) {
291
- var _param$meta, _param$meta2;
321
+ var _param$meta, _param$meta2, _param$meta4;
292
322
  if (param.type === "params") {
293
323
  var params = config.getParams();
294
324
  return params[param.id];
@@ -303,28 +333,52 @@ var getNextValue = function getNextValue(props, config, event) {
303
333
  var componentNameWithId = getComponentNameWithId(param, config, event);
304
334
  // 变量组件直接返回 Subject,不加 .id 后缀
305
335
  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")) {
336
+ var _param$meta3;
337
+ // 从 outputToInputPinMap 中查找对应的输入端口ID
338
+ var _key = "".concat((_param$meta3 = param.meta) === null || _param$meta3 === void 0 ? void 0 : _param$meta3.id, "_").concat(param.id);
339
+ var _inputPinId = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(_key);
340
+ if (_inputPinId) {
341
+ return "".concat(componentNameWithId, "_").concat(_inputPinId, "_result");
342
+ }
306
343
  return "".concat(componentNameWithId, "_result");
307
344
  }
345
+
346
+ // 从 outputToInputPinMap 中查找对应的输入端口ID
347
+ // key = `${componentId}_${outputPinId}`
348
+ var key = "".concat((_param$meta4 = param.meta) === null || _param$meta4 === void 0 ? void 0 : _param$meta4.id, "_").concat(param.id);
349
+ var inputPinId = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(key);
350
+ if (inputPinId) {
351
+ return "".concat(componentNameWithId, "_").concat(inputPinId, "_result.").concat(param.id);
352
+ }
308
353
  return "".concat(componentNameWithId, "_result.").concat(param.id);
309
354
  });
310
355
  return nextValue.join(", ");
311
356
  };
312
357
  var getNextValueWithParam = function getNextValueWithParam(param, config, event) {
313
- var _param$meta3, _param$meta4;
358
+ var _param$meta5, _param$meta6;
314
359
  if (param.type === "params") {
315
360
  var params = config.getParams();
316
361
  return params[param.id];
317
362
  }
318
363
 
319
364
  // 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") {
365
+ 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
366
  return getFrameInputValueExpr(param.meta, config, event);
322
367
  }
323
368
  var componentNameWithId = getComponentNameWithId(param, config, event);
324
369
  // 变量组件直接返回 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")) {
370
+ 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")) {
371
+ var _connectId = param.connectId;
372
+ if (_connectId) {
373
+ return "".concat(componentNameWithId, "_").concat(_connectId, "_result");
374
+ }
326
375
  return "".concat(componentNameWithId, "_result");
327
376
  }
377
+ // 使用 connectId(连接ID)来引用对应的 result 变量
378
+ var connectId = param.connectId;
379
+ if (connectId) {
380
+ return "".concat(componentNameWithId, "_").concat(connectId, "_result.").concat(param.id);
381
+ }
328
382
  return "".concat(componentNameWithId, "_result.").concat(param.id);
329
383
  };
330
384
  var getCurrentProvider = function getCurrentProvider(params, config) {
@@ -381,7 +435,7 @@ var generateJsCalculationComponentCode = function generateJsCalculationComponent
381
435
  return "\"".concat(input, "\"");
382
436
  }).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, "outputs: [").concat(props.outputs.map(function (output) {
383
437
  return "\"".concat(output, "\"");
384
- }).join(", "), "],") : "") + "\n".concat(indent, "}, appContext)\n");
438
+ }).join(", "), "],") : "") + "\n".concat(indent, "}, appContext, '").concat(meta.id, "')\n");
385
439
  };
386
440
 
387
441
  /**
@@ -430,5 +484,5 @@ var generateJsApiComponentCode = function generateJsApiComponentCode(params) {
430
484
  return "\"".concat(input, "\"");
431
485
  }).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, " outputs: [").concat(props.outputs.map(function (output) {
432
486
  return "\"".concat(output, "\"");
433
- }).join(", "), "],") : "") + "\n".concat(indent2, "},") + "\n".concat(indent2, "appContext") + "\n".concat(indent, "})\n");
487
+ }).join(", "), "],") : "") + "\n".concat(indent2, "},") + "\n".concat(indent2, "appContext") + "\n".concat(indent, "}, '").concat(meta.id, "')\n");
434
488
  };
@@ -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
  }
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.6",
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
- };
@@ -1,80 +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/_BackTo.ts
30
- var BackTo_exports = {};
31
- __export(BackTo_exports, {
32
- default: () => BackTo_default
33
- });
34
- module.exports = __toCommonJS(BackTo_exports);
35
- var import_taro = __toESM(require("@tarojs/taro"));
36
- var BackTo_default = (context) => {
37
- var _a;
38
- const data = context.data;
39
- const inputs = context.inputs;
40
- const outputs = context.outputs;
41
- (_a = inputs.back) == null ? void 0 : _a.call(inputs, (val) => {
42
- try {
43
- const delta = (val == null ? void 0 : val.delta) ?? data.delta ?? 1;
44
- const animation = (val == null ? void 0 : val.animation) !== void 0 ? val.animation : data.animation ?? true;
45
- const pages = import_taro.default.getCurrentPages();
46
- const currentIndex = pages.length - 1;
47
- if (currentIndex === 0) {
48
- outputs.onFail("已经是首页,无法返回");
49
- return;
50
- }
51
- if (delta > currentIndex) {
52
- outputs.onFail(`页面栈深度不足,无法返回${delta}层`);
53
- return;
54
- }
55
- if (delta === 1) {
56
- import_taro.default.navigateBack({
57
- delta: 1,
58
- animation,
59
- success: () => outputs.onSuccess({ delta: 1 }),
60
- fail: (err) => outputs.onFail(err.errMsg || "返回失败")
61
- });
62
- } else {
63
- const targetPage = pages[currentIndex - delta];
64
- if (targetPage) {
65
- import_taro.default.navigateBack({
66
- delta,
67
- animation,
68
- success: () => outputs.onSuccess({ delta, targetPage: targetPage.route }),
69
- fail: (err) => outputs.onFail(err.errMsg || "返回失败")
70
- });
71
- } else {
72
- outputs.onFail("目标页面不存在");
73
- }
74
- }
75
- } catch (error) {
76
- console.error("返回操作失败:", error);
77
- outputs.onFail((error == null ? void 0 : error.message) || "返回操作失败");
78
- }
79
- });
80
- };