@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
@@ -0,0 +1,56 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/core/utils/tabbar.ts
20
+ var tabbar_exports = {};
21
+ __export(tabbar_exports, {
22
+ tabbarIns: () => tabbarIns
23
+ });
24
+ module.exports = __toCommonJS(tabbar_exports);
25
+ var import_event = require("./event");
26
+ var isDefine = (val) => val !== void 0 && val !== null && val !== "";
27
+ var TabbarInstance = class {
28
+ constructor() {
29
+ this.list = [];
30
+ this.eventEmitter = new import_event.EventEmitter();
31
+ this.setTabBarBadge = ({ index, text }) => new Promise((resolve, reject) => {
32
+ if (isDefine(index)) {
33
+ this.list[index].active = true;
34
+ this.list[index].activeText = text;
35
+ console.log("change", this.list);
36
+ this.eventEmitter.dispatch("change", this.list);
37
+ }
38
+ });
39
+ this.hideTabBarRedDot = ({ index }) => new Promise((resolve, reject) => {
40
+ if (isDefine(index)) {
41
+ this.list[index].active = false;
42
+ this.list[index].activeText = 0;
43
+ this.eventEmitter.dispatch("change", this.list);
44
+ }
45
+ });
46
+ this.removeTabBarBadge = this.hideTabBarRedDot;
47
+ this.initWithLength = (len) => {
48
+ this.list = new Array(len).fill((t) => null).map(() => ({ active: false, activeText: "" }));
49
+ };
50
+ }
51
+ };
52
+ var tabbarIns = new TabbarInstance();
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ tabbarIns
56
+ });
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/core/utils/useContext.ts
@@ -23,9 +33,12 @@ __export(useContext_exports, {
23
33
  });
24
34
  module.exports = __toCommonJS(useContext_exports);
25
35
  var import_react = require("react");
36
+ var Taro = __toESM(require("@tarojs/taro"));
37
+ var import_request = require("@/common/request");
38
+ var import_tabbar = require("@/core/utils/tabbar");
39
+ var import_rootConfig = __toESM(require("@/common/rootConfig"));
26
40
  var import_hooks = require("./hooks");
27
41
  var import_pool = require("./pool");
28
- var import_request = require("@/common/request");
29
42
  function useAppCreateContext(id) {
30
43
  const todoPool = (0, import_react.useMemo)(() => new import_pool.TodoPool(), []);
31
44
  const comRefs = (0, import_react.useRef)((0, import_hooks.proxyRefs)({ $inputs: {}, $outputs: {} }, void 0, todoPool));
@@ -41,10 +54,37 @@ function useAppCreateContext(id) {
41
54
  canvas: {
42
55
  id
43
56
  },
57
+ runtime: {
58
+ debug: false
59
+ },
44
60
  env: {
45
61
  runtime: true,
46
- request: (connector, params, config) => (0, import_request.request)(connector, params, config, { $vars })
62
+ request: (connector, params, config) => (0, import_request.request)(connector, params, config, { $vars }),
63
+ tabbar: import_tabbar.tabbarIns,
64
+ uploadFile: (params) => {
65
+ var _a, _b, _c, _d;
66
+ let header = {};
67
+ let mybricksGlobalHeaders = Taro.getStorageSync(
68
+ "_MYBRICKS_GLOBAL_HEADERS_"
69
+ );
70
+ if (mybricksGlobalHeaders) {
71
+ header = {
72
+ ...mybricksGlobalHeaders,
73
+ ...header
74
+ };
75
+ }
76
+ if (!/^(http|https):\/\/.*/.test(params.url) && ((_b = (_a = import_rootConfig.default) == null ? void 0 : _a.status) == null ? void 0 : _b.defaultCallServiceHost)) {
77
+ params.url = `${(_d = (_c = import_rootConfig.default) == null ? void 0 : _c.status) == null ? void 0 : _d.defaultCallServiceHost}${params.url}`;
78
+ }
79
+ const { success, fail, ...rest } = params;
80
+ Taro.uploadFile({
81
+ ...rest,
82
+ success: (res) => success == null ? void 0 : success(res),
83
+ fail: (err) => fail == null ? void 0 : fail(err)
84
+ });
85
+ }
47
86
  },
87
+ rootScroll: {},
48
88
  edit: false,
49
89
  isH5: false,
50
90
  isDesigner: false,
@@ -41,7 +41,7 @@ var import_ComContext = __toESM(require("./ComContext"));
41
41
  var import_slots = require("./slots");
42
42
  var import_taro = require("@tarojs/taro");
43
43
  var WithCom = (props) => {
44
- var _a, _b;
44
+ var _a;
45
45
  const { component: Component, id = "", data, className, style, ...rest } = props;
46
46
  const { comRefs, appContext } = (0, import_ComContext.useAppContext)();
47
47
  const env = appContext;
@@ -49,47 +49,22 @@ var WithCom = (props) => {
49
49
  const [show, setShow] = (0, import_react.useState)(true);
50
50
  const [dynamicStyle, setDynamicStyle] = (0, import_react.useState)({});
51
51
  const _data = (0, import_index.useModel)(data || {});
52
- const handlers = {
53
- _setStyle: (style2) => {
54
- setDynamicStyle((prev) => ({ ...prev, ...style2 }));
55
- },
56
- _setData: (path, value) => {
57
- const paths = path.split(".");
58
- let current = _data;
59
- for (let i = 0; i < paths.length - 1; i++) {
60
- if (!current[paths[i]])
61
- current[paths[i]] = {};
62
- current = current[paths[i]];
63
- }
64
- current[paths[paths.length - 1]] = value;
65
- }
66
- };
67
- if (!isPopup) {
68
- Object.assign(handlers, {
69
- show: () => setShow(true),
70
- hide: () => setShow(false),
71
- showOrHide: () => setShow((prev) => !prev)
72
- });
73
- }
74
- const inputProxy = (0, import_index.useBindInputs)(comRefs, id, handlers);
75
52
  const { slots: rawSlots, parentSlot: parentSlotProp, ...restProps } = rest;
76
53
  const parentSlot = (0, import_slots.useResolvedParentSlot)(parentSlotProp);
77
- const eventProxy = (0, import_index.useBindEvents)(restProps, {
54
+ const enhancedSlots = (0, import_slots.useEnhancedSlots)(rawSlots, id);
55
+ const handlers = (0, import_index.useBuiltinHandlers)({ data: _data, setDynamicStyle, setShow, isPopup });
56
+ const inputProxy = (0, import_index.useBindInputs)(comRefs, id, handlers);
57
+ const outputProxy = (0, import_index.useBindOutputs)(comRefs, id, restProps, enhancedSlots, {
78
58
  id,
79
59
  name: props.name || id,
80
60
  parentSlot
81
61
  });
82
- if ((_a = comRefs == null ? void 0 : comRefs.current) == null ? void 0 : _a.$outputs) {
83
- comRefs.current.$outputs[id] = eventProxy;
84
- }
85
- comRefs.current[id] = inputProxy;
86
- const enhancedSlots = (0, import_slots.useEnhancedSlots)(rawSlots, id);
87
62
  const jsx = /* @__PURE__ */ import_react.default.createElement(
88
63
  Component,
89
64
  {
90
65
  ...restProps,
91
66
  inputs: inputProxy,
92
- outputs: eventProxy,
67
+ outputs: outputProxy,
93
68
  slots: enhancedSlots,
94
69
  parentSlot,
95
70
  data: _data,
@@ -98,18 +73,18 @@ var WithCom = (props) => {
98
73
  style
99
74
  }
100
75
  );
101
- if ((_b = parentSlot == null ? void 0 : parentSlot.params) == null ? void 0 : _b.itemWrap) {
76
+ if ((_a = parentSlot == null ? void 0 : parentSlot.params) == null ? void 0 : _a.itemWrap) {
102
77
  return parentSlot.params.itemWrap({
103
78
  id,
104
79
  name: props.name || id,
105
80
  jsx,
106
81
  def: Component.def,
107
82
  inputs: inputProxy,
108
- outputs: eventProxy,
83
+ outputs: outputProxy,
109
84
  style
110
85
  });
111
86
  }
112
- return show || isPopup ? /* @__PURE__ */ import_react.default.createElement(import_components.View, { className, style: { ...style, ...dynamicStyle } }, jsx, props.children) : null;
87
+ return show || isPopup ? /* @__PURE__ */ import_react.default.createElement(import_components.View, { id, className, style: { ...style, ...dynamicStyle } }, jsx, props.children) : null;
113
88
  };
114
89
  var WithWrapper = (id, Component) => {
115
90
  return function WrappedComponent(props) {
@@ -39,9 +39,10 @@ var import_commonDir = require("./utils/commonDir");
39
39
  var import_tabBarImages = require("./utils/tabBarImages");
40
40
  var import_pageImages = require("./utils/pageImages");
41
41
  var import_appConfig = require("./utils/appConfig");
42
+ var import_customTabBar = require("./utils/customTabBar");
42
43
  var import_genJSModules = require("../utils/logic/genJSModules");
43
44
  var generateTaroProjectJson = (result) => {
44
- var _a, _b;
45
+ var _a;
45
46
  const { files = [], assets = {} } = result;
46
47
  const templateJsonPath = path.join(__dirname, "../taro-template.json");
47
48
  if (!fs.existsSync(templateJsonPath)) {
@@ -146,23 +147,7 @@ ${item.content || ""}`;
146
147
  }
147
148
  (0, import_tabBarImages.handleTabBarImages)(tabbarDir, imageFiles);
148
149
  (0, import_pageImages.handlePageImages)(assetsDir, pageImages);
149
- const CUSTOM_TAB_BAR_CONFIG_PATH = "src/custom-tab-bar/mybricks/tabbar-config.ts";
150
- const customTabBarItem = files.find((item) => item.type === "customTabBar");
151
- if (customTabBarItem == null ? void 0 : customTabBarItem.content) {
152
- const customTabBarDir = (0, import_fileNode.ensureDir)(srcDir, "src/custom-tab-bar");
153
- const mybricksDir = (0, import_fileNode.ensureDir)(customTabBarDir, "src/custom-tab-bar/mybricks");
154
- const tabbarConfigFileIndex = (_b = mybricksDir.children) == null ? void 0 : _b.findIndex(
155
- (node) => 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
- }
150
+ (0, import_customTabBar.updateCustomTabBar)(srcDir, files);
166
151
  (0, import_commonDir.handleCommonDir)(commonDir, files);
167
152
  const apiItem = files.find((item) => item.type === "connector-api");
168
153
  if (apiItem) {
@@ -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
  }
@@ -22,24 +22,34 @@ __export(appConfig_exports, {
22
22
  updateAppConfig: () => updateAppConfig
23
23
  });
24
24
  module.exports = __toCommonJS(appConfig_exports);
25
+ var import_fileNode = require("./fileNode");
25
26
  function updateAppConfig(appConfigFile, normalItems, items) {
27
+ var _a;
26
28
  if (!appConfigFile.content) {
27
29
  return;
28
30
  }
29
- let content = appConfigFile.content;
30
- const newPagePaths = normalItems.map((item) => ` 'pages/${item.meta.id}/index'`).join(",\n");
31
- content = content.replace(/pages:\s*\[([\s\S]*?)\]/, `pages: [
32
- ${newPagePaths}
33
- ]`);
31
+ const content = (0, import_fileNode.parseLooseObject)(((_a = appConfigFile.content.match(/defineAppConfig\(([\s\S]*?)\)/)) == null ? void 0 : _a[1]) || "{}");
32
+ const newPagePaths = normalItems.map((item) => `pages/${item.meta.id}/index`);
33
+ content.pages = newPagePaths;
34
+ let entryPagePath = "";
35
+ normalItems.forEach((item) => {
36
+ var _a2, _b;
37
+ (_b = Object.values((_a2 = item.meta) == null ? void 0 : _a2.coms)) == null ? void 0 : _b.forEach((com) => {
38
+ var _a3, _b2;
39
+ if ((com == null ? void 0 : com.asRoot) && ((_b2 = (_a3 = com == null ? void 0 : com.model) == null ? void 0 : _a3.data) == null ? void 0 : _b2.isEntryPagePath)) {
40
+ entryPagePath = `pages/${item.meta.id}/index`;
41
+ }
42
+ });
43
+ });
44
+ if (entryPagePath) {
45
+ content.entryPagePath = entryPagePath;
46
+ }
34
47
  const tabBarConfigItem = items.find((item) => item.type === "tabBarConfig");
35
- if (tabBarConfigItem == null ? void 0 : tabBarConfigItem.tabBarConfig) {
36
- content = content.replace(
37
- /window:\s*\{([\s\S]*?)\n\s*\}/,
38
- (match) => `${match},
39
- ${tabBarConfigItem.tabBarConfig}`
40
- );
48
+ if (tabBarConfigItem == null ? void 0 : tabBarConfigItem.content) {
49
+ const tabBar = (0, import_fileNode.parseLooseObject)(`{${tabBarConfigItem.content}}`);
50
+ Object.assign(content, tabBar);
41
51
  }
42
- appConfigFile.content = content;
52
+ appConfigFile.content = `export default defineAppConfig(${JSON.stringify(content, null, 2)})`;
43
53
  }
44
54
  // Annotate the CommonJS export names for ESM import in node:
45
55
  0 && (module.exports = {
@@ -47,6 +47,15 @@ ${fileContent}` : fileContent;
47
47
  content: fullContent
48
48
  });
49
49
  }
50
+ const rootConfigItem = items.find((item) => item.type === "rootConfig");
51
+ if (rootConfigItem) {
52
+ const fileContent = rootConfigItem.content || "{}";
53
+ const fullContent = `export default ${fileContent}`;
54
+ commonDir.children.push({
55
+ path: "src/common/rootConfig.ts",
56
+ content: fullContent
57
+ });
58
+ }
50
59
  }
51
60
  // Annotate the CommonJS export names for ESM import in node:
52
61
  0 && (module.exports = {
@@ -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,73 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/generate/utils/customTabBar.ts
20
+ var customTabBar_exports = {};
21
+ __export(customTabBar_exports, {
22
+ updateCustomTabBar: () => updateCustomTabBar
23
+ });
24
+ module.exports = __toCommonJS(customTabBar_exports);
25
+ var import_fileNode = require("./fileNode");
26
+ var import_fileNode2 = require("./fileNode");
27
+ function updateCustomTabBar(srcDir, files) {
28
+ var _a, _b;
29
+ const customTabBarDir = (0, import_fileNode.ensureDir)(srcDir, "src/custom-tab-bar");
30
+ const customTabBarItem = files.find((item) => item.type === "customTabBar");
31
+ if (customTabBarItem == null ? void 0 : customTabBarItem.content) {
32
+ const CUSTOM_TAB_BAR_CONFIG_PATH = "src/custom-tab-bar/mybricks/tabbar-config.ts";
33
+ const mybricksDir = (0, import_fileNode.ensureDir)(
34
+ customTabBarDir,
35
+ "src/custom-tab-bar/mybricks"
36
+ );
37
+ const tabbarConfigFileIndex = (_a = mybricksDir.children) == null ? void 0 : _a.findIndex(
38
+ (node) => node.path === CUSTOM_TAB_BAR_CONFIG_PATH
39
+ );
40
+ if (tabbarConfigFileIndex === -1) {
41
+ mybricksDir.children.push({
42
+ path: CUSTOM_TAB_BAR_CONFIG_PATH,
43
+ content: customTabBarItem.content
44
+ });
45
+ } else {
46
+ mybricksDir.children[tabbarConfigFileIndex].content = customTabBarItem.content;
47
+ }
48
+ }
49
+ const tabBarConfigItem = files.find((item) => item.type === "tabBarConfig");
50
+ if (tabBarConfigItem == null ? void 0 : tabBarConfigItem.content) {
51
+ const contentStr = JSON.stringify(
52
+ (0, import_fileNode2.parseLooseObject)(`{${tabBarConfigItem.content}}`),
53
+ null,
54
+ 2
55
+ );
56
+ const tabBarJsonPath = `${customTabBarDir.path}/tabBar.json`;
57
+ const tabBarJsonIndex = (_b = customTabBarDir.children) == null ? void 0 : _b.findIndex(
58
+ (node) => node.path === tabBarJsonPath
59
+ );
60
+ if (tabBarJsonIndex === -1) {
61
+ customTabBarDir.children.push({
62
+ path: tabBarJsonPath,
63
+ content: contentStr
64
+ });
65
+ } else {
66
+ customTabBarDir.children[tabBarJsonIndex].content = contentStr;
67
+ }
68
+ }
69
+ }
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ updateCustomTabBar
73
+ });
@@ -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 {};
@@ -20,9 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var fileNode_exports = {};
21
21
  __export(fileNode_exports, {
22
22
  ensureDir: () => ensureDir,
23
- findDir: () => findDir
23
+ findDir: () => findDir,
24
+ parseLooseObject: () => parseLooseObject
24
25
  });
25
26
  module.exports = __toCommonJS(fileNode_exports);
27
+ var import_node_vm = require("node:vm");
26
28
  function findDir(nodes, targetPath) {
27
29
  for (const node of nodes) {
28
30
  if (node.path === targetPath) {
@@ -50,8 +52,16 @@ function ensureDir(parentDir, dirPath) {
50
52
  dir.children = dir.children || [];
51
53
  return dir;
52
54
  }
55
+ function parseLooseObject(raw) {
56
+ try {
57
+ return JSON.parse(raw);
58
+ } catch {
59
+ return (0, import_node_vm.runInNewContext)(`(${raw})`, /* @__PURE__ */ Object.create(null));
60
+ }
61
+ }
53
62
  // Annotate the CommonJS export names for ESM import in node:
54
63
  0 && (module.exports = {
55
64
  ensureDir,
56
- findDir
65
+ findDir,
66
+ parseLooseObject
57
67
  });
@@ -42,8 +42,9 @@ var import_handleDom = __toESM(require("./handleDom"));
42
42
  var import_processComEvents = require("./processors/processComEvents");
43
43
  var import_handleProcess = require("./utils/logic/handleProcess");
44
44
  var COM_PROTOCOL = {
45
- "mybricks.taro.formContainer": { useWrap: true },
46
- "mybricks.taro.formAdditionContainer": { useWrap: true }
45
+ "mybricks.taro.formContainer": { useWrap: true }
46
+ // 移除 FormAdditionContainer 的配置,因为它的 runtime 没有传递 wrap 函数
47
+ // "mybricks.taro.formAdditionContainer": { useWrap: true },
47
48
  };
48
49
  var handleCom = (com, config) => {
49
50
  const { meta, props } = com;
@@ -110,14 +111,10 @@ var prepareComponent = (com, config) => {
110
111
  };
111
112
  };
112
113
  var prepareStyles = (com) => {
113
- var _a, _b, _c;
114
+ var _a;
114
115
  const { meta, props } = com;
115
- const styleWithLayout = {
116
- ...props.style || {},
117
- layout: ((_a = props.data) == null ? void 0 : _a.layout) || ((_b = props.style) == null ? void 0 : _b.layout)
118
- };
119
- const resultStyle = (0, import_converter.convertComponentStyle)(styleWithLayout);
120
- const cssContent = (0, import_converter.convertStyleAryToCss)((_c = props.style) == null ? void 0 : _c.styleAry, meta.id);
116
+ const resultStyle = (0, import_converter.convertComponentStyle)(props.style || {});
117
+ const cssContent = (0, import_converter.convertStyleAryToCss)((_a = props.style) == null ? void 0 : _a.styleAry, meta.id);
121
118
  return { cssContent, rootStyle: resultStyle.root || {} };
122
119
  };
123
120
  var processComSlots = (com, config, initialCss) => {
@@ -131,18 +128,20 @@ var processComSlots = (com, config, initialCss) => {
131
128
  const renderManager = config.renderManager || new import_renderManager.RenderManager();
132
129
  const slotEntries = Object.entries(slots);
133
130
  slotEntries.forEach(([slotId, slot], index) => {
134
- var _a, _b, _c, _d;
131
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
135
132
  const children = slot.comAry || slot.children || [];
136
133
  const isLast = index === slotEntries.length - 1;
137
134
  const slotIndent = (0, import_templates.indentation)(config.codeStyle.indent * (config.depth + 2));
138
- if (children.length === 0) {
135
+ const effectEvent = (_a = config.getEffectEvent) == null ? void 0 : _a.call(config, { comId: meta.id, slotId });
136
+ const hasSlotLogic = effectEvent && (((_c = (_b = effectEvent.process) == null ? void 0 : _b.nodesDeclaration) == null ? void 0 : _c.length) > 0 || ((_e = (_d = effectEvent.process) == null ? void 0 : _d.nodesInvocation) == null ? void 0 : _e.length) > 0);
137
+ if (children.length === 0 && !hasSlotLogic) {
139
138
  slotsCode += `${slotIndent}${slotId}: {
140
139
  ${slotIndent} render: () => null
141
140
  ${slotIndent}}${isLast ? "" : ","}
142
141
  `;
143
142
  return;
144
143
  }
145
- const slotLayout = (_a = com.props.data) == null ? void 0 : _a.layout;
144
+ const slotLayout = (_f = com.props.data) == null ? void 0 : _f.layout;
146
145
  const result = (0, import_handleSlot.default)(slot, {
147
146
  ...config,
148
147
  checkIsRoot: () => false,
@@ -160,8 +159,8 @@ ${slotIndent}}${isLast ? "" : ","}
160
159
  }
161
160
  const renderId = `${meta.id}_${slotId}`;
162
161
  const rawContent = result.ui;
163
- if (meta.def.namespace === "mybricks.taro.formContainer" && Array.isArray((_b = props.data) == null ? void 0 : _b.items) && result.directChildren) {
164
- const items = (_c = props.data) == null ? void 0 : _c.items;
162
+ if (meta.def.namespace === "mybricks.taro.formContainer" && Array.isArray((_g = props.data) == null ? void 0 : _g.items) && result.directChildren) {
163
+ const items = (_h = props.data) == null ? void 0 : _h.items;
165
164
  result.directChildren.forEach((childRes) => {
166
165
  const itemConfig = items.find((it) => it.id === childRes.id);
167
166
  if (itemConfig == null ? void 0 : itemConfig.comName) {
@@ -183,7 +182,7 @@ ${slotIndent}}${isLast ? "" : ","}
183
182
  // 仅传入直接子组件,避免递归替换导致的结构破坏
184
183
  logicCode,
185
184
  slot.type,
186
- slot.wrap || slot.itemWrap || ((_d = COM_PROTOCOL[meta.def.namespace]) == null ? void 0 : _d.useWrap),
185
+ slot.wrap || slot.itemWrap || ((_i = COM_PROTOCOL[meta.def.namespace]) == null ? void 0 : _i.useWrap),
187
186
  description
188
187
  );
189
188
  if (result.childrenResults) {
@@ -219,7 +218,7 @@ var buildSlotLogicCode = (args) => {
219
218
  addParentDependencyImport: config.addParentDependencyImport,
220
219
  addConsumer: config.addConsumer,
221
220
  getParams: () => paramsProxy
222
- }).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.");
221
+ }).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.");
223
222
  if (!process.trim())
224
223
  return "";
225
224
  let code = `${indent}useEffect(() => {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 处理全局变量和全局Fx
2
+ * 处理全局变量、全局Fx、其他全局配置
3
3
  */
4
4
  import type { ToTaroCodeConfig, GeneratedFile } from "./toCodeTaro";
5
5
  interface HandleGlobalParams {
@@ -162,6 +162,12 @@ export const globalFxs = new GlobalFxs()`;
162
162
  });
163
163
  }
164
164
  return [
165
+ {
166
+ type: "rootConfig",
167
+ content: JSON.stringify(tojson.rootConfig, null, 2),
168
+ importManager: null,
169
+ name: "rootConfig"
170
+ },
165
171
  {
166
172
  type: "global",
167
173
  content: varCode + "\n\n" + fxCode,
@@ -108,16 +108,17 @@ var generateSlotUi = (ui, props, childrenUi, childrenResults, config) => {
108
108
  const slotStyle = ui.style || {};
109
109
  const propsStyle = props.style || {};
110
110
  const mergedStyle = { width: "100%", height: "100%", ...slotStyle, ...propsStyle };
111
- const layout = config.layout || ui.layout || mergedStyle.layout;
111
+ const layout = ui.layout || mergedStyle.layout;
112
112
  const smart = isSmartLayout(layout);
113
- const layoutAdjustment = smart ? { position: isHasInSmartLayout(childrenResults) ? "fixed" : "relative" } : hasFixedChildren(childrenResults) ? { transform: "translateX(0)" } : {};
113
+ const layoutAdjustment = smart ? { position: "relative" } : hasFixedChildren(childrenResults) ? { transform: "translateX(0)" } : {};
114
114
  const styleCode = JSON.stringify((0, import_utils.convertRootStyle)({ ...mergedStyle, layout, ...layoutAdjustment }));
115
115
  const rootClassName = (0, import_utils.getRootComponentClassName)(config.getCurrentScene(), config.checkIsRoot());
116
116
  const parentComId = config == null ? void 0 : config.parentComId;
117
- const slotMarkClass = parentComId ? `slot-${parentComId}` : "";
117
+ const slotMarkClass = parentComId ? `mybricks_slot slot-${parentComId}` : "";
118
118
  const classNameStr = [rootClassName, slotMarkClass].filter(Boolean).join(" ");
119
119
  const classNameAttr = classNameStr ? ` className='${classNameStr}'` : "";
120
- return `${indent}<View${classNameAttr} style={${styleCode}}>
120
+ const styleAttr = slotMarkClass ? `style={{...params.style || {}, ...${styleCode}}}` : `style={${styleCode}}`;
121
+ return `${indent}<View${classNameAttr} ${styleAttr}>
121
122
  ${childrenUi}
122
123
  ${indent}</View>`;
123
124
  };
@@ -146,10 +147,4 @@ var hasFixedChildren = (childrenResults) => {
146
147
  var isSmartLayout = (layout) => {
147
148
  return layout === "smart" || (layout == null ? void 0 : layout.position) === "smart";
148
149
  };
149
- var isHasInSmartLayout = (childrenResults) => {
150
- return childrenResults.some((item) => {
151
- var _a;
152
- return ((_a = item == null ? void 0 : item.rootStyle) == null ? void 0 : _a.inSmartLayout) === true;
153
- });
154
- };
155
150
  var handleSlot_default = handleSlot;
@@ -38,6 +38,17 @@ var import_renderManager = require("../utils/templates/renderManager");
38
38
  var import_createProvider = require("../utils/context/createProvider");
39
39
  var import_createEventQueries = require("../utils/context/createEventQueries");
40
40
  var import_collectJSModules = require("../utils/context/collectJSModules");
41
+ var getCallMethodName = (com, pinId, isTargetPopup) => {
42
+ var _a, _b;
43
+ if (pinId !== "open" || isTargetPopup)
44
+ return pinId;
45
+ const OPEN_TYPE_MAP = {
46
+ "blank": "open",
47
+ "redirect": "replace"
48
+ };
49
+ const openType = (_b = (_a = com == null ? void 0 : com.model) == null ? void 0 : _a.data) == null ? void 0 : _b.openType;
50
+ return OPEN_TYPE_MAP[openType] || openType || pinId;
51
+ };
41
52
  var processScene = (params) => {
42
53
  var _a, _b, _c;
43
54
  const {
@@ -112,9 +123,10 @@ var processScene = (params) => {
112
123
  const routerName = isTargetPopup ? "popupRouter" : "pageRouter";
113
124
  const isInput = (_b2 = targetScene == null ? void 0 : targetScene.inputs) == null ? void 0 : _b2.some((pin) => pin.id === pinId);
114
125
  const isOutput = (_c2 = targetScene == null ? void 0 : targetScene.outputs) == null ? void 0 : _c2.some((pin) => pin.id === pinId);
126
+ const callMethodName = getCallMethodName(com, pinId, isTargetPopup);
115
127
  if (isInput || isOutput) {
116
128
  return {
117
- code: `${routerName}.${pinId}("${((_d = config.getPageId) == null ? void 0 : _d.call(config, sceneId)) || sceneId}"${args ? `, ${args}` : ""})`,
129
+ code: `${routerName}.${callMethodName}("${((_d = config.getPageId) == null ? void 0 : _d.call(config, sceneId)) || sceneId}"${args ? `, ${args}` : ""})`,
118
130
  import: {
119
131
  packageName: config.getComponentPackageName(),
120
132
  dependencyNames: [routerName],
@@ -53,7 +53,7 @@ var processVarEvents = (currentScene, config, addDependencyImport, indent) => {
53
53
  const importParams = { isPopup: config.isPopup };
54
54
  addDependencyImport({
55
55
  packageName: config.getUtilsPackageName(importParams),
56
- dependencyNames: ["SUBJECT_SUBSCRIBE", "SUBJECT_VALUE"],
56
+ dependencyNames: ["SUBJECT_SUBSCRIBE"],
57
57
  importType: "named"
58
58
  });
59
59
  varEvents.forEach((varEvent) => {
@@ -85,10 +85,6 @@ ${process}
85
85
  ${indent} };`;
86
86
  code += `
87
87
  ${indent} $vars.current.${varName}.${pinId}?.()[SUBJECT_SUBSCRIBE](run_${varName}_${pinId});`;
88
- code += `
89
- ${indent} const init_${varName}_${pinId} = $vars.current.${varName}.get?.();`;
90
- code += `
91
- ${indent} run_${varName}_${pinId}(init_${varName}_${pinId}?.[SUBJECT_VALUE]);`;
92
88
  });
93
89
  return code;
94
90
  };
@@ -217,7 +213,7 @@ ${indent} };`;
217
213
  });
218
214
  code += `
219
215
  ${indent} ${controllerName}.getParams("${currentScene.id}")[SUBJECT_SUBSCRIBE]((val: any) => {
220
- ${indent} if (val) inputs.open(val);
216
+ ${indent} inputs.open(val);
221
217
  ${indent} });`;
222
218
  }
223
219
  }