@mybricks/taro-core 0.1.2 → 0.1.3

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.
package/dist/index.esm.js CHANGED
@@ -957,37 +957,29 @@ class ComRefResolver {
957
957
  // 4. 创建影子对象
958
958
  return this.createShadowProxy(id);
959
959
  }
960
- /**
961
- * 注册真实引用
962
- */
960
+ /** 注册真实引用,并向上渗透 */
963
961
  set(id, ref) {
964
962
  var _a;
965
963
  this.registry[id] = ref;
966
- // 向上渗透到父级
967
964
  (_a = this.parent) === null || _a === void 0 ? void 0 : _a.set(id, ref);
968
965
  }
969
- /**
970
- * 删除引用
971
- */
966
+ /** 删除引用 */
972
967
  delete(id) {
973
968
  var _a;
974
969
  delete this.registry[id];
975
970
  (_a = this.parent) === null || _a === void 0 ? void 0 : _a.delete(id);
976
971
  }
977
- /**
978
- * 查找真实引用(仅用于父级链查找)
979
- */
972
+ /** 在本地查找真实引用(不创建影子) */
980
973
  findRealRef(id) {
981
- var _a, _b;
982
- const local = this.registry[id];
983
- if (local && !local.__isShadow) {
984
- return local;
974
+ var _a;
975
+ if (this.registry[id] && !this.registry[id].__isShadow) {
976
+ return this.registry[id];
985
977
  }
986
- return (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.findRealRef(id)) !== null && _b !== void 0 ? _b : null;
978
+ return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.findRealRef(id);
987
979
  }
988
980
  /**
989
- * 创建影子对象
990
- * 关键:影子对象的方法被调用时,会动态查找真实引用
981
+ * 创建影子代理对象
982
+ * 调用时动态检查真实引用,未找到则缓冲到 TodoPool
991
983
  */
992
984
  createShadowProxy(id) {
993
985
  const registry = this.registry;
@@ -999,7 +991,6 @@ class ComRefResolver {
999
991
  return true;
1000
992
  return (...args) => {
1001
993
  // 动态检查是否已有真实引用
1002
- // 注意:这里直接检查 registry[id],因为真实引用注册时会覆盖它
1003
994
  const realRef = registry[id];
1004
995
  if (realRef && !realRef.__isShadow) {
1005
996
  if (typeof realRef[method] === 'function') {
@@ -1119,11 +1110,13 @@ function proxyRefs(target, parentComRefs, todoPool) {
1119
1110
  * 3. 生命周期自动化:卸载时自动注销引用渗透路径
1120
1111
  */
1121
1112
  function useBindInputs(scope, id, initialHandlers) {
1122
- var _a, _b, _c;
1113
+ var _a, _b, _c, _d, _e;
1123
1114
  const handlersRef = useRef({ ...initialHandlers });
1124
1115
  const { todoPool } = useAppContext();
1125
1116
  const parentSlot = useParentSlot();
1126
- const index = (_c = (_b = (_a = parentSlot === null || parentSlot === void 0 ? void 0 : parentSlot.params) === null || _a === void 0 ? void 0 : _a.inputValues) === null || _b === void 0 ? void 0 : _b.index) !== null && _c !== void 0 ? _c : 0;
1117
+ // 优先从 scope(comRefs)获取 $index,与 proxyRefs scopeIndex 保持一致
1118
+ // 避免条件容器 slot 继承了循环列表的 index 导致 push/pop 不匹配
1119
+ const index = (_e = (_b = (_a = scope === null || scope === void 0 ? void 0 : scope.current) === null || _a === void 0 ? void 0 : _a.$index) !== null && _b !== void 0 ? _b : (_d = (_c = parentSlot === null || parentSlot === void 0 ? void 0 : parentSlot.params) === null || _c === void 0 ? void 0 : _c.inputValues) === null || _d === void 0 ? void 0 : _d.index) !== null && _e !== void 0 ? _e : 0;
1127
1120
  useEffect(() => {
1128
1121
  return () => {
1129
1122
  if (scope === null || scope === void 0 ? void 0 : scope.current) {
@@ -1165,8 +1158,9 @@ function useBindInputs(scope, id, initialHandlers) {
1165
1158
  };
1166
1159
  }
1167
1160
  });
1168
- if (scope === null || scope === void 0 ? void 0 : scope.current)
1161
+ if (scope === null || scope === void 0 ? void 0 : scope.current) {
1169
1162
  scope.current[id] = proxy;
1163
+ }
1170
1164
  if (initialHandlers) {
1171
1165
  Object.keys(initialHandlers).forEach(pin => proxy[pin](initialHandlers[pin]));
1172
1166
  }
@@ -1196,7 +1190,7 @@ function useBuiltinHandlers(opts) {
1196
1190
  Object.assign(handlers, {
1197
1191
  show: () => setShow(true),
1198
1192
  hide: () => setShow(false),
1199
- showOrHide: () => setShow((prev) => !prev),
1193
+ showOrHide: (val) => setShow(!!val),
1200
1194
  });
1201
1195
  }
1202
1196
  return handlers;
@@ -1311,10 +1305,16 @@ class TabbarInstance {
1311
1305
  }
1312
1306
  const tabbarIns = new TabbarInstance();
1313
1307
 
1314
- function useAppCreateContext(id) {
1308
+ function useAppCreateContext(id, parentComRefs, moduleId, moduleOutputs) {
1315
1309
  const { request, rootConfig } = getCoreRuntime();
1316
1310
  const todoPool = useMemo(() => new TodoPool(), []);
1317
1311
  const comRefs = useRef(proxyRefs({ $inputs: {}, $outputs: {} }, undefined, todoPool));
1312
+ // 模块场景:把 $inputs 注册到页面 comRefs 上,使页面调用能找到 handler
1313
+ useMemo(() => {
1314
+ if ((parentComRefs === null || parentComRefs === void 0 ? void 0 : parentComRefs.current) && moduleId) {
1315
+ parentComRefs.current[moduleId] = comRefs.current.$inputs;
1316
+ }
1317
+ }, []);
1318
1318
  const $vars = useRef({});
1319
1319
  const $fxs = useRef({});
1320
1320
  const [popupState, setPopupState] = useState({
@@ -1373,12 +1373,14 @@ function useAppCreateContext(id) {
1373
1373
  tabBar: [],
1374
1374
  useTabBar: false,
1375
1375
  }).current;
1376
+ const moduleOutputsRef = useRef(moduleOutputs || {});
1376
1377
  return useMemo(() => ({
1377
1378
  comRefs,
1378
1379
  $vars,
1379
1380
  $fxs,
1380
1381
  todoPool,
1381
1382
  appContext,
1383
+ moduleOutputs: moduleOutputsRef.current,
1382
1384
  popupState,
1383
1385
  setPopupState
1384
1386
  }), [popupState]);
@@ -1575,7 +1577,8 @@ const WithCom = (props) => {
1575
1577
  };
1576
1578
  const WithWrapper = (id, Component) => {
1577
1579
  return function WrappedComponent(props) {
1578
- const contextStore = useAppCreateContext(id);
1580
+ const { controller, onEvents, parentComRefs, moduleId, ...restProps } = props;
1581
+ const contextStore = useAppCreateContext(id, parentComRefs, moduleId, onEvents);
1579
1582
  const { setPopupState } = contextStore;
1580
1583
  const isPopup = Component.isPopup;
1581
1584
  // 通过发布订阅模式解耦弹窗状态变化
@@ -1588,7 +1591,7 @@ const WithWrapper = (id, Component) => {
1588
1591
  return;
1589
1592
  closeActivePopupRouter();
1590
1593
  });
1591
- return (jsx(ComContext.Provider, { value: contextStore, children: jsx(Component, { ...props }) }));
1594
+ return (jsx(ComContext.Provider, { value: contextStore, children: jsx(Component, { ...restProps }) }));
1592
1595
  };
1593
1596
  };
1594
1597