@mybricks/to-code-taro 1.0.2 → 1.0.4

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 (256) hide show
  1. package/README.md +58 -0
  2. package/dist/cjs/core/comlib/_AesEncode.js +115 -0
  3. package/dist/cjs/core/comlib/_BackTo.js +80 -0
  4. package/dist/cjs/core/comlib/{Index.js → _CallPhone.js} +29 -16
  5. package/dist/cjs/core/comlib/_ChooseFile.js +103 -0
  6. package/dist/cjs/core/comlib/_ChooseMedia.js +70 -0
  7. package/dist/cjs/core/comlib/_Connector.js +92 -0
  8. package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +79 -0
  9. package/dist/cjs/core/comlib/_Format.js +123 -0
  10. package/dist/cjs/core/comlib/_GetLocation.js +60 -0
  11. package/dist/cjs/core/comlib/_GetStorage.js +68 -0
  12. package/dist/cjs/core/comlib/_GetSystemInfo.js +62 -0
  13. package/dist/cjs/core/comlib/_OpenCamera.js +73 -0
  14. package/dist/cjs/core/comlib/_OpenPetalMap.js +49 -0
  15. package/dist/cjs/core/comlib/_OpenUrl.js +62 -0
  16. package/dist/cjs/core/comlib/_RemoveStorage.js +68 -0
  17. package/dist/cjs/core/comlib/_Router.js +100 -0
  18. package/dist/cjs/core/comlib/_ScanQrcode.js +9 -10
  19. package/dist/cjs/core/comlib/_SetStorage.js +10 -19
  20. package/dist/cjs/core/comlib/_Share.js +58 -0
  21. package/dist/cjs/core/comlib/_ShowToast.js +23 -50
  22. package/dist/cjs/core/comlib/_TextToSpeech.js +120 -0
  23. package/dist/cjs/core/comlib/_TimerDebounce.js +72 -0
  24. package/dist/cjs/core/comlib/_TimerDelay.js +63 -0
  25. package/dist/cjs/core/comlib/_TimerThrottle.js +75 -0
  26. package/dist/cjs/core/comlib/_Vibrate.js +60 -0
  27. package/dist/cjs/core/comlib/index.js +111 -0
  28. package/dist/cjs/core/mybricks/index.js +47 -47
  29. package/dist/cjs/core/utils/ComContext.js +3 -0
  30. package/dist/cjs/core/utils/PopupRenderer.js +63 -0
  31. package/dist/cjs/core/utils/hooks.js +131 -0
  32. package/dist/cjs/core/utils/index.js +33 -57
  33. package/dist/cjs/core/utils/pageRouter.js +81 -0
  34. package/dist/cjs/core/utils/popupRouter.js +98 -0
  35. package/dist/cjs/core/utils/useContext.js +11 -2
  36. package/dist/cjs/core/utils/with.js +37 -13
  37. package/dist/cjs/generate/generateTaroProjectJson.d.ts +3 -14
  38. package/dist/cjs/generate/generateTaroProjectJson.js +39 -6
  39. package/dist/cjs/generate/utils/tabBarImages.d.ts +1 -1
  40. package/dist/cjs/handleCom.d.ts +1 -1
  41. package/dist/cjs/handleCom.js +91 -177
  42. package/dist/cjs/handleDom.js +7 -44
  43. package/dist/cjs/handleExtension.d.ts +2 -2
  44. package/dist/cjs/handleExtension.js +5 -5
  45. package/dist/cjs/handleGlobal.d.ts +2 -12
  46. package/dist/cjs/handleGlobal.js +23 -7
  47. package/dist/cjs/handleModule.js +3 -3
  48. package/dist/cjs/handleSlot.d.ts +4 -9
  49. package/dist/cjs/handleSlot.js +61 -150
  50. package/dist/cjs/processors/processComEvents.d.ts +9 -0
  51. package/dist/cjs/processors/processComEvents.js +164 -0
  52. package/dist/cjs/processors/processModule.d.ts +31 -0
  53. package/dist/cjs/processors/processModule.js +125 -0
  54. package/dist/cjs/processors/processScene.d.ts +32 -0
  55. package/dist/cjs/processors/processScene.js +128 -0
  56. package/dist/cjs/processors/processSceneLogic.d.ts +4 -0
  57. package/dist/cjs/processors/processSceneLogic.js +170 -0
  58. package/dist/cjs/shims-taro.d.ts +20 -0
  59. package/dist/cjs/taro-template.json +501 -351
  60. package/dist/cjs/toCodeTaro.d.ts +27 -6
  61. package/dist/cjs/toCodeTaro.js +68 -340
  62. package/dist/cjs/utils/builder/buildResult.d.ts +22 -0
  63. package/dist/cjs/utils/builder/buildResult.js +117 -0
  64. package/dist/cjs/utils/common/ImportManager.d.ts +19 -0
  65. package/dist/cjs/utils/common/ImportManager.js +105 -0
  66. package/dist/cjs/utils/common/helper.d.ts +2 -0
  67. package/dist/cjs/utils/common/helper.js +31 -0
  68. package/dist/cjs/utils/common/object.d.ts +5 -0
  69. package/dist/cjs/utils/common/object.js +58 -0
  70. package/dist/cjs/utils/common/string.d.ts +8 -0
  71. package/dist/cjs/utils/common/string.js +46 -0
  72. package/dist/cjs/utils/{pageConfig → config/content}/converter.js +1 -1
  73. package/dist/cjs/utils/{pageConfig → config/content}/index.js +9 -9
  74. package/dist/cjs/utils/{pageConfig → config/content}/pageConfig.js +12 -22
  75. package/dist/{esm/utils/pageConfig → cjs/utils/config/content}/saveBase64Image.d.ts +1 -1
  76. package/dist/cjs/utils/{pageConfig → config/content}/saveBase64Image.js +8 -17
  77. package/dist/cjs/utils/{pageConfig → config/content}/tabBarConfig.js +9 -32
  78. package/dist/cjs/utils/config/content/types.js +17 -0
  79. package/dist/cjs/utils/{pageConfig → config/content}/validator.js +1 -1
  80. package/dist/{esm/utils → cjs/utils/config}/handlePageConfig.d.ts +3 -2
  81. package/dist/cjs/utils/{handlePageConfig.js → config/handlePageConfig.js} +7 -6
  82. package/dist/cjs/utils/context/buildContext.d.ts +24 -0
  83. package/dist/cjs/utils/context/buildContext.js +65 -0
  84. package/dist/cjs/utils/context/buildFrameMap.d.ts +16 -0
  85. package/dist/cjs/utils/context/buildFrameMap.js +106 -0
  86. package/dist/cjs/utils/context/buildGlobalData.d.ts +13 -0
  87. package/dist/cjs/utils/context/buildGlobalData.js +58 -0
  88. package/dist/cjs/utils/context/collectJSModules.d.ts +37 -0
  89. package/dist/cjs/utils/context/collectJSModules.js +91 -0
  90. package/dist/cjs/utils/context/createEventQueries.d.ts +45 -0
  91. package/dist/cjs/utils/context/createEventQueries.js +99 -0
  92. package/dist/cjs/utils/context/createProvider.d.ts +21 -0
  93. package/dist/cjs/utils/context/createProvider.js +49 -0
  94. package/dist/cjs/utils/index.d.ts +10 -62
  95. package/dist/cjs/utils/index.js +21 -282
  96. package/dist/cjs/utils/{convertNamespace.js → logic/convertNamespace.js} +1 -1
  97. package/dist/cjs/utils/{genJSModules.js → logic/genJSModules.js} +1 -1
  98. package/dist/{esm/utils → cjs/utils/logic}/handleProcess.d.ts +2 -2
  99. package/dist/cjs/utils/{handleProcess.js → logic/handleProcess.js} +40 -16
  100. package/dist/cjs/utils/logic/processChildren.d.ts +12 -0
  101. package/dist/cjs/utils/logic/processChildren.js +82 -0
  102. package/dist/cjs/utils/style/color.d.ts +4 -0
  103. package/dist/cjs/utils/style/color.js +45 -0
  104. package/dist/cjs/utils/style/converter.d.ts +7 -0
  105. package/dist/cjs/utils/style/converter.js +181 -0
  106. package/dist/cjs/utils/{getComponentClassName.js → style/getComponentClassName.js} +1 -1
  107. package/dist/cjs/utils/{pxtransform.js → style/pxtransform.js} +1 -1
  108. package/dist/cjs/utils/style/types.d.ts +23 -0
  109. package/dist/cjs/utils/{pageConfig → style}/types.js +1 -1
  110. package/dist/cjs/utils/{code → templates}/component.js +1 -1
  111. package/dist/cjs/utils/{code → templates}/index.js +4 -4
  112. package/dist/cjs/utils/{code → templates}/renderManager.js +1 -1
  113. package/dist/cjs/utils/{code → templates}/scene.d.ts +3 -1
  114. package/dist/cjs/utils/{code → templates}/scene.js +17 -5
  115. package/dist/esm/core/comlib/_AesEncode.js +85 -0
  116. package/dist/esm/core/comlib/_BackTo.js +66 -0
  117. package/dist/esm/core/comlib/_CallPhone.js +30 -0
  118. package/dist/esm/core/comlib/_ChooseFile.js +81 -0
  119. package/dist/esm/core/comlib/_ChooseMedia.js +38 -0
  120. package/dist/esm/core/comlib/_Connector.js +60 -0
  121. package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +56 -0
  122. package/dist/esm/core/comlib/_Format.js +102 -0
  123. package/dist/esm/core/comlib/_GetLocation.js +26 -0
  124. package/dist/esm/core/comlib/_GetStorage.js +44 -0
  125. package/dist/esm/core/comlib/_GetSystemInfo.js +32 -0
  126. package/dist/esm/core/comlib/_OpenCamera.js +44 -0
  127. package/dist/esm/core/comlib/_OpenPetalMap.js +28 -0
  128. package/dist/esm/core/comlib/_OpenUrl.js +36 -0
  129. package/dist/esm/core/comlib/_RemoveStorage.js +42 -0
  130. package/dist/esm/core/comlib/_Router.js +113 -0
  131. package/dist/esm/core/comlib/_ScanQrcode.js +10 -11
  132. package/dist/esm/core/comlib/_SetStorage.js +13 -25
  133. package/dist/esm/core/comlib/_Share.js +28 -0
  134. package/dist/esm/core/comlib/_ShowToast.js +32 -55
  135. package/dist/esm/core/comlib/_TextToSpeech.js +117 -0
  136. package/dist/esm/core/comlib/_TimerDebounce.js +66 -0
  137. package/dist/esm/core/comlib/_TimerDelay.js +47 -0
  138. package/dist/esm/core/comlib/_TimerThrottle.js +69 -0
  139. package/dist/esm/core/comlib/_Vibrate.js +34 -0
  140. package/dist/esm/core/comlib/index.js +37 -0
  141. package/dist/esm/core/mybricks/index.js +1 -1
  142. package/dist/esm/core/utils/ComContext.js +1 -0
  143. package/dist/esm/core/utils/PopupRenderer.js +27 -0
  144. package/dist/esm/core/utils/hooks.js +130 -0
  145. package/dist/esm/core/utils/index.js +8 -57
  146. package/dist/esm/core/utils/pageRouter.js +69 -0
  147. package/dist/esm/core/utils/popupRouter.js +116 -0
  148. package/dist/esm/core/utils/useContext.js +16 -3
  149. package/dist/esm/core/utils/with.js +62 -19
  150. package/dist/esm/generate/generateTaroProjectJson.d.ts +3 -14
  151. package/dist/esm/generate/generateTaroProjectJson.js +62 -24
  152. package/dist/esm/generate/utils/tabBarImages.d.ts +1 -1
  153. package/dist/esm/handleCom.d.ts +1 -1
  154. package/dist/esm/handleCom.js +159 -244
  155. package/dist/esm/handleDom.js +9 -48
  156. package/dist/esm/handleExtension.d.ts +2 -2
  157. package/dist/esm/handleExtension.js +5 -5
  158. package/dist/esm/handleGlobal.d.ts +2 -12
  159. package/dist/esm/handleGlobal.js +17 -3
  160. package/dist/esm/handleModule.js +3 -3
  161. package/dist/esm/handleSlot.d.ts +4 -9
  162. package/dist/esm/handleSlot.js +112 -173
  163. package/dist/esm/processors/processComEvents.d.ts +9 -0
  164. package/dist/esm/processors/processComEvents.js +167 -0
  165. package/dist/esm/processors/processModule.d.ts +31 -0
  166. package/dist/esm/processors/processModule.js +126 -0
  167. package/dist/esm/processors/processScene.d.ts +32 -0
  168. package/dist/esm/processors/processScene.js +134 -0
  169. package/dist/esm/processors/processSceneLogic.d.ts +4 -0
  170. package/dist/esm/processors/processSceneLogic.js +170 -0
  171. package/dist/esm/shims-taro.d.ts +20 -0
  172. package/dist/esm/taro-template.json +501 -351
  173. package/dist/esm/toCodeTaro.d.ts +27 -6
  174. package/dist/esm/toCodeTaro.js +110 -395
  175. package/dist/esm/utils/builder/buildResult.d.ts +22 -0
  176. package/dist/esm/utils/builder/buildResult.js +82 -0
  177. package/dist/esm/utils/common/ImportManager.d.ts +19 -0
  178. package/dist/esm/utils/common/ImportManager.js +103 -0
  179. package/dist/esm/utils/common/helper.d.ts +2 -0
  180. package/dist/esm/utils/common/helper.js +4 -0
  181. package/dist/esm/utils/common/object.d.ts +5 -0
  182. package/dist/esm/utils/common/object.js +32 -0
  183. package/dist/esm/utils/common/string.d.ts +8 -0
  184. package/dist/esm/utils/common/string.js +21 -0
  185. package/dist/esm/utils/config/content/pageConfig.js +40 -0
  186. package/dist/{cjs/utils/pageConfig → esm/utils/config/content}/saveBase64Image.d.ts +1 -1
  187. package/dist/esm/utils/{pageConfig → config/content}/saveBase64Image.js +11 -30
  188. package/dist/esm/utils/{pageConfig → config/content}/tabBarConfig.js +12 -34
  189. package/dist/{cjs/utils → esm/utils/config}/handlePageConfig.d.ts +3 -2
  190. package/dist/esm/utils/{handlePageConfig.js → config/handlePageConfig.js} +6 -2
  191. package/dist/esm/utils/context/buildContext.d.ts +24 -0
  192. package/dist/esm/utils/context/buildContext.js +53 -0
  193. package/dist/esm/utils/context/buildFrameMap.d.ts +16 -0
  194. package/dist/esm/utils/context/buildFrameMap.js +131 -0
  195. package/dist/esm/utils/context/buildGlobalData.d.ts +13 -0
  196. package/dist/esm/utils/context/buildGlobalData.js +44 -0
  197. package/dist/esm/utils/context/collectJSModules.d.ts +37 -0
  198. package/dist/esm/utils/context/collectJSModules.js +87 -0
  199. package/dist/esm/utils/context/createEventQueries.d.ts +45 -0
  200. package/dist/esm/utils/context/createEventQueries.js +99 -0
  201. package/dist/esm/utils/context/createProvider.d.ts +21 -0
  202. package/dist/esm/utils/context/createProvider.js +33 -0
  203. package/dist/esm/utils/index.d.ts +10 -62
  204. package/dist/esm/utils/index.js +12 -345
  205. package/dist/{cjs/utils → esm/utils/logic}/handleProcess.d.ts +2 -2
  206. package/dist/esm/utils/{handleProcess.js → logic/handleProcess.js} +42 -9
  207. package/dist/esm/utils/logic/processChildren.d.ts +12 -0
  208. package/dist/esm/utils/logic/processChildren.js +48 -0
  209. package/dist/esm/utils/style/color.d.ts +4 -0
  210. package/dist/esm/utils/style/color.js +17 -0
  211. package/dist/esm/utils/style/converter.d.ts +7 -0
  212. package/dist/esm/utils/style/converter.js +176 -0
  213. package/dist/esm/utils/style/types.d.ts +23 -0
  214. package/dist/esm/utils/style/types.js +1 -0
  215. package/dist/esm/utils/{code → templates}/scene.d.ts +3 -1
  216. package/dist/esm/utils/{code → templates}/scene.js +13 -5
  217. package/package.json +4 -2
  218. package/dist/esm/core/comlib/Index.js +0 -3
  219. package/dist/esm/utils/pageConfig/pageConfig.js +0 -60
  220. /package/dist/cjs/utils/{pageConfig → config/content}/converter.d.ts +0 -0
  221. /package/dist/cjs/utils/{pageConfig → config/content}/index.d.ts +0 -0
  222. /package/dist/cjs/utils/{pageConfig → config/content}/pageConfig.d.ts +0 -0
  223. /package/dist/cjs/utils/{pageConfig → config/content}/tabBarConfig.d.ts +0 -0
  224. /package/dist/cjs/utils/{pageConfig → config/content}/types.d.ts +0 -0
  225. /package/dist/cjs/utils/{pageConfig → config/content}/validator.d.ts +0 -0
  226. /package/dist/cjs/utils/{convertNamespace.d.ts → logic/convertNamespace.d.ts} +0 -0
  227. /package/dist/cjs/utils/{genJSModules.d.ts → logic/genJSModules.d.ts} +0 -0
  228. /package/dist/cjs/utils/{getComponentClassName.d.ts → style/getComponentClassName.d.ts} +0 -0
  229. /package/dist/cjs/utils/{pxtransform.d.ts → style/pxtransform.d.ts} +0 -0
  230. /package/dist/cjs/utils/{code → templates}/component.d.ts +0 -0
  231. /package/dist/cjs/utils/{code → templates}/index.d.ts +0 -0
  232. /package/dist/cjs/utils/{code → templates}/renderManager.d.ts +0 -0
  233. /package/dist/esm/utils/{pageConfig → config/content}/converter.d.ts +0 -0
  234. /package/dist/esm/utils/{pageConfig → config/content}/converter.js +0 -0
  235. /package/dist/esm/utils/{pageConfig → config/content}/index.d.ts +0 -0
  236. /package/dist/esm/utils/{pageConfig → config/content}/index.js +0 -0
  237. /package/dist/esm/utils/{pageConfig → config/content}/pageConfig.d.ts +0 -0
  238. /package/dist/esm/utils/{pageConfig → config/content}/tabBarConfig.d.ts +0 -0
  239. /package/dist/esm/utils/{pageConfig → config/content}/types.d.ts +0 -0
  240. /package/dist/esm/utils/{pageConfig → config/content}/types.js +0 -0
  241. /package/dist/esm/utils/{pageConfig → config/content}/validator.d.ts +0 -0
  242. /package/dist/esm/utils/{pageConfig → config/content}/validator.js +0 -0
  243. /package/dist/esm/utils/{convertNamespace.d.ts → logic/convertNamespace.d.ts} +0 -0
  244. /package/dist/esm/utils/{convertNamespace.js → logic/convertNamespace.js} +0 -0
  245. /package/dist/esm/utils/{genJSModules.d.ts → logic/genJSModules.d.ts} +0 -0
  246. /package/dist/esm/utils/{genJSModules.js → logic/genJSModules.js} +0 -0
  247. /package/dist/esm/utils/{getComponentClassName.d.ts → style/getComponentClassName.d.ts} +0 -0
  248. /package/dist/esm/utils/{getComponentClassName.js → style/getComponentClassName.js} +0 -0
  249. /package/dist/esm/utils/{pxtransform.d.ts → style/pxtransform.d.ts} +0 -0
  250. /package/dist/esm/utils/{pxtransform.js → style/pxtransform.js} +0 -0
  251. /package/dist/esm/utils/{code → templates}/component.d.ts +0 -0
  252. /package/dist/esm/utils/{code → templates}/component.js +0 -0
  253. /package/dist/esm/utils/{code → templates}/index.d.ts +0 -0
  254. /package/dist/esm/utils/{code → templates}/index.js +0 -0
  255. /package/dist/esm/utils/{code → templates}/renderManager.d.ts +0 -0
  256. /package/dist/esm/utils/{code → templates}/renderManager.js +0 -0
@@ -0,0 +1,130 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
4
+ import { useState, useRef, useMemo } from 'react';
5
+ import { createReactiveInputHandler } from "../mybricks/createReactiveInputHandler";
6
+
7
+ /**
8
+ * 深度代理,支持自动路径初始化和响应式更新(鸿蒙化处理方案)
9
+ */
10
+ export function deepProxy(target, onSet) {
11
+ if (target === null || _typeof(target) !== 'object' || target.__isProxy) {
12
+ return target;
13
+ }
14
+ return new Proxy(target, {
15
+ get: function get(obj, prop) {
16
+ if (prop === '__isProxy') return true;
17
+ if (prop === 'toJSON') return function () {
18
+ return obj;
19
+ };
20
+ var value = obj[prop];
21
+
22
+ // 只有在访问不存在的对象属性时,才自动创建(实现类似 ensure 的效果)
23
+ // 特意排除 MyBricks 内置的方法名,以便在生成代码中进行初始化判断
24
+ var mybricksMethods = ['get', 'set', 'changed', 'reset', 'registerChange', 'call', 'apply', 'bind', 'push', 'pop'];
25
+ if (value === undefined && typeof prop === 'string' && !mybricksMethods.includes(prop)) {
26
+ value = obj[prop] = {};
27
+ }
28
+ if (_typeof(value) === 'object' && value !== null && !value.__isProxy) {
29
+ obj[prop] = deepProxy(value, onSet);
30
+ }
31
+ return obj[prop];
32
+ },
33
+ set: function set(obj, prop, value) {
34
+ var result = Reflect.set(obj, prop, value);
35
+ if (onSet) onSet();
36
+ return result;
37
+ }
38
+ });
39
+ }
40
+ export function useModel(rawData) {
41
+ var _useState = useState({}),
42
+ _useState2 = _slicedToArray(_useState, 2),
43
+ forceUpdate = _useState2[1];
44
+ var dataRef = useRef(rawData || {});
45
+ return useMemo(function () {
46
+ return deepProxy(dataRef.current, function () {
47
+ return forceUpdate({});
48
+ });
49
+ }, []);
50
+ }
51
+ export function useBindInputs(scope, id, initialHandlers) {
52
+ var handlersRef = useRef(_objectSpread({}, initialHandlers));
53
+
54
+ // 同步最新的 initialHandlers
55
+ if (initialHandlers) {
56
+ Object.assign(handlersRef.current, initialHandlers);
57
+ }
58
+ return useMemo(function () {
59
+ var proxy = new Proxy({}, {
60
+ get: function get(_target, pin) {
61
+ return function (arg) {
62
+ if (typeof arg === 'function') {
63
+ // 组件注册回调
64
+ handlersRef.current[pin] = arg;
65
+ } else {
66
+ // 逻辑流触发输入
67
+ var handler = handlersRef.current[pin];
68
+ if (typeof handler === 'function') {
69
+ if (pin === '_setData') {
70
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
71
+ args[_key - 1] = arguments[_key];
72
+ }
73
+ return handler.apply(void 0, [arg].concat(args));
74
+ }
75
+ // 构造 createReactiveInputHandler 需要的参数
76
+ return createReactiveInputHandler({
77
+ input: handler,
78
+ value: arg,
79
+ rels: {},
80
+ // 这里可以扩展 output 关联
81
+ title: id
82
+ });
83
+ }
84
+ }
85
+ };
86
+ }
87
+ });
88
+
89
+ // 将代理对象挂载到作用域,供外部 comRefs.current.id.pin() 调用
90
+ scope[id] = proxy;
91
+ return proxy;
92
+ }, [scope, id]);
93
+ }
94
+ export function useBindEvents(props) {
95
+ return useMemo(function () {
96
+ var _events = {};
97
+
98
+ // 预处理已存在的事件
99
+ Object.keys(props).forEach(function (key) {
100
+ if (key.startsWith('on') && typeof props[key] === 'function') {
101
+ var handler = props[key];
102
+ var wrapped = function wrapped() {
103
+ return handler.apply(void 0, arguments);
104
+ };
105
+ wrapped.getConnections = function () {
106
+ return [{
107
+ id: 'default'
108
+ }];
109
+ };
110
+ _events[key] = wrapped;
111
+ }
112
+ });
113
+ return new Proxy(_events, {
114
+ get: function get(target, key) {
115
+ if (typeof key === 'string' && key.startsWith('on')) {
116
+ if (target[key]) {
117
+ return target[key];
118
+ }
119
+ // 对未连接的事件返回兜底函数
120
+ var emptyFn = function emptyFn() {};
121
+ emptyFn.getConnections = function () {
122
+ return [];
123
+ };
124
+ return emptyFn;
125
+ }
126
+ return target[key];
127
+ }
128
+ });
129
+ }, [props]);
130
+ }
@@ -1,57 +1,8 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import { useState, useRef, useMemo } from 'react';
3
- export function useModel(rawData) {
4
- var _useState = useState({}),
5
- _useState2 = _slicedToArray(_useState, 2),
6
- forceUpdate = _useState2[1];
7
- var dataRef = useRef(rawData || {});
8
- return useMemo(function () {
9
- return new Proxy(dataRef.current, {
10
- get: function get(target, key) {
11
- return Reflect.get(target, key);
12
- },
13
- set: function set(target, key, value) {
14
- var result = Reflect.set(target, key, value);
15
- forceUpdate({});
16
- return result;
17
- }
18
- });
19
- }, []);
20
- }
21
- export function useBindInputs(scope, id) {
22
- return useMemo(function () {
23
- var controller = scope[id] = scope[id] || {};
24
- return new Proxy({}, {
25
- get: function get(_target, pin) {
26
- return function (arg) {
27
- if (typeof arg === 'function') {
28
- controller[pin] = arg;
29
- } else {
30
- var callback = controller[pin];
31
- if (typeof callback === 'function') {
32
- callback(arg);
33
- }
34
- }
35
- };
36
- }
37
- });
38
- }, [scope, id]);
39
- }
40
- export function useBindEvents(props) {
41
- return useMemo(function () {
42
- var _events = {};
43
- Object.keys(props).forEach(function (key) {
44
- if (key.startsWith('on')) {
45
- var handler = props[key];
46
- if (typeof handler === 'function') {
47
- _events[key] = handler;
48
- _events[key].getConnections = function () {
49
- return [1];
50
- };
51
- }
52
- }
53
- });
54
- return _events;
55
- }, [props]);
56
- }
57
- export { WithCom, WithWrapper } from "./with";
1
+ export * from "./hooks";
2
+ export { WithCom, WithWrapper } from "./with";
3
+ export { PopupRenderer } from "./PopupRenderer";
4
+ export { pageRouter, router } from "./pageRouter";
5
+ export { popupRouter, subscribePopupRouter, closeActivePopupRouter } from "./popupRouter";
6
+ export { useAppContext } from "./ComContext";
7
+ export { createVariable, createFx, merge } from "../mybricks";
8
+ export { SUBJECT_SUBSCRIBE, SUBJECT_VALUE } from "../mybricks/constant";
@@ -0,0 +1,69 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ // @ts-ignore 运行时由宿主项目提供 @tarojs/taro
5
+ import Taro from '@tarojs/taro';
6
+ import { Page } from "../mybricks";
7
+
8
+ /**
9
+ * Taro 路由驱动 (纯粹版)
10
+ * 只负责处理真正的 Taro 页面跳转
11
+ */
12
+ var TaroRouter = /*#__PURE__*/function () {
13
+ function TaroRouter() {
14
+ _classCallCheck(this, TaroRouter);
15
+ _defineProperty(this, "paramsBackup", {});
16
+ }
17
+ _createClass(TaroRouter, [{
18
+ key: "getParams",
19
+ value: function getParams(name) {
20
+ var _instance$router;
21
+ var instance = Taro.getCurrentInstance();
22
+ var params = ((_instance$router = instance.router) === null || _instance$router === void 0 ? void 0 : _instance$router.params) || {};
23
+
24
+ // 备份参数,解决某些生命周期下 Taro 获取不到 params 的问题
25
+ if (!params.data && this.paramsBackup[name]) {
26
+ params = {
27
+ data: this.paramsBackup[name]
28
+ };
29
+ }
30
+ return {
31
+ value: params
32
+ };
33
+ }
34
+ }, {
35
+ key: "push",
36
+ value: function push(name, _ref) {
37
+ var value = _ref.value;
38
+ var url = "/pages/".concat(name, "/index");
39
+ var dataStr = value ? encodeURIComponent(JSON.stringify(value)) : '';
40
+ if (dataStr) {
41
+ this.paramsBackup[name] = dataStr;
42
+ }
43
+ Taro.navigateTo({
44
+ url: "".concat(url).concat(dataStr ? "?data=".concat(dataStr) : '')
45
+ });
46
+ }
47
+ }, {
48
+ key: "replace",
49
+ value: function replace(name, _ref2) {
50
+ var value = _ref2.value;
51
+ var url = "/pages/".concat(name, "/index");
52
+ var dataStr = value ? encodeURIComponent(JSON.stringify(value)) : '';
53
+ if (dataStr) {
54
+ this.paramsBackup[name] = dataStr;
55
+ }
56
+ Taro.redirectTo({
57
+ url: "".concat(url).concat(dataStr ? "?data=".concat(dataStr) : '')
58
+ });
59
+ }
60
+ }, {
61
+ key: "pop",
62
+ value: function pop() {
63
+ Taro.navigateBack();
64
+ }
65
+ }]);
66
+ return TaroRouter;
67
+ }();
68
+ export var router = new TaroRouter();
69
+ export var pageRouter = new Page(router);
@@ -0,0 +1,116 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ import { Page } from "../mybricks";
5
+
6
+ /**
7
+ * 弹窗在 Taro 中被视为组件 兼容APP TODO
8
+ */
9
+ var PopupStore = /*#__PURE__*/function () {
10
+ function PopupStore() {
11
+ _classCallCheck(this, PopupStore);
12
+ _defineProperty(this, "activePopup", null);
13
+ _defineProperty(this, "listeners", new Set());
14
+ }
15
+ _createClass(PopupStore, [{
16
+ key: "subscribe",
17
+ value: /** 订阅弹窗状态变化 */
18
+ function subscribe(listener) {
19
+ var _this = this;
20
+ this.listeners.add(listener);
21
+ // 返回取消订阅函数
22
+ return function () {
23
+ _this.listeners.delete(listener);
24
+ };
25
+ }
26
+ }, {
27
+ key: "notify",
28
+ value: function notify() {
29
+ var _this2 = this;
30
+ this.listeners.forEach(function (l) {
31
+ return l(_this2.activePopup || {
32
+ visible: false,
33
+ name: '',
34
+ value: null,
35
+ controller: null
36
+ });
37
+ });
38
+ }
39
+
40
+ /** 获取弹窗参数 */
41
+ }, {
42
+ key: "getParams",
43
+ value: function getParams(name) {
44
+ if (this.activePopup && this.activePopup.name === name) {
45
+ return {
46
+ value: this.activePopup.value,
47
+ controller: this.activePopup.controller
48
+ };
49
+ }
50
+ return {
51
+ value: null
52
+ };
53
+ }
54
+
55
+ /** 获取当前激活的弹窗名称 */
56
+ }, {
57
+ key: "getActiveName",
58
+ value: function getActiveName() {
59
+ var _this$activePopup;
60
+ return (_this$activePopup = this.activePopup) === null || _this$activePopup === void 0 ? void 0 : _this$activePopup.name;
61
+ }
62
+
63
+ /** 打开弹窗 */
64
+ }, {
65
+ key: "push",
66
+ value: function push(name, _ref) {
67
+ var value = _ref.value,
68
+ controller = _ref.controller;
69
+ this.activePopup = {
70
+ visible: true,
71
+ name: name,
72
+ value: value,
73
+ controller: controller
74
+ };
75
+ this.notify();
76
+ }
77
+
78
+ /** 行为同 push */
79
+ }, {
80
+ key: "replace",
81
+ value: function replace(name, params) {
82
+ this.push(name, params);
83
+ }
84
+
85
+ /** 关闭弹窗 */
86
+ }, {
87
+ key: "pop",
88
+ value: function pop() {
89
+ this.activePopup = null;
90
+ this.notify();
91
+ }
92
+ }]);
93
+ return PopupStore;
94
+ }();
95
+ var popupStore = new PopupStore();
96
+
97
+ /**
98
+ * 订阅弹窗状态变化(统一入口,避免外部依赖内部实现细节)
99
+ */
100
+ export var subscribePopupRouter = function subscribePopupRouter(listener) {
101
+ return popupStore.subscribe(listener);
102
+ };
103
+
104
+ /** 弹窗控制器(命名与文件名保持一致) */
105
+ export var popupRouter = new Page(popupStore);
106
+
107
+ /**
108
+ * 关闭当前激活的弹窗(用于 TabBar 点击等场景)
109
+ * 不需要知道弹窗 id
110
+ */
111
+ export var closeActivePopupRouter = function closeActivePopupRouter() {
112
+ var name = popupStore.getActiveName();
113
+ if (!name) return;
114
+ // 走 Page.close,保证 close/commit/cancel 等控制器语义保持一致
115
+ popupRouter.close(name);
116
+ };
@@ -1,6 +1,17 @@
1
- import { useRef } from 'react';
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { useRef, useState } from 'react';
3
+ import { deepProxy } from "./hooks";
2
4
  export function useAppCreateContext() {
3
- var comRefs = useRef({});
5
+ var comRefs = useRef(deepProxy({}));
6
+ var _useState = useState({
7
+ visible: false,
8
+ name: '',
9
+ value: null,
10
+ controller: null
11
+ }),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ popupState = _useState2[0],
14
+ setPopupState = _useState2[1];
4
15
  var appContext = {
5
16
  canvas: {
6
17
  id: "u_7VvVn" // 使用 data 中的 id
@@ -19,6 +30,8 @@ export function useAppCreateContext() {
19
30
  };
20
31
  return {
21
32
  comRefs: comRefs,
22
- appContext: appContext
33
+ appContext: appContext,
34
+ popupState: popupState,
35
+ setPopupState: setPopupState
23
36
  };
24
37
  }
@@ -1,12 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
5
  var _excluded = ["component", "id", "data", "className", "style"];
5
- import React, { useEffect, useState } from 'react';
6
+ import React, { useState, useEffect } from 'react';
6
7
  import { View } from '@tarojs/components';
7
- import { useModel, useBindInputs, useBindEvents } from "./index";
8
+ import { useModel, useBindInputs, useBindEvents, subscribePopupRouter, closeActivePopupRouter } from "./index";
8
9
  import { useAppCreateContext } from "./useContext";
9
10
  import ComContext, { useAppContext } from "./ComContext";
11
+ // @ts-ignore 运行时由宿主项目提供 @tarojs/taro
12
+ import { useTabItemTap } from '@tarojs/taro';
10
13
  export var WithCom = function WithCom(props) {
11
14
  var Component = props.component,
12
15
  _props$id = props.id,
@@ -20,34 +23,59 @@ export var WithCom = function WithCom(props) {
20
23
  appContext = _useAppContext.appContext;
21
24
  var env = appContext; //TODO: 需要根据实际情况修改
22
25
 
26
+ var isPopup = Component.isPopup;
23
27
  var _useState = useState(true),
24
28
  _useState2 = _slicedToArray(_useState, 2),
25
29
  show = _useState2[0],
26
30
  setShow = _useState2[1];
31
+ var _useState3 = useState({}),
32
+ _useState4 = _slicedToArray(_useState3, 2),
33
+ dynamicStyle = _useState4[0],
34
+ setDynamicStyle = _useState4[1];
27
35
 
28
- //默认事件注册
29
- useEffect(function () {
30
- comRefs.current[id].hide(function () {
31
- setShow(false);
32
- });
33
- comRefs.current[id].show(function () {
34
- setShow(true);
35
- });
36
- comRefs.current[id].showOrHide(function () {
37
- setShow(function (prev) {
38
- return !prev;
36
+ //数据模型
37
+ var _data = useModel(data || {});
38
+
39
+ // 内置通用能力
40
+ var handlers = {
41
+ _setStyle: function _setStyle(style) {
42
+ setDynamicStyle(function (prev) {
43
+ return _objectSpread(_objectSpread({}, prev), style);
39
44
  });
45
+ },
46
+ _setData: function _setData(path, value) {
47
+ var paths = path.split('.');
48
+ var current = _data;
49
+ for (var i = 0; i < paths.length - 1; i++) {
50
+ if (!current[paths[i]]) current[paths[i]] = {};
51
+ current = current[paths[i]];
52
+ }
53
+ current[paths[paths.length - 1]] = value;
54
+ }
55
+ };
56
+ if (!isPopup) {
57
+ Object.assign(handlers, {
58
+ show: function show() {
59
+ return setShow(true);
60
+ },
61
+ hide: function hide() {
62
+ return setShow(false);
63
+ },
64
+ showOrHide: function showOrHide() {
65
+ return setShow(function (prev) {
66
+ return !prev;
67
+ });
68
+ }
40
69
  });
41
- }, [comRefs]);
70
+ }
42
71
 
43
- //数据模型
44
- var _data = useModel(data || {});
45
- var inputProxy = useBindInputs(comRefs, id);
72
+ // 绑定输入,传入初始 handlers
73
+ var inputProxy = useBindInputs(comRefs, id, handlers);
46
74
  var eventProxy = useBindEvents(rest);
47
75
  comRefs.current[id] = inputProxy;
48
- return show ? /*#__PURE__*/React.createElement(View, {
76
+ return show || isPopup ? /*#__PURE__*/React.createElement(View, {
49
77
  className: className,
50
- style: style
78
+ style: _objectSpread(_objectSpread({}, style), dynamicStyle)
51
79
  }, /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
52
80
  inputs: inputProxy,
53
81
  outputs: eventProxy,
@@ -60,6 +88,21 @@ export var WithCom = function WithCom(props) {
60
88
  export var WithWrapper = function WithWrapper(Component) {
61
89
  return function WrappedComponent(props) {
62
90
  var contextStore = useAppCreateContext();
91
+ var setPopupState = contextStore.setPopupState;
92
+ var isPopup = Component.isPopup;
93
+
94
+ // 通过发布订阅模式解耦弹窗状态变化
95
+ useEffect(function () {
96
+ return subscribePopupRouter(function (state) {
97
+ return setPopupState(state);
98
+ });
99
+ }, [setPopupState]);
100
+
101
+ // 点击 TabBar 时自动关闭弹窗(自定义 TabBar 或原生 TabBar 点击均会触发)
102
+ useTabItemTap(function () {
103
+ if (isPopup) return;
104
+ closeActivePopupRouter();
105
+ });
63
106
  return /*#__PURE__*/React.createElement(ComContext.Provider, {
64
107
  value: contextStore
65
108
  }, /*#__PURE__*/React.createElement(Component, props));
@@ -1,24 +1,13 @@
1
+ import type { GenerationResult } from "../toCodeTaro";
1
2
  interface FileNode {
2
3
  path: string;
3
4
  content: string | null;
4
5
  children?: FileNode[];
5
6
  }
6
- interface GenerateItem {
7
- type: string;
8
- content?: string;
9
- cssContent?: string;
10
- pageConfigContent?: string;
11
- name?: string;
12
- importManager?: {
13
- toCode: () => string;
14
- };
15
- tabBarConfig?: string;
16
- [key: string]: any;
17
- }
18
7
  /**
19
8
  * 根据数组生成文件结构 JSON 对象
20
- * @param items 包含 content、cssContent、pageConfigContent、tabBarConfig 等信息的数组
9
+ * @param result 包含 files 和 assets 的生成结果对象
21
10
  * @returns 返回文件结构的 JSON 对象数组
22
11
  */
23
- declare const generateTaroProjectJson: (items?: GenerateItem[]) => FileNode[];
12
+ declare const generateTaroProjectJson: (result: GenerationResult) => FileNode[];
24
13
  export default generateTaroProjectJson;