@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 {
@@ -58,6 +58,7 @@ var getCode = (params, config) => {
58
58
  const eventsMap = (0, import_buildContext.buildEventsMap)(tojson.frames);
59
59
  const getSceneById = (0, import_buildContext.createGetSceneById)(sceneMap);
60
60
  const getExtensionEventById = (0, import_buildContext.createGetExtensionEventById)(eventsMap);
61
+ const connectorMap = (0, import_buildContext.buildConnectorMap)(tojson.plugins);
61
62
  files.push(
62
63
  ...(0, import_handleExtension.default)(
63
64
  {
@@ -210,6 +211,7 @@ var getCode = (params, config) => {
210
211
  const finalResultData = (0, import_buildResult.buildFinalResults)({
211
212
  abstractEventTypeDefMap,
212
213
  jsModulesMap: jsModulesCollector.getMap(),
214
+ connectorMap,
213
215
  globalTabBarConfig: pageConfigHandler.getTabBarConfig(),
214
216
  tabBarImageFiles: pageConfigHandler.getTabBarImageFiles(),
215
217
  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[];
@@ -39,6 +39,7 @@ var buildFinalResults = (params) => {
39
39
  const {
40
40
  abstractEventTypeDefMap,
41
41
  jsModulesMap,
42
+ connectorMap,
42
43
  globalTabBarConfig,
43
44
  tabBarImageFiles,
44
45
  popupIds,
@@ -60,6 +61,14 @@ var buildFinalResults = (params) => {
60
61
  name: "jsModulesRuntime"
61
62
  });
62
63
  }
64
+ if (connectorMap) {
65
+ files.push({
66
+ type: "connector-api",
67
+ content: generateApi(connectorMap),
68
+ importManager: new import_ImportManager.ImportManager(config),
69
+ name: "api"
70
+ });
71
+ }
63
72
  if (popupIds.length > 0) {
64
73
  let registryContent = "";
65
74
  popupIds.forEach((id) => {
@@ -90,8 +99,7 @@ export const POPUP_MAP: Record<string, any> = {
90
99
  type: "tabBarConfig",
91
100
  content: globalTabBarConfig,
92
101
  importManager: new import_ImportManager.ImportManager(config),
93
- name: "tabBarConfig",
94
- tabBarConfig: globalTabBarConfig
102
+ name: "tabBarConfig"
95
103
  });
96
104
  files.push({
97
105
  type: "customTabBar",
@@ -105,6 +113,50 @@ export const POPUP_MAP: Record<string, any> = {
105
113
  tabBarImageFiles
106
114
  };
107
115
  };
116
+ function generateApi(connectorMap) {
117
+ const { connectors, config } = connectorMap;
118
+ let code = `/* eslint-disable @typescript-eslint/no-explicit-any */
119
+
120
+ `;
121
+ code += `export const api: Record<string, any> = {
122
+ `;
123
+ connectors.forEach((conn) => {
124
+ code += ` '${conn.id}': {
125
+ `;
126
+ code += ` type: '${conn.type}',
127
+ `;
128
+ code += ` input: ${conn.input || "function _RT_(params) { return params; }"},
129
+ `;
130
+ code += ` output: ${conn.output || "function _RT_(result) { return result; }"},
131
+ `;
132
+ code += ` method: '${conn.method}',
133
+ `;
134
+ code += ` path: '${conn.path}',
135
+ `;
136
+ code += ` globalMock: ${conn.globalMock || false},
137
+ `;
138
+ code += ` markList: ${JSON.stringify(conn.markList || [])}
139
+ `;
140
+ code += ` },
141
+ `;
142
+ });
143
+ code += `};
144
+
145
+ `;
146
+ code += `export const baseConfig = {
147
+ `;
148
+ code += ` globalParamsFn: ${config.paramsFn || "function _RT_(params) { return params; }"},
149
+ `;
150
+ code += ` globalResultFn: ${config.resultFn || "function _RT_(response) { return response; }"},
151
+ `;
152
+ code += ` globalErrorResultFn: ${config.errorResultFn || "function _RT_(error) { throw error; }"},
153
+ `;
154
+ code += ` globalMock: ${config.globalMock || false}
155
+ `;
156
+ code += `};
157
+ `;
158
+ return code;
159
+ }
108
160
  // Annotate the CommonJS export names for ESM import in node:
109
161
  0 && (module.exports = {
110
162
  buildFinalResults
@@ -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
  }
@@ -53,10 +53,28 @@ var ImportManager = class {
53
53
  });
54
54
  }
55
55
  }
56
+ /**
57
+ * 获取 import 排序优先级
58
+ * 1. 第三方包(react, @tarojs 等)
59
+ * 2. 绝对路径别名(@/xxx)
60
+ * 3. 相对路径(./xxx, ../xxx)
61
+ */
62
+ getImportPriority(packageName) {
63
+ if (packageName.startsWith("./") || packageName.startsWith("../")) {
64
+ return 3;
65
+ }
66
+ if (packageName.startsWith("@/")) {
67
+ return 2;
68
+ }
69
+ return 1;
70
+ }
56
71
  /** 依赖解析为code */
57
72
  toCode() {
58
73
  const indent = (0, import_helper.indentation)(this._config.codeStyle.indent);
59
- return Object.entries(this._imports).reduce(
74
+ const sortedEntries = Object.entries(this._imports).sort(([a], [b]) => {
75
+ return this.getImportPriority(a) - this.getImportPriority(b);
76
+ });
77
+ return sortedEntries.reduce(
60
78
  (pre, [packageName, dependencies]) => {
61
79
  var _a;
62
80
  let defaultDependency = "";
@@ -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
  */
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/utils/context/buildContext.ts
20
20
  var buildContext_exports = {};
21
21
  __export(buildContext_exports, {
22
+ buildConnectorMap: () => buildConnectorMap,
22
23
  buildEventsMap: () => buildEventsMap,
23
24
  buildSceneMap: () => buildSceneMap,
24
25
  createGetExtensionEventById: () => createGetExtensionEventById,
@@ -40,6 +41,15 @@ var buildEventsMap = (frames) => {
40
41
  return pre;
41
42
  }, {});
42
43
  };
44
+ var buildConnectorMap = (plugins) => {
45
+ const servicePlugin = plugins == null ? void 0 : plugins["@mybricks/plugins/service"];
46
+ if (!servicePlugin)
47
+ return null;
48
+ return {
49
+ connectors: servicePlugin.connectors || [],
50
+ config: servicePlugin.config || {}
51
+ };
52
+ };
43
53
  var createGetSceneById = (sceneMap) => {
44
54
  return (id) => {
45
55
  return sceneMap[id];
@@ -57,6 +67,7 @@ var createGetFrameById = (frameMap) => {
57
67
  };
58
68
  // Annotate the CommonJS export names for ESM import in node:
59
69
  0 && (module.exports = {
70
+ buildConnectorMap,
60
71
  buildEventsMap,
61
72
  buildSceneMap,
62
73
  createGetExtensionEventById,
@@ -83,7 +83,7 @@ var genScopedJSModules = (jsModules, importCreateJSHandleFrom, importRuntimeFrom
83
83
  import { createJSHandle } from "${importCreateJSHandleFrom}";
84
84
  import { _execJs } from "${importRuntimeFrom}";
85
85
 
86
- export const jsModules: Record<string, (props: any, appContext: any) => any> = {};
86
+ export const jsModules: Record<string, (props: any, appContext: any, handleKey?: string) => any> = {};
87
87
  `;
88
88
  jsModules.forEach((module2) => {
89
89
  const { id, title, transformCode } = module2;
@@ -100,7 +100,7 @@ export const jsModules: Record<string, (props: any, appContext: any) => any> = {
100
100
  `;
101
101
  code += `const _execJs_${id} = _execJs(js_${id});
102
102
  `;
103
- code += `jsModules.${id} = (props, appContext) => createJSHandle(_execJs_${id}, { props, appContext });
103
+ code += `jsModules.${id} = (props, appContext, handleKey) => createJSHandle(_execJs_${id}, { props, appContext }, handleKey);
104
104
  `;
105
105
  });
106
106
  code += `
@@ -29,7 +29,8 @@ var isJsCalculationComponent = (namespace) => {
29
29
  return namespace === "mybricks.taro._muilt-inputJs" || namespace === "mybricks.core-comlib.js-ai";
30
30
  };
31
31
  var isJsApiComponent = (namespace, rtType) => {
32
- return namespace.startsWith("mybricks.taro._") && (rtType == null ? void 0 : rtType.match(/^js/gi)) !== null;
32
+ const jsCompNamespace = ["mybricks.taro.", "mybricks.normal-pc."];
33
+ return jsCompNamespace.some((_namespace) => namespace.startsWith(_namespace)) && (rtType == null ? void 0 : rtType.match(/^js/gi)) !== null;
33
34
  };
34
35
  var handleProcess = (event, config) => {
35
36
  let code = "";
@@ -109,20 +110,25 @@ ${indent2}outputs: [${props.outputs.map((output) => `"${output}"`).join(", ")}],
109
110
  ${indent}}, appContext)
110
111
  `;
111
112
  });
113
+ const outputToInputPinMap = /* @__PURE__ */ new Map();
112
114
  process.nodesInvocation.forEach((props) => {
113
- var _a, _b, _c, _d;
115
+ var _a, _b, _c, _d, _e, _f, _g, _h;
114
116
  const { componentType, category, runType } = props;
115
- let nextValue = getNextValue(props, config, event);
117
+ const nextValue = getNextValue(props, config, event, outputToInputPinMap);
116
118
  const isSameScope = checkIsSameScope(event, props);
117
119
  const nextCode = getNextCode(props, config, isSameScope, event);
120
+ const inputPinId = props.id.replace(/[^a-zA-Z0-9_]/g, "_");
121
+ (_a = props.nextParam) == null ? void 0 : _a.forEach((np) => {
122
+ outputToInputPinMap.set(`${props.meta.id}_${np.id}`, inputPinId);
123
+ });
118
124
  if (code) {
119
125
  code += "\n";
120
126
  }
121
- const callTemplate = (_c = config.getCallTemplate) == null ? void 0 : _c.call(config, {
127
+ const callTemplate = (_d = config.getCallTemplate) == null ? void 0 : _d.call(config, {
122
128
  com: {
123
129
  ...props.meta,
124
130
  // 鸿蒙化:透传可能的场景 ID,增强识别能力
125
- sceneId: ((_b = (_a = props.meta.model) == null ? void 0 : _a.data) == null ? void 0 : _b._sceneId) || props.meta.id
131
+ sceneId: ((_c = (_b = props.meta.model) == null ? void 0 : _b.data) == null ? void 0 : _c._sceneId) || props.meta.id
126
132
  },
127
133
  pinId: props.id,
128
134
  args: nextValue
@@ -143,7 +149,7 @@ ${indent}${nextCode}${callTemplate.code}`;
143
149
  ${indent}${nextCode}this.${_sceneId}.${operateName}(${nextValue})`;
144
150
  } else if (category === "frameOutput") {
145
151
  const currentScene = config.getCurrentScene();
146
- const pinProxy = (_d = currentScene == null ? void 0 : currentScene.pinProxies) == null ? void 0 : _d[`${props.meta.id}-${props.id}`];
152
+ const pinProxy = (_e = currentScene == null ? void 0 : currentScene.pinProxies) == null ? void 0 : _e[`${props.meta.id}-${props.id}`];
147
153
  const method = (pinProxy == null ? void 0 : pinProxy.pinId) || props.id;
148
154
  const sceneId = (pinProxy == null ? void 0 : pinProxy.frameId) || (currentScene == null ? void 0 : currentScene.id);
149
155
  code += `${indent}/** ${props.meta.title} 输出 ${method} */
@@ -189,8 +195,24 @@ ${indent}${nextCode}this.$fxs.${props.meta.ioProxy.id}(${nextValue})`;
189
195
  }
190
196
  }
191
197
  } else {
192
- code += `${indent}/** 调用 ${props.meta.title} ${props.title} */
198
+ if (props.type === "frameOutput") {
199
+ const currentScene = config.getCurrentScene();
200
+ const parentComId = event.comId || ((_f = event.meta) == null ? void 0 : _f.parentComId);
201
+ const frameConEntry = Object.values(currentScene.cons || {}).flat().find((con) => {
202
+ if (con.type !== "frame" || con.pinId !== props.id)
203
+ return false;
204
+ if (parentComId && con.comId)
205
+ return con.comId === parentComId;
206
+ return true;
207
+ });
208
+ const comId = (frameConEntry == null ? void 0 : frameConEntry.comId) || props.meta.id;
209
+ const comTitle = ((_h = (_g = currentScene.coms) == null ? void 0 : _g[comId]) == null ? void 0 : _h.title) || props.meta.title || comId;
210
+ code += `${indent}/** 调用 ${comTitle} 的 ${props.title} */
211
+ ${indent}${nextCode}$outputs['${comId}'].${props.id}(${nextValue})`;
212
+ } else {
213
+ code += `${indent}/** 调用 ${props.meta.title} 的 ${props.title} */
193
214
  ${indent}${nextCode}this.${props.meta.id}.${props.id}(${nextValue})`;
215
+ }
194
216
  }
195
217
  });
196
218
  if (["fx", "extension-api", "extension-bus"].includes(event.type)) {
@@ -263,7 +285,9 @@ var getNextCode = (props, config, isSameScope, event) => {
263
285
  return "";
264
286
  }
265
287
  const componentNameWithId = getComponentNameWithId(props, config, event);
266
- return `const ${componentNameWithId}_result = `;
288
+ const pinId = props.id;
289
+ const sanitizedPinId = pinId.replace(/[^a-zA-Z0-9_]/g, "_");
290
+ return `const ${componentNameWithId}_${sanitizedPinId}_result: any = `;
267
291
  };
268
292
  function getFrameInputValueExpr(meta, config, event) {
269
293
  var _a, _b, _c;
@@ -276,10 +300,10 @@ function getFrameInputValueExpr(meta, config, event) {
276
300
  return `params?.inputValues?.[${JSON.stringify(pinId)}]`;
277
301
  }
278
302
  }
279
- var getNextValue = (props, config, event) => {
303
+ var getNextValue = (props, config, event, outputToInputPinMap) => {
280
304
  const { paramSource } = props;
281
305
  const nextValue = paramSource.map((param) => {
282
- var _a, _b, _c, _d, _e;
306
+ var _a, _b, _c, _d, _e, _f, _g;
283
307
  if (param.type === "params") {
284
308
  const params = config.getParams();
285
309
  return params[param.id];
@@ -291,8 +315,18 @@ var getNextValue = (props, config, event) => {
291
315
  }
292
316
  const componentNameWithId = getComponentNameWithId(param, config, event);
293
317
  if ((_e = (_d = (_c = param.meta) == null ? void 0 : _c.def) == null ? void 0 : _d.namespace) == null ? void 0 : _e.includes(".var")) {
318
+ const key2 = `${(_f = param.meta) == null ? void 0 : _f.id}_${param.id}`;
319
+ const inputPinId2 = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key2);
320
+ if (inputPinId2) {
321
+ return `${componentNameWithId}_${inputPinId2}_result`;
322
+ }
294
323
  return `${componentNameWithId}_result`;
295
324
  }
325
+ const key = `${(_g = param.meta) == null ? void 0 : _g.id}_${param.id}`;
326
+ const inputPinId = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key);
327
+ if (inputPinId) {
328
+ return `${componentNameWithId}_${inputPinId}_result.${param.id}`;
329
+ }
296
330
  return `${componentNameWithId}_result.${param.id}`;
297
331
  });
298
332
  return nextValue.join(", ");
@@ -308,8 +342,16 @@ var getNextValueWithParam = (param, config, event) => {
308
342
  }
309
343
  const componentNameWithId = getComponentNameWithId(param, config, event);
310
344
  if ((_e = (_d = (_c = param.meta) == null ? void 0 : _c.def) == null ? void 0 : _d.namespace) == null ? void 0 : _e.includes(".var")) {
345
+ const connectId2 = param.connectId;
346
+ if (connectId2) {
347
+ return `${componentNameWithId}_${connectId2}_result`;
348
+ }
311
349
  return `${componentNameWithId}_result`;
312
350
  }
351
+ const connectId = param.connectId;
352
+ if (connectId) {
353
+ return `${componentNameWithId}_${connectId}_result.${param.id}`;
354
+ }
313
355
  return `${componentNameWithId}_result.${param.id}`;
314
356
  };
315
357
  var getCurrentProvider = (params, config) => {
@@ -348,7 +390,7 @@ ${indent2}data: ${(0, import_object.genObjectCode)(jsData, {
348
390
  })},` : "") + (props.inputs ? `
349
391
  ${indent2}inputs: [${props.inputs.map((input) => `"${input}"`).join(", ")}],` : "") + (props.outputs ? `
350
392
  ${indent2}outputs: [${props.outputs.map((output) => `"${output}"`).join(", ")}],` : "") + `
351
- ${indent}}, appContext)
393
+ ${indent}}, appContext, '${meta.id}')
352
394
  `;
353
395
  };
354
396
  var generateJsApiComponentCode = (params) => {
@@ -397,7 +439,7 @@ ${indent2} inputs: [${props.inputs.map((input) => `"${input}"`).join(", ")}],`
397
439
  ${indent2} outputs: [${props.outputs.map((output) => `"${output}"`).join(", ")}],` : "") + `
398
440
  ${indent2}},
399
441
  ${indent2}appContext
400
- ${indent}})
442
+ ${indent}}, '${meta.id}')
401
443
  `;
402
444
  };
403
445
  // Annotate the CommonJS export names for ESM import in node:
@@ -58,8 +58,10 @@ var RenderManager = class {
58
58
  `;
59
59
  code += `${indent}${indent2}const { comRefs, $vars, $fxs, appContext } = useAppContext();
60
60
  `;
61
- code += `${indent}${indent2}const outputs = comRefs.current.$outputs;
61
+ if (logicCode == null ? void 0 : logicCode.includes("$outputs")) {
62
+ code += `${indent}${indent2}const $outputs = comRefs.current.$outputs;
62
63
  `;
64
+ }
63
65
  if (logicCode) {
64
66
  code += logicCode.split("\n").map((line) => `${indent}${line}`).join("\n") + "\n";
65
67
  }
@@ -101,7 +103,7 @@ var RenderManager = class {
101
103
  `;
102
104
  code += `${indent}${indent4}get inputs() { return comRefs.current['${child.id}'] },
103
105
  `;
104
- code += `${indent}${indent4}get outputs() { return outputs['${child.id}'] },
106
+ code += `${indent}${indent4}get outputs() { return comRefs.current.$outputs['${child.id}'] },
105
107
  `;
106
108
  code += `${indent}${indent4}jsx: ${varName},
107
109
  `;
@@ -19,16 +19,22 @@ export var Subject = /*#__PURE__*/function () {
19
19
  _defineProperty(this, "_log", undefined);
20
20
  _defineProperty(this, "_empty", true);
21
21
  this._log = params.log;
22
+ this._subjectNextCache = {};
22
23
  return new Proxy(this, {
23
24
  get: function get(target, prop) {
24
25
  if (prop in target) {
25
26
  return target[prop];
26
27
  }
27
- var subjectNext = new SubjectNext(prop);
28
- target[SUBJECT_SUBSCRIBE](function (value, extra) {
29
- subjectNext[SUBJECT_NEXT](value, extra);
30
- });
31
- return subjectNext;
28
+
29
+ // 缓存 SubjectNext,避免重复访问同一属性时创建新实例和新订阅
30
+ if (!target._subjectNextCache[prop]) {
31
+ var subjectNext = new SubjectNext(prop);
32
+ target[SUBJECT_SUBSCRIBE](function (value, extra) {
33
+ subjectNext[SUBJECT_NEXT](value, extra);
34
+ });
35
+ target._subjectNextCache[prop] = subjectNext;
36
+ }
37
+ return target._subjectNextCache[prop];
32
38
  }
33
39
  });
34
40
  }
@@ -11,11 +11,40 @@ export var validateJsMultipleInputs = function validateJsMultipleInputs(input) {
11
11
  return input.match(/\./); // input.xxx 为多输入模式
12
12
  };
13
13
 
14
+ // 全局缓存,用于防抖/节流等需要保持状态的组件
15
+ var handleCache = new Map();
16
+
17
+ /** 尝试从缓存获取 exe,命中时重置输出 Subject 状态 */
18
+ var getFromCache = function getFromCache(handleKey) {
19
+ if (!handleKey || !handleCache.has(handleKey)) return null;
20
+ var cached = handleCache.get(handleKey);
21
+ if (cached._rels) {
22
+ Object.values(cached._rels).forEach(function (subject) {
23
+ var _subject$_observers, _subject$_observers$c;
24
+ (_subject$_observers = subject._observers) === null || _subject$_observers === void 0 || (_subject$_observers$c = _subject$_observers.clear) === null || _subject$_observers$c === void 0 || _subject$_observers$c.call(_subject$_observers);
25
+ subject._values = [];
26
+ subject._empty = true;
27
+ });
28
+ }
29
+ return cached;
30
+ };
31
+
32
+ /** 将 exe 存入缓存 */
33
+ var setToCache = function setToCache(handleKey, exe, rels, needsCache) {
34
+ exe._rels = rels;
35
+ if (handleKey && needsCache) {
36
+ handleCache.set(handleKey, exe);
37
+ }
38
+ };
39
+
14
40
  // JS
15
- export var createJSHandle = function createJSHandle(fn, options) {
16
- var controller;
41
+ export var createJSHandle = function createJSHandle(fn, options, handleKey) {
17
42
  var props = options.props,
18
43
  appContext = options.appContext;
44
+ var cached = getFromCache(handleKey);
45
+ if (cached) return cached;
46
+ var needsCache = fn.__useCache === true;
47
+ var controller;
19
48
  var inputs = new Proxy({}, {
20
49
  getOwnPropertyDescriptor: function getOwnPropertyDescriptor() {
21
50
  return {
@@ -57,16 +86,27 @@ export var createJSHandle = function createJSHandle(fn, options) {
57
86
  inputs: inputs,
58
87
  outputs: outputs,
59
88
  logger: logger,
60
- env: appContext === null || appContext === void 0 ? void 0 : appContext.env
89
+ env: appContext === null || appContext === void 0 ? void 0 : appContext.env,
90
+ appContext: appContext
61
91
  });
62
92
  var isJsMultipleInputs = props.inputs[0] ? validateJsMultipleInputs(props.inputs[0]) : false;
93
+
94
+ // 缓存 exeOutputs 的属性访问结果,避免每次访问 .trigger 等属性时创建新的 SubjectNext
95
+ var exeOutputsCache = {};
63
96
  var exeOutputs = new Proxy({}, {
64
97
  get: function get(_, key) {
65
- return rels[key] || (rels[key] = new Subject({
66
- log: "".concat(EXE_TITLE_MAP["output"], " ").concat(props.title, " | ").concat(key)
67
- }));
98
+ if (!exeOutputsCache[key]) {
99
+ var subject = rels[key] || (rels[key] = new Subject({
100
+ log: "".concat(EXE_TITLE_MAP["output"], " ").concat(props.title, " | ").concat(key)
101
+ }));
102
+ exeOutputsCache[key] = subject;
103
+ }
104
+ return exeOutputsCache[key];
68
105
  }
69
106
  });
107
+
108
+ // 记录已订阅的 Subject,避免重复订阅
109
+ var subscribedSubjects = new Set();
70
110
  var exe = function exe() {
71
111
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
72
112
  args[_key] = arguments[_key];
@@ -79,6 +119,11 @@ export var createJSHandle = function createJSHandle(fn, options) {
79
119
  var valueAry = {};
80
120
  args.forEach(function (value, index) {
81
121
  if (value !== null && value !== void 0 && value[SUBJECT_SUBSCRIBE]) {
122
+ // 如果已经订阅过这个 Subject,跳过
123
+ if (subscribedSubjects.has(value)) {
124
+ return;
125
+ }
126
+ subscribedSubjects.add(value);
82
127
  value[SUBJECT_SUBSCRIBE](function (value) {
83
128
  log("".concat(EXE_TITLE_MAP["input"], " ").concat(props.title, " | ").concat(props.inputs[index]), JSON.stringify(value));
84
129
  valueAry[props.inputs[index]] = value;
@@ -112,6 +157,11 @@ export var createJSHandle = function createJSHandle(fn, options) {
112
157
  // 非多输入
113
158
  var value = args[0];
114
159
  if (value !== null && value !== void 0 && value[SUBJECT_SUBSCRIBE]) {
160
+ // 如果已经订阅过这个 Subject,跳过
161
+ if (subscribedSubjects.has(value)) {
162
+ return exeOutputs;
163
+ }
164
+ subscribedSubjects.add(value);
115
165
  value[SUBJECT_SUBSCRIBE](function (value) {
116
166
  log("".concat(EXE_TITLE_MAP["input"], " ").concat(props.title, " | ").concat(props.inputs[0]), JSON.stringify(value));
117
167
  createReactiveInputHandler({
@@ -134,5 +184,6 @@ export var createJSHandle = function createJSHandle(fn, options) {
134
184
  }
135
185
  return exeOutputs;
136
186
  };
187
+ setToCache(handleKey, exe, rels, needsCache);
137
188
  return exe;
138
189
  };
@@ -0,0 +1,134 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import { TodoPool } from "./pool";
4
+
5
+ /**
6
+ * 组件引用解析器
7
+ *
8
+ * 职责单一:管理组件引用的查找、创建和注册
9
+ *
10
+ * 核心机制:
11
+ * 1. 查找真实引用时,优先本地,再查父级
12
+ * 2. 未找到时创建影子对象,影子对象调用时会动态查找真实引用
13
+ * 3. 注册真实引用时,向上渗透到父级
14
+ */
15
+ export var ComRefResolver = /*#__PURE__*/function () {
16
+ function ComRefResolver(registry, parent, todoPool) {
17
+ var scopeIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
18
+ _classCallCheck(this, ComRefResolver);
19
+ this.registry = registry;
20
+ this.parent = parent;
21
+ this.todoPool = todoPool;
22
+ this.scopeIndex = scopeIndex;
23
+ }
24
+
25
+ /**
26
+ * 获取组件引用
27
+ * @returns 真实引用或影子对象
28
+ */
29
+ _createClass(ComRefResolver, [{
30
+ key: "get",
31
+ value: function get(id) {
32
+ var _this$parent, _this$registry$id;
33
+ // 1. 优先检查本地是否有真实引用
34
+ if (this.registry[id] && !this.registry[id].__isShadow) {
35
+ return this.registry[id];
36
+ }
37
+
38
+ // 2. 检查父级是否有真实引用
39
+ var parentRef = (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.findRealRef(id);
40
+ if (parentRef) {
41
+ return parentRef;
42
+ }
43
+
44
+ // 3. 如果已有影子对象,直接返回
45
+ if ((_this$registry$id = this.registry[id]) !== null && _this$registry$id !== void 0 && _this$registry$id.__isShadow) {
46
+ return this.registry[id];
47
+ }
48
+
49
+ // 4. 创建影子对象
50
+ return this.createShadowProxy(id);
51
+ }
52
+
53
+ /**
54
+ * 注册真实引用
55
+ */
56
+ }, {
57
+ key: "set",
58
+ value: function set(id, ref) {
59
+ var _this$parent2;
60
+ this.registry[id] = ref;
61
+ // 向上渗透到父级
62
+ (_this$parent2 = this.parent) === null || _this$parent2 === void 0 || _this$parent2.set(id, ref);
63
+ }
64
+
65
+ /**
66
+ * 删除引用
67
+ */
68
+ }, {
69
+ key: "delete",
70
+ value: function _delete(id) {
71
+ var _this$parent3;
72
+ delete this.registry[id];
73
+ (_this$parent3 = this.parent) === null || _this$parent3 === void 0 || _this$parent3.delete(id);
74
+ }
75
+
76
+ /**
77
+ * 查找真实引用(仅用于父级链查找)
78
+ */
79
+ }, {
80
+ key: "findRealRef",
81
+ value: function findRealRef(id) {
82
+ var _this$parent$findReal, _this$parent4;
83
+ var local = this.registry[id];
84
+ if (local && !local.__isShadow) {
85
+ return local;
86
+ }
87
+ return (_this$parent$findReal = (_this$parent4 = this.parent) === null || _this$parent4 === void 0 ? void 0 : _this$parent4.findRealRef(id)) !== null && _this$parent$findReal !== void 0 ? _this$parent$findReal : null;
88
+ }
89
+
90
+ /**
91
+ * 创建影子对象
92
+ * 关键:影子对象的方法被调用时,会动态查找真实引用
93
+ */
94
+ }, {
95
+ key: "createShadowProxy",
96
+ value: function createShadowProxy(id) {
97
+ var resolver = this;
98
+ var registry = this.registry;
99
+ var todoPool = this.todoPool;
100
+ var scopeIndex = this.scopeIndex;
101
+ var shadow = new Proxy({
102
+ __isShadow: true
103
+ }, {
104
+ get: function get(_, method) {
105
+ if (method === '__isShadow') return true;
106
+ return function () {
107
+ // 动态检查是否已有真实引用
108
+ // 注意:这里直接检查 registry[id],因为真实引用注册时会覆盖它
109
+ var realRef = registry[id];
110
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
111
+ args[_key] = arguments[_key];
112
+ }
113
+ if (realRef && !realRef.__isShadow) {
114
+ if (typeof realRef[method] === 'function') {
115
+ return realRef[method].apply(realRef, args);
116
+ }
117
+ return;
118
+ }
119
+
120
+ // 未找到真实引用,缓冲到 TodoPool
121
+ if (todoPool instanceof TodoPool) {
122
+ todoPool.push(id, scopeIndex, method, args);
123
+ }
124
+ };
125
+ }
126
+ });
127
+
128
+ // 存储影子对象
129
+ this.registry[id] = shadow;
130
+ return shadow;
131
+ }
132
+ }]);
133
+ return ComRefResolver;
134
+ }();