@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
@@ -0,0 +1,32 @@
1
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ export var EventEmitter = /*#__PURE__*/_createClass(function EventEmitter() {
5
+ var _this = this;
6
+ _classCallCheck(this, EventEmitter);
7
+ _defineProperty(this, "eventsCache", {});
8
+ _defineProperty(this, "addEventListner", function (evtName, listner) {
9
+ if (!_this.eventsCache[evtName]) {
10
+ _this.eventsCache[evtName] = new Set([listner]);
11
+ return;
12
+ }
13
+ _this.eventsCache[evtName].add(listner);
14
+ });
15
+ _defineProperty(this, "removeEventListner", function (evtName, listner) {
16
+ if (_this.eventsCache[evtName]) {
17
+ _this.eventsCache[evtName].delete(listner);
18
+ }
19
+ });
20
+ _defineProperty(this, "dispatch", function (evtName, detail) {
21
+ var _this$eventsCache$evt;
22
+ if (!_this.eventsCache[evtName]) {
23
+ // console.warn(`no listner on this ${evtName}`);
24
+ return;
25
+ }
26
+ var hasPreventDefault = false;
27
+ ((_this$eventsCache$evt = _this.eventsCache[evtName]) !== null && _this$eventsCache$evt !== void 0 ? _this$eventsCache$evt : []).forEach(function (listner) {
28
+ return listner(detail);
29
+ });
30
+ return hasPreventDefault;
31
+ });
32
+ });
@@ -1,3 +1,4 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
4
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
@@ -5,6 +6,7 @@ import _typeof from "@babel/runtime/helpers/esm/typeof";
5
6
  import { useState, useRef, useMemo, useEffect } from 'react';
6
7
  import { createReactiveInputHandler } from "../mybricks/createReactiveInputHandler";
7
8
  import { useAppContext, useParentSlot } from "./ComContext";
9
+ import { ComRefResolver } from "./comRefResolver";
8
10
 
9
11
  /** 深度代理:支持响应式更新 */
10
12
  export function deepProxy(target, onSet) {
@@ -42,47 +44,46 @@ export function useModel(rawData) {
42
44
  }, []);
43
45
  }
44
46
 
45
- /**
47
+ /**
46
48
  * 组件引用代理:
47
49
  * 1. 自动缓冲:访问未渲染组件时返回影子对象,缓冲后续指令
48
50
  * 2. 引用渗透:子作用域注册的真实引用自动同步至父级
49
51
  * 3. 自动同步清理:卸载时从作用域链中彻底移除,防止僵尸引用
52
+ *
53
+ * 使用 ComRefResolver 统一处理引用解析逻辑
50
54
  */
51
- export function proxyRefs(target, parentComRefs, globalTodoPool) {
55
+ export function proxyRefs(target, parentComRefs, todoPool) {
56
+ var _parentComRefs$curren, _target$$index;
57
+ // 创建解析器,链接父级解析器
58
+ var parentResolver = parentComRefs === null || parentComRefs === void 0 || (_parentComRefs$curren = parentComRefs.current) === null || _parentComRefs$curren === void 0 ? void 0 : _parentComRefs$curren.__resolver;
59
+ var scopeIndex = (_target$$index = target.$index) !== null && _target$$index !== void 0 ? _target$$index : 0;
60
+ var resolver = new ComRefResolver(target, parentResolver, todoPool, scopeIndex);
61
+
62
+ // 存储解析器引用,供子级使用
63
+ target.__resolver = resolver;
52
64
  return new Proxy(target, {
53
65
  get: function get(obj, prop) {
54
66
  if (prop === '__isProxy') return true;
67
+ if (prop === '__resolver') return resolver;
55
68
  if (prop === 'toJSON') return function () {
56
69
  return obj;
57
70
  };
58
- if (typeof prop === 'string' && prop.startsWith('u_') && obj[prop] === undefined) {
59
- // 懒加载影子对象
60
- return obj[prop] = new Proxy({
61
- __isShadow: true
62
- }, {
63
- get: function get(_, method) {
64
- if (method === '__isShadow') return true;
65
- return function () {
66
- var _obj$$index;
67
- if (!(globalTodoPool instanceof Map)) return;
68
- var instances = globalTodoPool.get(prop) || [];
69
- if (!globalTodoPool.has(prop)) globalTodoPool.set(prop, instances);
70
- var index = (_obj$$index = obj.$index) !== null && _obj$$index !== void 0 ? _obj$$index : 0;
71
- var todo = instances[index] || (instances[index] = {});
72
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
73
- args[_key] = arguments[_key];
74
- }
75
- todo[method] = args;
76
- };
77
- }
78
- });
71
+
72
+ // u_ 开头的组件引用,统一由解析器处理
73
+ if (typeof prop === 'string' && prop.startsWith('u_')) {
74
+ return resolver.get(prop);
79
75
  }
80
76
  return obj[prop];
81
77
  },
82
78
  set: function set(obj, prop, value) {
83
79
  var result = Reflect.set(obj, prop, value);
80
+
81
+ // 真实引用注册时,同步到解析器
84
82
  var isRealRef = typeof prop === 'string' && !prop.startsWith('$') && (value === null || value === void 0 ? void 0 : value.__isShadow) !== true;
85
- if (isRealRef && parentComRefs !== null && parentComRefs !== void 0 && parentComRefs.current) {
83
+ if (isRealRef && typeof prop === 'string' && prop.startsWith('u_')) {
84
+ resolver.set(prop, value);
85
+ } else if (isRealRef && parentComRefs !== null && parentComRefs !== void 0 && parentComRefs.current) {
86
+ // 非 u_ 开头的属性,保持原有的父级渗透逻辑
86
87
  try {
87
88
  parentComRefs.current[prop] = value;
88
89
  } catch (_unused) {}
@@ -91,8 +92,9 @@ export function proxyRefs(target, parentComRefs, globalTodoPool) {
91
92
  },
92
93
  deleteProperty: function deleteProperty(obj, prop) {
93
94
  var result = Reflect.deleteProperty(obj, prop);
94
- var isRealRef = typeof prop === 'string' && !prop.startsWith('$');
95
- if (isRealRef && parentComRefs !== null && parentComRefs !== void 0 && parentComRefs.current) {
95
+ if (typeof prop === 'string' && prop.startsWith('u_')) {
96
+ resolver.delete(prop);
97
+ } else if (typeof prop === 'string' && !prop.startsWith('$') && parentComRefs !== null && parentComRefs !== void 0 && parentComRefs.current) {
96
98
  try {
97
99
  delete parentComRefs.current[prop];
98
100
  } catch (_unused2) {}
@@ -102,7 +104,7 @@ export function proxyRefs(target, parentComRefs, globalTodoPool) {
102
104
  });
103
105
  }
104
106
 
105
- /**
107
+ /**
106
108
  * 组件输入绑定 Hook:
107
109
  * 1. 注册输入执行器
108
110
  * 2. 自动重放缓冲指令(精准索引匹配)
@@ -112,7 +114,7 @@ export function useBindInputs(scope, id, initialHandlers) {
112
114
  var _parentSlot$params$in, _parentSlot$params;
113
115
  var handlersRef = useRef(_objectSpread({}, initialHandlers));
114
116
  var _useAppContext = useAppContext(),
115
- globalTodoInputs = _useAppContext.globalTodoInputs;
117
+ todoPool = _useAppContext.todoPool;
116
118
  var parentSlot = useParentSlot();
117
119
  var index = (_parentSlot$params$in = parentSlot === null || parentSlot === void 0 || (_parentSlot$params = parentSlot.params) === null || _parentSlot$params === void 0 || (_parentSlot$params = _parentSlot$params.inputValues) === null || _parentSlot$params === void 0 ? void 0 : _parentSlot$params.index) !== null && _parentSlot$params$in !== void 0 ? _parentSlot$params$in : 0;
118
120
  useEffect(function () {
@@ -126,6 +128,7 @@ export function useBindInputs(scope, id, initialHandlers) {
126
128
  var proxy = new Proxy({}, {
127
129
  get: function get(target, pin) {
128
130
  if (pin === '__isShadow') return false;
131
+ if (pin === '__isLazyProxy') return false;
129
132
  if (pin === 'toJSON') return function () {
130
133
  return target;
131
134
  };
@@ -134,10 +137,8 @@ export function useBindInputs(scope, id, initialHandlers) {
134
137
  handlersRef.current[pin] = arg;
135
138
 
136
139
  // 处理指令重放
137
- var instances = globalTodoInputs === null || globalTodoInputs === void 0 ? void 0 : globalTodoInputs.get(id);
138
- var todo = (instances === null || instances === void 0 ? void 0 : instances[index]) || (instances === null || instances === void 0 ? void 0 : instances[0]);
139
- if (todo !== null && todo !== void 0 && todo[pin]) {
140
- var pendingArgs = todo[pin];
140
+ var pendingArgs = todoPool === null || todoPool === void 0 ? void 0 : todoPool.pop(id, index, pin);
141
+ if (pendingArgs) {
141
142
  if (pin === '_setData') {
142
143
  arg.apply(void 0, _toConsumableArray(pendingArgs));
143
144
  } else {
@@ -148,19 +149,12 @@ export function useBindInputs(scope, id, initialHandlers) {
148
149
  title: id
149
150
  });
150
151
  }
151
- delete todo[pin];
152
-
153
- // 检查全局清理
154
- var hasTasks = instances === null || instances === void 0 ? void 0 : instances.some(function (inst) {
155
- return inst && Object.keys(inst).length > 0;
156
- });
157
- if (!hasTasks) globalTodoInputs.delete(id);
158
152
  }
159
153
  } else {
160
154
  var handler = handlersRef.current[pin];
161
155
  if (typeof handler === 'function') {
162
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
163
- args[_key2 - 1] = arguments[_key2];
156
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
157
+ args[_key - 1] = arguments[_key];
164
158
  }
165
159
  return pin === '_setData' ? handler.apply(void 0, [arg].concat(args)) : createReactiveInputHandler({
166
160
  input: handler,
@@ -180,24 +174,65 @@ export function useBindInputs(scope, id, initialHandlers) {
180
174
  });
181
175
  }
182
176
  return proxy;
183
- }, [scope, id, globalTodoInputs, index]);
177
+ }, [scope, id, todoPool, index]);
184
178
  }
185
179
 
186
- /** 组件事件绑定 Hook */
187
- export function useBindEvents(props, context) {
180
+ /** 内置通用能力 Hook:_setStyle / _setData / show / hide / showOrHide */
181
+ export function useBuiltinHandlers(opts) {
182
+ var data = opts.data,
183
+ setDynamicStyle = opts.setDynamicStyle,
184
+ setShow = opts.setShow,
185
+ isPopup = opts.isPopup;
188
186
  return useMemo(function () {
187
+ var handlers = {
188
+ _setStyle: function _setStyle(style) {
189
+ setDynamicStyle(function (prev) {
190
+ return _objectSpread(_objectSpread({}, prev), style);
191
+ });
192
+ },
193
+ _setData: function _setData(path, value) {
194
+ var paths = path.split('.');
195
+ var current = data;
196
+ for (var i = 0; i < paths.length - 1; i++) {
197
+ if (!current[paths[i]]) current[paths[i]] = {};
198
+ current = current[paths[i]];
199
+ }
200
+ current[paths[paths.length - 1]] = value;
201
+ }
202
+ };
203
+ if (!isPopup) {
204
+ Object.assign(handlers, {
205
+ show: function show() {
206
+ return setShow(true);
207
+ },
208
+ hide: function hide() {
209
+ return setShow(false);
210
+ },
211
+ showOrHide: function showOrHide() {
212
+ return setShow(function (prev) {
213
+ return !prev;
214
+ });
215
+ }
216
+ });
217
+ }
218
+ return handlers;
219
+ }, [data, setDynamicStyle, setShow, isPopup]);
220
+ }
221
+
222
+ /**
223
+ * 组件输出绑定 Hook(与 useBindInputs 对称)
224
+ * - 从 props 提取事件函数,创建 eventProxy
225
+ * - 合并 slot outputs,注册到 comRefs.current.$outputs[id]
226
+ */
227
+ export function useBindOutputs(comRefs, id, props, enhancedSlots, context) {
228
+ var _comRefs$current;
229
+ var eventProxy = useMemo(function () {
189
230
  var events = {};
190
231
  Object.keys(props).forEach(function (key) {
191
232
  if (typeof props[key] === 'function') {
192
233
  var handler = props[key];
193
234
  var wrapped = function wrapped(original) {
194
- var _context$parentSlot;
195
- var value = context !== null && context !== void 0 && (_context$parentSlot = context.parentSlot) !== null && _context$parentSlot !== void 0 && (_context$parentSlot = _context$parentSlot.params) !== null && _context$parentSlot !== void 0 && _context$parentSlot.itemWrap ? {
196
- id: context.id,
197
- name: context.name,
198
- value: original
199
- } : original;
200
- return handler(value);
235
+ return handler(original);
201
236
  };
202
237
  wrapped.getConnections = function () {
203
238
  return [{
@@ -221,4 +256,32 @@ export function useBindEvents(props, context) {
221
256
  }
222
257
  });
223
258
  }, [props, context]);
259
+ if (comRefs !== null && comRefs !== void 0 && (_comRefs$current = comRefs.current) !== null && _comRefs$current !== void 0 && _comRefs$current.$outputs) {
260
+ var slotOutputsList = Object.values(enhancedSlots || {}).map(function (slot) {
261
+ return slot === null || slot === void 0 ? void 0 : slot.outputs;
262
+ }).filter(Boolean);
263
+ if (slotOutputsList.length > 0) {
264
+ comRefs.current.$outputs[id] = new Proxy({}, {
265
+ get: function get(_, prop) {
266
+ var _iterator = _createForOfIteratorHelper(slotOutputsList),
267
+ _step;
268
+ try {
269
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
270
+ var outputs = _step.value;
271
+ var fn = outputs[prop];
272
+ if (fn) return fn;
273
+ }
274
+ } catch (err) {
275
+ _iterator.e(err);
276
+ } finally {
277
+ _iterator.f();
278
+ }
279
+ return eventProxy[prop];
280
+ }
281
+ });
282
+ } else {
283
+ comRefs.current.$outputs[id] = eventProxy;
284
+ }
285
+ }
286
+ return eventProxy;
224
287
  }
@@ -1,4 +1,6 @@
1
1
  export * from "./hooks";
2
+ export { TodoPool } from "./pool";
3
+ export { ComRefResolver } from "./comRefResolver";
2
4
  export { WithCom, WithWrapper } from "./with";
3
5
  export { PopupRenderer } from "./PopupRenderer";
4
6
  export { pageRouter, router } from "./pageRouter";
@@ -1,8 +1,11 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
3
  import _createClass from "@babel/runtime/helpers/esm/createClass";
3
4
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
5
  // @ts-ignore 运行时由宿主项目提供 @tarojs/taro
5
- import Taro from '@tarojs/taro';
6
+ import Taro from "@tarojs/taro";
7
+ // @ts-ignore 运行时由宿主项目提供
8
+ import tabBarConfig from "@/custom-tab-bar/tabBar.json";
6
9
  import { Page } from "../mybricks";
7
10
 
8
11
  /**
@@ -19,7 +22,17 @@ var TaroRouter = /*#__PURE__*/function () {
19
22
  value: function getParams(name) {
20
23
  var _instance$router;
21
24
  var instance = Taro.getCurrentInstance();
22
- var params = ((_instance$router = instance.router) === null || _instance$router === void 0 ? void 0 : _instance$router.params) || {};
25
+ var inputParams = ((_instance$router = instance.router) === null || _instance$router === void 0 ? void 0 : _instance$router.params) || {};
26
+
27
+ // 直接页面"打开",会有data包裹参数
28
+ // 使用“跳转到”逻辑组件,会直接传递参数
29
+ // TODO: 没有特殊字段和结构可以判断,现只能尽量加条件来判断
30
+ var params = Object.keys(inputParams).length === 2 && inputParams.data && typeof inputParams.data === "string" ? inputParams : {
31
+ data: Object.keys(inputParams).length > 1 ? JSON.stringify(_objectSpread(_objectSpread({}, inputParams), {}, {
32
+ $taroTimestamp: undefined
33
+ })) : undefined,
34
+ $taroTimestamp: inputParams.$taroTimestamp
35
+ };
23
36
 
24
37
  // 备份参数,解决某些生命周期下 Taro 获取不到 params 的问题
25
38
  if (!params.data && this.paramsBackup[name]) {
@@ -27,34 +40,50 @@ var TaroRouter = /*#__PURE__*/function () {
27
40
  data: this.paramsBackup[name]
28
41
  };
29
42
  }
43
+
44
+ // 解析真实参数
45
+ var paramsDataStr = params.data ? decodeURIComponent(params.data) : undefined;
46
+ var paramsData;
47
+ try {
48
+ paramsData = paramsDataStr ? JSON.parse(paramsDataStr) : undefined;
49
+ } catch (error) {
50
+ paramsData = paramsDataStr;
51
+ }
30
52
  return {
31
- value: params
53
+ value: paramsData
32
54
  };
33
55
  }
34
56
  }, {
35
57
  key: "push",
36
58
  value: function push(name, _ref) {
37
59
  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) : '')
60
+ var path = "pages/".concat(name, "/index");
61
+ var navigateType = this.isTabBarPage(path) ? "switchTab" : "navigateTo";
62
+ this.navigate(navigateType, name, {
63
+ value: value
45
64
  });
46
65
  }
47
66
  }, {
48
67
  key: "replace",
49
68
  value: function replace(name, _ref2) {
50
69
  var value = _ref2.value;
70
+ var path = "pages/".concat(name, "/index");
71
+ var navigateType = this.isTabBarPage(path) ? "switchTab" : "redirectTo";
72
+ this.navigate(navigateType, name, {
73
+ value: value
74
+ });
75
+ }
76
+ }, {
77
+ key: "navigate",
78
+ value: function navigate(type, name, _ref3) {
79
+ var value = _ref3.value;
51
80
  var url = "/pages/".concat(name, "/index");
52
- var dataStr = value ? encodeURIComponent(JSON.stringify(value)) : '';
81
+ var dataStr = value ? encodeURIComponent(JSON.stringify(value)) : "";
53
82
  if (dataStr) {
54
83
  this.paramsBackup[name] = dataStr;
55
84
  }
56
- Taro.redirectTo({
57
- url: "".concat(url).concat(dataStr ? "?data=".concat(dataStr) : '')
85
+ Taro[type]({
86
+ url: "".concat(url).concat(dataStr ? "?data=".concat(dataStr) : "")
58
87
  });
59
88
  }
60
89
  }, {
@@ -62,6 +91,20 @@ var TaroRouter = /*#__PURE__*/function () {
62
91
  value: function pop() {
63
92
  Taro.navigateBack();
64
93
  }
94
+
95
+ /**
96
+ * 判断是否为标签栏页面
97
+ * @param pagePath 页面路径
98
+ * @returns 是否为标签栏页面
99
+ */
100
+ }, {
101
+ key: "isTabBarPage",
102
+ value: function isTabBarPage(pagePath) {
103
+ var _tabBarConfig$tabBar;
104
+ return tabBarConfig === null || tabBarConfig === void 0 || (_tabBarConfig$tabBar = tabBarConfig.tabBar) === null || _tabBarConfig$tabBar === void 0 || (_tabBarConfig$tabBar = _tabBarConfig$tabBar.list) === null || _tabBarConfig$tabBar === void 0 ? void 0 : _tabBarConfig$tabBar.some(function (item) {
105
+ return item.pagePath === pagePath;
106
+ });
107
+ }
65
108
  }]);
66
109
  return TaroRouter;
67
110
  }();
@@ -0,0 +1,52 @@
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
+ /**
5
+ * 待执行指令池
6
+ * 结构:Map<组件ID, Map<索引, Record<方法名, 参数数组>>>
7
+ */
8
+ export var TodoPool = /*#__PURE__*/function () {
9
+ function TodoPool() {
10
+ _classCallCheck(this, TodoPool);
11
+ _defineProperty(this, "pool", new Map());
12
+ }
13
+ _createClass(TodoPool, [{
14
+ key: "push",
15
+ value: /** 存:记录待执行指令 */
16
+ function push(id, index, method, args) {
17
+ if (!this.pool.has(id)) {
18
+ this.pool.set(id, new Map());
19
+ }
20
+ var instances = this.pool.get(id);
21
+ if (!instances.has(index)) {
22
+ instances.set(index, {});
23
+ }
24
+ instances.get(index)[method] = args;
25
+ }
26
+
27
+ /** 取:获取并物理删除指令 */
28
+ }, {
29
+ key: "pop",
30
+ value: function pop(id, index, method) {
31
+ var instances = this.pool.get(id);
32
+ if (!instances) return undefined;
33
+ var todo = instances.get(index);
34
+ if (todo && todo[method]) {
35
+ var args = todo[method];
36
+ delete todo[method];
37
+
38
+ // 自动清理:如果当前索引下没指令了,删掉索引容器
39
+ if (Object.keys(todo).length === 0) {
40
+ instances.delete(index);
41
+ }
42
+ // 如果当前组件下没索引了,删掉整个 ID
43
+ if (instances.size === 0) {
44
+ this.pool.delete(id);
45
+ }
46
+ return args;
47
+ }
48
+ return undefined;
49
+ }
50
+ }]);
51
+ return TodoPool;
52
+ }();
@@ -1,13 +1,52 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- import React, { useMemo, useRef } from "react";
3
+ import React, { useMemo, useRef, useState } from "react";
4
4
  import ComContext, { SlotProvider, useAppContext, useParentSlot } from "./ComContext";
5
5
  import { createReactiveInputHandler } from "../mybricks/createReactiveInputHandler";
6
6
  import { proxyRefs } from "./hooks";
7
+
8
+ /** Channel Proxy 类型 */
9
+
10
+ /** Slot 渲染函数类型 */
11
+
12
+ /** 浅比较两个对象的第一层 key-value */
13
+ function shallowEqual(a, b) {
14
+ if (a === b) return true;
15
+ if (!a || !b) return false;
16
+ var keysA = Object.keys(a);
17
+ var keysB = Object.keys(b);
18
+ if (keysA.length !== keysB.length) return false;
19
+ return keysA.every(function (key) {
20
+ return a[key] === b[key];
21
+ });
22
+ }
23
+
24
+ /**
25
+ * 合并 slot 参数
26
+ * 只有当有实际的 inputValues 时才合并,否则保持 undefined 以便从父级继承
27
+ */
28
+ function mergeSlotParams(stateInputValues, params) {
29
+ var hasStateInputValues = stateInputValues && Object.keys(stateInputValues).length > 0;
30
+ var hasParamsInputValues = (params === null || params === void 0 ? void 0 : params.inputValues) && Object.keys(params.inputValues).length > 0;
31
+ if (!hasStateInputValues && !hasParamsInputValues) {
32
+ return params || {};
33
+ }
34
+ return _objectSpread(_objectSpread({}, params || {}), {}, {
35
+ inputValues: _objectSpread(_objectSpread({}, stateInputValues || {}), (params === null || params === void 0 ? void 0 : params.inputValues) || {})
36
+ });
37
+ }
38
+
39
+ /**
40
+ * 生成作用域 ID
41
+ */
42
+ function createScopeId(id, slotKey, rawScope) {
43
+ return "".concat(id, ".").concat(slotKey, "::").concat(String(rawScope));
44
+ }
45
+
7
46
  /**
8
- * 创建一个具有“向上渗透”和“隔离 Todo 池”能力的 comRefs 对象
47
+ * 创建一个具有"向上渗透"和"隔离 Todo 池"能力的 comRefs 对象
9
48
  */
10
- function createPenetratingComRefs(parentComRefs, globalTodoPool) {
49
+ function createPenetratingComRefs(parentComRefs, todoPool) {
11
50
  var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
12
51
  var localTarget = {
13
52
  $inputs: {},
@@ -15,7 +54,7 @@ function createPenetratingComRefs(parentComRefs, globalTodoPool) {
15
54
  $index: index
16
55
  };
17
56
  return {
18
- current: proxyRefs(localTarget, parentComRefs, globalTodoPool)
57
+ current: proxyRefs(localTarget, parentComRefs, todoPool)
19
58
  };
20
59
  }
21
60
  function SlotParamsBridge(props) {
@@ -32,7 +71,7 @@ function SlotParamsBridge(props) {
32
71
  })
33
72
  }, content);
34
73
  }
35
- function createChannelProxy(title) {
74
+ function createChannelProxy(title, onInputCall) {
36
75
  var handlersMap = {};
37
76
  return new Proxy({}, {
38
77
  get: function get(_t, pin) {
@@ -41,6 +80,8 @@ function createChannelProxy(title) {
41
80
  handlersMap[pin] = arg;
42
81
  return;
43
82
  }
83
+ // 通知外部有输入调用(用于 scope 插槽的 inputValues 更新)
84
+ onInputCall === null || onInputCall === void 0 || onInputCall(pin, arg);
44
85
  var handler = handlersMap[pin];
45
86
  if (typeof handler === "function") {
46
87
  return createReactiveInputHandler({
@@ -57,8 +98,12 @@ function createChannelProxy(title) {
57
98
  export function useEnhancedSlots(rawSlots, id) {
58
99
  var _useAppContext = useAppContext(),
59
100
  parentComRefs = _useAppContext.comRefs,
60
- globalTodoInputs = _useAppContext.globalTodoInputs;
101
+ todoPool = _useAppContext.todoPool;
61
102
  var slotStoreRef = useRef({});
103
+ // 用于触发重渲染的状态
104
+ var _useState = useState({}),
105
+ _useState2 = _slicedToArray(_useState, 2),
106
+ forceUpdate = _useState2[1];
62
107
  return useMemo(function () {
63
108
  if (!rawSlots) return {};
64
109
  var nextSlots = {};
@@ -66,33 +111,54 @@ export function useEnhancedSlots(rawSlots, id) {
66
111
  var _ref2 = _slicedToArray(_ref, 2),
67
112
  slotKey = _ref2[0],
68
113
  slotDef = _ref2[1];
114
+ // 创建输入回调,当 inputs 被调用时更新 inputValues 并触发重渲染
115
+ var onInputCall = function onInputCall(pin, value) {
116
+ var state = slotStoreRef.current[slotKey];
117
+ if (state) {
118
+ if (!state._inputValues) state._inputValues = {};
119
+ state._inputValues[pin] = value;
120
+ // 触发重渲染
121
+ forceUpdate({});
122
+ }
123
+ };
69
124
  var state = slotStoreRef.current[slotKey] || (slotStoreRef.current[slotKey] = {
70
- inputs: createChannelProxy("".concat(id, ".").concat(slotKey, ".inputs")),
125
+ inputs: createChannelProxy("".concat(id, ".").concat(slotKey, ".inputs"), onInputCall),
71
126
  outputs: createChannelProxy("".concat(id, ".").concat(slotKey, ".outputs")),
72
127
  _inputs: createChannelProxy("".concat(id, ".").concat(slotKey, "._inputs")),
73
128
  _scopedComRefs: {},
129
+ _inputValues: {},
74
130
  _render: undefined,
75
131
  render: function render(params) {
76
- var _ref3, _params$key, _params$inputValues, _params$inputValues2, _params$inputValues$i, _params$inputValues3, _ref4;
132
+ var _state$_lastMergedPar, _stableParams$inputVa, _stableParams$inputVa2, _stableParams$inputVa3, _stableParams$inputVa4, _state$_scopedComRefs;
77
133
  var r = state._render;
78
- // 只有存在 key index 时才认为是“多实例作用域插槽”,需要实例隔离
79
- var rawScope = (_ref3 = (_params$key = params === null || params === void 0 ? void 0 : params.key) !== null && _params$key !== void 0 ? _params$key : params === null || params === void 0 || (_params$inputValues = params.inputValues) === null || _params$inputValues === void 0 ? void 0 : _params$inputValues.index) !== null && _ref3 !== void 0 ? _ref3 : params === null || params === void 0 || (_params$inputValues2 = params.inputValues) === null || _params$inputValues2 === void 0 || (_params$inputValues2 = _params$inputValues2.itemData) === null || _params$inputValues2 === void 0 ? void 0 : _params$inputValues2.id;
134
+ var mergedParams = mergeSlotParams(state._inputValues, params);
135
+
136
+ // 浅比较 inputValues,内容不变时复用上次引用,避免 useEffect 死循环
137
+ if (state._lastMergedParams && shallowEqual(mergedParams === null || mergedParams === void 0 ? void 0 : mergedParams.inputValues, (_state$_lastMergedPar = state._lastMergedParams) === null || _state$_lastMergedPar === void 0 ? void 0 : _state$_lastMergedPar.inputValues)) {
138
+ // 内容没变,复用旧引用
139
+ } else {
140
+ state._lastMergedParams = mergedParams;
141
+ }
142
+ var stableParams = state._lastMergedParams;
143
+
144
+ // 只有存在 key 或 index 时才认为是"多实例作用域插槽",需要实例隔离
145
+ var rawScope = (_stableParams$inputVa = stableParams === null || stableParams === void 0 || (_stableParams$inputVa2 = stableParams.inputValues) === null || _stableParams$inputVa2 === void 0 ? void 0 : _stableParams$inputVa2.index) !== null && _stableParams$inputVa !== void 0 ? _stableParams$inputVa : params === null || params === void 0 ? void 0 : params.key;
80
146
  if (rawScope === undefined || rawScope === null) {
81
147
  return /*#__PURE__*/React.createElement(SlotParamsBridge, {
82
148
  state: state,
83
- params: params,
149
+ params: stableParams,
84
150
  render: r
85
151
  });
86
152
  }
87
- var scopeId = "".concat(id, ".").concat(slotKey, "::").concat(String(rawScope));
88
- var index = (_params$inputValues$i = params === null || params === void 0 || (_params$inputValues3 = params.inputValues) === null || _params$inputValues3 === void 0 ? void 0 : _params$inputValues3.index) !== null && _params$inputValues$i !== void 0 ? _params$inputValues$i : 0;
89
- var scopedComRefs = (_ref4 = state._scopedComRefs)[scopeId] || (_ref4[scopeId] = createPenetratingComRefs(parentComRefs, globalTodoInputs, index));
153
+ var scopeId = createScopeId(id, slotKey, rawScope);
154
+ var index = (_stableParams$inputVa3 = stableParams === null || stableParams === void 0 || (_stableParams$inputVa4 = stableParams.inputValues) === null || _stableParams$inputVa4 === void 0 ? void 0 : _stableParams$inputVa4.index) !== null && _stableParams$inputVa3 !== void 0 ? _stableParams$inputVa3 : 0;
155
+ var scopedComRefs = (_state$_scopedComRefs = state._scopedComRefs)[scopeId] || (_state$_scopedComRefs[scopeId] = createPenetratingComRefs(parentComRefs, todoPool, index));
90
156
  return /*#__PURE__*/React.createElement(ScopedComContextProvider, {
91
157
  comRefs: scopedComRefs,
92
158
  scopeId: scopeId
93
159
  }, /*#__PURE__*/React.createElement(SlotParamsBridge, {
94
160
  state: state,
95
- params: params,
161
+ params: stableParams,
96
162
  render: r
97
163
  }));
98
164
  }
@@ -106,7 +172,7 @@ export function useEnhancedSlots(rawSlots, id) {
106
172
  });
107
173
  });
108
174
  return nextSlots;
109
- }, [rawSlots, id, parentComRefs, globalTodoInputs]);
175
+ }, [rawSlots, id, parentComRefs, todoPool]);
110
176
  }
111
177
  export function ScopedComContextProvider(props) {
112
178
  var parent = useAppContext();