@mybricks/to-code-taro 1.1.4 → 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 (169) hide show
  1. package/dist/cjs/core/mybricks/Subject.js +9 -5
  2. package/dist/cjs/core/mybricks/createJSHandle.js +45 -4
  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 +76 -39
  6. package/dist/cjs/core/utils/index.js +6 -0
  7. package/dist/cjs/core/utils/pageRouter.js +34 -11
  8. package/dist/cjs/core/utils/pool.js +63 -0
  9. package/dist/cjs/core/utils/slots.js +59 -13
  10. package/dist/cjs/core/utils/tabbar.js +56 -0
  11. package/dist/cjs/core/utils/useContext.js +46 -4
  12. package/dist/cjs/core/utils/with.js +9 -34
  13. package/dist/cjs/generate/generateTaroProjectJson.js +11 -18
  14. package/dist/cjs/generate/utils/appConfig.d.ts +1 -1
  15. package/dist/cjs/generate/utils/appConfig.js +23 -12
  16. package/dist/cjs/generate/utils/commonDir.js +9 -0
  17. package/dist/cjs/generate/utils/customTabBar.d.ts +11 -0
  18. package/dist/cjs/generate/utils/customTabBar.js +73 -0
  19. package/dist/cjs/generate/utils/fileNode.d.ts +4 -0
  20. package/dist/cjs/generate/utils/fileNode.js +12 -2
  21. package/dist/cjs/handleCom.js +15 -16
  22. package/dist/cjs/handleGlobal.d.ts +1 -1
  23. package/dist/cjs/handleGlobal.js +6 -0
  24. package/dist/cjs/handleSlot.js +4 -9
  25. package/dist/cjs/processors/processScene.js +13 -1
  26. package/dist/cjs/processors/processSceneLogic.js +2 -6
  27. package/dist/cjs/taro-template.json +1318 -1016
  28. package/dist/cjs/toCodeTaro.d.ts +1 -2
  29. package/dist/cjs/toCodeTaro.js +2 -0
  30. package/dist/cjs/utils/builder/buildResult.d.ts +1 -0
  31. package/dist/cjs/utils/builder/buildResult.js +54 -2
  32. package/dist/cjs/utils/common/ImportManager.d.ts +7 -0
  33. package/dist/cjs/utils/common/ImportManager.js +19 -1
  34. package/dist/cjs/utils/context/buildContext.d.ts +7 -0
  35. package/dist/cjs/utils/context/buildContext.js +11 -0
  36. package/dist/cjs/utils/logic/genJSModules.js +2 -2
  37. package/dist/cjs/utils/logic/handleProcess.js +54 -12
  38. package/dist/cjs/utils/templates/renderManager.js +4 -2
  39. package/dist/esm/core/mybricks/Subject.js +11 -5
  40. package/dist/esm/core/mybricks/createJSHandle.js +57 -6
  41. package/dist/esm/core/utils/comRefResolver.js +134 -0
  42. package/dist/esm/core/utils/event.js +32 -0
  43. package/dist/esm/core/utils/hooks.js +114 -51
  44. package/dist/esm/core/utils/index.js +2 -0
  45. package/dist/esm/core/utils/pageRouter.js +56 -13
  46. package/dist/esm/core/utils/pool.js +52 -0
  47. package/dist/esm/core/utils/slots.js +82 -16
  48. package/dist/esm/core/utils/tabbar.js +47 -0
  49. package/dist/esm/core/utils/useContext.js +53 -4
  50. package/dist/esm/core/utils/with.js +19 -53
  51. package/dist/esm/generate/generateTaroProjectJson.js +14 -20
  52. package/dist/esm/generate/utils/appConfig.d.ts +1 -1
  53. package/dist/esm/generate/utils/appConfig.js +29 -9
  54. package/dist/esm/generate/utils/commonDir.js +13 -0
  55. package/dist/esm/generate/utils/customTabBar.d.ts +11 -0
  56. package/dist/esm/generate/utils/customTabBar.js +52 -0
  57. package/dist/esm/generate/utils/fileNode.d.ts +4 -0
  58. package/dist/esm/generate/utils/fileNode.js +13 -0
  59. package/dist/esm/handleCom.js +24 -21
  60. package/dist/esm/handleGlobal.d.ts +1 -1
  61. package/dist/esm/handleGlobal.js +6 -1
  62. package/dist/esm/handleSlot.js +6 -11
  63. package/dist/esm/processors/processScene.js +23 -3
  64. package/dist/esm/processors/processSceneLogic.js +3 -5
  65. package/dist/esm/taro-template.json +1318 -1016
  66. package/dist/esm/toCodeTaro.d.ts +1 -2
  67. package/dist/esm/toCodeTaro.js +4 -2
  68. package/dist/esm/utils/builder/buildResult.d.ts +1 -0
  69. package/dist/esm/utils/builder/buildResult.js +42 -3
  70. package/dist/esm/utils/common/ImportManager.d.ts +7 -0
  71. package/dist/esm/utils/common/ImportManager.js +42 -14
  72. package/dist/esm/utils/context/buildContext.d.ts +7 -0
  73. package/dist/esm/utils/context/buildContext.js +12 -0
  74. package/dist/esm/utils/logic/genJSModules.js +2 -2
  75. package/dist/esm/utils/logic/handleProcess.js +66 -12
  76. package/dist/esm/utils/templates/renderManager.js +4 -4
  77. package/package.json +1 -1
  78. package/dist/cjs/core/comlib/Index.js +0 -114
  79. package/dist/cjs/core/comlib/_AesEncode.js +0 -115
  80. package/dist/cjs/core/comlib/_BackTo.js +0 -80
  81. package/dist/cjs/core/comlib/_CallPhone.js +0 -58
  82. package/dist/cjs/core/comlib/_ChooseFile.js +0 -103
  83. package/dist/cjs/core/comlib/_ChooseMedia.js +0 -70
  84. package/dist/cjs/core/comlib/_Connector.js +0 -92
  85. package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +0 -79
  86. package/dist/cjs/core/comlib/_Format.js +0 -123
  87. package/dist/cjs/core/comlib/_GetLocation.js +0 -60
  88. package/dist/cjs/core/comlib/_GetStorage.js +0 -68
  89. package/dist/cjs/core/comlib/_GetSystemInfo.js +0 -62
  90. package/dist/cjs/core/comlib/_Modal.js +0 -68
  91. package/dist/cjs/core/comlib/_OpenCamera.js +0 -73
  92. package/dist/cjs/core/comlib/_OpenPetalMap.js +0 -49
  93. package/dist/cjs/core/comlib/_OpenUrl.js +0 -62
  94. package/dist/cjs/core/comlib/_RemoveStorage.js +0 -68
  95. package/dist/cjs/core/comlib/_Router.js +0 -100
  96. package/dist/cjs/core/comlib/_ScanQrcode.js +0 -59
  97. package/dist/cjs/core/comlib/_SetStorage.js +0 -67
  98. package/dist/cjs/core/comlib/_Share.js +0 -58
  99. package/dist/cjs/core/comlib/_ShowToast.js +0 -69
  100. package/dist/cjs/core/comlib/_TextToSpeech.js +0 -120
  101. package/dist/cjs/core/comlib/_TimerDebounce.js +0 -72
  102. package/dist/cjs/core/comlib/_TimerDelay.js +0 -88
  103. package/dist/cjs/core/comlib/_TimerThrottle.js +0 -75
  104. package/dist/cjs/core/comlib/_Vibrate.js +0 -60
  105. package/dist/esm/abstractEventTypeDef.d.ts.map +0 -1
  106. package/dist/esm/core/comlib/Index.js +0 -39
  107. package/dist/esm/core/comlib/_AesEncode.js +0 -85
  108. package/dist/esm/core/comlib/_BackTo.js +0 -66
  109. package/dist/esm/core/comlib/_CallPhone.js +0 -30
  110. package/dist/esm/core/comlib/_ChooseFile.js +0 -81
  111. package/dist/esm/core/comlib/_ChooseMedia.js +0 -38
  112. package/dist/esm/core/comlib/_Connector.js +0 -60
  113. package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +0 -56
  114. package/dist/esm/core/comlib/_Format.js +0 -102
  115. package/dist/esm/core/comlib/_GetLocation.js +0 -26
  116. package/dist/esm/core/comlib/_GetStorage.js +0 -44
  117. package/dist/esm/core/comlib/_GetSystemInfo.js +0 -32
  118. package/dist/esm/core/comlib/_Modal.js +0 -51
  119. package/dist/esm/core/comlib/_OpenCamera.js +0 -44
  120. package/dist/esm/core/comlib/_OpenPetalMap.js +0 -28
  121. package/dist/esm/core/comlib/_OpenUrl.js +0 -36
  122. package/dist/esm/core/comlib/_RemoveStorage.js +0 -42
  123. package/dist/esm/core/comlib/_Router.js +0 -113
  124. package/dist/esm/core/comlib/_ScanQrcode.js +0 -26
  125. package/dist/esm/core/comlib/_SetStorage.js +0 -40
  126. package/dist/esm/core/comlib/_Share.js +0 -28
  127. package/dist/esm/core/comlib/_ShowToast.js +0 -45
  128. package/dist/esm/core/comlib/_TextToSpeech.js +0 -117
  129. package/dist/esm/core/comlib/_TimerDebounce.js +0 -66
  130. package/dist/esm/core/comlib/_TimerDelay.js +0 -79
  131. package/dist/esm/core/comlib/_TimerThrottle.js +0 -69
  132. package/dist/esm/core/comlib/_Vibrate.js +0 -34
  133. package/dist/esm/generate/generateTaroTempalteJson.d.ts.map +0 -1
  134. package/dist/esm/generate/utils/appConfig.d.ts.map +0 -1
  135. package/dist/esm/generate/utils/fileNode.d.ts.map +0 -1
  136. package/dist/esm/generate/utils/index.d.ts.map +0 -1
  137. package/dist/esm/generate/utils/pageImages.d.ts.map +0 -1
  138. package/dist/esm/generate/utils/tabBarImages.d.ts.map +0 -1
  139. package/dist/esm/handleExtension.d.ts.map +0 -1
  140. package/dist/esm/handleModule.d.ts.map +0 -1
  141. package/dist/esm/index.d.ts.map +0 -1
  142. package/dist/esm/processors/processComEvents.d.ts.map +0 -1
  143. package/dist/esm/processors/processModule.d.ts.map +0 -1
  144. package/dist/esm/processors/processScene.d.ts.map +0 -1
  145. package/dist/esm/processors/processSceneLogic.d.ts.map +0 -1
  146. package/dist/esm/toCodeTaro.d.ts.map +0 -1
  147. package/dist/esm/utils/builder/buildResult.d.ts.map +0 -1
  148. package/dist/esm/utils/common/ImportManager.d.ts.map +0 -1
  149. package/dist/esm/utils/common/helper.d.ts.map +0 -1
  150. package/dist/esm/utils/common/object.d.ts.map +0 -1
  151. package/dist/esm/utils/common/string.d.ts.map +0 -1
  152. package/dist/esm/utils/config/content/index.d.ts.map +0 -1
  153. package/dist/esm/utils/config/content/types.d.ts.map +0 -1
  154. package/dist/esm/utils/config/content/validator.d.ts.map +0 -1
  155. package/dist/esm/utils/config/handlePageConfig.d.ts.map +0 -1
  156. package/dist/esm/utils/context/buildContext.d.ts.map +0 -1
  157. package/dist/esm/utils/context/buildFrameMap.d.ts.map +0 -1
  158. package/dist/esm/utils/context/buildGlobalData.d.ts.map +0 -1
  159. package/dist/esm/utils/context/collectJSModules.d.ts.map +0 -1
  160. package/dist/esm/utils/context/createEventQueries.d.ts.map +0 -1
  161. package/dist/esm/utils/context/createProvider.d.ts.map +0 -1
  162. package/dist/esm/utils/index.d.ts.map +0 -1
  163. package/dist/esm/utils/logic/convertNamespace.d.ts.map +0 -1
  164. package/dist/esm/utils/logic/genJSModules.d.ts.map +0 -1
  165. package/dist/esm/utils/style/color.d.ts.map +0 -1
  166. package/dist/esm/utils/style/getComponentClassName.d.ts.map +0 -1
  167. package/dist/esm/utils/style/pxtransform.d.ts.map +0 -1
  168. package/dist/esm/utils/style/types.d.ts.map +0 -1
  169. package/dist/esm/utils/templates/component.d.ts.map +0 -1
@@ -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" | "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 {
@@ -15,7 +15,7 @@ import { replaceBase64InText } from "./utils/config/content";
15
15
 
16
16
  // 工具函数
17
17
  import { buildFrameMap } from "./utils/context/buildFrameMap";
18
- import { buildSceneMap, buildEventsMap, createGetSceneById, createGetExtensionEventById, createGetFrameById } from "./utils/context/buildContext";
18
+ import { buildSceneMap, buildEventsMap, buildConnectorMap, createGetSceneById, createGetExtensionEventById, createGetFrameById } from "./utils/context/buildContext";
19
19
  import { createJSModulesCollector } from "./utils/context/collectJSModules";
20
20
  import { buildGlobalVarTypeDef, buildDefaultFxsMap } from "./utils/context/buildGlobalData";
21
21
  import { buildFinalResults } from "./utils/builder/buildResult";
@@ -63,6 +63,7 @@ var getCode = function getCode(params, config) {
63
63
  var eventsMap = buildEventsMap(tojson.frames);
64
64
  var getSceneById = createGetSceneById(sceneMap);
65
65
  var getExtensionEventById = createGetExtensionEventById(eventsMap);
66
+ var connectorMap = buildConnectorMap(tojson.plugins);
66
67
 
67
68
  // ========== 第二步:处理扩展事件 ==========
68
69
  files.push.apply(files, _toConsumableArray(handleExtension({
@@ -78,7 +79,7 @@ var getCode = function getCode(params, config) {
78
79
  var globalVarTypeDef = buildGlobalVarTypeDef(tojson.global.comsReg);
79
80
  var defaultFxsMap = buildDefaultFxsMap(tojson.global.fxFrames || []);
80
81
 
81
- // ========== 第四步:处理全局变量和 FX ==========
82
+ // ========== 第四步:处理全局变量、FX、其他全局配置 ==========
82
83
  files.push.apply(files, _toConsumableArray(handleGlobal({
83
84
  tojson: tojson,
84
85
  globalFxs: globalFxs,
@@ -224,6 +225,7 @@ var getCode = function getCode(params, config) {
224
225
  var finalResultData = buildFinalResults({
225
226
  abstractEventTypeDefMap: abstractEventTypeDefMap,
226
227
  jsModulesMap: jsModulesCollector.getMap(),
228
+ connectorMap: connectorMap,
227
229
  globalTabBarConfig: pageConfigHandler.getTabBarConfig(),
228
230
  tabBarImageFiles: pageConfigHandler.getTabBarImageFiles(),
229
231
  customTabBarFileContent: pageConfigHandler.getCustomTabBarFileContent(),
@@ -7,6 +7,7 @@ import type { JSModulesMap } from "../context/collectJSModules";
7
7
  interface BuildResultParams {
8
8
  abstractEventTypeDefMap: Record<string, any>;
9
9
  jsModulesMap: JSModulesMap;
10
+ connectorMap: any;
10
11
  globalTabBarConfig: string | null;
11
12
  tabBarImageFiles: any[];
12
13
  popupIds: string[];
@@ -12,6 +12,7 @@ import { genJSModulesRuntime } from "../logic/genJSModules";
12
12
  export var buildFinalResults = function buildFinalResults(params) {
13
13
  var abstractEventTypeDefMap = params.abstractEventTypeDefMap,
14
14
  jsModulesMap = params.jsModulesMap,
15
+ connectorMap = params.connectorMap,
15
16
  globalTabBarConfig = params.globalTabBarConfig,
16
17
  tabBarImageFiles = params.tabBarImageFiles,
17
18
  popupIds = params.popupIds,
@@ -37,6 +38,16 @@ export var buildFinalResults = function buildFinalResults(params) {
37
38
  });
38
39
  }
39
40
 
41
+ // 生成 API 定义
42
+ if (connectorMap) {
43
+ files.push({
44
+ type: "connector-api",
45
+ content: generateApi(connectorMap),
46
+ importManager: new ImportManager(config),
47
+ name: "api"
48
+ });
49
+ }
50
+
40
51
  // 生成弹窗汇总文件 (popup.ts)
41
52
  if (popupIds.length > 0) {
42
53
  var registryContent = "";
@@ -63,8 +74,7 @@ export var buildFinalResults = function buildFinalResults(params) {
63
74
  type: "tabBarConfig",
64
75
  content: globalTabBarConfig,
65
76
  importManager: new ImportManager(config),
66
- name: "tabBarConfig",
67
- tabBarConfig: globalTabBarConfig
77
+ name: "tabBarConfig"
68
78
  });
69
79
  files.push({
70
80
  type: "customTabBar",
@@ -77,4 +87,33 @@ export var buildFinalResults = function buildFinalResults(params) {
77
87
  files: files,
78
88
  tabBarImageFiles: tabBarImageFiles
79
89
  };
80
- };
90
+ };
91
+
92
+ /**
93
+ * 生成 API 定义代码
94
+ */
95
+ function generateApi(connectorMap) {
96
+ var connectors = connectorMap.connectors,
97
+ config = connectorMap.config;
98
+ var code = "/* eslint-disable @typescript-eslint/no-explicit-any */\n\n";
99
+ code += "export const api: Record<string, any> = {\n";
100
+ connectors.forEach(function (conn) {
101
+ code += " '".concat(conn.id, "': {\n");
102
+ code += " type: '".concat(conn.type, "',\n");
103
+ code += " input: ".concat(conn.input || 'function _RT_(params) { return params; }', ",\n");
104
+ code += " output: ".concat(conn.output || 'function _RT_(result) { return result; }', ",\n");
105
+ code += " method: '".concat(conn.method, "',\n");
106
+ code += " path: '".concat(conn.path, "',\n");
107
+ code += " globalMock: ".concat(conn.globalMock || false, ",\n");
108
+ code += " markList: ".concat(JSON.stringify(conn.markList || []), "\n");
109
+ code += " },\n";
110
+ });
111
+ code += "};\n\n";
112
+ code += "export const baseConfig = {\n";
113
+ code += " globalParamsFn: ".concat(config.paramsFn || 'function _RT_(params) { return params; }', ",\n");
114
+ code += " globalResultFn: ".concat(config.resultFn || 'function _RT_(response) { return response; }', ",\n");
115
+ code += " globalErrorResultFn: ".concat(config.errorResultFn || 'function _RT_(error) { throw error; }', ",\n");
116
+ code += " globalMock: ".concat(config.globalMock || false, "\n");
117
+ code += "};\n";
118
+ return code;
119
+ }
@@ -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") {
@@ -10,6 +10,13 @@ export declare const buildSceneMap: (scenes: any[]) => any;
10
10
  * 构建扩展事件映射表
11
11
  */
12
12
  export declare const buildEventsMap: (frames: any[]) => any;
13
+ /**
14
+ * 构建连接器映射表
15
+ */
16
+ export declare const buildConnectorMap: (plugins: any) => {
17
+ connectors: any;
18
+ config: any;
19
+ };
13
20
  /**
14
21
  * 创建场景查询函数
15
22
  */
@@ -25,6 +25,18 @@ export var buildEventsMap = function buildEventsMap(frames) {
25
25
  }, {});
26
26
  };
27
27
 
28
+ /**
29
+ * 构建连接器映射表
30
+ */
31
+ export var buildConnectorMap = function buildConnectorMap(plugins) {
32
+ var servicePlugin = plugins === null || plugins === void 0 ? void 0 : plugins["@mybricks/plugins/service"];
33
+ if (!servicePlugin) return null;
34
+ return {
35
+ connectors: servicePlugin.connectors || [],
36
+ config: servicePlugin.config || {}
37
+ };
38
+ };
39
+
28
40
  /**
29
41
  * 创建场景查询函数
30
42
  */
@@ -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,10 +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 += "".concat(indent).concat(indent2, "const outputs = comRefs.current.$outputs;\n");
59
+ if (logicCode !== null && logicCode !== void 0 && logicCode.includes('$outputs')) {
60
+ code += "".concat(indent).concat(indent2, "const $outputs = comRefs.current.$outputs;\n");
61
+ }
62
62
  if (logicCode) {
63
63
  code += logicCode.split("\n").map(function (line) {
64
64
  return "".concat(indent).concat(line);
@@ -100,7 +100,7 @@ export var RenderManager = /*#__PURE__*/function () {
100
100
  code += "".concat(indent).concat(indent4, "name: ").concat(child.name !== undefined ? "'".concat(child.name, "'") : 'undefined', ",\n");
101
101
  code += "".concat(indent).concat(indent4, "style: ").concat(childStyle, ",\n");
102
102
  code += "".concat(indent).concat(indent4, "get inputs() { return comRefs.current['").concat(child.id, "'] },\n");
103
- 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");
104
104
  code += "".concat(indent).concat(indent4, "jsx: ").concat(varName, ",\n");
105
105
  code += "".concat(indent).concat(indent3, "},\n");
106
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mybricks/to-code-taro",
3
- "version": "1.1.4",
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
- });