@mybricks/to-code-taro 1.0.7 → 1.1.0

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 (120) hide show
  1. package/dist/cjs/core/comlib/_Modal.js +68 -0
  2. package/dist/cjs/core/comlib/_TimerDelay.js +55 -30
  3. package/dist/cjs/core/comlib/index.js +3 -0
  4. package/dist/cjs/core/mybricks/log.js +0 -1
  5. package/dist/cjs/core/utils/hooks.js +3 -2
  6. package/dist/cjs/core/utils/slots.js +11 -5
  7. package/dist/cjs/core/utils/useContext.js +5 -3
  8. package/dist/cjs/core/utils/with.js +5 -6
  9. package/dist/cjs/generate/generateTaroProjectJson.js +18 -1
  10. package/dist/cjs/handleCom.js +47 -73
  11. package/dist/cjs/handleSlot.js +5 -3
  12. package/dist/cjs/processors/processComEvents.js +2 -3
  13. package/dist/cjs/processors/processModule.js +23 -0
  14. package/dist/cjs/processors/processScene.js +23 -0
  15. package/dist/cjs/processors/processSceneLogic.d.ts +4 -1
  16. package/dist/cjs/processors/processSceneLogic.js +72 -12
  17. package/dist/cjs/taro-template.json +68 -42
  18. package/dist/cjs/toCodeTaro.d.ts +14 -1
  19. package/dist/cjs/toCodeTaro.js +1 -0
  20. package/dist/cjs/utils/builder/buildResult.d.ts +1 -0
  21. package/dist/cjs/utils/builder/buildResult.js +8 -1
  22. package/dist/cjs/utils/common/helper.d.ts +10 -0
  23. package/dist/cjs/utils/common/helper.js +21 -0
  24. package/dist/cjs/utils/common/string.d.ts +10 -0
  25. package/dist/cjs/utils/common/string.js +13 -0
  26. package/dist/cjs/utils/config/content/converter.js +1 -0
  27. package/dist/cjs/utils/config/content/tabBarConfig.d.ts +19 -4
  28. package/dist/cjs/utils/config/content/tabBarConfig.js +18 -1
  29. package/dist/cjs/utils/config/content/types.d.ts +15 -10
  30. package/dist/cjs/utils/config/handlePageConfig.d.ts +6 -0
  31. package/dist/cjs/utils/config/handlePageConfig.js +13 -1
  32. package/dist/cjs/utils/logic/handleProcess.js +50 -33
  33. package/dist/cjs/utils/style/converter.js +1 -6
  34. package/dist/cjs/utils/templates/index.d.ts +1 -0
  35. package/dist/cjs/utils/templates/index.js +11 -4
  36. package/dist/cjs/utils/templates/renderManager.js +4 -2
  37. package/dist/cjs/utils/templates/scene.d.ts +2 -1
  38. package/dist/cjs/utils/templates/scene.js +4 -3
  39. package/dist/esm/abstractEventTypeDef.d.ts.map +1 -0
  40. package/dist/esm/core/comlib/_Modal.js +51 -0
  41. package/dist/esm/core/comlib/_TimerDelay.js +46 -14
  42. package/dist/esm/core/comlib/index.js +2 -0
  43. package/dist/esm/core/mybricks/log.js +1 -5
  44. package/dist/esm/core/utils/hooks.js +7 -2
  45. package/dist/esm/core/utils/slots.js +28 -10
  46. package/dist/esm/core/utils/useContext.js +9 -3
  47. package/dist/esm/core/utils/with.js +5 -9
  48. package/dist/esm/generate/generateTaroProjectJson.d.ts.map +1 -0
  49. package/dist/esm/generate/generateTaroProjectJson.js +22 -0
  50. package/dist/esm/generate/generateTaroTempalteJson.d.ts.map +1 -0
  51. package/dist/esm/generate/utils/appConfig.d.ts.map +1 -0
  52. package/dist/esm/generate/utils/commonDir.d.ts.map +1 -0
  53. package/dist/esm/generate/utils/fileNode.d.ts.map +1 -0
  54. package/dist/esm/generate/utils/index.d.ts.map +1 -0
  55. package/dist/esm/generate/utils/tabBarImages.d.ts.map +1 -0
  56. package/dist/esm/handleCom.js +60 -95
  57. package/dist/esm/handleDom.d.ts.map +1 -0
  58. package/dist/esm/handleExtension.d.ts.map +1 -0
  59. package/dist/esm/handleGlobal.d.ts.map +1 -0
  60. package/dist/esm/handleModule.d.ts.map +1 -0
  61. package/dist/esm/handleSlot.js +9 -4
  62. package/dist/esm/index.d.ts.map +1 -0
  63. package/dist/esm/processors/processComEvents.js +6 -3
  64. package/dist/esm/processors/processModule.d.ts.map +1 -0
  65. package/dist/esm/processors/processModule.js +35 -0
  66. package/dist/esm/processors/processScene.d.ts.map +1 -0
  67. package/dist/esm/processors/processScene.js +35 -0
  68. package/dist/esm/processors/processSceneLogic.d.ts +4 -1
  69. package/dist/esm/processors/processSceneLogic.js +90 -15
  70. package/dist/esm/taro-template.json +68 -42
  71. package/dist/esm/toCodeTaro.d.ts +14 -1
  72. package/dist/esm/toCodeTaro.d.ts.map +1 -0
  73. package/dist/esm/toCodeTaro.js +1 -0
  74. package/dist/esm/utils/builder/buildResult.d.ts +1 -0
  75. package/dist/esm/utils/builder/buildResult.d.ts.map +1 -0
  76. package/dist/esm/utils/builder/buildResult.js +8 -1
  77. package/dist/esm/utils/common/ImportManager.d.ts.map +1 -0
  78. package/dist/esm/utils/common/helper.d.ts +10 -0
  79. package/dist/esm/utils/common/helper.js +29 -0
  80. package/dist/esm/utils/common/object.d.ts.map +1 -0
  81. package/dist/esm/utils/common/string.d.ts +10 -0
  82. package/dist/esm/utils/common/string.d.ts.map +1 -0
  83. package/dist/esm/utils/common/string.js +16 -0
  84. package/dist/esm/utils/config/content/converter.d.ts.map +1 -0
  85. package/dist/esm/utils/config/content/converter.js +1 -0
  86. package/dist/esm/utils/config/content/index.d.ts.map +1 -0
  87. package/dist/esm/utils/config/content/pageConfig.d.ts.map +1 -0
  88. package/dist/esm/utils/config/content/saveBase64Image.d.ts.map +1 -0
  89. package/dist/esm/utils/config/content/tabBarConfig.d.ts +19 -4
  90. package/dist/esm/utils/config/content/tabBarConfig.d.ts.map +1 -0
  91. package/dist/esm/utils/config/content/tabBarConfig.js +28 -4
  92. package/dist/esm/utils/config/content/types.d.ts +15 -10
  93. package/dist/esm/utils/config/content/types.d.ts.map +1 -0
  94. package/dist/esm/utils/config/content/validator.d.ts.map +1 -0
  95. package/dist/esm/utils/config/handlePageConfig.d.ts +6 -0
  96. package/dist/esm/utils/config/handlePageConfig.d.ts.map +1 -0
  97. package/dist/esm/utils/config/handlePageConfig.js +17 -2
  98. package/dist/esm/utils/context/buildContext.d.ts.map +1 -0
  99. package/dist/esm/utils/context/buildFrameMap.d.ts.map +1 -0
  100. package/dist/esm/utils/context/buildGlobalData.d.ts.map +1 -0
  101. package/dist/esm/utils/context/collectJSModules.d.ts.map +1 -0
  102. package/dist/esm/utils/context/createEventQueries.d.ts.map +1 -0
  103. package/dist/esm/utils/context/createProvider.d.ts.map +1 -0
  104. package/dist/esm/utils/index.d.ts.map +1 -0
  105. package/dist/esm/utils/logic/convertNamespace.d.ts.map +1 -0
  106. package/dist/esm/utils/logic/genJSModules.d.ts.map +1 -0
  107. package/dist/esm/utils/logic/handleProcess.js +66 -40
  108. package/dist/esm/utils/logic/processChildren.d.ts.map +1 -0
  109. package/dist/esm/utils/style/color.d.ts.map +1 -0
  110. package/dist/esm/utils/style/converter.js +11 -8
  111. package/dist/esm/utils/style/getComponentClassName.d.ts.map +1 -0
  112. package/dist/esm/utils/style/pxtransform.d.ts.map +1 -0
  113. package/dist/esm/utils/style/types.d.ts.map +1 -0
  114. package/dist/esm/utils/templates/component.d.ts.map +1 -0
  115. package/dist/esm/utils/templates/index.d.ts +1 -0
  116. package/dist/esm/utils/templates/index.js +20 -10
  117. package/dist/esm/utils/templates/renderManager.js +5 -2
  118. package/dist/esm/utils/templates/scene.d.ts +2 -1
  119. package/dist/esm/utils/templates/scene.js +7 -6
  120. package/package.json +1 -1
@@ -62,7 +62,7 @@ export interface GeneratedFile {
62
62
  cssContent?: string;
63
63
  pageConfigContent?: string;
64
64
  importManager: ImportManager;
65
- type: "normal" | "popup" | "module" | "global" | "extension-config" | "extension-api" | "extension-bus" | "abstractEventTypeDef" | "fx" | "api" | "extension-event" | "jsModules" | "commonIndex" | "tabBarConfig";
65
+ type: "normal" | "popup" | "module" | "global" | "extension-config" | "extension-api" | "extension-bus" | "abstractEventTypeDef" | "fx" | "api" | "extension-event" | "jsModules" | "commonIndex" | "tabBarConfig" | "customTabBar";
66
66
  meta?: ReturnType<typeof toCode>["scenes"][0]["scene"];
67
67
  name: string;
68
68
  tabBarConfig?: string;
@@ -147,6 +147,19 @@ export interface BaseConfig extends ToTaroCodeConfig {
147
147
  typeDef: any;
148
148
  schema: any;
149
149
  }) => void;
150
+ /** 获取组件/场景调用的代码模板(解耦核心) */
151
+ getCallTemplate?: (params: {
152
+ com: any;
153
+ pinId: string;
154
+ args: string;
155
+ }) => {
156
+ code: string;
157
+ import?: {
158
+ packageName: string;
159
+ dependencyNames: string[];
160
+ importType: "default" | "named";
161
+ };
162
+ } | undefined;
150
163
  /** 根据 ID 获取 DSL 中的稳定组件名(参考鸿蒙实现) */
151
164
  getDslComNameById?: (id: string) => string | undefined;
152
165
  }
@@ -134,6 +134,7 @@ var getCode = (params, config) => {
134
134
  jsModulesMap: jsModulesCollector.getMap(),
135
135
  globalTabBarConfig: pageConfigHandler.getTabBarConfig(),
136
136
  tabBarImageFiles: pageConfigHandler.getTabBarImageFiles(),
137
+ customTabBarFileContent: pageConfigHandler.getCustomTabBarFileContent(),
137
138
  popupIds: Array.from(popupIds),
138
139
  config
139
140
  });
@@ -11,6 +11,7 @@ interface BuildResultParams {
11
11
  tabBarImageFiles: any[];
12
12
  popupIds: string[];
13
13
  config: ToTaroCodeConfig;
14
+ customTabBarFileContent: string | null;
14
15
  }
15
16
  /**
16
17
  * 构建最终结果
@@ -42,7 +42,8 @@ var buildFinalResults = (params) => {
42
42
  globalTabBarConfig,
43
43
  tabBarImageFiles,
44
44
  popupIds,
45
- config
45
+ config,
46
+ customTabBarFileContent
46
47
  } = params;
47
48
  const files = [];
48
49
  files.push({
@@ -105,6 +106,12 @@ export const POPUP_MAP: Record<string, any> = {
105
106
  name: "tabBarConfig",
106
107
  tabBarConfig: globalTabBarConfig
107
108
  });
109
+ files.push({
110
+ type: "customTabBar",
111
+ content: customTabBarFileContent,
112
+ importManager: new import_ImportManager.ImportManager(config),
113
+ name: "customTabBar"
114
+ });
108
115
  }
109
116
  return {
110
117
  files,
@@ -1,2 +1,12 @@
1
1
  /** 缩进 */
2
2
  export declare const indentation: (level: number) => string;
3
+ /**
4
+ * 根据 schema.type 推导变量默认 initValue
5
+ * - string: ''(未提供 initValue)
6
+ * - number: 0
7
+ * - boolean: false
8
+ * - array: []
9
+ * - object: {}
10
+ * - 其他/未知: 优先使用 initValue,否则 {}
11
+ */
12
+ export declare const getInitValueBySchema: (schema: any, initValue: any) => any;
@@ -19,13 +19,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/utils/common/helper.ts
20
20
  var helper_exports = {};
21
21
  __export(helper_exports, {
22
+ getInitValueBySchema: () => getInitValueBySchema,
22
23
  indentation: () => indentation
23
24
  });
24
25
  module.exports = __toCommonJS(helper_exports);
25
26
  var indentation = (level) => {
26
27
  return " ".repeat(level);
27
28
  };
29
+ var getInitValueBySchema = (schema, initValue) => {
30
+ if (initValue !== void 0)
31
+ return initValue;
32
+ const type = schema == null ? void 0 : schema.type;
33
+ switch (type) {
34
+ case "string":
35
+ return "";
36
+ case "number":
37
+ return 0;
38
+ case "boolean":
39
+ return false;
40
+ case "array":
41
+ return [];
42
+ case "object":
43
+ return {};
44
+ default:
45
+ return {};
46
+ }
47
+ };
28
48
  // Annotate the CommonJS export names for ESM import in node:
29
49
  0 && (module.exports = {
50
+ getInitValueBySchema,
30
51
  indentation
31
52
  });
@@ -6,3 +6,13 @@ export declare const firstCharToLowerCase: (str: string) => string;
6
6
  export declare const camelToKebab: (str: string) => string;
7
7
  /** 中划线转驼峰 */
8
8
  export declare const kebabToCamel: (str: string) => string;
9
+ /** 检查字符串是否包含中文 */
10
+ export declare const hasChinese: (str: string) => boolean;
11
+ /**
12
+ * 获取安全的变量名
13
+ * 优先使用 title,如果 title 包含中文则使用 id
14
+ */
15
+ export declare const getSafeVarName: (com: {
16
+ title?: string;
17
+ id: string;
18
+ }) => string;
@@ -22,6 +22,8 @@ __export(string_exports, {
22
22
  camelToKebab: () => camelToKebab,
23
23
  firstCharToLowerCase: () => firstCharToLowerCase,
24
24
  firstCharToUpperCase: () => firstCharToUpperCase,
25
+ getSafeVarName: () => getSafeVarName,
26
+ hasChinese: () => hasChinese,
25
27
  kebabToCamel: () => kebabToCamel
26
28
  });
27
29
  module.exports = __toCommonJS(string_exports);
@@ -37,10 +39,21 @@ var camelToKebab = (str) => {
37
39
  var kebabToCamel = (str) => {
38
40
  return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
39
41
  };
42
+ var hasChinese = (str) => {
43
+ return /[\u4e00-\u9fa5]/.test(str);
44
+ };
45
+ var getSafeVarName = (com) => {
46
+ if (com.title && !hasChinese(com.title)) {
47
+ return com.title;
48
+ }
49
+ return com.id;
50
+ };
40
51
  // Annotate the CommonJS export names for ESM import in node:
41
52
  0 && (module.exports = {
42
53
  camelToKebab,
43
54
  firstCharToLowerCase,
44
55
  firstCharToUpperCase,
56
+ getSafeVarName,
57
+ hasChinese,
45
58
  kebabToCamel
46
59
  });
@@ -54,6 +54,7 @@ function convertToTaroTabBarConfig(tabBar, pageIdToPath = (pageId) => `pages/${p
54
54
  (item, index) => convertTabBarItem(item, pageIdToPath, index, processIcon)
55
55
  );
56
56
  const config = {
57
+ custom: true,
57
58
  list
58
59
  };
59
60
  const firstItem = validation.validItems[0];
@@ -2,12 +2,27 @@
2
2
  * TabBar 配置工具
3
3
  * 负责从 tabBar 数据生成 app.config.ts 中的 tabBar 配置字符串
4
4
  */
5
- import type { ImageFileInfo } from './types';
5
+ import type { TaroTabBarConfig, ImageFileInfo } from './types';
6
6
  /**
7
- * 从 tabBar 数据生成 TabBar 配置字符串(用于 app.config.ts)
7
+ * 从 tabBar 数据生成 TabBar 配置JSON(用于 app.config.ts)
8
8
  * @param tabBar tabBar 数据数组(来自 scenes[x].coms[id].model.data.tabBar)
9
9
  * @param pageIdToPath 页面 ID 到路径的映射函数(默认使用 pages/${pageId}/index)
10
10
  * @param imageFiles 用于收集需要保存的图片文件的数组(可选)
11
- * @returns TabBar 配置字符串,如果验证失败则返回 null
11
+ * @returns TabBar 配置JSON,如果验证失败则返回 null
12
12
  */
13
- export declare function generateTabBarConfigContent(tabBar: any[] | undefined, pageIdToPath?: (pageId: string) => string, imageFiles?: ImageFileInfo[]): string | null;
13
+ export declare function generateTabBarConfigContent(tabBar: any[] | undefined, pageIdToPath?: (pageId: string) => string, imageFiles?: ImageFileInfo[]): TaroTabBarConfig | null;
14
+ /**
15
+ * 将 TabBar 配置转换为 app.config.ts 中的字符串格式
16
+ * @param config TabBar 配置
17
+ * @param indent 缩进字符串,默认为 2 个空格
18
+ * @returns 配置字符串
19
+ */
20
+ export declare function formatTabBarConfigForAppConfig(config: TaroTabBarConfig, indent?: string): string;
21
+ /**
22
+ * 生成转换后的自定义Tabbar项配置文件内容
23
+ * 增加页面路径pagePath
24
+ * normalIconPath/selectedIconPath替换成本地图片路径
25
+ * @param tabBar tabBar 数据数组(来自 scenes[x].coms[id].model.data.tabBar)
26
+ * @param config TabBar 配置
27
+ */
28
+ export declare function generateCustomTabBarFileContent(tabBar: any[] | undefined, config: TaroTabBarConfig): string;
@@ -19,6 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/utils/config/content/tabBarConfig.ts
20
20
  var tabBarConfig_exports = {};
21
21
  __export(tabBarConfig_exports, {
22
+ formatTabBarConfigForAppConfig: () => formatTabBarConfigForAppConfig,
23
+ generateCustomTabBarFileContent: () => generateCustomTabBarFileContent,
22
24
  generateTabBarConfigContent: () => generateTabBarConfigContent
23
25
  });
24
26
  module.exports = __toCommonJS(tabBarConfig_exports);
@@ -33,7 +35,7 @@ function generateTabBarConfigContent(tabBar, pageIdToPath = (pageId) => `pages/$
33
35
  if (!config) {
34
36
  return null;
35
37
  }
36
- return formatTabBarConfigForAppConfig(config);
38
+ return config;
37
39
  }
38
40
  function formatTabBarConfigForAppConfig(config, indent = " ") {
39
41
  const tabBarJson = JSON.stringify(config, null, 2);
@@ -45,7 +47,22 @@ function formatTabBarConfigForAppConfig(config, indent = " ") {
45
47
  return `${indent}${line}`;
46
48
  }).join("\n");
47
49
  }
50
+ function generateCustomTabBarFileContent(tabBar, config) {
51
+ const customTabbarConfig = tabBar.map((item, index) => {
52
+ const { iconPath, selectedIconPath } = config.list[index];
53
+ return {
54
+ ...item,
55
+ pagePath: config.list[index].pagePath,
56
+ normalIconPath: iconPath ? `/${iconPath}` : void 0,
57
+ selectedIconPath: selectedIconPath ? `/${selectedIconPath}` : void 0
58
+ };
59
+ });
60
+ const tabBarJson = JSON.stringify(customTabbarConfig, null, 2);
61
+ return `export default ${tabBarJson} as any`;
62
+ }
48
63
  // Annotate the CommonJS export names for ESM import in node:
49
64
  0 && (module.exports = {
65
+ formatTabBarConfigForAppConfig,
66
+ generateCustomTabBarFileContent,
50
67
  generateTabBarConfigContent
51
68
  });
@@ -13,6 +13,12 @@ export interface TabBarItemSource {
13
13
  };
14
14
  text?: string;
15
15
  type?: string;
16
+ normalIconUseImg?: boolean;
17
+ selectedIconUseImg?: boolean;
18
+ normalIcon?: string;
19
+ selectedIcon?: string;
20
+ normalFontIconStyle?: Record<string, any>;
21
+ selectedFontIconStyle?: Record<string, any>;
16
22
  normalIconPath?: string;
17
23
  selectedIconPath?: string;
18
24
  normalTextStyle?: Record<string, any>;
@@ -21,16 +27,14 @@ export interface TabBarItemSource {
21
27
  selectedIconStyle?: Record<string, any>;
22
28
  normalBackgroundStyle?: Record<string, any>;
23
29
  selectedBackgroundStyle?: Record<string, any>;
24
- subMenu?: Array<{
25
- scene: {
26
- id: string;
27
- title?: string;
28
- };
29
- normalIconPath?: string;
30
- normalTextStyle?: Record<string, any>;
31
- normalIconStyle?: Record<string, any>;
32
- normalBackgroundStyle?: Record<string, any>;
33
- }>;
30
+ }
31
+ /**
32
+ * 转换后的自定义Tabbar项配置
33
+ * 增加页面路径pagePath
34
+ * normalIconPath/selectedIconPath替换成本地图片路径
35
+ */
36
+ export interface CustomTabbarConfig extends TabBarItemSource {
37
+ pagePath: string;
34
38
  }
35
39
  /**
36
40
  * Taro TabBar 项配置
@@ -45,6 +49,7 @@ export interface TaroTabBarItem {
45
49
  * Taro TabBar 配置
46
50
  */
47
51
  export interface TaroTabBarConfig {
52
+ custom?: boolean;
48
53
  color?: string;
49
54
  selectedColor?: string;
50
55
  backgroundColor?: string;
@@ -7,6 +7,7 @@ import { type ImageFileInfo } from "./content";
7
7
  export declare class HandlePageConfig {
8
8
  private globalTabBarConfig;
9
9
  private tabBarImageFiles;
10
+ private customTabbarFileContent;
10
11
  /**
11
12
  * 处理页面配置(提取 systemPage 组件数据)
12
13
  * @param scene 场景数据
@@ -22,4 +23,9 @@ export declare class HandlePageConfig {
22
23
  * 获取 TabBar 图片文件数组
23
24
  */
24
25
  getTabBarImageFiles(): ImageFileInfo[];
26
+ /**
27
+ * 获取自定义 TabBar 配置文件数据
28
+ * 用于生成文件/src/custom-tab-bar/mybricks/tabbar-config.ts
29
+ */
30
+ getCustomTabBarFileContent(): string | null;
25
31
  }
@@ -27,6 +27,7 @@ var HandlePageConfig = class {
27
27
  constructor() {
28
28
  this.globalTabBarConfig = null;
29
29
  this.tabBarImageFiles = [];
30
+ this.customTabbarFileContent = null;
30
31
  }
31
32
  /**
32
33
  * 处理页面配置(提取 systemPage 组件数据)
@@ -46,11 +47,15 @@ var HandlePageConfig = class {
46
47
  pageConfigContent = (0, import_content.generatePageConfigContent)(systemPageData);
47
48
  if (!this.globalTabBarConfig && systemPageData.tabBar && Array.isArray(systemPageData.tabBar)) {
48
49
  const pageIdToPath = (pageId) => `pages/${pageId}/index`;
49
- this.globalTabBarConfig = (0, import_content.generateTabBarConfigContent)(
50
+ const globalTabBarConfigJson = (0, import_content.generateTabBarConfigContent)(
50
51
  systemPageData.tabBar,
51
52
  pageIdToPath,
52
53
  this.tabBarImageFiles
53
54
  );
55
+ this.globalTabBarConfig = (0, import_content.formatTabBarConfigForAppConfig)(globalTabBarConfigJson);
56
+ if (this.globalTabBarConfig) {
57
+ this.customTabbarFileContent = (0, import_content.generateCustomTabBarFileContent)(systemPageData.tabBar, globalTabBarConfigJson);
58
+ }
54
59
  }
55
60
  }
56
61
  return pageConfigContent;
@@ -67,6 +72,13 @@ var HandlePageConfig = class {
67
72
  getTabBarImageFiles() {
68
73
  return this.tabBarImageFiles;
69
74
  }
75
+ /**
76
+ * 获取自定义 TabBar 配置文件数据
77
+ * 用于生成文件/src/custom-tab-bar/mybricks/tabbar-config.ts
78
+ */
79
+ getCustomTabBarFileContent() {
80
+ return this.customTabbarFileContent;
81
+ }
70
82
  };
71
83
  // Annotate the CommonJS export names for ESM import in node:
72
84
  0 && (module.exports = {
@@ -23,6 +23,7 @@ __export(handleProcess_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(handleProcess_exports);
25
25
  var import_helper = require("../common/helper");
26
+ var import_string = require("../common/string");
26
27
  var import_object = require("../common/object");
27
28
  var isJsCalculationComponent = (namespace) => {
28
29
  return namespace === "mybricks.taro._muilt-inputJs" || namespace === "mybricks.core-comlib.js-ai";
@@ -109,7 +110,7 @@ ${indent}}, appContext)
109
110
  `;
110
111
  });
111
112
  process.nodesInvocation.forEach((props) => {
112
- var _a, _b, _c;
113
+ var _a, _b, _c, _d;
113
114
  const { componentType, category, runType } = props;
114
115
  let nextValue = getNextValue(props, config, event);
115
116
  const isSameScope = checkIsSameScope(event, props);
@@ -117,43 +118,42 @@ ${indent}}, appContext)
117
118
  if (code) {
118
119
  code += "\n";
119
120
  }
121
+ const callTemplate = (_c = config.getCallTemplate) == null ? void 0 : _c.call(config, {
122
+ com: {
123
+ ...props.meta,
124
+ // 鸿蒙化:透传可能的场景 ID,增强识别能力
125
+ sceneId: ((_b = (_a = props.meta.model) == null ? void 0 : _a.data) == null ? void 0 : _b._sceneId) || props.meta.id
126
+ },
127
+ pinId: props.id,
128
+ args: nextValue
129
+ });
130
+ if (callTemplate) {
131
+ if (callTemplate.import) {
132
+ config.addParentDependencyImport(callTemplate.import);
133
+ }
134
+ code += `${indent}/** ${props.meta.title} */
135
+ ${indent}${nextCode}${callTemplate.code}`;
136
+ return;
137
+ }
120
138
  if (componentType === "js") {
121
139
  if (category === "scene") {
122
140
  const _sceneId = props.meta.model.data._sceneId;
123
- const targetScene = config.getSceneById(_sceneId);
124
- const isPopup = (targetScene == null ? void 0 : targetScene.type) === "popup" || ((_a = targetScene == null ? void 0 : targetScene.deps) == null ? void 0 : _a.some((dep) => dep.namespace === "mybricks.taro.popup"));
125
- const controllerName = isPopup ? "popupRouter" : "pageRouter";
126
- config.addParentDependencyImport({
127
- packageName: config.getComponentPackageName(),
128
- dependencyNames: [controllerName],
129
- importType: "named"
130
- });
131
141
  const operateName = props.meta.model.data.openType === "redirect" ? "replace" : "open";
132
142
  code += `${indent}/** 打开 ${props.meta.title} */
133
- ${indent}${nextCode}${controllerName}.${operateName}("${((_b = config.getPageId) == null ? void 0 : _b.call(config, _sceneId)) || _sceneId}", ${nextValue})`;
143
+ ${indent}${nextCode}this.${_sceneId}.${operateName}(${nextValue})`;
134
144
  } else if (category === "frameOutput") {
135
145
  const currentScene = config.getCurrentScene();
136
- const pinProxy = (_c = currentScene == null ? void 0 : currentScene.pinProxies) == null ? void 0 : _c[`${props.meta.id}-${props.id}`];
137
- if ((pinProxy == null ? void 0 : pinProxy.frameId) && (pinProxy == null ? void 0 : pinProxy.pinId)) {
138
- const method = pinProxy.pinId;
139
- const controllerName = config.isPopup ? "popupRouter" : "pageRouter";
140
- config.addParentDependencyImport({
141
- packageName: config.getComponentPackageName(),
142
- dependencyNames: [controllerName],
143
- importType: "named"
144
- });
145
- if (["commit", "cancel", "apply", "close"].includes(method)) {
146
- const sceneId = pinProxy.frameId || (currentScene == null ? void 0 : currentScene.id);
147
- const argCode = nextValue ? `, ${nextValue}` : "";
148
- code += `${indent}/** ${props.meta.title} 输出 ${method} */
149
- ${indent}${nextCode}${controllerName}.${method}("${sceneId}"${argCode})`;
150
- }
151
- }
146
+ const pinProxy = (_d = currentScene == null ? void 0 : currentScene.pinProxies) == null ? void 0 : _d[`${props.meta.id}-${props.id}`];
147
+ const method = (pinProxy == null ? void 0 : pinProxy.pinId) || props.id;
148
+ const sceneId = (pinProxy == null ? void 0 : pinProxy.frameId) || (currentScene == null ? void 0 : currentScene.id);
149
+ code += `${indent}/** ${props.meta.title} 输出 ${method} */
150
+ ${indent}${nextCode}this.${sceneId}.${method}(${nextValue})`;
152
151
  } else if (category === "normal") {
153
152
  let componentNameWithId = getComponentNameWithId(props, config, event);
154
153
  code += `${indent}/** 调用 ${props.meta.title} */
155
154
  ${indent}${nextCode}${componentNameWithId}(${runType === "input" ? nextValue : ""})`;
156
155
  } else if (category === "var") {
156
+ const varKey = (0, import_string.getSafeVarName)(props.meta);
157
157
  if (props.meta.global) {
158
158
  config.addParentDependencyImport({
159
159
  packageName: config.getComponentPackageName(),
@@ -161,14 +161,14 @@ ${indent}${nextCode}${componentNameWithId}(${runType === "input" ? nextValue : "
161
161
  importType: "named"
162
162
  });
163
163
  code += `${indent}/** ${props.title} 全局变量 ${props.meta.title} */
164
- ${indent}${nextCode}globalVars.${props.meta.title}.${props.id}(${nextValue})`;
164
+ ${indent}${nextCode}globalVars.${varKey}.${props.id}(${nextValue})`;
165
165
  } else {
166
166
  const currentProvider = getCurrentProvider(
167
167
  { isSameScope, props },
168
168
  config
169
169
  );
170
170
  code += `${indent}/** ${props.title} 变量 ${props.meta.title} */
171
- ${indent}${nextCode}this.${currentProvider.name}_Vars.${props.meta.title}.${props.id}(${nextValue})`;
171
+ ${indent}${nextCode}this.$vars.${varKey}.${props.id}(${nextValue})`;
172
172
  }
173
173
  } else if (category === "fx") {
174
174
  if (props.meta.global) {
@@ -185,7 +185,7 @@ ${indent}${nextCode}globalFxs.${props.meta.ioProxy.id}(${nextValue})`;
185
185
  config
186
186
  );
187
187
  code += `${indent}/** 调用Fx ${props.meta.title} */
188
- ${indent}${nextCode}this.${currentProvider.name}_Fxs.${props.meta.ioProxy.id}(${nextValue})`;
188
+ ${indent}${nextCode}this.$fxs.${props.meta.ioProxy.id}(${nextValue})`;
189
189
  }
190
190
  }
191
191
  } else {
@@ -265,18 +265,32 @@ var getNextCode = (props, config, isSameScope, event) => {
265
265
  const componentNameWithId = getComponentNameWithId(props, config, event);
266
266
  return `const ${componentNameWithId}_result = `;
267
267
  };
268
+ function getFrameInputValueExpr(meta, config, event) {
269
+ var _a, _b, _c;
270
+ const scene = (_a = config.getCurrentScene) == null ? void 0 : _a.call(config);
271
+ const inputPinId = ((_b = meta == null ? void 0 : meta.inputs) == null ? void 0 : _b[0]) || "getCurValue";
272
+ const proxyKey = `${meta == null ? void 0 : meta.id}-${inputPinId}`;
273
+ const pinProxy = (_c = scene == null ? void 0 : scene.pinValueProxies) == null ? void 0 : _c[proxyKey];
274
+ const pinId = pinProxy == null ? void 0 : pinProxy.pinId;
275
+ if (typeof pinId === "string" && pinId) {
276
+ return `params?.inputValues?.[${JSON.stringify(pinId)}]`;
277
+ }
278
+ }
268
279
  var getNextValue = (props, config, event) => {
269
280
  const { paramSource } = props;
270
281
  const nextValue = paramSource.map((param) => {
271
- var _a, _b, _c;
282
+ var _a, _b, _c, _d, _e;
272
283
  if (param.type === "params") {
273
284
  const params = config.getParams();
274
285
  return params[param.id];
275
286
  } else if (param.type === "constant") {
276
287
  return JSON.stringify(param.value);
277
288
  }
289
+ if (((_b = (_a = param.meta) == null ? void 0 : _a.def) == null ? void 0 : _b.namespace) === "mybricks.core-comlib.frame-input" && param.id === "return") {
290
+ return getFrameInputValueExpr(param.meta, config, event);
291
+ }
278
292
  const componentNameWithId = getComponentNameWithId(param, config, event);
279
- if ((_c = (_b = (_a = param.meta) == null ? void 0 : _a.def) == null ? void 0 : _b.namespace) == null ? void 0 : _c.includes(".var")) {
293
+ if ((_e = (_d = (_c = param.meta) == null ? void 0 : _c.def) == null ? void 0 : _d.namespace) == null ? void 0 : _e.includes(".var")) {
280
294
  return `${componentNameWithId}_result`;
281
295
  }
282
296
  return `${componentNameWithId}_result.${param.id}`;
@@ -284,13 +298,16 @@ var getNextValue = (props, config, event) => {
284
298
  return nextValue.join(", ");
285
299
  };
286
300
  var getNextValueWithParam = (param, config, event) => {
287
- var _a, _b, _c;
301
+ var _a, _b, _c, _d, _e;
288
302
  if (param.type === "params") {
289
303
  const params = config.getParams();
290
304
  return params[param.id];
291
305
  }
306
+ if (((_b = (_a = param.meta) == null ? void 0 : _a.def) == null ? void 0 : _b.namespace) === "mybricks.core-comlib.frame-input" && param.id === "return") {
307
+ return getFrameInputValueExpr(param.meta, config, event);
308
+ }
292
309
  const componentNameWithId = getComponentNameWithId(param, config, event);
293
- if ((_c = (_b = (_a = param.meta) == null ? void 0 : _a.def) == null ? void 0 : _b.namespace) == null ? void 0 : _c.includes(".var")) {
310
+ if ((_e = (_d = (_c = param.meta) == null ? void 0 : _c.def) == null ? void 0 : _d.namespace) == null ? void 0 : _e.includes(".var")) {
294
311
  return `${componentNameWithId}_result`;
295
312
  }
296
313
  return `${componentNameWithId}_result.${param.id}`;
@@ -154,12 +154,7 @@ var convertStyleAryToCss = (styleAry, parentSelector) => {
154
154
  let finalSelector = selector.trim();
155
155
  if (parentSelector) {
156
156
  const prefix2 = `.${parentSelector}`;
157
- if (finalSelector.startsWith(">")) {
158
- const subSelector = finalSelector.substring(1).trim();
159
- finalSelector = `${prefix2} ${subSelector}, ${prefix2}${subSelector}`;
160
- } else {
161
- finalSelector = `${prefix2} ${finalSelector}, ${prefix2}${finalSelector}`;
162
- }
157
+ finalSelector = `${prefix2} ${finalSelector}, ${prefix2}${finalSelector}`;
163
158
  }
164
159
  const transformedCss = {};
165
160
  Object.entries(css).forEach(([key, value]) => {
@@ -25,4 +25,5 @@ export declare const getUiComponentCode: (params: {
25
25
  };
26
26
  depth: number;
27
27
  verbose?: boolean;
28
+ checkIsRoot: () => boolean;
28
29
  }) => string;
@@ -38,6 +38,14 @@ var formatSlotContent = (uiContent, baseIndentSize, renderBodyIndent) => {
38
38
  var toPascalCase = (str) => {
39
39
  return str.split(/[_-]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
40
40
  };
41
+ var formatData = (data, isRoot) => {
42
+ if (!data)
43
+ return {};
44
+ if (!isRoot)
45
+ return data;
46
+ const delKeys = ["tabBar", "navigationStyle", "navigationBarBackgroundColor", "navigationBarTextStyle", "navigationBarTitleText", "backgroundColorTop", "backgroundColorBottom"];
47
+ return Object.fromEntries(Object.entries(data).filter(([key]) => !delKeys.includes(key)));
48
+ };
41
49
  var getUiComponentCode = (params, config) => {
42
50
  const {
43
51
  componentName,
@@ -48,6 +56,7 @@ var getUiComponentCode = (params, config) => {
48
56
  slotsCode,
49
57
  eventHandlers = {}
50
58
  } = params;
59
+ const isRoot = config.checkIsRoot();
51
60
  const indent = (0, import__.indentation)(config.codeStyle.indent * config.depth);
52
61
  const indent2 = (0, import__.indentation)(config.codeStyle.indent * (config.depth + 1));
53
62
  let ui = `${indent}<WithCom`;
@@ -56,7 +65,7 @@ ${indent2}component={${componentName}}`;
56
65
  ui += `
57
66
  ${indent2}id='${meta.id}'`;
58
67
  ui += `
59
- ${indent2}className='${meta.id}'`;
68
+ ${indent2}className='${meta.id} mybricks_com'`;
60
69
  if (meta.name) {
61
70
  ui += `
62
71
  ${indent2}name='${meta.name}'`;
@@ -66,7 +75,7 @@ ${indent2}name='${meta.name}'`;
66
75
  ui += `
67
76
  ${indent2}style={${styleCode}}`;
68
77
  }
69
- const initialDataCode = dataCode ?? JSON.stringify(props.data || {});
78
+ const initialDataCode = dataCode ?? JSON.stringify(formatData(props.data, isRoot));
70
79
  ui += `
71
80
  ${indent2}data={${initialDataCode}}`;
72
81
  Object.entries(eventHandlers).forEach(([eventName, handlerCode]) => {
@@ -74,12 +83,10 @@ ${indent2}data={${initialDataCode}}`;
74
83
  ${indent2}${eventName}={${handlerCode}}`;
75
84
  });
76
85
  if (slotsCode) {
77
- console.log(`[getUiComponentCode] Component ${meta.id} has slotsCode, length: ${slotsCode.length}`);
78
86
  ui += `
79
87
  ${indent2}slots={{
80
88
  ${slotsCode}${indent2}}}`;
81
89
  } else {
82
- console.log(`[getUiComponentCode] Component ${meta.id} has NO slotsCode`);
83
90
  }
84
91
  ui += `
85
92
  ${indent}/>`;
@@ -56,7 +56,9 @@ var RenderManager = class {
56
56
  }
57
57
  code += `${indent}function ${renderFunctionName}(params: any) {
58
58
  `;
59
- code += `${indent}${indent2}const { comRefs, outputs } = useAppContext();
59
+ code += `${indent}${indent2}const { comRefs, $vars, $fxs, appContext } = useAppContext();
60
+ `;
61
+ code += `${indent}${indent2}const outputs = comRefs.current.$outputs;
60
62
  `;
61
63
  if (logicCode) {
62
64
  code += logicCode.split("\n").map((line) => `${indent}${line}`).join("\n") + "\n";
@@ -99,7 +101,7 @@ var RenderManager = class {
99
101
  `;
100
102
  code += `${indent}${indent4}get inputs() { return comRefs.current['${child.id}'] },
101
103
  `;
102
- code += `${indent}${indent4}get outputs() { return outputs.current['${child.id}'] },
104
+ code += `${indent}${indent4}get outputs() { return outputs['${child.id}'] },
103
105
  `;
104
106
  code += `${indent}${indent4}jsx: ${varName},
105
107
  `;
@@ -7,7 +7,8 @@ export declare const genSlotDefineCode: (indent: string) => string;
7
7
  /** 生成控制器初始化代码 */
8
8
  export declare const genControllerInitCode: (indent: string, providerName: string) => string;
9
9
  /** 生成完整的函数组件模板 */
10
- export declare const genComponentTemplate: ({ componentName, combinedJsCode, renderDefinitions, uiResult, outputsConfig, scopeName, utilsPackageName, isPopup, hasPopups, }: {
10
+ export declare const genComponentTemplate: ({ componentId, componentName, combinedJsCode, renderDefinitions, uiResult, outputsConfig, scopeName, utilsPackageName, isPopup, hasPopups, }: {
11
+ componentId: string;
11
12
  componentName: string;
12
13
  combinedJsCode: string;
13
14
  renderDefinitions?: string;
@@ -31,7 +31,7 @@ var genReactiveDataManager = (indent, utilsPackageName) => {
31
31
  return ``;
32
32
  };
33
33
  var genRootDefineCode = (indent, utilsPackageName, hasJsModules = false) => {
34
- let code = `${indent}const {comRefs, appContext} = useAppContext();
34
+ let code = `${indent}const {comRefs, $vars, $fxs, appContext} = useAppContext();
35
35
  `;
36
36
  if (hasJsModules) {
37
37
  code += `${indent}const comModules = jsModules({ createJSHandle });
@@ -40,7 +40,7 @@ var genRootDefineCode = (indent, utilsPackageName, hasJsModules = false) => {
40
40
  return code;
41
41
  };
42
42
  var genSlotDefineCode = (indent) => {
43
- return `${indent}const {comRefs, appContext} = useAppContext();
43
+ return `${indent}const {comRefs, $vars, $fxs, appContext} = useAppContext();
44
44
  `;
45
45
  };
46
46
  var genControllerInitCode = (indent, providerName) => {
@@ -48,6 +48,7 @@ var genControllerInitCode = (indent, providerName) => {
48
48
  `;
49
49
  };
50
50
  var genComponentTemplate = ({
51
+ componentId,
51
52
  componentName,
52
53
  combinedJsCode,
53
54
  renderDefinitions = "",
@@ -76,7 +77,7 @@ ${uiResult.split("\n").map((line) => ` ${line}`).join("\n")}
76
77
 
77
78
  `;
78
79
  }
79
- code += `export default WithWrapper(${componentName})`;
80
+ code += `export default WithWrapper("${componentId}", ${componentName})`;
80
81
  return code;
81
82
  };
82
83
  var wrapInEffect = (indent, effectCode) => {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstractEventTypeDef.d.ts","sourceRoot":"","sources":["abstractEventTypeDef.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,KAAK,uBAAuB,GAAG,MAAM,CACnC,MAAM,EACN;IACE,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB,OAAO,EAAE;QACP,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC7B,CAAC;CACH,CACF,CAAC;AAEF,QAAA,MAAM,oBAAoB,4BACC,uBAAuB,UACxC,gBAAgB,WA6EzB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}