@mybricks/to-code-taro 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/cjs/core/mybricks/Subject.js +9 -5
  2. package/dist/cjs/core/mybricks/createJSHandle.js +43 -3
  3. package/dist/cjs/core/utils/comRefResolver.js +112 -0
  4. package/dist/cjs/core/utils/event.js +53 -0
  5. package/dist/cjs/core/utils/hooks.js +71 -29
  6. package/dist/cjs/core/utils/index.js +3 -0
  7. package/dist/cjs/core/utils/pageRouter.js +34 -11
  8. package/dist/cjs/core/utils/slots.js +55 -9
  9. package/dist/cjs/core/utils/tabbar.js +56 -0
  10. package/dist/cjs/core/utils/useContext.js +42 -2
  11. package/dist/cjs/core/utils/with.js +9 -34
  12. package/dist/cjs/generate/generateTaroProjectJson.js +3 -18
  13. package/dist/cjs/generate/utils/appConfig.d.ts +1 -1
  14. package/dist/cjs/generate/utils/appConfig.js +22 -12
  15. package/dist/cjs/generate/utils/commonDir.js +9 -0
  16. package/dist/cjs/generate/utils/customTabBar.d.ts +11 -0
  17. package/dist/cjs/generate/utils/customTabBar.js +73 -0
  18. package/dist/cjs/generate/utils/fileNode.d.ts +4 -0
  19. package/dist/cjs/generate/utils/fileNode.js +12 -2
  20. package/dist/cjs/handleCom.js +15 -16
  21. package/dist/cjs/handleGlobal.d.ts +1 -1
  22. package/dist/cjs/handleGlobal.js +6 -0
  23. package/dist/cjs/handleSlot.js +5 -10
  24. package/dist/cjs/processors/processScene.js +13 -1
  25. package/dist/cjs/processors/processSceneLogic.js +2 -6
  26. package/dist/cjs/taro-template.json +364 -66
  27. package/dist/cjs/toCodeTaro.d.ts +1 -2
  28. package/dist/cjs/utils/builder/buildResult.js +1 -2
  29. package/dist/cjs/utils/common/ImportManager.d.ts +7 -0
  30. package/dist/cjs/utils/common/ImportManager.js +19 -1
  31. package/dist/cjs/utils/logic/genJSModules.js +2 -2
  32. package/dist/cjs/utils/logic/handleProcess.js +59 -13
  33. package/dist/cjs/utils/templates/index.js +1 -1
  34. package/dist/cjs/utils/templates/renderManager.js +5 -5
  35. package/dist/cjs/utils/templates/scene.js +4 -4
  36. package/dist/esm/core/mybricks/Subject.js +11 -5
  37. package/dist/esm/core/mybricks/createJSHandle.js +55 -5
  38. package/dist/esm/core/utils/comRefResolver.js +134 -0
  39. package/dist/esm/core/utils/event.js +32 -0
  40. package/dist/esm/core/utils/hooks.js +109 -39
  41. package/dist/esm/core/utils/index.js +1 -0
  42. package/dist/esm/core/utils/pageRouter.js +56 -13
  43. package/dist/esm/core/utils/slots.js +78 -12
  44. package/dist/esm/core/utils/tabbar.js +47 -0
  45. package/dist/esm/core/utils/useContext.js +42 -2
  46. package/dist/esm/core/utils/with.js +19 -53
  47. package/dist/esm/generate/generateTaroProjectJson.js +2 -20
  48. package/dist/esm/generate/utils/appConfig.d.ts +1 -1
  49. package/dist/esm/generate/utils/appConfig.js +28 -9
  50. package/dist/esm/generate/utils/commonDir.js +13 -0
  51. package/dist/esm/generate/utils/customTabBar.d.ts +11 -0
  52. package/dist/esm/generate/utils/customTabBar.js +52 -0
  53. package/dist/esm/generate/utils/fileNode.d.ts +4 -0
  54. package/dist/esm/generate/utils/fileNode.js +13 -0
  55. package/dist/esm/handleCom.js +24 -21
  56. package/dist/esm/handleGlobal.d.ts +1 -1
  57. package/dist/esm/handleGlobal.js +6 -1
  58. package/dist/esm/handleSlot.js +7 -12
  59. package/dist/esm/processors/processScene.js +23 -3
  60. package/dist/esm/processors/processSceneLogic.js +3 -5
  61. package/dist/esm/taro-template.json +364 -66
  62. package/dist/esm/toCodeTaro.d.ts +1 -2
  63. package/dist/esm/toCodeTaro.js +1 -1
  64. package/dist/esm/utils/builder/buildResult.js +1 -2
  65. package/dist/esm/utils/common/ImportManager.d.ts +7 -0
  66. package/dist/esm/utils/common/ImportManager.js +42 -14
  67. package/dist/esm/utils/logic/genJSModules.js +2 -2
  68. package/dist/esm/utils/logic/handleProcess.js +73 -12
  69. package/dist/esm/utils/templates/index.js +1 -1
  70. package/dist/esm/utils/templates/renderManager.js +4 -7
  71. package/dist/esm/utils/templates/scene.js +2 -2
  72. package/package.json +1 -1
  73. package/dist/cjs/core/comlib/Index.js +0 -114
  74. package/dist/cjs/core/comlib/_AesEncode.js +0 -115
  75. package/dist/cjs/core/comlib/_BackTo.js +0 -80
  76. package/dist/cjs/core/comlib/_CallPhone.js +0 -58
  77. package/dist/cjs/core/comlib/_ChooseFile.js +0 -103
  78. package/dist/cjs/core/comlib/_ChooseMedia.js +0 -70
  79. package/dist/cjs/core/comlib/_Connector.js +0 -79
  80. package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +0 -79
  81. package/dist/cjs/core/comlib/_Format.js +0 -123
  82. package/dist/cjs/core/comlib/_GetLocation.js +0 -60
  83. package/dist/cjs/core/comlib/_GetStorage.js +0 -68
  84. package/dist/cjs/core/comlib/_GetSystemInfo.js +0 -62
  85. package/dist/cjs/core/comlib/_Modal.js +0 -68
  86. package/dist/cjs/core/comlib/_OpenCamera.js +0 -73
  87. package/dist/cjs/core/comlib/_OpenPetalMap.js +0 -49
  88. package/dist/cjs/core/comlib/_OpenUrl.js +0 -62
  89. package/dist/cjs/core/comlib/_RemoveStorage.js +0 -68
  90. package/dist/cjs/core/comlib/_Router.js +0 -100
  91. package/dist/cjs/core/comlib/_ScanQrcode.js +0 -59
  92. package/dist/cjs/core/comlib/_SetStorage.js +0 -67
  93. package/dist/cjs/core/comlib/_Share.js +0 -58
  94. package/dist/cjs/core/comlib/_ShowToast.js +0 -69
  95. package/dist/cjs/core/comlib/_TextToSpeech.js +0 -120
  96. package/dist/cjs/core/comlib/_TimerDebounce.js +0 -72
  97. package/dist/cjs/core/comlib/_TimerDelay.js +0 -88
  98. package/dist/cjs/core/comlib/_TimerThrottle.js +0 -75
  99. package/dist/cjs/core/comlib/_Vibrate.js +0 -60
  100. package/dist/esm/core/comlib/Index.js +0 -39
  101. package/dist/esm/core/comlib/_AesEncode.js +0 -85
  102. package/dist/esm/core/comlib/_BackTo.js +0 -66
  103. package/dist/esm/core/comlib/_CallPhone.js +0 -30
  104. package/dist/esm/core/comlib/_ChooseFile.js +0 -81
  105. package/dist/esm/core/comlib/_ChooseMedia.js +0 -38
  106. package/dist/esm/core/comlib/_Connector.js +0 -77
  107. package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +0 -56
  108. package/dist/esm/core/comlib/_Format.js +0 -102
  109. package/dist/esm/core/comlib/_GetLocation.js +0 -26
  110. package/dist/esm/core/comlib/_GetStorage.js +0 -44
  111. package/dist/esm/core/comlib/_GetSystemInfo.js +0 -32
  112. package/dist/esm/core/comlib/_Modal.js +0 -51
  113. package/dist/esm/core/comlib/_OpenCamera.js +0 -44
  114. package/dist/esm/core/comlib/_OpenPetalMap.js +0 -28
  115. package/dist/esm/core/comlib/_OpenUrl.js +0 -36
  116. package/dist/esm/core/comlib/_RemoveStorage.js +0 -42
  117. package/dist/esm/core/comlib/_Router.js +0 -113
  118. package/dist/esm/core/comlib/_ScanQrcode.js +0 -26
  119. package/dist/esm/core/comlib/_SetStorage.js +0 -40
  120. package/dist/esm/core/comlib/_Share.js +0 -28
  121. package/dist/esm/core/comlib/_ShowToast.js +0 -45
  122. package/dist/esm/core/comlib/_TextToSpeech.js +0 -117
  123. package/dist/esm/core/comlib/_TimerDebounce.js +0 -66
  124. package/dist/esm/core/comlib/_TimerDelay.js +0 -79
  125. package/dist/esm/core/comlib/_TimerThrottle.js +0 -69
  126. package/dist/esm/core/comlib/_Vibrate.js +0 -34
@@ -1,5 +1,5 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
5
  var _excluded = ["component", "id", "data", "className", "style"],
@@ -7,14 +7,14 @@ var _excluded = ["component", "id", "data", "className", "style"],
7
7
  import React, { useState, useEffect } from 'react';
8
8
  // @ts-ignore 运行时由宿主项目提供 @tarojs/components
9
9
  import { View } from '@tarojs/components';
10
- import { useModel, useBindInputs, useBindEvents, subscribePopupRouter, closeActivePopupRouter } from "./index";
10
+ import { useModel, useBindInputs, useBuiltinHandlers, useBindOutputs, subscribePopupRouter, closeActivePopupRouter } from "./index";
11
11
  import { useAppCreateContext } from "./useContext";
12
12
  import ComContext, { useAppContext } from "./ComContext";
13
13
  import { useEnhancedSlots, useResolvedParentSlot } from "./slots";
14
14
  // @ts-ignore 运行时由宿主项目提供 @tarojs/taro
15
15
  import { useTabItemTap } from '@tarojs/taro';
16
16
  export var WithCom = function WithCom(props) {
17
- var _comRefs$current, _parentSlot$params;
17
+ var _parentSlot$params;
18
18
  var Component = props.component,
19
19
  _props$id = props.id,
20
20
  id = _props$id === void 0 ? '' : _props$id,
@@ -39,66 +39,33 @@ export var WithCom = function WithCom(props) {
39
39
 
40
40
  //数据模型
41
41
  var _data = useModel(data || {});
42
-
43
- // 内置通用能力
44
- var handlers = {
45
- _setStyle: function _setStyle(style) {
46
- setDynamicStyle(function (prev) {
47
- return _objectSpread(_objectSpread({}, prev), style);
48
- });
49
- },
50
- _setData: function _setData(path, value) {
51
- var paths = path.split('.');
52
- var current = _data;
53
- for (var i = 0; i < paths.length - 1; i++) {
54
- if (!current[paths[i]]) current[paths[i]] = {};
55
- current = current[paths[i]];
56
- }
57
- current[paths[paths.length - 1]] = value;
58
- }
59
- };
60
- if (!isPopup) {
61
- Object.assign(handlers, {
62
- show: function show() {
63
- return setShow(true);
64
- },
65
- hide: function hide() {
66
- return setShow(false);
67
- },
68
- showOrHide: function showOrHide() {
69
- return setShow(function (prev) {
70
- return !prev;
71
- });
72
- }
73
- });
74
- }
75
-
76
- // 绑定输入,传入初始 handlers
77
- var inputProxy = useBindInputs(comRefs, id, handlers);
78
42
  var _ref = rest,
79
43
  rawSlots = _ref.slots,
80
44
  parentSlotProp = _ref.parentSlot,
81
45
  restProps = _objectWithoutProperties(_ref, _excluded2);
82
46
  var parentSlot = useResolvedParentSlot(parentSlotProp);
47
+ var enhancedSlots = useEnhancedSlots(rawSlots, id);
83
48
 
84
- // 绑定事件,带上上下文(用于事件流自动封装 id/name)
85
- var eventProxy = useBindEvents(restProps, {
49
+ // ---- inputs ----
50
+ var handlers = useBuiltinHandlers({
51
+ data: _data,
52
+ setDynamicStyle: setDynamicStyle,
53
+ setShow: setShow,
54
+ isPopup: isPopup
55
+ });
56
+ var inputProxy = useBindInputs(comRefs, id, handlers);
57
+
58
+ // ---- outputs ----
59
+ var outputProxy = useBindOutputs(comRefs, id, restProps, enhancedSlots, {
86
60
  id: id,
87
61
  name: props.name || id,
88
62
  parentSlot: parentSlot
89
63
  });
90
64
 
91
- // 注册 outputs 到注册表(按组件 id)
92
- if (comRefs !== null && comRefs !== void 0 && (_comRefs$current = comRefs.current) !== null && _comRefs$current !== void 0 && _comRefs$current.$outputs) {
93
- comRefs.current.$outputs[id] = eventProxy;
94
- }
95
-
96
- // 鸿蒙规范:确保 comRefs 中挂载的是最新的 inputProxy
97
- comRefs.current[id] = inputProxy;
98
- var enhancedSlots = useEnhancedSlots(rawSlots, id);
65
+ // ---- render ----
99
66
  var jsx = /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {
100
67
  inputs: inputProxy,
101
- outputs: eventProxy,
68
+ outputs: outputProxy,
102
69
  slots: enhancedSlots,
103
70
  parentSlot: parentSlot,
104
71
  data: _data,
@@ -106,8 +73,6 @@ export var WithCom = function WithCom(props) {
106
73
  id: id,
107
74
  style: style
108
75
  }));
109
-
110
- // 鸿蒙化处理:支持 itemWrap 协议
111
76
  if (parentSlot !== null && parentSlot !== void 0 && (_parentSlot$params = parentSlot.params) !== null && _parentSlot$params !== void 0 && _parentSlot$params.itemWrap) {
112
77
  return parentSlot.params.itemWrap({
113
78
  id: id,
@@ -115,11 +80,12 @@ export var WithCom = function WithCom(props) {
115
80
  jsx: jsx,
116
81
  def: Component.def,
117
82
  inputs: inputProxy,
118
- outputs: eventProxy,
83
+ outputs: outputProxy,
119
84
  style: style
120
85
  });
121
86
  }
122
87
  return show || isPopup ? /*#__PURE__*/React.createElement(View, {
88
+ id: id,
123
89
  className: className,
124
90
  style: _objectSpread(_objectSpread({}, style), dynamicStyle)
125
91
  }, jsx, props.children) : null;
@@ -6,6 +6,7 @@ import { handleCommonDir } from "./utils/commonDir";
6
6
  import { handleTabBarImages } from "./utils/tabBarImages";
7
7
  import { handlePageImages } from "./utils/pageImages";
8
8
  import { updateAppConfig } from "./utils/appConfig";
9
+ import { updateCustomTabBar } from "./utils/customTabBar";
9
10
  import { genScopedJSModules } from "../utils/logic/genJSModules";
10
11
  /**
11
12
  * 根据数组生成文件结构 JSON 对象
@@ -143,26 +144,7 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
143
144
  handlePageImages(assetsDir, pageImages);
144
145
 
145
146
  // 替换自定义 Tabbar 配置文件
146
- var CUSTOM_TAB_BAR_CONFIG_PATH = "src/custom-tab-bar/mybricks/tabbar-config.ts";
147
- var customTabBarItem = files.find(function (item) {
148
- return item.type === 'customTabBar';
149
- });
150
- if (customTabBarItem !== null && customTabBarItem !== void 0 && customTabBarItem.content) {
151
- var _mybricksDir$children;
152
- var customTabBarDir = ensureDir(srcDir, "src/custom-tab-bar");
153
- var mybricksDir = ensureDir(customTabBarDir, "src/custom-tab-bar/mybricks");
154
- var tabbarConfigFileIndex = (_mybricksDir$children = mybricksDir.children) === null || _mybricksDir$children === void 0 ? void 0 : _mybricksDir$children.findIndex(function (node) {
155
- return node.path === CUSTOM_TAB_BAR_CONFIG_PATH;
156
- });
157
- if (tabbarConfigFileIndex === -1) {
158
- mybricksDir.children.push({
159
- path: CUSTOM_TAB_BAR_CONFIG_PATH,
160
- content: customTabBarItem.content
161
- });
162
- } else {
163
- mybricksDir.children[tabbarConfigFileIndex].content = customTabBarItem.content;
164
- }
165
- }
147
+ updateCustomTabBar(srcDir, files);
166
148
 
167
149
  // 处理 common 目录下的文件
168
150
  handleCommonDir(commonDir, files);
@@ -8,9 +8,9 @@ interface FileNode {
8
8
  }
9
9
  interface GenerateItem {
10
10
  type: string;
11
- tabBarConfig?: string;
12
11
  meta?: {
13
12
  id: string;
13
+ coms?: Record<string, any>;
14
14
  };
15
15
  [key: string]: any;
16
16
  }
@@ -1,3 +1,5 @@
1
+ import { parseLooseObject } from "./fileNode";
2
+
1
3
  /**
2
4
  * app.config.ts 更新工具
3
5
  */
@@ -6,25 +8,42 @@
6
8
  * 更新 app.config.ts
7
9
  */
8
10
  export function updateAppConfig(appConfigFile, normalItems, items) {
11
+ var _appConfigFile$conten;
9
12
  if (!appConfigFile.content) {
10
13
  return;
11
14
  }
12
- var content = appConfigFile.content;
15
+
16
+ // 提取export default defineAppConfig()里的内容
17
+ var content = parseLooseObject(((_appConfigFile$conten = appConfigFile.content.match(/defineAppConfig\(([\s\S]*?)\)/)) === null || _appConfigFile$conten === void 0 ? void 0 : _appConfigFile$conten[1]) || '{}');
13
18
 
14
19
  // 更新 pages 配置(使用 scene id)
15
20
  var newPagePaths = normalItems.map(function (item) {
16
- return " 'pages/".concat(item.meta.id, "/index'");
17
- }).join(',\n');
18
- content = content.replace(/pages:\s*\[([\s\S]*?)\]/, "pages: [\n".concat(newPagePaths, "\n ]"));
21
+ return "pages/".concat(item.meta.id, "/index");
22
+ });
23
+ content.pages = newPagePaths;
24
+
25
+ // 提取首页
26
+ var entryPagePath = '';
27
+ normalItems.forEach(function (item) {
28
+ var _Object$values, _item$meta;
29
+ (_Object$values = Object.values((_item$meta = item.meta) === null || _item$meta === void 0 ? void 0 : _item$meta.coms)) === null || _Object$values === void 0 || _Object$values.forEach(function (com) {
30
+ var _com$model;
31
+ if (com !== null && com !== void 0 && com.asRoot && com !== null && com !== void 0 && (_com$model = com.model) !== null && _com$model !== void 0 && (_com$model = _com$model.data) !== null && _com$model !== void 0 && _com$model.isEntryPagePath) {
32
+ entryPagePath = "pages/".concat(item.meta.id, "/index");
33
+ }
34
+ });
35
+ });
36
+ if (entryPagePath) {
37
+ content.entryPagePath = entryPagePath;
38
+ }
19
39
 
20
40
  // 添加 TabBar 配置(从 items 中读取)
21
41
  var tabBarConfigItem = items.find(function (item) {
22
42
  return item.type === 'tabBarConfig';
23
43
  });
24
- if (tabBarConfigItem !== null && tabBarConfigItem !== void 0 && tabBarConfigItem.tabBarConfig) {
25
- content = content.replace(/window:\s*\{([\s\S]*?)\n\s*\}/, function (match) {
26
- return "".concat(match, ",\n").concat(tabBarConfigItem.tabBarConfig);
27
- });
44
+ if (tabBarConfigItem !== null && tabBarConfigItem !== void 0 && tabBarConfigItem.content) {
45
+ var tabBar = parseLooseObject("{".concat(tabBarConfigItem.content, "}"));
46
+ Object.assign(content, tabBar);
28
47
  }
29
- appConfigFile.content = content;
48
+ appConfigFile.content = "export default defineAppConfig(".concat(JSON.stringify(content, null, 2), ")");
30
49
  }
@@ -37,4 +37,17 @@ export function handleCommonDir(commonDir, items) {
37
37
  content: _fullContent
38
38
  });
39
39
  }
40
+
41
+ // 处理rootConfig
42
+ var rootConfigItem = items.find(function (item) {
43
+ return item.type === 'rootConfig';
44
+ });
45
+ if (rootConfigItem) {
46
+ var _fileContent2 = rootConfigItem.content || '{}';
47
+ var _fullContent2 = "export default ".concat(_fileContent2);
48
+ commonDir.children.push({
49
+ path: 'src/common/rootConfig.ts',
50
+ content: _fullContent2
51
+ });
52
+ }
40
53
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 更新自定义 TabBar 配置文件
3
+ */
4
+ import { GeneratedFile } from '../../toCodeTaro';
5
+ interface FileNode {
6
+ path: string;
7
+ content: string | null;
8
+ children?: FileNode[];
9
+ }
10
+ export declare function updateCustomTabBar(srcDir: FileNode, files: GeneratedFile[]): void;
11
+ export {};
@@ -0,0 +1,52 @@
1
+ /**
2
+ * 更新自定义 TabBar 配置文件
3
+ */
4
+
5
+ import { ensureDir } from "./fileNode";
6
+ import { parseLooseObject } from "./fileNode";
7
+ export function updateCustomTabBar(srcDir, files) {
8
+ var customTabBarDir = ensureDir(srcDir, 'src/custom-tab-bar');
9
+
10
+ // 将mybricks的tabbar数据写入/custom-tab-bar/mybricks/tabbar-config.ts
11
+ var customTabBarItem = files.find(function (item) {
12
+ return item.type === 'customTabBar';
13
+ });
14
+ if (customTabBarItem !== null && customTabBarItem !== void 0 && customTabBarItem.content) {
15
+ var _mybricksDir$children;
16
+ var CUSTOM_TAB_BAR_CONFIG_PATH = 'src/custom-tab-bar/mybricks/tabbar-config.ts';
17
+ var mybricksDir = ensureDir(customTabBarDir, 'src/custom-tab-bar/mybricks');
18
+ var tabbarConfigFileIndex = (_mybricksDir$children = mybricksDir.children) === null || _mybricksDir$children === void 0 ? void 0 : _mybricksDir$children.findIndex(function (node) {
19
+ return node.path === CUSTOM_TAB_BAR_CONFIG_PATH;
20
+ });
21
+ if (tabbarConfigFileIndex === -1) {
22
+ mybricksDir.children.push({
23
+ path: CUSTOM_TAB_BAR_CONFIG_PATH,
24
+ content: customTabBarItem.content
25
+ });
26
+ } else {
27
+ mybricksDir.children[tabbarConfigFileIndex].content = customTabBarItem.content;
28
+ }
29
+ }
30
+
31
+ // 将app.config.ts中的tabbar配置写入/custom-tab-bar/tabBar.json
32
+ // 后续可以用来判断页面是否标签页
33
+ var tabBarConfigItem = files.find(function (item) {
34
+ return item.type === 'tabBarConfig';
35
+ });
36
+ if (tabBarConfigItem !== null && tabBarConfigItem !== void 0 && tabBarConfigItem.content) {
37
+ var _customTabBarDir$chil;
38
+ var contentStr = JSON.stringify(parseLooseObject("{".concat(tabBarConfigItem.content, "}")), null, 2);
39
+ var tabBarJsonPath = "".concat(customTabBarDir.path, "/tabBar.json");
40
+ var tabBarJsonIndex = (_customTabBarDir$chil = customTabBarDir.children) === null || _customTabBarDir$chil === void 0 ? void 0 : _customTabBarDir$chil.findIndex(function (node) {
41
+ return node.path === tabBarJsonPath;
42
+ });
43
+ if (tabBarJsonIndex === -1) {
44
+ customTabBarDir.children.push({
45
+ path: tabBarJsonPath,
46
+ content: contentStr
47
+ });
48
+ } else {
49
+ customTabBarDir.children[tabBarJsonIndex].content = contentStr;
50
+ }
51
+ }
52
+ }
@@ -14,4 +14,8 @@ export declare function findDir(nodes: FileNode[], targetPath: string): FileNode
14
14
  * 确保目录存在,如果不存在则创建
15
15
  */
16
16
  export declare function ensureDir(parentDir: FileNode, dirPath: string): FileNode;
17
+ /**
18
+ * 解析宽松格式的对象字符串
19
+ */
20
+ export declare function parseLooseObject(raw: string): any;
17
21
  export {};
@@ -1,4 +1,6 @@
1
1
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
+ import { runInNewContext } from 'node:vm';
3
+
2
4
  /**
3
5
  * 文件节点相关工具函数
4
6
  */
@@ -46,4 +48,15 @@ export function ensureDir(parentDir, dirPath) {
46
48
  }
47
49
  dir.children = dir.children || [];
48
50
  return dir;
51
+ }
52
+
53
+ /**
54
+ * 解析宽松格式的对象字符串
55
+ */
56
+ export function parseLooseObject(raw) {
57
+ try {
58
+ return JSON.parse(raw);
59
+ } catch (_unused) {
60
+ return runInNewContext("(".concat(raw, ")"), Object.create(null));
61
+ }
49
62
  }
@@ -17,10 +17,9 @@ import { handleProcess } from "./utils/logic/handleProcess";
17
17
  var COM_PROTOCOL = {
18
18
  "mybricks.taro.formContainer": {
19
19
  useWrap: true
20
- },
21
- "mybricks.taro.formAdditionContainer": {
22
- useWrap: true
23
20
  }
21
+ // 移除 FormAdditionContainer 的配置,因为它的 runtime 没有传递 wrap 函数
22
+ // "mybricks.taro.formAdditionContainer": { useWrap: true },
24
23
  };
25
24
 
26
25
  /**
@@ -127,15 +126,11 @@ var prepareComponent = function prepareComponent(com, config) {
127
126
  * 准备样式转换
128
127
  */
129
128
  var prepareStyles = function prepareStyles(com) {
130
- var _props$data, _props$style, _props$style2;
129
+ var _props$style;
131
130
  var meta = com.meta,
132
131
  props = com.props;
133
- // 鸿蒙化:合并 data.layout 到样式中,确保容器布局生效
134
- var styleWithLayout = _objectSpread(_objectSpread({}, props.style || {}), {}, {
135
- layout: ((_props$data = props.data) === null || _props$data === void 0 ? void 0 : _props$data.layout) || ((_props$style = props.style) === null || _props$style === void 0 ? void 0 : _props$style.layout)
136
- });
137
- var resultStyle = convertComponentStyle(styleWithLayout);
138
- var cssContent = convertStyleAryToCss((_props$style2 = props.style) === null || _props$style2 === void 0 ? void 0 : _props$style2.styleAry, meta.id);
132
+ var resultStyle = convertComponentStyle(props.style || {});
133
+ var cssContent = convertStyleAryToCss((_props$style = props.style) === null || _props$style === void 0 ? void 0 : _props$style.styleAry, meta.id);
139
134
  return {
140
135
  cssContent: cssContent,
141
136
  rootStyle: resultStyle.root || {}
@@ -162,15 +157,23 @@ var processComSlots = function processComSlots(com, config, initialCss) {
162
157
  var renderManager = config.renderManager || new RenderManager();
163
158
  var slotEntries = Object.entries(slots);
164
159
  slotEntries.forEach(function (_ref2, index) {
165
- var _com$props$data, _props$data2, _COM_PROTOCOL$meta$de;
160
+ var _config$getEffectEven, _effectEvent$process, _effectEvent$process2, _com$props$data, _props$data, _COM_PROTOCOL$meta$de;
166
161
  var _ref3 = _slicedToArray(_ref2, 2),
167
162
  slotId = _ref3[0],
168
163
  slot = _ref3[1];
169
- // 鸿蒙规范:如果插槽内没有组件,直接渲染空
170
164
  var children = slot.comAry || slot.children || [];
171
165
  var isLast = index === slotEntries.length - 1;
172
166
  var slotIndent = indentation(config.codeStyle.indent * (config.depth + 2));
173
- if (children.length === 0) {
167
+
168
+ // 检查是否有插槽级别的 effectEvent(即使 children 为空也可能有逻辑代码)
169
+ var effectEvent = (_config$getEffectEven = config.getEffectEvent) === null || _config$getEffectEven === void 0 ? void 0 : _config$getEffectEven.call(config, {
170
+ comId: meta.id,
171
+ slotId: slotId
172
+ });
173
+ var hasSlotLogic = effectEvent && (((_effectEvent$process = effectEvent.process) === null || _effectEvent$process === void 0 || (_effectEvent$process = _effectEvent$process.nodesDeclaration) === null || _effectEvent$process === void 0 ? void 0 : _effectEvent$process.length) > 0 || ((_effectEvent$process2 = effectEvent.process) === null || _effectEvent$process2 === void 0 || (_effectEvent$process2 = _effectEvent$process2.nodesInvocation) === null || _effectEvent$process2 === void 0 ? void 0 : _effectEvent$process2.length) > 0);
174
+
175
+ // 如果插槽内没有组件且没有逻辑代码,直接渲染空
176
+ if (children.length === 0 && !hasSlotLogic) {
174
177
  slotsCode += "".concat(slotIndent).concat(slotId, ": {\n").concat(slotIndent, " render: () => null\n").concat(slotIndent, "}").concat(isLast ? '' : ',', "\n");
175
178
  return;
176
179
  }
@@ -198,9 +201,9 @@ var processComSlots = function processComSlots(com, config, initialCss) {
198
201
  var rawContent = result.ui;
199
202
 
200
203
  // 鸿蒙化处理:针对表单容器进行别名对齐
201
- if (meta.def.namespace === "mybricks.taro.formContainer" && Array.isArray((_props$data2 = props.data) === null || _props$data2 === void 0 ? void 0 : _props$data2.items) && result.directChildren) {
202
- var _props$data3;
203
- var items = (_props$data3 = props.data) === null || _props$data3 === void 0 ? void 0 : _props$data3.items;
204
+ if (meta.def.namespace === "mybricks.taro.formContainer" && Array.isArray((_props$data = props.data) === null || _props$data === void 0 ? void 0 : _props$data.items) && result.directChildren) {
205
+ var _props$data2;
206
+ var items = (_props$data2 = props.data) === null || _props$data2 === void 0 ? void 0 : _props$data2.items;
204
207
  result.directChildren.forEach(function (childRes) {
205
208
  var itemConfig = items.find(function (it) {
206
209
  return it.id === childRes.id;
@@ -248,7 +251,7 @@ var processComSlots = function processComSlots(com, config, initialCss) {
248
251
  * 生成插槽内部的驱动逻辑 (useEffect 监听 inputValues 并调用子组件 inputs)
249
252
  */
250
253
  var buildSlotLogicCode = function buildSlotLogicCode(args) {
251
- var _config$getEffectEven;
254
+ var _config$getEffectEven2;
252
255
  var parentComId = args.parentComId,
253
256
  slotKey = args.slotKey,
254
257
  config = args.config;
@@ -257,7 +260,7 @@ var buildSlotLogicCode = function buildSlotLogicCode(args) {
257
260
 
258
261
  // 更直接:用 to-code-react 已经解析好的“effect event”(底层来自 diagrams[].conAry)
259
262
  // buildSlotLogicCode 只负责包一层 useEffect,不再自己扫描/猜测 cons/pinValueProxies
260
- var effectEvent = (_config$getEffectEven = config.getEffectEvent) === null || _config$getEffectEven === void 0 ? void 0 : _config$getEffectEven.call(config, {
263
+ var effectEvent = (_config$getEffectEven2 = config.getEffectEvent) === null || _config$getEffectEven2 === void 0 ? void 0 : _config$getEffectEven2.call(config, {
261
264
  comId: parentComId,
262
265
  slotId: slotKey
263
266
  });
@@ -277,7 +280,7 @@ var buildSlotLogicCode = function buildSlotLogicCode(args) {
277
280
  getParams: function getParams() {
278
281
  return paramsProxy;
279
282
  }
280
- })).replace(/this\./g, "comRefs.current.").replace(/comRefs\.current\.([a-zA-Z0-9_]+)\.controller_/g, "comRefs.current.$1.").replace(/comRefs\.current\.slot_Index\./g, "comRefs.current.");
283
+ })).replace(/this\.\$vars\./g, "$vars.current.").replace(/this\.\$fxs\./g, "$fxs.current.").replace(/this\./g, "comRefs.current.").replace(/comRefs\.current\.([a-zA-Z0-9_]+)\.controller_/g, "comRefs.current.$1.").replace(/comRefs\.current\.slot_Index\./g, "comRefs.current.");
281
284
  if (!process.trim()) return "";
282
285
  var code = "".concat(indent, "useEffect(() => {\n");
283
286
  code += "".concat(indent2, "if (!params?.inputValues) return;\n");
@@ -320,10 +323,10 @@ var generateUiCode = function generateUiCode(com, config, componentName, rootSty
320
323
  * JS 计算组件专用处理
321
324
  */
322
325
  var handleJsCalculation = function handleJsCalculation(com, config) {
323
- var _props$data4, _props$data5, _props$data6;
326
+ var _props$data3, _props$data4, _props$data5;
324
327
  var meta = com.meta,
325
328
  props = com.props;
326
- var transformCode = ((_props$data4 = props.data) === null || _props$data4 === void 0 || (_props$data4 = _props$data4.fns) === null || _props$data4 === void 0 ? void 0 : _props$data4.code) || ((_props$data5 = props.data) === null || _props$data5 === void 0 || (_props$data5 = _props$data5.fns) === null || _props$data5 === void 0 ? void 0 : _props$data5.transformCode) || ((_props$data6 = props.data) === null || _props$data6 === void 0 ? void 0 : _props$data6.fns);
329
+ var transformCode = ((_props$data3 = props.data) === null || _props$data3 === void 0 || (_props$data3 = _props$data3.fns) === null || _props$data3 === void 0 ? void 0 : _props$data3.code) || ((_props$data4 = props.data) === null || _props$data4 === void 0 || (_props$data4 = _props$data4.fns) === null || _props$data4 === void 0 ? void 0 : _props$data4.transformCode) || ((_props$data5 = props.data) === null || _props$data5 === void 0 ? void 0 : _props$data5.fns);
327
330
  if (transformCode && config.addJSModule) {
328
331
  var _meta$model, _meta$model2;
329
332
  config.addJSModule({
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 处理全局变量和全局Fx
2
+ * 处理全局变量、全局Fx、其他全局配置
3
3
  */
4
4
  import type { ToTaroCodeConfig, GeneratedFile } from "./toCodeTaro";
5
5
  interface HandleGlobalParams {
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  /**
5
- * 处理全局变量和全局Fx
5
+ * 处理全局变量、全局Fx、其他全局配置
6
6
  */
7
7
 
8
8
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -124,6 +124,11 @@ var handleGlobal = function handleGlobal(params, config) {
124
124
  });
125
125
  }
126
126
  return [{
127
+ type: "rootConfig",
128
+ content: JSON.stringify(tojson.rootConfig, null, 2),
129
+ importManager: null,
130
+ name: "rootConfig"
131
+ }, {
127
132
  type: "global",
128
133
  content: varCode + "\n\n" + fxCode,
129
134
  importManager: globalImportManager,
@@ -145,12 +145,10 @@ var generateSlotUi = function generateSlotUi(ui, props, childrenUi, childrenResu
145
145
  width: "100%",
146
146
  height: "100%"
147
147
  }, slotStyle), propsStyle);
148
-
149
- // 鸿蒙化:优先使用 config 中传递的 layout(来自父容器 data.layout),否则使用 slot 自身的 layout
150
- var layout = config.layout || ui.layout || mergedStyle.layout;
148
+ var layout = ui.layout || mergedStyle.layout;
151
149
  var smart = isSmartLayout(layout);
152
150
  var layoutAdjustment = smart ? {
153
- position: isHasInSmartLayout(childrenResults) ? "fixed" : "relative"
151
+ position: "relative"
154
152
  } : hasFixedChildren(childrenResults) ? {
155
153
  transform: "translateX(0)"
156
154
  } : {};
@@ -161,10 +159,13 @@ var generateSlotUi = function generateSlotUi(ui, props, childrenUi, childrenResu
161
159
  // 插槽根容器增强:加上可读的标识,便于用户定位/调试
162
160
  // - className: slot-<parentComId>
163
161
  var parentComId = config === null || config === void 0 ? void 0 : config.parentComId;
164
- var slotMarkClass = parentComId ? "slot-".concat(parentComId) : "";
162
+ var slotMarkClass = parentComId ? "mybricks_slot slot-".concat(parentComId) : "";
165
163
  var classNameStr = [rootClassName, slotMarkClass].filter(Boolean).join(" ");
166
164
  var classNameAttr = classNameStr ? " className='".concat(classNameStr, "'") : "";
167
- return "".concat(indent, "<View").concat(classNameAttr, " style={").concat(styleCode, "}>\n").concat(childrenUi, "\n").concat(indent, "</View>");
165
+
166
+ // 支持通过 params.style 传递额外样式
167
+ var styleAttr = slotMarkClass ? "style={{...params.style || {}, ...".concat(styleCode, "}}") : "style={".concat(styleCode, "}");
168
+ return "".concat(indent, "<View").concat(classNameAttr, " ").concat(styleAttr, ">\n").concat(childrenUi, "\n").concat(indent, "</View>");
168
169
  };
169
170
 
170
171
  /**
@@ -208,10 +209,4 @@ var hasFixedChildren = function hasFixedChildren(childrenResults) {
208
209
  var isSmartLayout = function isSmartLayout(layout) {
209
210
  return layout === "smart" || (layout === null || layout === void 0 ? void 0 : layout.position) === "smart";
210
211
  };
211
- var isHasInSmartLayout = function isHasInSmartLayout(childrenResults) {
212
- return childrenResults.some(function (item) {
213
- var _item$rootStyle2;
214
- return (item === null || item === void 0 || (_item$rootStyle2 = item.rootStyle) === null || _item$rootStyle2 === void 0 ? void 0 : _item$rootStyle2.inSmartLayout) === true;
215
- });
216
- };
217
212
  export default handleSlot;
@@ -10,6 +10,23 @@ import { RenderManager } from "../utils/templates/renderManager";
10
10
  import { createProvider, createProviderMap } from "../utils/context/createProvider";
11
11
  import { createEventQueries } from "../utils/context/createEventQueries";
12
12
  import { collectJSModulesFromScene, extractJSModuleFromCom } from "../utils/context/collectJSModules";
13
+ /**
14
+ * 获取需要调用的路由方法名
15
+ */
16
+ var getCallMethodName = function getCallMethodName(com, pinId, isTargetPopup) {
17
+ var _com$model;
18
+ // 不是 open 方法,或者是弹窗,直接返回 pinId
19
+ if (pinId !== 'open' || isTargetPopup) return pinId;
20
+
21
+ // 页面跳转类型映射
22
+ var OPEN_TYPE_MAP = {
23
+ 'blank': 'open',
24
+ 'redirect': 'replace'
25
+ };
26
+ var openType = com === null || com === void 0 || (_com$model = com.model) === null || _com$model === void 0 || (_com$model = _com$model.data) === null || _com$model === void 0 ? void 0 : _com$model.openType;
27
+ return OPEN_TYPE_MAP[openType] || openType || pinId;
28
+ };
29
+
13
30
  /**
14
31
  * 处理单个场景
15
32
  */
@@ -76,7 +93,7 @@ export var processScene = function processScene(params) {
76
93
  var scanComs = function scanComs(coms) {
77
94
  if (!Array.isArray(coms)) return;
78
95
  coms.forEach(function (com) {
79
- var _com$def, _com$model;
96
+ var _com$def, _com$model2;
80
97
  if (com.name) dslComIdToNameMap[com.id] = com.name;
81
98
  if (com.slots) {
82
99
  var slotList = Array.isArray(com.slots) ? com.slots : Object.values(com.slots);
@@ -86,7 +103,7 @@ export var processScene = function processScene(params) {
86
103
  });
87
104
  }
88
105
  // 特殊处理表单容器
89
- if (((_com$def = com.def) === null || _com$def === void 0 ? void 0 : _com$def.namespace) === 'mybricks.taro.formContainer' && (_com$model = com.model) !== null && _com$model !== void 0 && (_com$model = _com$model.data) !== null && _com$model !== void 0 && _com$model.items) {
106
+ if (((_com$def = com.def) === null || _com$def === void 0 ? void 0 : _com$def.namespace) === 'mybricks.taro.formContainer' && (_com$model2 = com.model) !== null && _com$model2 !== void 0 && (_com$model2 = _com$model2.data) !== null && _com$model2 !== void 0 && _com$model2.items) {
90
107
  com.model.data.items.forEach(function (item) {
91
108
  if (item.comName) dslComIdToNameMap[item.id] = item.comName;
92
109
  });
@@ -123,10 +140,13 @@ export var processScene = function processScene(params) {
123
140
  var isOutput = targetScene === null || targetScene === void 0 || (_targetScene$outputs = targetScene.outputs) === null || _targetScene$outputs === void 0 ? void 0 : _targetScene$outputs.some(function (pin) {
124
141
  return pin.id === pinId;
125
142
  });
143
+
144
+ // 调用的方法名
145
+ var callMethodName = getCallMethodName(com, pinId, isTargetPopup);
126
146
  if (isInput || isOutput) {
127
147
  var _config$getPageId;
128
148
  return {
129
- code: "".concat(routerName, ".").concat(pinId, "(\"").concat(((_config$getPageId = config.getPageId) === null || _config$getPageId === void 0 ? void 0 : _config$getPageId.call(config, sceneId)) || sceneId, "\"").concat(args ? ", ".concat(args) : "", ")"),
149
+ code: "".concat(routerName, ".").concat(callMethodName, "(\"").concat(((_config$getPageId = config.getPageId) === null || _config$getPageId === void 0 ? void 0 : _config$getPageId.call(config, sceneId)) || sceneId, "\"").concat(args ? ", ".concat(args) : "", ")"),
130
150
  import: {
131
151
  packageName: config.getComponentPackageName(),
132
152
  dependencyNames: [routerName],
@@ -59,7 +59,7 @@ var processVarEvents = function processVarEvents(currentScene, config, addDepend
59
59
  };
60
60
  addDependencyImport({
61
61
  packageName: config.getUtilsPackageName(importParams),
62
- dependencyNames: ["SUBJECT_SUBSCRIBE", "SUBJECT_VALUE"],
62
+ dependencyNames: ["SUBJECT_SUBSCRIBE"],
63
63
  importType: "named"
64
64
  });
65
65
  varEvents.forEach(function (varEvent) {
@@ -87,11 +87,9 @@ var processVarEvents = function processVarEvents(currentScene, config, addDepend
87
87
  })).replace(/this\.\$vars\./g, "$vars.current.").replace(/this\.\$fxs\./g, "$fxs.current.").replace(/this\./g, "comRefs.current.").replace(/comRefs\.current\.([a-zA-Z0-9_]+)\.controller_/g, "comRefs.current.$1.").replace(/comRefs\.current\.slot_Index\./g, "comRefs.current.");
88
88
  if (!process.trim()) return;
89
89
  code += "\n".concat(indent, " /** \u53D8\u91CF ").concat(sanitizeBlockComment(com.title || varName), " \u7684 ").concat(pinId, " */");
90
- // 统一逻辑函数:changed 触发 + 首次 get() 回放(解决“set 早于订阅”的丢事件)
90
+ // 订阅变量的 changed 事件
91
91
  code += "\n".concat(indent, " const run_").concat(varName, "_").concat(pinId, " = (value: any) => {\n").concat(process, "\n").concat(indent, " };");
92
92
  code += "\n".concat(indent, " $vars.current.").concat(varName, ".").concat(pinId, "?.()[SUBJECT_SUBSCRIBE](run_").concat(varName, "_").concat(pinId, ");");
93
- code += "\n".concat(indent, " const init_").concat(varName, "_").concat(pinId, " = $vars.current.").concat(varName, ".get?.();");
94
- code += "\n".concat(indent, " run_").concat(varName, "_").concat(pinId, "(init_").concat(varName, "_").concat(pinId, "?.[SUBJECT_VALUE]);");
95
93
  });
96
94
  return code;
97
95
  };
@@ -239,7 +237,7 @@ var processSceneInputs = function processSceneInputs(currentScene, config, addDe
239
237
  importType: "named"
240
238
  });
241
239
  // 使用 SUBJECT_SUBSCRIBE 订阅,不修改 Subject.js
242
- code += "\n".concat(indent, " ").concat(controllerName, ".getParams(\"").concat(currentScene.id, "\")[SUBJECT_SUBSCRIBE]((val: any) => {\n").concat(indent, " if (val) inputs.open(val);\n").concat(indent, " });");
240
+ code += "\n".concat(indent, " ").concat(controllerName, ".getParams(\"").concat(currentScene.id, "\")[SUBJECT_SUBSCRIBE]((val: any) => {\n").concat(indent, " inputs.open(val);\n").concat(indent, " });");
243
241
  }
244
242
  }
245
243
  });