@mybricks/to-code-taro 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/dist/cjs/core/mybricks/Subject.js +9 -5
  2. package/dist/cjs/core/mybricks/createJSHandle.js +45 -4
  3. package/dist/cjs/core/utils/comRefResolver.js +112 -0
  4. package/dist/cjs/core/utils/event.js +53 -0
  5. package/dist/cjs/core/utils/hooks.js +76 -39
  6. package/dist/cjs/core/utils/index.js +6 -0
  7. package/dist/cjs/core/utils/pageRouter.js +34 -11
  8. package/dist/cjs/core/utils/pool.js +63 -0
  9. package/dist/cjs/core/utils/slots.js +59 -13
  10. package/dist/cjs/core/utils/tabbar.js +56 -0
  11. package/dist/cjs/core/utils/useContext.js +46 -4
  12. package/dist/cjs/core/utils/with.js +9 -34
  13. package/dist/cjs/generate/generateTaroProjectJson.js +11 -18
  14. package/dist/cjs/generate/utils/appConfig.d.ts +1 -1
  15. package/dist/cjs/generate/utils/appConfig.js +23 -12
  16. package/dist/cjs/generate/utils/commonDir.js +9 -0
  17. package/dist/cjs/generate/utils/customTabBar.d.ts +11 -0
  18. package/dist/cjs/generate/utils/customTabBar.js +73 -0
  19. package/dist/cjs/generate/utils/fileNode.d.ts +4 -0
  20. package/dist/cjs/generate/utils/fileNode.js +12 -2
  21. package/dist/cjs/handleCom.js +15 -16
  22. package/dist/cjs/handleGlobal.d.ts +1 -1
  23. package/dist/cjs/handleGlobal.js +6 -0
  24. package/dist/cjs/handleSlot.js +4 -9
  25. package/dist/cjs/processors/processScene.js +13 -1
  26. package/dist/cjs/processors/processSceneLogic.js +2 -6
  27. package/dist/cjs/taro-template.json +1318 -1016
  28. package/dist/cjs/toCodeTaro.d.ts +1 -2
  29. package/dist/cjs/toCodeTaro.js +2 -0
  30. package/dist/cjs/utils/builder/buildResult.d.ts +1 -0
  31. package/dist/cjs/utils/builder/buildResult.js +54 -2
  32. package/dist/cjs/utils/common/ImportManager.d.ts +7 -0
  33. package/dist/cjs/utils/common/ImportManager.js +19 -1
  34. package/dist/cjs/utils/context/buildContext.d.ts +7 -0
  35. package/dist/cjs/utils/context/buildContext.js +11 -0
  36. package/dist/cjs/utils/logic/genJSModules.js +2 -2
  37. package/dist/cjs/utils/logic/handleProcess.js +54 -12
  38. package/dist/cjs/utils/templates/renderManager.js +4 -2
  39. package/dist/esm/core/mybricks/Subject.js +11 -5
  40. package/dist/esm/core/mybricks/createJSHandle.js +57 -6
  41. package/dist/esm/core/utils/comRefResolver.js +134 -0
  42. package/dist/esm/core/utils/event.js +32 -0
  43. package/dist/esm/core/utils/hooks.js +114 -51
  44. package/dist/esm/core/utils/index.js +2 -0
  45. package/dist/esm/core/utils/pageRouter.js +56 -13
  46. package/dist/esm/core/utils/pool.js +52 -0
  47. package/dist/esm/core/utils/slots.js +82 -16
  48. package/dist/esm/core/utils/tabbar.js +47 -0
  49. package/dist/esm/core/utils/useContext.js +53 -4
  50. package/dist/esm/core/utils/with.js +19 -53
  51. package/dist/esm/generate/generateTaroProjectJson.js +14 -20
  52. package/dist/esm/generate/utils/appConfig.d.ts +1 -1
  53. package/dist/esm/generate/utils/appConfig.js +29 -9
  54. package/dist/esm/generate/utils/commonDir.js +13 -0
  55. package/dist/esm/generate/utils/customTabBar.d.ts +11 -0
  56. package/dist/esm/generate/utils/customTabBar.js +52 -0
  57. package/dist/esm/generate/utils/fileNode.d.ts +4 -0
  58. package/dist/esm/generate/utils/fileNode.js +13 -0
  59. package/dist/esm/handleCom.js +24 -21
  60. package/dist/esm/handleGlobal.d.ts +1 -1
  61. package/dist/esm/handleGlobal.js +6 -1
  62. package/dist/esm/handleSlot.js +6 -11
  63. package/dist/esm/processors/processScene.js +23 -3
  64. package/dist/esm/processors/processSceneLogic.js +3 -5
  65. package/dist/esm/taro-template.json +1318 -1016
  66. package/dist/esm/toCodeTaro.d.ts +1 -2
  67. package/dist/esm/toCodeTaro.js +4 -2
  68. package/dist/esm/utils/builder/buildResult.d.ts +1 -0
  69. package/dist/esm/utils/builder/buildResult.js +42 -3
  70. package/dist/esm/utils/common/ImportManager.d.ts +7 -0
  71. package/dist/esm/utils/common/ImportManager.js +42 -14
  72. package/dist/esm/utils/context/buildContext.d.ts +7 -0
  73. package/dist/esm/utils/context/buildContext.js +12 -0
  74. package/dist/esm/utils/logic/genJSModules.js +2 -2
  75. package/dist/esm/utils/logic/handleProcess.js +66 -12
  76. package/dist/esm/utils/templates/renderManager.js +4 -4
  77. package/package.json +1 -1
  78. package/dist/cjs/core/comlib/Index.js +0 -114
  79. package/dist/cjs/core/comlib/_AesEncode.js +0 -115
  80. package/dist/cjs/core/comlib/_BackTo.js +0 -80
  81. package/dist/cjs/core/comlib/_CallPhone.js +0 -58
  82. package/dist/cjs/core/comlib/_ChooseFile.js +0 -103
  83. package/dist/cjs/core/comlib/_ChooseMedia.js +0 -70
  84. package/dist/cjs/core/comlib/_Connector.js +0 -92
  85. package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +0 -79
  86. package/dist/cjs/core/comlib/_Format.js +0 -123
  87. package/dist/cjs/core/comlib/_GetLocation.js +0 -60
  88. package/dist/cjs/core/comlib/_GetStorage.js +0 -68
  89. package/dist/cjs/core/comlib/_GetSystemInfo.js +0 -62
  90. package/dist/cjs/core/comlib/_Modal.js +0 -68
  91. package/dist/cjs/core/comlib/_OpenCamera.js +0 -73
  92. package/dist/cjs/core/comlib/_OpenPetalMap.js +0 -49
  93. package/dist/cjs/core/comlib/_OpenUrl.js +0 -62
  94. package/dist/cjs/core/comlib/_RemoveStorage.js +0 -68
  95. package/dist/cjs/core/comlib/_Router.js +0 -100
  96. package/dist/cjs/core/comlib/_ScanQrcode.js +0 -59
  97. package/dist/cjs/core/comlib/_SetStorage.js +0 -67
  98. package/dist/cjs/core/comlib/_Share.js +0 -58
  99. package/dist/cjs/core/comlib/_ShowToast.js +0 -69
  100. package/dist/cjs/core/comlib/_TextToSpeech.js +0 -120
  101. package/dist/cjs/core/comlib/_TimerDebounce.js +0 -72
  102. package/dist/cjs/core/comlib/_TimerDelay.js +0 -88
  103. package/dist/cjs/core/comlib/_TimerThrottle.js +0 -75
  104. package/dist/cjs/core/comlib/_Vibrate.js +0 -60
  105. package/dist/esm/abstractEventTypeDef.d.ts.map +0 -1
  106. package/dist/esm/core/comlib/Index.js +0 -39
  107. package/dist/esm/core/comlib/_AesEncode.js +0 -85
  108. package/dist/esm/core/comlib/_BackTo.js +0 -66
  109. package/dist/esm/core/comlib/_CallPhone.js +0 -30
  110. package/dist/esm/core/comlib/_ChooseFile.js +0 -81
  111. package/dist/esm/core/comlib/_ChooseMedia.js +0 -38
  112. package/dist/esm/core/comlib/_Connector.js +0 -60
  113. package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +0 -56
  114. package/dist/esm/core/comlib/_Format.js +0 -102
  115. package/dist/esm/core/comlib/_GetLocation.js +0 -26
  116. package/dist/esm/core/comlib/_GetStorage.js +0 -44
  117. package/dist/esm/core/comlib/_GetSystemInfo.js +0 -32
  118. package/dist/esm/core/comlib/_Modal.js +0 -51
  119. package/dist/esm/core/comlib/_OpenCamera.js +0 -44
  120. package/dist/esm/core/comlib/_OpenPetalMap.js +0 -28
  121. package/dist/esm/core/comlib/_OpenUrl.js +0 -36
  122. package/dist/esm/core/comlib/_RemoveStorage.js +0 -42
  123. package/dist/esm/core/comlib/_Router.js +0 -113
  124. package/dist/esm/core/comlib/_ScanQrcode.js +0 -26
  125. package/dist/esm/core/comlib/_SetStorage.js +0 -40
  126. package/dist/esm/core/comlib/_Share.js +0 -28
  127. package/dist/esm/core/comlib/_ShowToast.js +0 -45
  128. package/dist/esm/core/comlib/_TextToSpeech.js +0 -117
  129. package/dist/esm/core/comlib/_TimerDebounce.js +0 -66
  130. package/dist/esm/core/comlib/_TimerDelay.js +0 -79
  131. package/dist/esm/core/comlib/_TimerThrottle.js +0 -69
  132. package/dist/esm/core/comlib/_Vibrate.js +0 -34
  133. package/dist/esm/generate/generateTaroTempalteJson.d.ts.map +0 -1
  134. package/dist/esm/generate/utils/appConfig.d.ts.map +0 -1
  135. package/dist/esm/generate/utils/fileNode.d.ts.map +0 -1
  136. package/dist/esm/generate/utils/index.d.ts.map +0 -1
  137. package/dist/esm/generate/utils/pageImages.d.ts.map +0 -1
  138. package/dist/esm/generate/utils/tabBarImages.d.ts.map +0 -1
  139. package/dist/esm/handleExtension.d.ts.map +0 -1
  140. package/dist/esm/handleModule.d.ts.map +0 -1
  141. package/dist/esm/index.d.ts.map +0 -1
  142. package/dist/esm/processors/processComEvents.d.ts.map +0 -1
  143. package/dist/esm/processors/processModule.d.ts.map +0 -1
  144. package/dist/esm/processors/processScene.d.ts.map +0 -1
  145. package/dist/esm/processors/processSceneLogic.d.ts.map +0 -1
  146. package/dist/esm/toCodeTaro.d.ts.map +0 -1
  147. package/dist/esm/utils/builder/buildResult.d.ts.map +0 -1
  148. package/dist/esm/utils/common/ImportManager.d.ts.map +0 -1
  149. package/dist/esm/utils/common/helper.d.ts.map +0 -1
  150. package/dist/esm/utils/common/object.d.ts.map +0 -1
  151. package/dist/esm/utils/common/string.d.ts.map +0 -1
  152. package/dist/esm/utils/config/content/index.d.ts.map +0 -1
  153. package/dist/esm/utils/config/content/types.d.ts.map +0 -1
  154. package/dist/esm/utils/config/content/validator.d.ts.map +0 -1
  155. package/dist/esm/utils/config/handlePageConfig.d.ts.map +0 -1
  156. package/dist/esm/utils/context/buildContext.d.ts.map +0 -1
  157. package/dist/esm/utils/context/buildFrameMap.d.ts.map +0 -1
  158. package/dist/esm/utils/context/buildGlobalData.d.ts.map +0 -1
  159. package/dist/esm/utils/context/collectJSModules.d.ts.map +0 -1
  160. package/dist/esm/utils/context/createEventQueries.d.ts.map +0 -1
  161. package/dist/esm/utils/context/createProvider.d.ts.map +0 -1
  162. package/dist/esm/utils/index.d.ts.map +0 -1
  163. package/dist/esm/utils/logic/convertNamespace.d.ts.map +0 -1
  164. package/dist/esm/utils/logic/genJSModules.d.ts.map +0 -1
  165. package/dist/esm/utils/style/color.d.ts.map +0 -1
  166. package/dist/esm/utils/style/getComponentClassName.d.ts.map +0 -1
  167. package/dist/esm/utils/style/pxtransform.d.ts.map +0 -1
  168. package/dist/esm/utils/style/types.d.ts.map +0 -1
  169. package/dist/esm/utils/templates/component.d.ts.map +0 -1
@@ -38,9 +38,37 @@ var import_react = __toESM(require("react"));
38
38
  var import_ComContext = __toESM(require("./ComContext"));
39
39
  var import_createReactiveInputHandler = require("../mybricks/createReactiveInputHandler");
40
40
  var import_hooks = require("./hooks");
41
- function createPenetratingComRefs(parentComRefs, globalTodoPool, index = 0) {
41
+ function shallowEqual(a, b) {
42
+ if (a === b)
43
+ return true;
44
+ if (!a || !b)
45
+ return false;
46
+ const keysA = Object.keys(a);
47
+ const keysB = Object.keys(b);
48
+ if (keysA.length !== keysB.length)
49
+ return false;
50
+ return keysA.every((key) => a[key] === b[key]);
51
+ }
52
+ function mergeSlotParams(stateInputValues, params) {
53
+ const hasStateInputValues = stateInputValues && Object.keys(stateInputValues).length > 0;
54
+ const hasParamsInputValues = (params == null ? void 0 : params.inputValues) && Object.keys(params.inputValues).length > 0;
55
+ if (!hasStateInputValues && !hasParamsInputValues) {
56
+ return params || {};
57
+ }
58
+ return {
59
+ ...params || {},
60
+ inputValues: {
61
+ ...stateInputValues || {},
62
+ ...(params == null ? void 0 : params.inputValues) || {}
63
+ }
64
+ };
65
+ }
66
+ function createScopeId(id, slotKey, rawScope) {
67
+ return `${id}.${slotKey}::${String(rawScope)}`;
68
+ }
69
+ function createPenetratingComRefs(parentComRefs, todoPool, index = 0) {
42
70
  const localTarget = { $inputs: {}, $outputs: {}, $index: index };
43
- return { current: (0, import_hooks.proxyRefs)(localTarget, parentComRefs, globalTodoPool) };
71
+ return { current: (0, import_hooks.proxyRefs)(localTarget, parentComRefs, todoPool) };
44
72
  }
45
73
  function SlotParamsBridge(props) {
46
74
  var _a, _b;
@@ -50,7 +78,7 @@ function SlotParamsBridge(props) {
50
78
  const content = SlotComp ? /* @__PURE__ */ import_react.default.createElement(SlotComp, { ...mergedParams || {} }) : props.children ?? null;
51
79
  return /* @__PURE__ */ import_react.default.createElement(import_ComContext.SlotProvider, { value: { ...props.state, params: mergedParams } }, content);
52
80
  }
53
- function createChannelProxy(title) {
81
+ function createChannelProxy(title, onInputCall) {
54
82
  const handlersMap = {};
55
83
  return new Proxy(
56
84
  {},
@@ -61,6 +89,7 @@ function createChannelProxy(title) {
61
89
  handlersMap[pin] = arg;
62
90
  return;
63
91
  }
92
+ onInputCall == null ? void 0 : onInputCall(pin, arg);
64
93
  const handler = handlersMap[pin];
65
94
  if (typeof handler === "function") {
66
95
  return (0, import_createReactiveInputHandler.createReactiveInputHandler)({
@@ -76,30 +105,47 @@ function createChannelProxy(title) {
76
105
  );
77
106
  }
78
107
  function useEnhancedSlots(rawSlots, id) {
79
- const { comRefs: parentComRefs, globalTodoInputs } = (0, import_ComContext.useAppContext)();
108
+ const { comRefs: parentComRefs, todoPool } = (0, import_ComContext.useAppContext)();
80
109
  const slotStoreRef = (0, import_react.useRef)({});
110
+ const [, forceUpdate] = (0, import_react.useState)({});
81
111
  return (0, import_react.useMemo)(() => {
82
112
  if (!rawSlots)
83
113
  return {};
84
114
  const nextSlots = {};
85
115
  Object.entries(rawSlots).forEach(([slotKey, slotDef]) => {
116
+ const onInputCall = (pin, value) => {
117
+ const state2 = slotStoreRef.current[slotKey];
118
+ if (state2) {
119
+ if (!state2._inputValues)
120
+ state2._inputValues = {};
121
+ state2._inputValues[pin] = value;
122
+ forceUpdate({});
123
+ }
124
+ };
86
125
  const state = slotStoreRef.current[slotKey] || (slotStoreRef.current[slotKey] = {
87
- inputs: createChannelProxy(`${id}.${slotKey}.inputs`),
126
+ inputs: createChannelProxy(`${id}.${slotKey}.inputs`, onInputCall),
88
127
  outputs: createChannelProxy(`${id}.${slotKey}.outputs`),
89
128
  _inputs: createChannelProxy(`${id}.${slotKey}._inputs`),
90
129
  _scopedComRefs: {},
130
+ _inputValues: {},
91
131
  _render: void 0,
92
132
  render: (params) => {
93
- var _a, _b, _c, _d, _e;
133
+ var _a, _b, _c, _d;
94
134
  const r = state._render;
95
- const rawScope = (params == null ? void 0 : params.key) ?? ((_a = params == null ? void 0 : params.inputValues) == null ? void 0 : _a.index) ?? ((_c = (_b = params == null ? void 0 : params.inputValues) == null ? void 0 : _b.itemData) == null ? void 0 : _c.id);
135
+ const mergedParams = mergeSlotParams(state._inputValues, params);
136
+ if (state._lastMergedParams && shallowEqual(mergedParams == null ? void 0 : mergedParams.inputValues, (_a = state._lastMergedParams) == null ? void 0 : _a.inputValues)) {
137
+ } else {
138
+ state._lastMergedParams = mergedParams;
139
+ }
140
+ const stableParams = state._lastMergedParams;
141
+ const rawScope = ((_b = stableParams == null ? void 0 : stableParams.inputValues) == null ? void 0 : _b.index) ?? (params == null ? void 0 : params.key);
96
142
  if (rawScope === void 0 || rawScope === null) {
97
- return /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params, render: r });
143
+ return /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params: stableParams, render: r });
98
144
  }
99
- const scopeId = `${id}.${slotKey}::${String(rawScope)}`;
100
- const index = ((_d = params == null ? void 0 : params.inputValues) == null ? void 0 : _d.index) ?? 0;
101
- const scopedComRefs = (_e = state._scopedComRefs)[scopeId] || (_e[scopeId] = createPenetratingComRefs(parentComRefs, globalTodoInputs, index));
102
- return /* @__PURE__ */ import_react.default.createElement(ScopedComContextProvider, { comRefs: scopedComRefs, scopeId }, /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params, render: r }));
145
+ const scopeId = createScopeId(id, slotKey, rawScope);
146
+ const index = ((_c = stableParams == null ? void 0 : stableParams.inputValues) == null ? void 0 : _c.index) ?? 0;
147
+ const scopedComRefs = (_d = state._scopedComRefs)[scopeId] || (_d[scopeId] = createPenetratingComRefs(parentComRefs, todoPool, index));
148
+ return /* @__PURE__ */ import_react.default.createElement(ScopedComContextProvider, { comRefs: scopedComRefs, scopeId }, /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params: stableParams, render: r }));
103
149
  }
104
150
  });
105
151
  state._render = slotDef == null ? void 0 : slotDef.render;
@@ -112,7 +158,7 @@ function useEnhancedSlots(rawSlots, id) {
112
158
  };
113
159
  });
114
160
  return nextSlots;
115
- }, [rawSlots, id, parentComRefs, globalTodoInputs]);
161
+ }, [rawSlots, id, parentComRefs, todoPool]);
116
162
  }
117
163
  function ScopedComContextProvider(props) {
118
164
  const parent = (0, import_ComContext.useAppContext)();
@@ -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,11 +33,15 @@ __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
- var GLOBAL_TODO_POOL = /* @__PURE__ */ new Map();
41
+ var import_pool = require("./pool");
28
42
  function useAppCreateContext(id) {
29
- const globalTodoInputs = (0, import_react.useRef)(GLOBAL_TODO_POOL);
30
- const comRefs = (0, import_react.useRef)((0, import_hooks.proxyRefs)({ $inputs: {}, $outputs: {} }, void 0, globalTodoInputs.current));
43
+ const todoPool = (0, import_react.useMemo)(() => new import_pool.TodoPool(), []);
44
+ const comRefs = (0, import_react.useRef)((0, import_hooks.proxyRefs)({ $inputs: {}, $outputs: {} }, void 0, todoPool));
31
45
  const $vars = (0, import_react.useRef)({});
32
46
  const $fxs = (0, import_react.useRef)({});
33
47
  const [popupState, setPopupState] = (0, import_react.useState)({
@@ -43,6 +57,34 @@ function useAppCreateContext(id) {
43
57
  runtime: {
44
58
  debug: false
45
59
  },
60
+ env: {
61
+ runtime: true,
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
+ }
86
+ },
87
+ rootScroll: {},
46
88
  edit: false,
47
89
  isH5: false,
48
90
  isDesigner: false,
@@ -58,7 +100,7 @@ function useAppCreateContext(id) {
58
100
  comRefs,
59
101
  $vars,
60
102
  $fxs,
61
- globalTodoInputs: globalTodoInputs.current,
103
+ todoPool,
62
104
  appContext,
63
105
  popupState,
64
106
  setPopupState
@@ -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,24 +147,16 @@ ${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);
152
+ const apiItem = files.find((item) => item.type === "connector-api");
153
+ if (apiItem) {
154
+ commonDir.children = commonDir.children || [];
155
+ commonDir.children.push({
156
+ path: "src/common/api.ts",
157
+ content: apiItem.content
158
+ });
159
+ }
167
160
  const popupFile = files.find((f) => f.type === "popup" && !f.meta);
168
161
  if (popupFile) {
169
162
  commonDir.children.push({
@@ -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,35 @@ __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
+ }
47
+ content.window = content.window || {};
34
48
  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
- );
49
+ if (tabBarConfigItem == null ? void 0 : tabBarConfigItem.content) {
50
+ const tabBar = (0, import_fileNode.parseLooseObject)(`{${tabBarConfigItem.content}}`);
51
+ Object.assign(content.window, tabBar);
41
52
  }
42
- appConfigFile.content = content;
53
+ appConfigFile.content = `export default defineAppConfig(${JSON.stringify(content, null, 2)})`;
43
54
  }
44
55
  // Annotate the CommonJS export names for ESM import in node:
45
56
  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
  });