@mybricks/to-code-taro 1.1.5 → 1.1.7
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/cjs/core/mybricks/Subject.js +9 -5
- package/dist/cjs/core/mybricks/createJSHandle.js +43 -3
- package/dist/cjs/core/utils/comRefResolver.js +112 -0
- package/dist/cjs/core/utils/event.js +53 -0
- package/dist/cjs/core/utils/hooks.js +71 -29
- package/dist/cjs/core/utils/index.js +3 -0
- package/dist/cjs/core/utils/pageRouter.js +34 -11
- package/dist/cjs/core/utils/slots.js +55 -9
- package/dist/cjs/core/utils/tabbar.js +56 -0
- package/dist/cjs/core/utils/useContext.js +42 -2
- package/dist/cjs/core/utils/with.js +9 -34
- package/dist/cjs/generate/generateTaroProjectJson.js +3 -18
- package/dist/cjs/generate/utils/appConfig.d.ts +1 -1
- package/dist/cjs/generate/utils/appConfig.js +22 -12
- package/dist/cjs/generate/utils/commonDir.js +9 -0
- package/dist/cjs/generate/utils/customTabBar.d.ts +11 -0
- package/dist/cjs/generate/utils/customTabBar.js +73 -0
- package/dist/cjs/generate/utils/fileNode.d.ts +4 -0
- package/dist/cjs/generate/utils/fileNode.js +12 -2
- package/dist/cjs/handleCom.js +15 -16
- package/dist/cjs/handleGlobal.d.ts +1 -1
- package/dist/cjs/handleGlobal.js +6 -0
- package/dist/cjs/handleSlot.js +5 -10
- package/dist/cjs/processors/processScene.js +13 -1
- package/dist/cjs/processors/processSceneLogic.js +2 -6
- package/dist/cjs/taro-template.json +364 -66
- package/dist/cjs/toCodeTaro.d.ts +1 -2
- package/dist/cjs/utils/builder/buildResult.js +1 -2
- package/dist/cjs/utils/common/ImportManager.d.ts +7 -0
- package/dist/cjs/utils/common/ImportManager.js +19 -1
- package/dist/cjs/utils/logic/genJSModules.js +2 -2
- package/dist/cjs/utils/logic/handleProcess.js +59 -13
- package/dist/cjs/utils/templates/index.js +1 -1
- package/dist/cjs/utils/templates/renderManager.js +5 -5
- package/dist/cjs/utils/templates/scene.js +4 -4
- package/dist/esm/core/mybricks/Subject.js +11 -5
- package/dist/esm/core/mybricks/createJSHandle.js +55 -5
- package/dist/esm/core/utils/comRefResolver.js +134 -0
- package/dist/esm/core/utils/event.js +32 -0
- package/dist/esm/core/utils/hooks.js +109 -39
- package/dist/esm/core/utils/index.js +1 -0
- package/dist/esm/core/utils/pageRouter.js +56 -13
- package/dist/esm/core/utils/slots.js +78 -12
- package/dist/esm/core/utils/tabbar.js +47 -0
- package/dist/esm/core/utils/useContext.js +42 -2
- package/dist/esm/core/utils/with.js +19 -53
- package/dist/esm/generate/generateTaroProjectJson.js +2 -20
- package/dist/esm/generate/utils/appConfig.d.ts +1 -1
- package/dist/esm/generate/utils/appConfig.js +28 -9
- package/dist/esm/generate/utils/commonDir.js +13 -0
- package/dist/esm/generate/utils/customTabBar.d.ts +11 -0
- package/dist/esm/generate/utils/customTabBar.js +52 -0
- package/dist/esm/generate/utils/fileNode.d.ts +4 -0
- package/dist/esm/generate/utils/fileNode.js +13 -0
- package/dist/esm/handleCom.js +24 -21
- package/dist/esm/handleGlobal.d.ts +1 -1
- package/dist/esm/handleGlobal.js +6 -1
- package/dist/esm/handleSlot.js +7 -12
- package/dist/esm/processors/processScene.js +23 -3
- package/dist/esm/processors/processSceneLogic.js +3 -5
- package/dist/esm/taro-template.json +364 -66
- package/dist/esm/toCodeTaro.d.ts +1 -2
- package/dist/esm/toCodeTaro.js +1 -1
- package/dist/esm/utils/builder/buildResult.js +1 -2
- package/dist/esm/utils/common/ImportManager.d.ts +7 -0
- package/dist/esm/utils/common/ImportManager.js +42 -14
- package/dist/esm/utils/logic/genJSModules.js +2 -2
- package/dist/esm/utils/logic/handleProcess.js +73 -12
- package/dist/esm/utils/templates/index.js +1 -1
- package/dist/esm/utils/templates/renderManager.js +4 -7
- package/dist/esm/utils/templates/scene.js +2 -2
- package/package.json +1 -1
- package/dist/cjs/core/comlib/Index.js +0 -114
- package/dist/cjs/core/comlib/_AesEncode.js +0 -115
- package/dist/cjs/core/comlib/_BackTo.js +0 -80
- package/dist/cjs/core/comlib/_CallPhone.js +0 -58
- package/dist/cjs/core/comlib/_ChooseFile.js +0 -103
- package/dist/cjs/core/comlib/_ChooseMedia.js +0 -70
- package/dist/cjs/core/comlib/_Connector.js +0 -79
- package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +0 -79
- package/dist/cjs/core/comlib/_Format.js +0 -123
- package/dist/cjs/core/comlib/_GetLocation.js +0 -60
- package/dist/cjs/core/comlib/_GetStorage.js +0 -68
- package/dist/cjs/core/comlib/_GetSystemInfo.js +0 -62
- package/dist/cjs/core/comlib/_Modal.js +0 -68
- package/dist/cjs/core/comlib/_OpenCamera.js +0 -73
- package/dist/cjs/core/comlib/_OpenPetalMap.js +0 -49
- package/dist/cjs/core/comlib/_OpenUrl.js +0 -62
- package/dist/cjs/core/comlib/_RemoveStorage.js +0 -68
- package/dist/cjs/core/comlib/_Router.js +0 -100
- package/dist/cjs/core/comlib/_ScanQrcode.js +0 -59
- package/dist/cjs/core/comlib/_SetStorage.js +0 -67
- package/dist/cjs/core/comlib/_Share.js +0 -58
- package/dist/cjs/core/comlib/_ShowToast.js +0 -69
- package/dist/cjs/core/comlib/_TextToSpeech.js +0 -120
- package/dist/cjs/core/comlib/_TimerDebounce.js +0 -72
- package/dist/cjs/core/comlib/_TimerDelay.js +0 -88
- package/dist/cjs/core/comlib/_TimerThrottle.js +0 -75
- package/dist/cjs/core/comlib/_Vibrate.js +0 -60
- package/dist/esm/core/comlib/Index.js +0 -39
- package/dist/esm/core/comlib/_AesEncode.js +0 -85
- package/dist/esm/core/comlib/_BackTo.js +0 -66
- package/dist/esm/core/comlib/_CallPhone.js +0 -30
- package/dist/esm/core/comlib/_ChooseFile.js +0 -81
- package/dist/esm/core/comlib/_ChooseMedia.js +0 -38
- package/dist/esm/core/comlib/_Connector.js +0 -77
- package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +0 -56
- package/dist/esm/core/comlib/_Format.js +0 -102
- package/dist/esm/core/comlib/_GetLocation.js +0 -26
- package/dist/esm/core/comlib/_GetStorage.js +0 -44
- package/dist/esm/core/comlib/_GetSystemInfo.js +0 -32
- package/dist/esm/core/comlib/_Modal.js +0 -51
- package/dist/esm/core/comlib/_OpenCamera.js +0 -44
- package/dist/esm/core/comlib/_OpenPetalMap.js +0 -28
- package/dist/esm/core/comlib/_OpenUrl.js +0 -36
- package/dist/esm/core/comlib/_RemoveStorage.js +0 -42
- package/dist/esm/core/comlib/_Router.js +0 -113
- package/dist/esm/core/comlib/_ScanQrcode.js +0 -26
- package/dist/esm/core/comlib/_SetStorage.js +0 -40
- package/dist/esm/core/comlib/_Share.js +0 -28
- package/dist/esm/core/comlib/_ShowToast.js +0 -45
- package/dist/esm/core/comlib/_TextToSpeech.js +0 -117
- package/dist/esm/core/comlib/_TimerDebounce.js +0 -66
- package/dist/esm/core/comlib/_TimerDelay.js +0 -79
- package/dist/esm/core/comlib/_TimerThrottle.js +0 -69
- package/dist/esm/core/comlib/_Vibrate.js +0 -34
|
@@ -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,7 +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";
|
|
8
|
-
import {
|
|
9
|
+
import { ComRefResolver } from "./comRefResolver";
|
|
9
10
|
|
|
10
11
|
/** 深度代理:支持响应式更新 */
|
|
11
12
|
export function deepProxy(target, onSet) {
|
|
@@ -43,48 +44,46 @@ export function useModel(rawData) {
|
|
|
43
44
|
}, []);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
/**
|
|
47
|
+
/**
|
|
47
48
|
* 组件引用代理:
|
|
48
49
|
* 1. 自动缓冲:访问未渲染组件时返回影子对象,缓冲后续指令
|
|
49
50
|
* 2. 引用渗透:子作用域注册的真实引用自动同步至父级
|
|
50
51
|
* 3. 自动同步清理:卸载时从作用域链中彻底移除,防止僵尸引用
|
|
52
|
+
*
|
|
53
|
+
* 使用 ComRefResolver 统一处理引用解析逻辑
|
|
51
54
|
*/
|
|
52
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;
|
|
53
64
|
return new Proxy(target, {
|
|
54
65
|
get: function get(obj, prop) {
|
|
55
66
|
if (prop === '__isProxy') return true;
|
|
67
|
+
if (prop === '__resolver') return resolver;
|
|
56
68
|
if (prop === 'toJSON') return function () {
|
|
57
69
|
return obj;
|
|
58
70
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return parentComRefs.current[prop];
|
|
64
|
-
}
|
|
65
|
-
// 在当前作用域创建影子对象,使用当前作用域的 $index
|
|
66
|
-
var currentIndex = (_obj$$index = obj.$index) !== null && _obj$$index !== void 0 ? _obj$$index : 0;
|
|
67
|
-
return obj[prop] = new Proxy({
|
|
68
|
-
__isShadow: true
|
|
69
|
-
}, {
|
|
70
|
-
get: function get(_, method) {
|
|
71
|
-
if (method === '__isShadow') return true;
|
|
72
|
-
return function () {
|
|
73
|
-
if (!(todoPool instanceof TodoPool)) return;
|
|
74
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
75
|
-
args[_key] = arguments[_key];
|
|
76
|
-
}
|
|
77
|
-
todoPool.push(prop, currentIndex, method, args);
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
});
|
|
71
|
+
|
|
72
|
+
// u_ 开头的组件引用,统一由解析器处理
|
|
73
|
+
if (typeof prop === 'string' && prop.startsWith('u_')) {
|
|
74
|
+
return resolver.get(prop);
|
|
81
75
|
}
|
|
82
76
|
return obj[prop];
|
|
83
77
|
},
|
|
84
78
|
set: function set(obj, prop, value) {
|
|
85
79
|
var result = Reflect.set(obj, prop, value);
|
|
80
|
+
|
|
81
|
+
// 真实引用注册时,同步到解析器
|
|
86
82
|
var isRealRef = typeof prop === 'string' && !prop.startsWith('$') && (value === null || value === void 0 ? void 0 : value.__isShadow) !== true;
|
|
87
|
-
if (isRealRef &&
|
|
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_ 开头的属性,保持原有的父级渗透逻辑
|
|
88
87
|
try {
|
|
89
88
|
parentComRefs.current[prop] = value;
|
|
90
89
|
} catch (_unused) {}
|
|
@@ -93,8 +92,9 @@ export function proxyRefs(target, parentComRefs, todoPool) {
|
|
|
93
92
|
},
|
|
94
93
|
deleteProperty: function deleteProperty(obj, prop) {
|
|
95
94
|
var result = Reflect.deleteProperty(obj, prop);
|
|
96
|
-
|
|
97
|
-
|
|
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) {
|
|
98
98
|
try {
|
|
99
99
|
delete parentComRefs.current[prop];
|
|
100
100
|
} catch (_unused2) {}
|
|
@@ -104,7 +104,7 @@ export function proxyRefs(target, parentComRefs, todoPool) {
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
/**
|
|
107
|
+
/**
|
|
108
108
|
* 组件输入绑定 Hook:
|
|
109
109
|
* 1. 注册输入执行器
|
|
110
110
|
* 2. 自动重放缓冲指令(精准索引匹配)
|
|
@@ -128,6 +128,7 @@ export function useBindInputs(scope, id, initialHandlers) {
|
|
|
128
128
|
var proxy = new Proxy({}, {
|
|
129
129
|
get: function get(target, pin) {
|
|
130
130
|
if (pin === '__isShadow') return false;
|
|
131
|
+
if (pin === '__isLazyProxy') return false;
|
|
131
132
|
if (pin === 'toJSON') return function () {
|
|
132
133
|
return target;
|
|
133
134
|
};
|
|
@@ -152,8 +153,8 @@ export function useBindInputs(scope, id, initialHandlers) {
|
|
|
152
153
|
} else {
|
|
153
154
|
var handler = handlersRef.current[pin];
|
|
154
155
|
if (typeof handler === 'function') {
|
|
155
|
-
for (var
|
|
156
|
-
args[
|
|
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];
|
|
157
158
|
}
|
|
158
159
|
return pin === '_setData' ? handler.apply(void 0, [arg].concat(args)) : createReactiveInputHandler({
|
|
159
160
|
input: handler,
|
|
@@ -176,21 +177,62 @@ export function useBindInputs(scope, id, initialHandlers) {
|
|
|
176
177
|
}, [scope, id, todoPool, index]);
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
/**
|
|
180
|
-
export function
|
|
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;
|
|
181
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 () {
|
|
182
230
|
var events = {};
|
|
183
231
|
Object.keys(props).forEach(function (key) {
|
|
184
232
|
if (typeof props[key] === 'function') {
|
|
185
233
|
var handler = props[key];
|
|
186
234
|
var wrapped = function wrapped(original) {
|
|
187
|
-
|
|
188
|
-
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 ? {
|
|
189
|
-
id: context.id,
|
|
190
|
-
name: context.name,
|
|
191
|
-
value: original
|
|
192
|
-
} : original;
|
|
193
|
-
return handler(value);
|
|
235
|
+
return handler(original);
|
|
194
236
|
};
|
|
195
237
|
wrapped.getConnections = function () {
|
|
196
238
|
return [{
|
|
@@ -214,4 +256,32 @@ export function useBindEvents(props, context) {
|
|
|
214
256
|
}
|
|
215
257
|
});
|
|
216
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;
|
|
217
287
|
}
|
|
@@ -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
|
|
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
|
|
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:
|
|
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
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
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
|
}();
|
|
@@ -1,11 +1,50 @@
|
|
|
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
|
-
*
|
|
47
|
+
* 创建一个具有"向上渗透"和"隔离 Todo 池"能力的 comRefs 对象
|
|
9
48
|
*/
|
|
10
49
|
function createPenetratingComRefs(parentComRefs, todoPool) {
|
|
11
50
|
var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
@@ -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({
|
|
@@ -59,6 +100,10 @@ export function useEnhancedSlots(rawSlots, id) {
|
|
|
59
100
|
parentComRefs = _useAppContext.comRefs,
|
|
60
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
|
|
132
|
+
var _state$_lastMergedPar, _stableParams$inputVa, _stableParams$inputVa2, _stableParams$inputVa3, _stableParams$inputVa4, _state$_scopedComRefs;
|
|
77
133
|
var r = state._render;
|
|
78
|
-
|
|
79
|
-
|
|
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:
|
|
149
|
+
params: stableParams,
|
|
84
150
|
render: r
|
|
85
151
|
});
|
|
86
152
|
}
|
|
87
|
-
var scopeId =
|
|
88
|
-
var index = (
|
|
89
|
-
var scopedComRefs = (
|
|
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:
|
|
161
|
+
params: stableParams,
|
|
96
162
|
render: r
|
|
97
163
|
}));
|
|
98
164
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
import { EventEmitter } from "./event";
|
|
5
|
+
var isDefine = function isDefine(val) {
|
|
6
|
+
return val !== undefined && val !== null && val !== '';
|
|
7
|
+
};
|
|
8
|
+
var TabbarInstance = /*#__PURE__*/_createClass(function TabbarInstance() {
|
|
9
|
+
var _this = this;
|
|
10
|
+
_classCallCheck(this, TabbarInstance);
|
|
11
|
+
_defineProperty(this, "list", []);
|
|
12
|
+
_defineProperty(this, "eventEmitter", new EventEmitter());
|
|
13
|
+
_defineProperty(this, "setTabBarBadge", function (_ref) {
|
|
14
|
+
var index = _ref.index,
|
|
15
|
+
text = _ref.text;
|
|
16
|
+
return new Promise(function (resolve, reject) {
|
|
17
|
+
if (isDefine(index)) {
|
|
18
|
+
_this.list[index].active = true;
|
|
19
|
+
_this.list[index].activeText = text;
|
|
20
|
+
console.log('change', _this.list);
|
|
21
|
+
_this.eventEmitter.dispatch('change', _this.list);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
_defineProperty(this, "hideTabBarRedDot", function (_ref2) {
|
|
26
|
+
var index = _ref2.index;
|
|
27
|
+
return new Promise(function (resolve, reject) {
|
|
28
|
+
if (isDefine(index)) {
|
|
29
|
+
_this.list[index].active = false;
|
|
30
|
+
_this.list[index].activeText = 0;
|
|
31
|
+
_this.eventEmitter.dispatch('change', _this.list);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
_defineProperty(this, "removeTabBarBadge", this.hideTabBarRedDot);
|
|
36
|
+
_defineProperty(this, "initWithLength", function (len) {
|
|
37
|
+
_this.list = new Array(len).fill(function (t) {
|
|
38
|
+
return null;
|
|
39
|
+
}).map(function () {
|
|
40
|
+
return {
|
|
41
|
+
active: false,
|
|
42
|
+
activeText: ''
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
export var tabbarIns = new TabbarInstance();
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
var _excluded = ["success", "fail"];
|
|
2
5
|
import { useRef, useState, useMemo } from 'react';
|
|
3
|
-
|
|
4
|
-
import
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import * as Taro from '@tarojs/taro';
|
|
5
8
|
// @ts-ignore
|
|
6
9
|
import { request as _request } from '@/common/request';
|
|
10
|
+
import { tabbarIns } from "@/core/utils/tabbar";
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
import rootConfig from '@/common/rootConfig';
|
|
13
|
+
import { proxyRefs } from "./hooks";
|
|
14
|
+
import { TodoPool } from "./pool";
|
|
7
15
|
export function useAppCreateContext(id) {
|
|
8
16
|
var todoPool = useMemo(function () {
|
|
9
17
|
return new TodoPool();
|
|
@@ -27,14 +35,46 @@ export function useAppCreateContext(id) {
|
|
|
27
35
|
canvas: {
|
|
28
36
|
id: id
|
|
29
37
|
},
|
|
38
|
+
runtime: {
|
|
39
|
+
debug: false
|
|
40
|
+
},
|
|
30
41
|
env: {
|
|
31
42
|
runtime: true,
|
|
32
43
|
request: function request(connector, params, config) {
|
|
33
44
|
return _request(connector, params, config, {
|
|
34
45
|
$vars: $vars
|
|
35
46
|
});
|
|
47
|
+
},
|
|
48
|
+
tabbar: tabbarIns,
|
|
49
|
+
uploadFile: function uploadFile(params) {
|
|
50
|
+
var _rootConfig$status;
|
|
51
|
+
var header = {};
|
|
52
|
+
var mybricksGlobalHeaders = Taro.getStorageSync("_MYBRICKS_GLOBAL_HEADERS_");
|
|
53
|
+
if (mybricksGlobalHeaders) {
|
|
54
|
+
header = _objectSpread(_objectSpread({}, mybricksGlobalHeaders), header);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 如果 url 不以 http 开头,添加默认域名
|
|
59
|
+
*/
|
|
60
|
+
if (!/^(http|https):\/\/.*/.test(params.url) && rootConfig !== null && rootConfig !== void 0 && (_rootConfig$status = rootConfig.status) !== null && _rootConfig$status !== void 0 && _rootConfig$status.defaultCallServiceHost) {
|
|
61
|
+
var _rootConfig$status2;
|
|
62
|
+
params.url = "".concat(rootConfig === null || rootConfig === void 0 || (_rootConfig$status2 = rootConfig.status) === null || _rootConfig$status2 === void 0 ? void 0 : _rootConfig$status2.defaultCallServiceHost).concat(params.url);
|
|
63
|
+
}
|
|
64
|
+
var _success = params.success,
|
|
65
|
+
_fail = params.fail,
|
|
66
|
+
rest = _objectWithoutProperties(params, _excluded);
|
|
67
|
+
Taro.uploadFile(_objectSpread(_objectSpread({}, rest), {}, {
|
|
68
|
+
success: function success(res) {
|
|
69
|
+
return _success === null || _success === void 0 ? void 0 : _success(res);
|
|
70
|
+
},
|
|
71
|
+
fail: function fail(err) {
|
|
72
|
+
return _fail === null || _fail === void 0 ? void 0 : _fail(err);
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
36
75
|
}
|
|
37
76
|
},
|
|
77
|
+
rootScroll: {},
|
|
38
78
|
edit: false,
|
|
39
79
|
isH5: false,
|
|
40
80
|
isDesigner: false,
|