@mybricks/to-code-taro 1.1.2 → 1.1.4
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/utils/PopupRenderer.js +1 -1
- package/dist/cjs/core/utils/hooks.js +102 -38
- package/dist/cjs/core/utils/slots.js +11 -4
- package/dist/cjs/core/utils/useContext.js +6 -4
- package/dist/cjs/core/utils/with.js +3 -3
- package/dist/cjs/generate/generateTaroProjectJson.js +7 -4
- package/dist/cjs/generate/utils/commonDir.js +12 -1
- package/dist/cjs/generate/utils/pageImages.d.ts +14 -0
- package/dist/cjs/generate/utils/pageImages.js +36 -0
- package/dist/cjs/handleCom.js +37 -14
- package/dist/cjs/handleDom.d.ts +2 -0
- package/dist/cjs/handleDom.js +5 -2
- package/dist/cjs/handleGlobal.js +4 -2
- package/dist/cjs/handleSlot.d.ts +3 -0
- package/dist/cjs/handleSlot.js +31 -7
- package/dist/cjs/taro-template.json +1250 -946
- package/dist/cjs/toCodeTaro.d.ts +1 -0
- package/dist/cjs/toCodeTaro.js +80 -1
- package/dist/cjs/utils/config/content/converter.js +2 -2
- package/dist/cjs/utils/config/content/pageConfig.js +4 -1
- package/dist/cjs/utils/config/content/saveBase64Image.d.ts +10 -0
- package/dist/cjs/utils/config/content/saveBase64Image.js +44 -3
- package/dist/cjs/utils/config/content/tabBarConfig.js +8 -2
- package/dist/cjs/utils/logic/handleProcess.js +3 -3
- package/dist/cjs/utils/logic/processChildren.d.ts +14 -1
- package/dist/cjs/utils/logic/processChildren.js +30 -6
- package/dist/cjs/utils/style/converter.js +34 -72
- package/dist/cjs/utils/templates/index.d.ts +1 -0
- package/dist/cjs/utils/templates/index.js +11 -2
- package/dist/cjs/utils/templates/renderManager.d.ts +4 -0
- package/dist/cjs/utils/templates/renderManager.js +10 -3
- package/dist/cjs/utils/templates/scene.js +2 -0
- package/dist/esm/core/utils/PopupRenderer.js +1 -1
- package/dist/esm/core/utils/hooks.js +137 -53
- package/dist/esm/core/utils/popupRouter.js +2 -1
- package/dist/esm/core/utils/slots.js +24 -22
- package/dist/esm/core/utils/useContext.js +8 -10
- package/dist/esm/core/utils/with.js +3 -3
- package/dist/esm/generate/generateTaroProjectJson.js +7 -2
- package/dist/esm/generate/utils/commonDir.js +15 -0
- package/dist/esm/generate/utils/pageImages.d.ts +14 -0
- package/dist/esm/generate/utils/pageImages.d.ts.map +1 -0
- package/dist/esm/generate/utils/pageImages.js +15 -0
- package/dist/esm/handleCom.js +44 -17
- package/dist/esm/handleDom.d.ts +2 -0
- package/dist/esm/handleDom.js +6 -4
- package/dist/esm/handleGlobal.js +4 -2
- package/dist/esm/handleSlot.d.ts +3 -0
- package/dist/esm/handleSlot.js +52 -10
- package/dist/esm/taro-template.json +1250 -946
- package/dist/esm/toCodeTaro.d.ts +1 -0
- package/dist/esm/toCodeTaro.d.ts.map +1 -1
- package/dist/esm/toCodeTaro.js +89 -4
- package/dist/esm/utils/config/content/converter.js +2 -2
- package/dist/esm/utils/config/content/pageConfig.js +4 -1
- package/dist/esm/utils/config/content/saveBase64Image.d.ts +10 -0
- package/dist/esm/utils/config/content/saveBase64Image.js +42 -1
- package/dist/esm/utils/config/content/tabBarConfig.js +7 -2
- package/dist/esm/utils/config/handlePageConfig.d.ts.map +1 -0
- package/dist/esm/utils/logic/genJSModules.d.ts.map +1 -0
- package/dist/esm/utils/logic/handleProcess.js +3 -3
- package/dist/esm/utils/logic/processChildren.d.ts +14 -1
- package/dist/esm/utils/logic/processChildren.js +45 -8
- package/dist/esm/utils/style/converter.js +57 -106
- package/dist/esm/utils/templates/index.d.ts +1 -0
- package/dist/esm/utils/templates/index.js +9 -2
- package/dist/esm/utils/templates/renderManager.d.ts +4 -0
- package/dist/esm/utils/templates/renderManager.js +17 -4
- package/dist/esm/utils/templates/scene.js +1 -0
- package/package.json +1 -1
- package/dist/esm/generate/utils/commonDir.d.ts.map +0 -1
- package/dist/esm/handleCom.d.ts.map +0 -1
- package/dist/esm/handleDom.d.ts.map +0 -1
- package/dist/esm/handleGlobal.d.ts.map +0 -1
- package/dist/esm/utils/config/content/converter.d.ts.map +0 -1
- package/dist/esm/utils/config/content/pageConfig.d.ts.map +0 -1
- package/dist/esm/utils/config/content/saveBase64Image.d.ts.map +0 -1
- package/dist/esm/utils/config/content/tabBarConfig.d.ts.map +0 -1
- package/dist/esm/utils/logic/handleProcess.d.ts.map +0 -1
- package/dist/esm/utils/logic/processChildren.d.ts.map +0 -1
- package/dist/esm/utils/templates/index.d.ts.map +0 -1
- package/dist/esm/utils/templates/renderManager.d.ts.map +0 -1
|
@@ -1,16 +1,14 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
2
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
4
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
4
|
-
import { useState, useRef, useMemo } from 'react';
|
|
5
|
+
import { useState, useRef, useMemo, useEffect } from 'react';
|
|
5
6
|
import { createReactiveInputHandler } from "../mybricks/createReactiveInputHandler";
|
|
7
|
+
import { useAppContext, useParentSlot } from "./ComContext";
|
|
6
8
|
|
|
7
|
-
/**
|
|
8
|
-
* 深度代理,支持自动路径初始化和响应式更新(鸿蒙化处理方案)
|
|
9
|
-
*/
|
|
9
|
+
/** 深度代理:支持响应式更新 */
|
|
10
10
|
export function deepProxy(target, onSet) {
|
|
11
|
-
if (target === null || _typeof(target) !== 'object' || target.__isProxy)
|
|
12
|
-
return target;
|
|
13
|
-
}
|
|
11
|
+
if (target === null || _typeof(target) !== 'object' || target.__isProxy) return target;
|
|
14
12
|
return new Proxy(target, {
|
|
15
13
|
get: function get(obj, prop) {
|
|
16
14
|
if (prop === '__isProxy') return true;
|
|
@@ -18,9 +16,6 @@ export function deepProxy(target, onSet) {
|
|
|
18
16
|
return obj;
|
|
19
17
|
};
|
|
20
18
|
var value = obj[prop];
|
|
21
|
-
|
|
22
|
-
// 只代理已存在的对象属性,不自动创建空对象
|
|
23
|
-
// 避免访问不存在的属性(如 disabled)时污染原始数据
|
|
24
19
|
if (_typeof(value) === 'object' && value !== null && !value.__isProxy) {
|
|
25
20
|
obj[prop] = deepProxy(value, onSet);
|
|
26
21
|
}
|
|
@@ -28,11 +23,13 @@ export function deepProxy(target, onSet) {
|
|
|
28
23
|
},
|
|
29
24
|
set: function set(obj, prop, value) {
|
|
30
25
|
var result = Reflect.set(obj, prop, value);
|
|
31
|
-
|
|
26
|
+
onSet === null || onSet === void 0 || onSet();
|
|
32
27
|
return result;
|
|
33
28
|
}
|
|
34
29
|
});
|
|
35
30
|
}
|
|
31
|
+
|
|
32
|
+
/** 状态 Hook:提供响应式数据能力 */
|
|
36
33
|
export function useModel(rawData) {
|
|
37
34
|
var _useState = useState({}),
|
|
38
35
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -44,36 +41,131 @@ export function useModel(rawData) {
|
|
|
44
41
|
});
|
|
45
42
|
}, []);
|
|
46
43
|
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 组件引用代理:
|
|
47
|
+
* 1. 自动缓冲:访问未渲染组件时返回影子对象,缓冲后续指令
|
|
48
|
+
* 2. 引用渗透:子作用域注册的真实引用自动同步至父级
|
|
49
|
+
* 3. 自动同步清理:卸载时从作用域链中彻底移除,防止僵尸引用
|
|
50
|
+
*/
|
|
51
|
+
export function proxyRefs(target, parentComRefs, globalTodoPool) {
|
|
52
|
+
return new Proxy(target, {
|
|
53
|
+
get: function get(obj, prop) {
|
|
54
|
+
if (prop === '__isProxy') return true;
|
|
55
|
+
if (prop === 'toJSON') return function () {
|
|
56
|
+
return obj;
|
|
57
|
+
};
|
|
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
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return obj[prop];
|
|
81
|
+
},
|
|
82
|
+
set: function set(obj, prop, value) {
|
|
83
|
+
var result = Reflect.set(obj, prop, value);
|
|
84
|
+
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) {
|
|
86
|
+
try {
|
|
87
|
+
parentComRefs.current[prop] = value;
|
|
88
|
+
} catch (_unused) {}
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
},
|
|
92
|
+
deleteProperty: function deleteProperty(obj, prop) {
|
|
93
|
+
var result = Reflect.deleteProperty(obj, prop);
|
|
94
|
+
var isRealRef = typeof prop === 'string' && !prop.startsWith('$');
|
|
95
|
+
if (isRealRef && parentComRefs !== null && parentComRefs !== void 0 && parentComRefs.current) {
|
|
96
|
+
try {
|
|
97
|
+
delete parentComRefs.current[prop];
|
|
98
|
+
} catch (_unused2) {}
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 组件输入绑定 Hook:
|
|
107
|
+
* 1. 注册输入执行器
|
|
108
|
+
* 2. 自动重放缓冲指令(精准索引匹配)
|
|
109
|
+
* 3. 生命周期自动化:卸载时自动注销引用渗透路径
|
|
110
|
+
*/
|
|
47
111
|
export function useBindInputs(scope, id, initialHandlers) {
|
|
112
|
+
var _parentSlot$params$in, _parentSlot$params;
|
|
48
113
|
var handlersRef = useRef(_objectSpread({}, initialHandlers));
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
114
|
+
var _useAppContext = useAppContext(),
|
|
115
|
+
globalTodoInputs = _useAppContext.globalTodoInputs;
|
|
116
|
+
var parentSlot = useParentSlot();
|
|
117
|
+
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
|
+
useEffect(function () {
|
|
119
|
+
return function () {
|
|
120
|
+
if (scope !== null && scope !== void 0 && scope.current) {
|
|
121
|
+
delete scope.current[id];
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}, [scope, id]);
|
|
54
125
|
return useMemo(function () {
|
|
55
126
|
var proxy = new Proxy({}, {
|
|
56
|
-
get: function get(
|
|
127
|
+
get: function get(target, pin) {
|
|
128
|
+
if (pin === '__isShadow') return false;
|
|
129
|
+
if (pin === 'toJSON') return function () {
|
|
130
|
+
return target;
|
|
131
|
+
};
|
|
57
132
|
return function (arg) {
|
|
58
133
|
if (typeof arg === 'function') {
|
|
59
|
-
// 组件注册回调
|
|
60
134
|
handlersRef.current[pin] = arg;
|
|
135
|
+
|
|
136
|
+
// 处理指令重放
|
|
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];
|
|
141
|
+
if (pin === '_setData') {
|
|
142
|
+
arg.apply(void 0, _toConsumableArray(pendingArgs));
|
|
143
|
+
} else {
|
|
144
|
+
createReactiveInputHandler({
|
|
145
|
+
input: arg,
|
|
146
|
+
value: pendingArgs[0],
|
|
147
|
+
rels: {},
|
|
148
|
+
title: id
|
|
149
|
+
});
|
|
150
|
+
}
|
|
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
|
+
}
|
|
61
159
|
} else {
|
|
62
|
-
// 逻辑流触发输入
|
|
63
160
|
var handler = handlersRef.current[pin];
|
|
64
161
|
if (typeof handler === 'function') {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
args[_key - 1] = arguments[_key];
|
|
68
|
-
}
|
|
69
|
-
return handler.apply(void 0, [arg].concat(args));
|
|
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];
|
|
70
164
|
}
|
|
71
|
-
|
|
72
|
-
return createReactiveInputHandler({
|
|
165
|
+
return pin === '_setData' ? handler.apply(void 0, [arg].concat(args)) : createReactiveInputHandler({
|
|
73
166
|
input: handler,
|
|
74
167
|
value: arg,
|
|
75
168
|
rels: {},
|
|
76
|
-
// 这里可以扩展 output 关联
|
|
77
169
|
title: id
|
|
78
170
|
});
|
|
79
171
|
}
|
|
@@ -81,34 +173,30 @@ export function useBindInputs(scope, id, initialHandlers) {
|
|
|
81
173
|
};
|
|
82
174
|
}
|
|
83
175
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
176
|
+
if (scope !== null && scope !== void 0 && scope.current) scope.current[id] = proxy;
|
|
177
|
+
if (initialHandlers) {
|
|
178
|
+
Object.keys(initialHandlers).forEach(function (pin) {
|
|
179
|
+
return proxy[pin](initialHandlers[pin]);
|
|
180
|
+
});
|
|
88
181
|
}
|
|
89
182
|
return proxy;
|
|
90
|
-
}, [scope, id]);
|
|
183
|
+
}, [scope, id, globalTodoInputs, index]);
|
|
91
184
|
}
|
|
185
|
+
|
|
186
|
+
/** 组件事件绑定 Hook */
|
|
92
187
|
export function useBindEvents(props, context) {
|
|
93
188
|
return useMemo(function () {
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
// 预处理已存在的事件
|
|
189
|
+
var events = {};
|
|
97
190
|
Object.keys(props).forEach(function (key) {
|
|
98
|
-
// 兼容:MyBricks 输出 pin 既可能是 onChange,也可能是 changeTab 这种非 on 前缀
|
|
99
191
|
if (typeof props[key] === 'function') {
|
|
100
192
|
var handler = props[key];
|
|
101
|
-
var wrapped = function wrapped(
|
|
193
|
+
var wrapped = function wrapped(original) {
|
|
102
194
|
var _context$parentSlot;
|
|
103
|
-
// 鸿蒙/render-web 规范:如果是在插槽中触发事件,且存在父级协议,则自动封装元数据
|
|
104
|
-
// 这解决了 FormContainer 等组件识别子项的需求
|
|
105
|
-
// 注意:不要仅凭 parentSlot 存在就封装,否则会影响 Tabs2/changeTab 这类事件直接给 JS 计算组件传参
|
|
106
|
-
// 仅在父级 slot 使用 itemWrap 协议时才需要这层元数据
|
|
107
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 ? {
|
|
108
196
|
id: context.id,
|
|
109
197
|
name: context.name,
|
|
110
|
-
value:
|
|
111
|
-
} :
|
|
198
|
+
value: original
|
|
199
|
+
} : original;
|
|
112
200
|
return handler(value);
|
|
113
201
|
};
|
|
114
202
|
wrapped.getConnections = function () {
|
|
@@ -116,22 +204,18 @@ export function useBindEvents(props, context) {
|
|
|
116
204
|
id: 'default'
|
|
117
205
|
}];
|
|
118
206
|
};
|
|
119
|
-
|
|
207
|
+
events[key] = wrapped;
|
|
120
208
|
}
|
|
121
209
|
});
|
|
122
|
-
return new Proxy(
|
|
210
|
+
return new Proxy(events, {
|
|
123
211
|
get: function get(target, key) {
|
|
124
|
-
// 对 onXXX 事件(不少组件 runtime 直接 outputs["onChange"](...))提供兜底函数,避免未连线时报错
|
|
125
212
|
if (typeof key === 'string' && key.startsWith('on')) {
|
|
126
|
-
if (target[key])
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// 对未连接的事件返回兜底函数
|
|
130
|
-
var emptyFn = function emptyFn() {};
|
|
131
|
-
emptyFn.getConnections = function () {
|
|
213
|
+
if (target[key]) return target[key];
|
|
214
|
+
var fn = function fn() {};
|
|
215
|
+
fn.getConnections = function () {
|
|
132
216
|
return [];
|
|
133
217
|
};
|
|
134
|
-
return
|
|
218
|
+
return fn;
|
|
135
219
|
}
|
|
136
220
|
return target[key];
|
|
137
221
|
}
|
|
@@ -4,7 +4,8 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
4
4
|
import { Page } from "../mybricks";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* 弹窗状态管理(解耦版)
|
|
8
|
+
* 弹窗在 Taro 中被视为组件,不走路由栈
|
|
8
9
|
*/
|
|
9
10
|
var PopupStore = /*#__PURE__*/function () {
|
|
10
11
|
function PopupStore() {
|
|
@@ -3,6 +3,21 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
3
3
|
import React, { useMemo, useRef } from "react";
|
|
4
4
|
import ComContext, { SlotProvider, useAppContext, useParentSlot } from "./ComContext";
|
|
5
5
|
import { createReactiveInputHandler } from "../mybricks/createReactiveInputHandler";
|
|
6
|
+
import { proxyRefs } from "./hooks";
|
|
7
|
+
/**
|
|
8
|
+
* 创建一个具有“向上渗透”和“隔离 Todo 池”能力的 comRefs 对象
|
|
9
|
+
*/
|
|
10
|
+
function createPenetratingComRefs(parentComRefs, globalTodoPool) {
|
|
11
|
+
var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
12
|
+
var localTarget = {
|
|
13
|
+
$inputs: {},
|
|
14
|
+
$outputs: {},
|
|
15
|
+
$index: index
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
current: proxyRefs(localTarget, parentComRefs, globalTodoPool)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
6
21
|
function SlotParamsBridge(props) {
|
|
7
22
|
var _props$params, _parentSlot$params, _props$children;
|
|
8
23
|
var parentSlot = useParentSlot();
|
|
@@ -39,13 +54,10 @@ function createChannelProxy(title) {
|
|
|
39
54
|
}
|
|
40
55
|
});
|
|
41
56
|
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 参考鸿蒙的 createSlotsIO:
|
|
45
|
-
* - 确保每个 slot 都具备 inputs / outputs / _inputs 三套通道,避免 runtime 访问时报 undefined
|
|
46
|
-
* - render 时通过 SlotProvider 注入 parentSlot(slot 内子组件可 useParentSlot 获取)
|
|
47
|
-
*/
|
|
48
57
|
export function useEnhancedSlots(rawSlots, id) {
|
|
58
|
+
var _useAppContext = useAppContext(),
|
|
59
|
+
parentComRefs = _useAppContext.comRefs,
|
|
60
|
+
globalTodoInputs = _useAppContext.globalTodoInputs;
|
|
49
61
|
var slotStoreRef = useRef({});
|
|
50
62
|
return useMemo(function () {
|
|
51
63
|
if (!rawSlots) return {};
|
|
@@ -61,7 +73,7 @@ export function useEnhancedSlots(rawSlots, id) {
|
|
|
61
73
|
_scopedComRefs: {},
|
|
62
74
|
_render: undefined,
|
|
63
75
|
render: function render(params) {
|
|
64
|
-
var _ref3, _params$key, _params$inputValues, _params$inputValues2, _ref4;
|
|
76
|
+
var _ref3, _params$key, _params$inputValues, _params$inputValues2, _params$inputValues$i, _params$inputValues3, _ref4;
|
|
65
77
|
var r = state._render;
|
|
66
78
|
// 只有存在 key 或 index 时才认为是“多实例作用域插槽”,需要实例隔离
|
|
67
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;
|
|
@@ -73,24 +85,16 @@ export function useEnhancedSlots(rawSlots, id) {
|
|
|
73
85
|
});
|
|
74
86
|
}
|
|
75
87
|
var scopeId = "".concat(id, ".").concat(slotKey, "::").concat(String(rawScope));
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
$outputs: {}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return /*#__PURE__*/React.createElement(SlotProvider, {
|
|
83
|
-
value: _objectSpread(_objectSpread({}, state), {}, {
|
|
84
|
-
params: params
|
|
85
|
-
})
|
|
86
|
-
}, /*#__PURE__*/React.createElement(ScopedComContextProvider, {
|
|
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));
|
|
90
|
+
return /*#__PURE__*/React.createElement(ScopedComContextProvider, {
|
|
87
91
|
comRefs: scopedComRefs,
|
|
88
92
|
scopeId: scopeId
|
|
89
93
|
}, /*#__PURE__*/React.createElement(SlotParamsBridge, {
|
|
90
94
|
state: state,
|
|
91
95
|
params: params,
|
|
92
96
|
render: r
|
|
93
|
-
}))
|
|
97
|
+
}));
|
|
94
98
|
}
|
|
95
99
|
});
|
|
96
100
|
state._render = slotDef === null || slotDef === void 0 ? void 0 : slotDef.render;
|
|
@@ -102,13 +106,11 @@ export function useEnhancedSlots(rawSlots, id) {
|
|
|
102
106
|
});
|
|
103
107
|
});
|
|
104
108
|
return nextSlots;
|
|
105
|
-
}, [rawSlots, id]);
|
|
109
|
+
}, [rawSlots, id, parentComRefs, globalTodoInputs]);
|
|
106
110
|
}
|
|
107
111
|
export function ScopedComContextProvider(props) {
|
|
108
112
|
var parent = useAppContext();
|
|
109
113
|
var value = useMemo(function () {
|
|
110
|
-
// $outputs 与 $inputs 一样:在 scoped 下应当隔离(由 scopedComRefs.current.$outputs 提供)
|
|
111
|
-
// 如果没有显式传 comRefs,则沿用父级的,但依然带上新的 scopeId
|
|
112
114
|
return _objectSpread(_objectSpread({}, parent), {}, {
|
|
113
115
|
comRefs: props.comRefs || parent.comRefs,
|
|
114
116
|
$scopeId: props.scopeId
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import { useRef, useState, useMemo } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// - comRefs: 组件实例/inputs/outputs 注册表(可 scoped)
|
|
9
|
-
// - $vars/$fxs: 逻辑能力注册表(仅页面级,全作用域共享)
|
|
10
|
-
var comRefs = useRef(deepProxy({
|
|
3
|
+
import { proxyRefs } from "./hooks";
|
|
4
|
+
var GLOBAL_TODO_POOL = new Map();
|
|
5
|
+
export function useAppCreateContext(id) {
|
|
6
|
+
var globalTodoInputs = useRef(GLOBAL_TODO_POOL);
|
|
7
|
+
var comRefs = useRef(proxyRefs({
|
|
11
8
|
$inputs: {},
|
|
12
9
|
$outputs: {}
|
|
13
|
-
}));
|
|
10
|
+
}, undefined, globalTodoInputs.current));
|
|
14
11
|
var $vars = useRef({});
|
|
15
12
|
var $fxs = useRef({});
|
|
16
13
|
var _useState = useState({
|
|
@@ -24,7 +21,7 @@ export function useAppCreateContext() {
|
|
|
24
21
|
setPopupState = _useState2[1];
|
|
25
22
|
var appContext = useRef({
|
|
26
23
|
canvas: {
|
|
27
|
-
id:
|
|
24
|
+
id: id
|
|
28
25
|
},
|
|
29
26
|
runtime: {
|
|
30
27
|
debug: false
|
|
@@ -45,6 +42,7 @@ export function useAppCreateContext() {
|
|
|
45
42
|
comRefs: comRefs,
|
|
46
43
|
$vars: $vars,
|
|
47
44
|
$fxs: $fxs,
|
|
45
|
+
globalTodoInputs: globalTodoInputs.current,
|
|
48
46
|
appContext: appContext,
|
|
49
47
|
popupState: popupState,
|
|
50
48
|
setPopupState: setPopupState
|
|
@@ -122,11 +122,11 @@ export var WithCom = function WithCom(props) {
|
|
|
122
122
|
return show || isPopup ? /*#__PURE__*/React.createElement(View, {
|
|
123
123
|
className: className,
|
|
124
124
|
style: _objectSpread(_objectSpread({}, style), dynamicStyle)
|
|
125
|
-
}, jsx) : null;
|
|
125
|
+
}, jsx, props.children) : null;
|
|
126
126
|
};
|
|
127
|
-
export var WithWrapper = function WithWrapper(Component) {
|
|
127
|
+
export var WithWrapper = function WithWrapper(id, Component) {
|
|
128
128
|
return function WrappedComponent(props) {
|
|
129
|
-
var contextStore = useAppCreateContext();
|
|
129
|
+
var contextStore = useAppCreateContext(id);
|
|
130
130
|
var setPopupState = contextStore.setPopupState;
|
|
131
131
|
var isPopup = Component.isPopup;
|
|
132
132
|
|
|
@@ -4,6 +4,7 @@ import * as path from "path";
|
|
|
4
4
|
import { findDir, ensureDir } from "./utils/fileNode";
|
|
5
5
|
import { handleCommonDir } from "./utils/commonDir";
|
|
6
6
|
import { handleTabBarImages } from "./utils/tabBarImages";
|
|
7
|
+
import { handlePageImages } from "./utils/pageImages";
|
|
7
8
|
import { updateAppConfig } from "./utils/appConfig";
|
|
8
9
|
import { genScopedJSModules } from "../utils/logic/genJSModules";
|
|
9
10
|
/**
|
|
@@ -47,6 +48,7 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
|
|
|
47
48
|
|
|
48
49
|
// 从 assets 中获取 TabBar 图片文件信息
|
|
49
50
|
var imageFiles = assets.tabBarImages || [];
|
|
51
|
+
var pageImages = assets.pageImages || [];
|
|
50
52
|
|
|
51
53
|
// 过滤出类型为 normal 的项
|
|
52
54
|
var normalItems = files.filter(function (item) {
|
|
@@ -81,7 +83,7 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
|
|
|
81
83
|
if (item.jsModules && item.jsModules.length > 0) {
|
|
82
84
|
pageChildren.push({
|
|
83
85
|
path: "src/pages/".concat(pageName, "/index.jsModules.ts"),
|
|
84
|
-
content: genScopedJSModules(item.jsModules, "
|
|
86
|
+
content: genScopedJSModules(item.jsModules, "@/core/mybricks/index", "@/common/jsModulesRuntime")
|
|
85
87
|
});
|
|
86
88
|
}
|
|
87
89
|
|
|
@@ -116,7 +118,7 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
|
|
|
116
118
|
if (item.jsModules && item.jsModules.length > 0) {
|
|
117
119
|
popupChildren.push({
|
|
118
120
|
path: "src/popupComponents/".concat(popupId, "/index.jsModules.ts"),
|
|
119
|
-
content: genScopedJSModules(item.jsModules, "
|
|
121
|
+
content: genScopedJSModules(item.jsModules, "@/core/mybricks/index", "@/common/jsModulesRuntime")
|
|
120
122
|
});
|
|
121
123
|
}
|
|
122
124
|
popupComponentsDir.children.push({
|
|
@@ -137,6 +139,9 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
|
|
|
137
139
|
// 处理 TabBar 图片文件
|
|
138
140
|
handleTabBarImages(tabbarDir, imageFiles);
|
|
139
141
|
|
|
142
|
+
// 处理页面 base64 图片文件(与 tabbar 同级别)
|
|
143
|
+
handlePageImages(assetsDir, pageImages);
|
|
144
|
+
|
|
140
145
|
// 替换自定义 Tabbar 配置文件
|
|
141
146
|
var CUSTOM_TAB_BAR_CONFIG_PATH = "src/custom-tab-bar/mybricks/tabbar-config.ts";
|
|
142
147
|
var customTabBarItem = files.find(function (item) {
|
|
@@ -22,4 +22,19 @@ export function handleCommonDir(commonDir, items) {
|
|
|
22
22
|
content: fullContent
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
// 处理 global
|
|
27
|
+
var globalItem = items.find(function (item) {
|
|
28
|
+
return item.type === 'global';
|
|
29
|
+
});
|
|
30
|
+
if (globalItem) {
|
|
31
|
+
var _globalItem$importMan;
|
|
32
|
+
var _importCode = ((_globalItem$importMan = globalItem.importManager) === null || _globalItem$importMan === void 0 ? void 0 : _globalItem$importMan.toCode()) || '';
|
|
33
|
+
var _fileContent = globalItem.content || '';
|
|
34
|
+
var _fullContent = _importCode ? "".concat(_importCode, "\n").concat(_fileContent) : _fileContent;
|
|
35
|
+
commonDir.children.push({
|
|
36
|
+
path: 'src/common/global.ts',
|
|
37
|
+
content: _fullContent
|
|
38
|
+
});
|
|
39
|
+
}
|
|
25
40
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 页面图片文件处理工具
|
|
3
|
+
*/
|
|
4
|
+
import type { ImageFileInfo } from '../../utils/config/content';
|
|
5
|
+
interface FileNode {
|
|
6
|
+
path: string;
|
|
7
|
+
content: string | null;
|
|
8
|
+
children?: FileNode[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 处理页面 base64 图片文件
|
|
12
|
+
*/
|
|
13
|
+
export declare function handlePageImages(assetsDir: FileNode, imageFiles: ImageFileInfo[]): void;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageImages.d.ts","sourceRoot":"","sources":["pageImages.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,QAAQ,EACnB,UAAU,EAAE,aAAa,EAAE,GAC1B,IAAI,CAON"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 页面图片文件处理工具
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 处理页面 base64 图片文件
|
|
7
|
+
*/
|
|
8
|
+
export function handlePageImages(assetsDir, imageFiles) {
|
|
9
|
+
imageFiles.forEach(function (imageFile) {
|
|
10
|
+
assetsDir.children.push({
|
|
11
|
+
path: imageFile.filePath,
|
|
12
|
+
content: imageFile.fileContent.toString('base64')
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
}
|