@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.cjs.js +28 -25
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +28 -25
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -977,37 +977,29 @@ class ComRefResolver {
|
|
|
977
977
|
// 4. 创建影子对象
|
|
978
978
|
return this.createShadowProxy(id);
|
|
979
979
|
}
|
|
980
|
-
/**
|
|
981
|
-
* 注册真实引用
|
|
982
|
-
*/
|
|
980
|
+
/** 注册真实引用,并向上渗透 */
|
|
983
981
|
set(id, ref) {
|
|
984
982
|
var _a;
|
|
985
983
|
this.registry[id] = ref;
|
|
986
|
-
// 向上渗透到父级
|
|
987
984
|
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.set(id, ref);
|
|
988
985
|
}
|
|
989
|
-
/**
|
|
990
|
-
* 删除引用
|
|
991
|
-
*/
|
|
986
|
+
/** 删除引用 */
|
|
992
987
|
delete(id) {
|
|
993
988
|
var _a;
|
|
994
989
|
delete this.registry[id];
|
|
995
990
|
(_a = this.parent) === null || _a === void 0 ? void 0 : _a.delete(id);
|
|
996
991
|
}
|
|
997
|
-
/**
|
|
998
|
-
* 查找真实引用(仅用于父级链查找)
|
|
999
|
-
*/
|
|
992
|
+
/** 在本地查找真实引用(不创建影子) */
|
|
1000
993
|
findRealRef(id) {
|
|
1001
|
-
var _a
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
return local;
|
|
994
|
+
var _a;
|
|
995
|
+
if (this.registry[id] && !this.registry[id].__isShadow) {
|
|
996
|
+
return this.registry[id];
|
|
1005
997
|
}
|
|
1006
|
-
return (
|
|
998
|
+
return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.findRealRef(id);
|
|
1007
999
|
}
|
|
1008
1000
|
/**
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
1001
|
+
* 创建影子代理对象
|
|
1002
|
+
* 调用时动态检查真实引用,未找到则缓冲到 TodoPool
|
|
1011
1003
|
*/
|
|
1012
1004
|
createShadowProxy(id) {
|
|
1013
1005
|
const registry = this.registry;
|
|
@@ -1019,7 +1011,6 @@ class ComRefResolver {
|
|
|
1019
1011
|
return true;
|
|
1020
1012
|
return (...args) => {
|
|
1021
1013
|
// 动态检查是否已有真实引用
|
|
1022
|
-
// 注意:这里直接检查 registry[id],因为真实引用注册时会覆盖它
|
|
1023
1014
|
const realRef = registry[id];
|
|
1024
1015
|
if (realRef && !realRef.__isShadow) {
|
|
1025
1016
|
if (typeof realRef[method] === 'function') {
|
|
@@ -1139,11 +1130,13 @@ function proxyRefs(target, parentComRefs, todoPool) {
|
|
|
1139
1130
|
* 3. 生命周期自动化:卸载时自动注销引用渗透路径
|
|
1140
1131
|
*/
|
|
1141
1132
|
function useBindInputs(scope, id, initialHandlers) {
|
|
1142
|
-
var _a, _b, _c;
|
|
1133
|
+
var _a, _b, _c, _d, _e;
|
|
1143
1134
|
const handlersRef = react.useRef({ ...initialHandlers });
|
|
1144
1135
|
const { todoPool } = useAppContext();
|
|
1145
1136
|
const parentSlot = useParentSlot();
|
|
1146
|
-
|
|
1137
|
+
// 优先从 scope(comRefs)获取 $index,与 proxyRefs 的 scopeIndex 保持一致
|
|
1138
|
+
// 避免条件容器 slot 继承了循环列表的 index 导致 push/pop 不匹配
|
|
1139
|
+
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;
|
|
1147
1140
|
react.useEffect(() => {
|
|
1148
1141
|
return () => {
|
|
1149
1142
|
if (scope === null || scope === void 0 ? void 0 : scope.current) {
|
|
@@ -1185,8 +1178,9 @@ function useBindInputs(scope, id, initialHandlers) {
|
|
|
1185
1178
|
};
|
|
1186
1179
|
}
|
|
1187
1180
|
});
|
|
1188
|
-
if (scope === null || scope === void 0 ? void 0 : scope.current)
|
|
1181
|
+
if (scope === null || scope === void 0 ? void 0 : scope.current) {
|
|
1189
1182
|
scope.current[id] = proxy;
|
|
1183
|
+
}
|
|
1190
1184
|
if (initialHandlers) {
|
|
1191
1185
|
Object.keys(initialHandlers).forEach(pin => proxy[pin](initialHandlers[pin]));
|
|
1192
1186
|
}
|
|
@@ -1216,7 +1210,7 @@ function useBuiltinHandlers(opts) {
|
|
|
1216
1210
|
Object.assign(handlers, {
|
|
1217
1211
|
show: () => setShow(true),
|
|
1218
1212
|
hide: () => setShow(false),
|
|
1219
|
-
showOrHide: () => setShow(
|
|
1213
|
+
showOrHide: (val) => setShow(!!val),
|
|
1220
1214
|
});
|
|
1221
1215
|
}
|
|
1222
1216
|
return handlers;
|
|
@@ -1331,10 +1325,16 @@ class TabbarInstance {
|
|
|
1331
1325
|
}
|
|
1332
1326
|
const tabbarIns = new TabbarInstance();
|
|
1333
1327
|
|
|
1334
|
-
function useAppCreateContext(id) {
|
|
1328
|
+
function useAppCreateContext(id, parentComRefs, moduleId, moduleOutputs) {
|
|
1335
1329
|
const { request, rootConfig } = getCoreRuntime();
|
|
1336
1330
|
const todoPool = react.useMemo(() => new TodoPool(), []);
|
|
1337
1331
|
const comRefs = react.useRef(proxyRefs({ $inputs: {}, $outputs: {} }, undefined, todoPool));
|
|
1332
|
+
// 模块场景:把 $inputs 注册到页面 comRefs 上,使页面调用能找到 handler
|
|
1333
|
+
react.useMemo(() => {
|
|
1334
|
+
if ((parentComRefs === null || parentComRefs === void 0 ? void 0 : parentComRefs.current) && moduleId) {
|
|
1335
|
+
parentComRefs.current[moduleId] = comRefs.current.$inputs;
|
|
1336
|
+
}
|
|
1337
|
+
}, []);
|
|
1338
1338
|
const $vars = react.useRef({});
|
|
1339
1339
|
const $fxs = react.useRef({});
|
|
1340
1340
|
const [popupState, setPopupState] = react.useState({
|
|
@@ -1393,12 +1393,14 @@ function useAppCreateContext(id) {
|
|
|
1393
1393
|
tabBar: [],
|
|
1394
1394
|
useTabBar: false,
|
|
1395
1395
|
}).current;
|
|
1396
|
+
const moduleOutputsRef = react.useRef(moduleOutputs || {});
|
|
1396
1397
|
return react.useMemo(() => ({
|
|
1397
1398
|
comRefs,
|
|
1398
1399
|
$vars,
|
|
1399
1400
|
$fxs,
|
|
1400
1401
|
todoPool,
|
|
1401
1402
|
appContext,
|
|
1403
|
+
moduleOutputs: moduleOutputsRef.current,
|
|
1402
1404
|
popupState,
|
|
1403
1405
|
setPopupState
|
|
1404
1406
|
}), [popupState]);
|
|
@@ -1595,7 +1597,8 @@ const WithCom = (props) => {
|
|
|
1595
1597
|
};
|
|
1596
1598
|
const WithWrapper = (id, Component) => {
|
|
1597
1599
|
return function WrappedComponent(props) {
|
|
1598
|
-
const
|
|
1600
|
+
const { controller, onEvents, parentComRefs, moduleId, ...restProps } = props;
|
|
1601
|
+
const contextStore = useAppCreateContext(id, parentComRefs, moduleId, onEvents);
|
|
1599
1602
|
const { setPopupState } = contextStore;
|
|
1600
1603
|
const isPopup = Component.isPopup;
|
|
1601
1604
|
// 通过发布订阅模式解耦弹窗状态变化
|
|
@@ -1608,7 +1611,7 @@ const WithWrapper = (id, Component) => {
|
|
|
1608
1611
|
return;
|
|
1609
1612
|
closeActivePopupRouter();
|
|
1610
1613
|
});
|
|
1611
|
-
return (jsxRuntime.jsx(ComContext.Provider, { value: contextStore, children: jsxRuntime.jsx(Component, { ...
|
|
1614
|
+
return (jsxRuntime.jsx(ComContext.Provider, { value: contextStore, children: jsxRuntime.jsx(Component, { ...restProps }) }));
|
|
1612
1615
|
};
|
|
1613
1616
|
};
|
|
1614
1617
|
|