@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
|
@@ -31,16 +31,20 @@ var Subject = class {
|
|
|
31
31
|
_empty = true;
|
|
32
32
|
constructor(params = {}) {
|
|
33
33
|
this._log = params.log;
|
|
34
|
+
this._subjectNextCache = {};
|
|
34
35
|
return new Proxy(this, {
|
|
35
36
|
get(target, prop) {
|
|
36
37
|
if (prop in target) {
|
|
37
38
|
return target[prop];
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
if (!target._subjectNextCache[prop]) {
|
|
41
|
+
const subjectNext = new SubjectNext(prop);
|
|
42
|
+
target[import_constant.SUBJECT_SUBSCRIBE]((value, extra) => {
|
|
43
|
+
subjectNext[import_constant.SUBJECT_NEXT](value, extra);
|
|
44
|
+
});
|
|
45
|
+
target._subjectNextCache[prop] = subjectNext;
|
|
46
|
+
}
|
|
47
|
+
return target._subjectNextCache[prop];
|
|
44
48
|
}
|
|
45
49
|
});
|
|
46
50
|
}
|
|
@@ -30,9 +30,34 @@ var import_createReactiveInputHandler = require("./createReactiveInputHandler");
|
|
|
30
30
|
var validateJsMultipleInputs = (input) => {
|
|
31
31
|
return input.match(/\./);
|
|
32
32
|
};
|
|
33
|
-
var
|
|
34
|
-
|
|
33
|
+
var handleCache = /* @__PURE__ */ new Map();
|
|
34
|
+
var getFromCache = (handleKey) => {
|
|
35
|
+
if (!handleKey || !handleCache.has(handleKey))
|
|
36
|
+
return null;
|
|
37
|
+
const cached = handleCache.get(handleKey);
|
|
38
|
+
if (cached._rels) {
|
|
39
|
+
Object.values(cached._rels).forEach((subject) => {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
(_b = (_a = subject._observers) == null ? void 0 : _a.clear) == null ? void 0 : _b.call(_a);
|
|
42
|
+
subject._values = [];
|
|
43
|
+
subject._empty = true;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return cached;
|
|
47
|
+
};
|
|
48
|
+
var setToCache = (handleKey, exe, rels, needsCache) => {
|
|
49
|
+
exe._rels = rels;
|
|
50
|
+
if (handleKey && needsCache) {
|
|
51
|
+
handleCache.set(handleKey, exe);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var createJSHandle = (fn, options, handleKey) => {
|
|
35
55
|
const { props, appContext } = options;
|
|
56
|
+
const cached = getFromCache(handleKey);
|
|
57
|
+
if (cached)
|
|
58
|
+
return cached;
|
|
59
|
+
const needsCache = fn.__useCache === true;
|
|
60
|
+
let controller;
|
|
36
61
|
const inputs = new Proxy({}, {
|
|
37
62
|
getOwnPropertyDescriptor() {
|
|
38
63
|
return {
|
|
@@ -75,14 +100,20 @@ var createJSHandle = (fn, options) => {
|
|
|
75
100
|
appContext
|
|
76
101
|
});
|
|
77
102
|
const isJsMultipleInputs = props.inputs[0] ? validateJsMultipleInputs(props.inputs[0]) : false;
|
|
103
|
+
const exeOutputsCache = {};
|
|
78
104
|
const exeOutputs = new Proxy(
|
|
79
105
|
{},
|
|
80
106
|
{
|
|
81
107
|
get(_, key) {
|
|
82
|
-
|
|
108
|
+
if (!exeOutputsCache[key]) {
|
|
109
|
+
const subject = rels[key] || (rels[key] = new import_Subject.Subject({ log: `${import_constant.EXE_TITLE_MAP["output"]} ${props.title} | ${key}` }));
|
|
110
|
+
exeOutputsCache[key] = subject;
|
|
111
|
+
}
|
|
112
|
+
return exeOutputsCache[key];
|
|
83
113
|
}
|
|
84
114
|
}
|
|
85
115
|
);
|
|
116
|
+
const subscribedSubjects = /* @__PURE__ */ new Set();
|
|
86
117
|
const exe = (...args) => {
|
|
87
118
|
if (args.length) {
|
|
88
119
|
if (isJsMultipleInputs) {
|
|
@@ -90,6 +121,10 @@ var createJSHandle = (fn, options) => {
|
|
|
90
121
|
let valueAry = {};
|
|
91
122
|
args.forEach((value, index) => {
|
|
92
123
|
if (value == null ? void 0 : value[import_constant.SUBJECT_SUBSCRIBE]) {
|
|
124
|
+
if (subscribedSubjects.has(value)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
subscribedSubjects.add(value);
|
|
93
128
|
value[import_constant.SUBJECT_SUBSCRIBE]((value2) => {
|
|
94
129
|
(0, import_log.log)(`${import_constant.EXE_TITLE_MAP["input"]} ${props.title} | ${props.inputs[index]}`, JSON.stringify(value2));
|
|
95
130
|
valueAry[props.inputs[index]] = value2;
|
|
@@ -120,6 +155,10 @@ var createJSHandle = (fn, options) => {
|
|
|
120
155
|
} else {
|
|
121
156
|
const value = args[0];
|
|
122
157
|
if (value == null ? void 0 : value[import_constant.SUBJECT_SUBSCRIBE]) {
|
|
158
|
+
if (subscribedSubjects.has(value)) {
|
|
159
|
+
return exeOutputs;
|
|
160
|
+
}
|
|
161
|
+
subscribedSubjects.add(value);
|
|
123
162
|
value[import_constant.SUBJECT_SUBSCRIBE]((value2) => {
|
|
124
163
|
(0, import_log.log)(`${import_constant.EXE_TITLE_MAP["input"]} ${props.title} | ${props.inputs[0]}`, JSON.stringify(value2));
|
|
125
164
|
(0, import_createReactiveInputHandler.createReactiveInputHandler)({
|
|
@@ -142,6 +181,7 @@ var createJSHandle = (fn, options) => {
|
|
|
142
181
|
}
|
|
143
182
|
return exeOutputs;
|
|
144
183
|
};
|
|
184
|
+
setToCache(handleKey, exe, rels, needsCache);
|
|
145
185
|
return exe;
|
|
146
186
|
};
|
|
147
187
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/core/utils/comRefResolver.ts
|
|
20
|
+
var comRefResolver_exports = {};
|
|
21
|
+
__export(comRefResolver_exports, {
|
|
22
|
+
ComRefResolver: () => ComRefResolver
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(comRefResolver_exports);
|
|
25
|
+
var import_pool = require("./pool");
|
|
26
|
+
var ComRefResolver = class {
|
|
27
|
+
constructor(registry, parent, todoPool, scopeIndex = 0) {
|
|
28
|
+
this.registry = registry;
|
|
29
|
+
this.parent = parent;
|
|
30
|
+
this.todoPool = todoPool;
|
|
31
|
+
this.scopeIndex = scopeIndex;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 获取组件引用
|
|
35
|
+
* @returns 真实引用或影子对象
|
|
36
|
+
*/
|
|
37
|
+
get(id) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
if (this.registry[id] && !this.registry[id].__isShadow) {
|
|
40
|
+
return this.registry[id];
|
|
41
|
+
}
|
|
42
|
+
const parentRef = (_a = this.parent) == null ? void 0 : _a.findRealRef(id);
|
|
43
|
+
if (parentRef) {
|
|
44
|
+
return parentRef;
|
|
45
|
+
}
|
|
46
|
+
if ((_b = this.registry[id]) == null ? void 0 : _b.__isShadow) {
|
|
47
|
+
return this.registry[id];
|
|
48
|
+
}
|
|
49
|
+
return this.createShadowProxy(id);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 注册真实引用
|
|
53
|
+
*/
|
|
54
|
+
set(id, ref) {
|
|
55
|
+
var _a;
|
|
56
|
+
this.registry[id] = ref;
|
|
57
|
+
(_a = this.parent) == null ? void 0 : _a.set(id, ref);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 删除引用
|
|
61
|
+
*/
|
|
62
|
+
delete(id) {
|
|
63
|
+
var _a;
|
|
64
|
+
delete this.registry[id];
|
|
65
|
+
(_a = this.parent) == null ? void 0 : _a.delete(id);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 查找真实引用(仅用于父级链查找)
|
|
69
|
+
*/
|
|
70
|
+
findRealRef(id) {
|
|
71
|
+
var _a;
|
|
72
|
+
const local = this.registry[id];
|
|
73
|
+
if (local && !local.__isShadow) {
|
|
74
|
+
return local;
|
|
75
|
+
}
|
|
76
|
+
return ((_a = this.parent) == null ? void 0 : _a.findRealRef(id)) ?? null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 创建影子对象
|
|
80
|
+
* 关键:影子对象的方法被调用时,会动态查找真实引用
|
|
81
|
+
*/
|
|
82
|
+
createShadowProxy(id) {
|
|
83
|
+
const resolver = this;
|
|
84
|
+
const registry = this.registry;
|
|
85
|
+
const todoPool = this.todoPool;
|
|
86
|
+
const scopeIndex = this.scopeIndex;
|
|
87
|
+
const shadow = new Proxy({ __isShadow: true }, {
|
|
88
|
+
get(_, method) {
|
|
89
|
+
if (method === "__isShadow")
|
|
90
|
+
return true;
|
|
91
|
+
return (...args) => {
|
|
92
|
+
const realRef = registry[id];
|
|
93
|
+
if (realRef && !realRef.__isShadow) {
|
|
94
|
+
if (typeof realRef[method] === "function") {
|
|
95
|
+
return realRef[method](...args);
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (todoPool instanceof import_pool.TodoPool) {
|
|
100
|
+
todoPool.push(id, scopeIndex, method, args);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
this.registry[id] = shadow;
|
|
106
|
+
return shadow;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
ComRefResolver
|
|
112
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/core/utils/event.ts
|
|
20
|
+
var event_exports = {};
|
|
21
|
+
__export(event_exports, {
|
|
22
|
+
EventEmitter: () => EventEmitter
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(event_exports);
|
|
25
|
+
var EventEmitter = class {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.eventsCache = {};
|
|
28
|
+
this.addEventListner = (evtName, listner) => {
|
|
29
|
+
if (!this.eventsCache[evtName]) {
|
|
30
|
+
this.eventsCache[evtName] = /* @__PURE__ */ new Set([listner]);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.eventsCache[evtName].add(listner);
|
|
34
|
+
};
|
|
35
|
+
this.removeEventListner = (evtName, listner) => {
|
|
36
|
+
if (this.eventsCache[evtName]) {
|
|
37
|
+
this.eventsCache[evtName].delete(listner);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
this.dispatch = (evtName, detail) => {
|
|
41
|
+
if (!this.eventsCache[evtName]) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
let hasPreventDefault = false;
|
|
45
|
+
(this.eventsCache[evtName] ?? []).forEach((listner) => listner(detail));
|
|
46
|
+
return hasPreventDefault;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
EventEmitter
|
|
53
|
+
});
|
|
@@ -21,15 +21,16 @@ var hooks_exports = {};
|
|
|
21
21
|
__export(hooks_exports, {
|
|
22
22
|
deepProxy: () => deepProxy,
|
|
23
23
|
proxyRefs: () => proxyRefs,
|
|
24
|
-
useBindEvents: () => useBindEvents,
|
|
25
24
|
useBindInputs: () => useBindInputs,
|
|
25
|
+
useBindOutputs: () => useBindOutputs,
|
|
26
|
+
useBuiltinHandlers: () => useBuiltinHandlers,
|
|
26
27
|
useModel: () => useModel
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(hooks_exports);
|
|
29
30
|
var import_react = require("react");
|
|
30
31
|
var import_createReactiveInputHandler = require("../mybricks/createReactiveInputHandler");
|
|
31
32
|
var import_ComContext = require("./ComContext");
|
|
32
|
-
var
|
|
33
|
+
var import_comRefResolver = require("./comRefResolver");
|
|
33
34
|
function deepProxy(target, onSet) {
|
|
34
35
|
if (target === null || typeof target !== "object" || target.__isProxy)
|
|
35
36
|
return target;
|
|
@@ -58,36 +59,30 @@ function useModel(rawData) {
|
|
|
58
59
|
return (0, import_react.useMemo)(() => deepProxy(dataRef.current, () => forceUpdate({})), []);
|
|
59
60
|
}
|
|
60
61
|
function proxyRefs(target, parentComRefs, todoPool) {
|
|
62
|
+
var _a;
|
|
63
|
+
const parentResolver = (_a = parentComRefs == null ? void 0 : parentComRefs.current) == null ? void 0 : _a.__resolver;
|
|
64
|
+
const scopeIndex = target.$index ?? 0;
|
|
65
|
+
const resolver = new import_comRefResolver.ComRefResolver(target, parentResolver, todoPool, scopeIndex);
|
|
66
|
+
target.__resolver = resolver;
|
|
61
67
|
return new Proxy(target, {
|
|
62
68
|
get(obj, prop) {
|
|
63
|
-
var _a;
|
|
64
69
|
if (prop === "__isProxy")
|
|
65
70
|
return true;
|
|
71
|
+
if (prop === "__resolver")
|
|
72
|
+
return resolver;
|
|
66
73
|
if (prop === "toJSON")
|
|
67
74
|
return () => obj;
|
|
68
|
-
if (typeof prop === "string" && prop.startsWith("u_")
|
|
69
|
-
|
|
70
|
-
return parentComRefs.current[prop];
|
|
71
|
-
}
|
|
72
|
-
const currentIndex = obj.$index ?? 0;
|
|
73
|
-
return obj[prop] = new Proxy({ __isShadow: true }, {
|
|
74
|
-
get(_, method) {
|
|
75
|
-
if (method === "__isShadow")
|
|
76
|
-
return true;
|
|
77
|
-
return (...args) => {
|
|
78
|
-
if (!(todoPool instanceof import_pool.TodoPool))
|
|
79
|
-
return;
|
|
80
|
-
todoPool.push(prop, currentIndex, method, args);
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
});
|
|
75
|
+
if (typeof prop === "string" && prop.startsWith("u_")) {
|
|
76
|
+
return resolver.get(prop);
|
|
84
77
|
}
|
|
85
78
|
return obj[prop];
|
|
86
79
|
},
|
|
87
80
|
set(obj, prop, value) {
|
|
88
81
|
const result = Reflect.set(obj, prop, value);
|
|
89
82
|
const isRealRef = typeof prop === "string" && !prop.startsWith("$") && (value == null ? void 0 : value.__isShadow) !== true;
|
|
90
|
-
if (isRealRef &&
|
|
83
|
+
if (isRealRef && typeof prop === "string" && prop.startsWith("u_")) {
|
|
84
|
+
resolver.set(prop, value);
|
|
85
|
+
} else if (isRealRef && (parentComRefs == null ? void 0 : parentComRefs.current)) {
|
|
91
86
|
try {
|
|
92
87
|
parentComRefs.current[prop] = value;
|
|
93
88
|
} catch {
|
|
@@ -97,8 +92,9 @@ function proxyRefs(target, parentComRefs, todoPool) {
|
|
|
97
92
|
},
|
|
98
93
|
deleteProperty(obj, prop) {
|
|
99
94
|
const result = Reflect.deleteProperty(obj, prop);
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
if (typeof prop === "string" && prop.startsWith("u_")) {
|
|
96
|
+
resolver.delete(prop);
|
|
97
|
+
} else if (typeof prop === "string" && !prop.startsWith("$") && (parentComRefs == null ? void 0 : parentComRefs.current)) {
|
|
102
98
|
try {
|
|
103
99
|
delete parentComRefs.current[prop];
|
|
104
100
|
} catch {
|
|
@@ -126,6 +122,8 @@ function useBindInputs(scope, id, initialHandlers) {
|
|
|
126
122
|
get: (target, pin) => {
|
|
127
123
|
if (pin === "__isShadow")
|
|
128
124
|
return false;
|
|
125
|
+
if (pin === "__isLazyProxy")
|
|
126
|
+
return false;
|
|
129
127
|
if (pin === "toJSON")
|
|
130
128
|
return () => target;
|
|
131
129
|
return (arg, ...args) => {
|
|
@@ -156,17 +154,42 @@ function useBindInputs(scope, id, initialHandlers) {
|
|
|
156
154
|
return proxy;
|
|
157
155
|
}, [scope, id, todoPool, index]);
|
|
158
156
|
}
|
|
159
|
-
function
|
|
157
|
+
function useBuiltinHandlers(opts) {
|
|
158
|
+
const { data, setDynamicStyle, setShow, isPopup } = opts;
|
|
160
159
|
return (0, import_react.useMemo)(() => {
|
|
160
|
+
const handlers = {
|
|
161
|
+
_setStyle: (style) => {
|
|
162
|
+
setDynamicStyle((prev) => ({ ...prev, ...style }));
|
|
163
|
+
},
|
|
164
|
+
_setData: (path, value) => {
|
|
165
|
+
const paths = path.split(".");
|
|
166
|
+
let current = data;
|
|
167
|
+
for (let i = 0; i < paths.length - 1; i++) {
|
|
168
|
+
if (!current[paths[i]])
|
|
169
|
+
current[paths[i]] = {};
|
|
170
|
+
current = current[paths[i]];
|
|
171
|
+
}
|
|
172
|
+
current[paths[paths.length - 1]] = value;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
if (!isPopup) {
|
|
176
|
+
Object.assign(handlers, {
|
|
177
|
+
show: () => setShow(true),
|
|
178
|
+
hide: () => setShow(false),
|
|
179
|
+
showOrHide: () => setShow((prev) => !prev)
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return handlers;
|
|
183
|
+
}, [data, setDynamicStyle, setShow, isPopup]);
|
|
184
|
+
}
|
|
185
|
+
function useBindOutputs(comRefs, id, props, enhancedSlots, context) {
|
|
186
|
+
var _a;
|
|
187
|
+
const eventProxy = (0, import_react.useMemo)(() => {
|
|
161
188
|
const events = {};
|
|
162
189
|
Object.keys(props).forEach((key) => {
|
|
163
190
|
if (typeof props[key] === "function") {
|
|
164
191
|
const handler = props[key];
|
|
165
|
-
const wrapped = (original) =>
|
|
166
|
-
var _a, _b;
|
|
167
|
-
const value = ((_b = (_a = context == null ? void 0 : context.parentSlot) == null ? void 0 : _a.params) == null ? void 0 : _b.itemWrap) ? { id: context.id, name: context.name, value: original } : original;
|
|
168
|
-
return handler(value);
|
|
169
|
-
};
|
|
192
|
+
const wrapped = (original) => handler(original);
|
|
170
193
|
wrapped.getConnections = () => [{ id: "default" }];
|
|
171
194
|
events[key] = wrapped;
|
|
172
195
|
}
|
|
@@ -185,12 +208,31 @@ function useBindEvents(props, context) {
|
|
|
185
208
|
}
|
|
186
209
|
});
|
|
187
210
|
}, [props, context]);
|
|
211
|
+
if ((_a = comRefs == null ? void 0 : comRefs.current) == null ? void 0 : _a.$outputs) {
|
|
212
|
+
const slotOutputsList = Object.values(enhancedSlots || {}).map((slot) => slot == null ? void 0 : slot.outputs).filter(Boolean);
|
|
213
|
+
if (slotOutputsList.length > 0) {
|
|
214
|
+
comRefs.current.$outputs[id] = new Proxy({}, {
|
|
215
|
+
get(_, prop) {
|
|
216
|
+
for (const outputs of slotOutputsList) {
|
|
217
|
+
const fn = outputs[prop];
|
|
218
|
+
if (fn)
|
|
219
|
+
return fn;
|
|
220
|
+
}
|
|
221
|
+
return eventProxy[prop];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
comRefs.current.$outputs[id] = eventProxy;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return eventProxy;
|
|
188
229
|
}
|
|
189
230
|
// Annotate the CommonJS export names for ESM import in node:
|
|
190
231
|
0 && (module.exports = {
|
|
191
232
|
deepProxy,
|
|
192
233
|
proxyRefs,
|
|
193
|
-
useBindEvents,
|
|
194
234
|
useBindInputs,
|
|
235
|
+
useBindOutputs,
|
|
236
|
+
useBuiltinHandlers,
|
|
195
237
|
useModel
|
|
196
238
|
});
|
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/core/utils/index.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
+
ComRefResolver: () => import_comRefResolver.ComRefResolver,
|
|
23
24
|
PopupRenderer: () => import_PopupRenderer.PopupRenderer,
|
|
24
25
|
SUBJECT_SUBSCRIBE: () => import_constant.SUBJECT_SUBSCRIBE,
|
|
25
26
|
SUBJECT_VALUE: () => import_constant.SUBJECT_VALUE,
|
|
@@ -41,6 +42,7 @@ __export(utils_exports, {
|
|
|
41
42
|
module.exports = __toCommonJS(utils_exports);
|
|
42
43
|
__reExport(utils_exports, require("./hooks"), module.exports);
|
|
43
44
|
var import_pool = require("./pool");
|
|
45
|
+
var import_comRefResolver = require("./comRefResolver");
|
|
44
46
|
var import_with = require("./with");
|
|
45
47
|
var import_PopupRenderer = require("./PopupRenderer");
|
|
46
48
|
var import_pageRouter = require("./pageRouter");
|
|
@@ -52,6 +54,7 @@ var import_constant = require("../mybricks/constant");
|
|
|
52
54
|
__reExport(utils_exports, require("./slots"), module.exports);
|
|
53
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
54
56
|
0 && (module.exports = {
|
|
57
|
+
ComRefResolver,
|
|
55
58
|
PopupRenderer,
|
|
56
59
|
SUBJECT_SUBSCRIBE,
|
|
57
60
|
SUBJECT_VALUE,
|
|
@@ -34,6 +34,7 @@ __export(pageRouter_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(pageRouter_exports);
|
|
36
36
|
var import_taro = __toESM(require("@tarojs/taro"));
|
|
37
|
+
var import_tabBar = __toESM(require("@/custom-tab-bar/tabBar.json"));
|
|
37
38
|
var import_mybricks = require("../mybricks");
|
|
38
39
|
var TaroRouter = class {
|
|
39
40
|
constructor() {
|
|
@@ -42,35 +43,57 @@ var TaroRouter = class {
|
|
|
42
43
|
getParams(name) {
|
|
43
44
|
var _a;
|
|
44
45
|
const instance = import_taro.default.getCurrentInstance();
|
|
45
|
-
|
|
46
|
+
const inputParams = ((_a = instance.router) == null ? void 0 : _a.params) || {};
|
|
47
|
+
let params = Object.keys(inputParams).length === 2 && inputParams.data && typeof inputParams.data === "string" ? inputParams : {
|
|
48
|
+
data: Object.keys(inputParams).length > 1 ? JSON.stringify({ ...inputParams, $taroTimestamp: void 0 }) : void 0,
|
|
49
|
+
$taroTimestamp: inputParams.$taroTimestamp
|
|
50
|
+
};
|
|
46
51
|
if (!params.data && this.paramsBackup[name]) {
|
|
47
52
|
params = { data: this.paramsBackup[name] };
|
|
48
53
|
}
|
|
49
|
-
|
|
54
|
+
const paramsDataStr = params.data ? decodeURIComponent(params.data) : void 0;
|
|
55
|
+
let paramsData;
|
|
56
|
+
try {
|
|
57
|
+
paramsData = paramsDataStr ? JSON.parse(paramsDataStr) : void 0;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
paramsData = paramsDataStr;
|
|
60
|
+
}
|
|
61
|
+
return { value: paramsData };
|
|
50
62
|
}
|
|
51
63
|
push(name, { value }) {
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
this.paramsBackup[name] = dataStr;
|
|
56
|
-
}
|
|
57
|
-
import_taro.default.navigateTo({
|
|
58
|
-
url: `${url}${dataStr ? `?data=${dataStr}` : ""}`
|
|
59
|
-
});
|
|
64
|
+
const path = `pages/${name}/index`;
|
|
65
|
+
const navigateType = this.isTabBarPage(path) ? "switchTab" : "navigateTo";
|
|
66
|
+
this.navigate(navigateType, name, { value });
|
|
60
67
|
}
|
|
61
68
|
replace(name, { value }) {
|
|
69
|
+
const path = `pages/${name}/index`;
|
|
70
|
+
const navigateType = this.isTabBarPage(path) ? "switchTab" : "redirectTo";
|
|
71
|
+
this.navigate(navigateType, name, { value });
|
|
72
|
+
}
|
|
73
|
+
navigate(type, name, { value }) {
|
|
62
74
|
const url = `/pages/${name}/index`;
|
|
63
75
|
const dataStr = value ? encodeURIComponent(JSON.stringify(value)) : "";
|
|
64
76
|
if (dataStr) {
|
|
65
77
|
this.paramsBackup[name] = dataStr;
|
|
66
78
|
}
|
|
67
|
-
import_taro.default
|
|
79
|
+
import_taro.default[type]({
|
|
68
80
|
url: `${url}${dataStr ? `?data=${dataStr}` : ""}`
|
|
69
81
|
});
|
|
70
82
|
}
|
|
71
83
|
pop() {
|
|
72
84
|
import_taro.default.navigateBack();
|
|
73
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* 判断是否为标签栏页面
|
|
88
|
+
* @param pagePath 页面路径
|
|
89
|
+
* @returns 是否为标签栏页面
|
|
90
|
+
*/
|
|
91
|
+
isTabBarPage(pagePath) {
|
|
92
|
+
var _a, _b, _c;
|
|
93
|
+
return (_c = (_b = (_a = import_tabBar.default) == null ? void 0 : _a.tabBar) == null ? void 0 : _b.list) == null ? void 0 : _c.some(
|
|
94
|
+
(item) => item.pagePath === pagePath
|
|
95
|
+
);
|
|
96
|
+
}
|
|
74
97
|
};
|
|
75
98
|
var router = new TaroRouter();
|
|
76
99
|
var pageRouter = new import_mybricks.Page(router);
|
|
@@ -38,6 +38,34 @@ var import_react = __toESM(require("react"));
|
|
|
38
38
|
var import_ComContext = __toESM(require("./ComContext"));
|
|
39
39
|
var import_createReactiveInputHandler = require("../mybricks/createReactiveInputHandler");
|
|
40
40
|
var import_hooks = require("./hooks");
|
|
41
|
+
function shallowEqual(a, b) {
|
|
42
|
+
if (a === b)
|
|
43
|
+
return true;
|
|
44
|
+
if (!a || !b)
|
|
45
|
+
return false;
|
|
46
|
+
const keysA = Object.keys(a);
|
|
47
|
+
const keysB = Object.keys(b);
|
|
48
|
+
if (keysA.length !== keysB.length)
|
|
49
|
+
return false;
|
|
50
|
+
return keysA.every((key) => a[key] === b[key]);
|
|
51
|
+
}
|
|
52
|
+
function mergeSlotParams(stateInputValues, params) {
|
|
53
|
+
const hasStateInputValues = stateInputValues && Object.keys(stateInputValues).length > 0;
|
|
54
|
+
const hasParamsInputValues = (params == null ? void 0 : params.inputValues) && Object.keys(params.inputValues).length > 0;
|
|
55
|
+
if (!hasStateInputValues && !hasParamsInputValues) {
|
|
56
|
+
return params || {};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...params || {},
|
|
60
|
+
inputValues: {
|
|
61
|
+
...stateInputValues || {},
|
|
62
|
+
...(params == null ? void 0 : params.inputValues) || {}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function createScopeId(id, slotKey, rawScope) {
|
|
67
|
+
return `${id}.${slotKey}::${String(rawScope)}`;
|
|
68
|
+
}
|
|
41
69
|
function createPenetratingComRefs(parentComRefs, todoPool, index = 0) {
|
|
42
70
|
const localTarget = { $inputs: {}, $outputs: {}, $index: index };
|
|
43
71
|
return { current: (0, import_hooks.proxyRefs)(localTarget, parentComRefs, todoPool) };
|
|
@@ -50,7 +78,7 @@ function SlotParamsBridge(props) {
|
|
|
50
78
|
const content = SlotComp ? /* @__PURE__ */ import_react.default.createElement(SlotComp, { ...mergedParams || {} }) : props.children ?? null;
|
|
51
79
|
return /* @__PURE__ */ import_react.default.createElement(import_ComContext.SlotProvider, { value: { ...props.state, params: mergedParams } }, content);
|
|
52
80
|
}
|
|
53
|
-
function createChannelProxy(title) {
|
|
81
|
+
function createChannelProxy(title, onInputCall) {
|
|
54
82
|
const handlersMap = {};
|
|
55
83
|
return new Proxy(
|
|
56
84
|
{},
|
|
@@ -61,6 +89,7 @@ function createChannelProxy(title) {
|
|
|
61
89
|
handlersMap[pin] = arg;
|
|
62
90
|
return;
|
|
63
91
|
}
|
|
92
|
+
onInputCall == null ? void 0 : onInputCall(pin, arg);
|
|
64
93
|
const handler = handlersMap[pin];
|
|
65
94
|
if (typeof handler === "function") {
|
|
66
95
|
return (0, import_createReactiveInputHandler.createReactiveInputHandler)({
|
|
@@ -78,28 +107,45 @@ function createChannelProxy(title) {
|
|
|
78
107
|
function useEnhancedSlots(rawSlots, id) {
|
|
79
108
|
const { comRefs: parentComRefs, todoPool } = (0, import_ComContext.useAppContext)();
|
|
80
109
|
const slotStoreRef = (0, import_react.useRef)({});
|
|
110
|
+
const [, forceUpdate] = (0, import_react.useState)({});
|
|
81
111
|
return (0, import_react.useMemo)(() => {
|
|
82
112
|
if (!rawSlots)
|
|
83
113
|
return {};
|
|
84
114
|
const nextSlots = {};
|
|
85
115
|
Object.entries(rawSlots).forEach(([slotKey, slotDef]) => {
|
|
116
|
+
const onInputCall = (pin, value) => {
|
|
117
|
+
const state2 = slotStoreRef.current[slotKey];
|
|
118
|
+
if (state2) {
|
|
119
|
+
if (!state2._inputValues)
|
|
120
|
+
state2._inputValues = {};
|
|
121
|
+
state2._inputValues[pin] = value;
|
|
122
|
+
forceUpdate({});
|
|
123
|
+
}
|
|
124
|
+
};
|
|
86
125
|
const state = slotStoreRef.current[slotKey] || (slotStoreRef.current[slotKey] = {
|
|
87
|
-
inputs: createChannelProxy(`${id}.${slotKey}.inputs
|
|
126
|
+
inputs: createChannelProxy(`${id}.${slotKey}.inputs`, onInputCall),
|
|
88
127
|
outputs: createChannelProxy(`${id}.${slotKey}.outputs`),
|
|
89
128
|
_inputs: createChannelProxy(`${id}.${slotKey}._inputs`),
|
|
90
129
|
_scopedComRefs: {},
|
|
130
|
+
_inputValues: {},
|
|
91
131
|
_render: void 0,
|
|
92
132
|
render: (params) => {
|
|
93
|
-
var _a, _b, _c;
|
|
133
|
+
var _a, _b, _c, _d;
|
|
94
134
|
const r = state._render;
|
|
95
|
-
const
|
|
135
|
+
const mergedParams = mergeSlotParams(state._inputValues, params);
|
|
136
|
+
if (state._lastMergedParams && shallowEqual(mergedParams == null ? void 0 : mergedParams.inputValues, (_a = state._lastMergedParams) == null ? void 0 : _a.inputValues)) {
|
|
137
|
+
} else {
|
|
138
|
+
state._lastMergedParams = mergedParams;
|
|
139
|
+
}
|
|
140
|
+
const stableParams = state._lastMergedParams;
|
|
141
|
+
const rawScope = ((_b = stableParams == null ? void 0 : stableParams.inputValues) == null ? void 0 : _b.index) ?? (params == null ? void 0 : params.key);
|
|
96
142
|
if (rawScope === void 0 || rawScope === null) {
|
|
97
|
-
return /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params, render: r });
|
|
143
|
+
return /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params: stableParams, render: r });
|
|
98
144
|
}
|
|
99
|
-
const scopeId =
|
|
100
|
-
const index = ((
|
|
101
|
-
const scopedComRefs = (
|
|
102
|
-
return /* @__PURE__ */ import_react.default.createElement(ScopedComContextProvider, { comRefs: scopedComRefs, scopeId }, /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params, render: r }));
|
|
145
|
+
const scopeId = createScopeId(id, slotKey, rawScope);
|
|
146
|
+
const index = ((_c = stableParams == null ? void 0 : stableParams.inputValues) == null ? void 0 : _c.index) ?? 0;
|
|
147
|
+
const scopedComRefs = (_d = state._scopedComRefs)[scopeId] || (_d[scopeId] = createPenetratingComRefs(parentComRefs, todoPool, index));
|
|
148
|
+
return /* @__PURE__ */ import_react.default.createElement(ScopedComContextProvider, { comRefs: scopedComRefs, scopeId }, /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params: stableParams, render: r }));
|
|
103
149
|
}
|
|
104
150
|
});
|
|
105
151
|
state._render = slotDef == null ? void 0 : slotDef.render;
|