@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
|
@@ -39,7 +39,7 @@ var PopupRenderer = ({ popupMap }) => {
|
|
|
39
39
|
const { popupState } = (0, import_ComContext.useAppContext)();
|
|
40
40
|
const ActivePopup = popupState.visible && popupMap[popupState.name] ? popupMap[popupState.name] : null;
|
|
41
41
|
if (!ActivePopup)
|
|
42
|
-
return null;
|
|
42
|
+
return /* @__PURE__ */ import_react.default.createElement(import_components.View, null);
|
|
43
43
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
44
44
|
import_components.View,
|
|
45
45
|
{
|
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var hooks_exports = {};
|
|
21
21
|
__export(hooks_exports, {
|
|
22
22
|
deepProxy: () => deepProxy,
|
|
23
|
+
proxyRefs: () => proxyRefs,
|
|
23
24
|
useBindEvents: () => useBindEvents,
|
|
24
25
|
useBindInputs: () => useBindInputs,
|
|
25
26
|
useModel: () => useModel
|
|
@@ -27,17 +28,17 @@ __export(hooks_exports, {
|
|
|
27
28
|
module.exports = __toCommonJS(hooks_exports);
|
|
28
29
|
var import_react = require("react");
|
|
29
30
|
var import_createReactiveInputHandler = require("../mybricks/createReactiveInputHandler");
|
|
31
|
+
var import_ComContext = require("./ComContext");
|
|
30
32
|
function deepProxy(target, onSet) {
|
|
31
|
-
if (target === null || typeof target !== "object" || target.__isProxy)
|
|
33
|
+
if (target === null || typeof target !== "object" || target.__isProxy)
|
|
32
34
|
return target;
|
|
33
|
-
}
|
|
34
35
|
return new Proxy(target, {
|
|
35
36
|
get(obj, prop) {
|
|
36
37
|
if (prop === "__isProxy")
|
|
37
38
|
return true;
|
|
38
39
|
if (prop === "toJSON")
|
|
39
40
|
return () => obj;
|
|
40
|
-
|
|
41
|
+
const value = obj[prop];
|
|
41
42
|
if (typeof value === "object" && value !== null && !value.__isProxy) {
|
|
42
43
|
obj[prop] = deepProxy(value, onSet);
|
|
43
44
|
}
|
|
@@ -45,8 +46,7 @@ function deepProxy(target, onSet) {
|
|
|
45
46
|
},
|
|
46
47
|
set(obj, prop, value) {
|
|
47
48
|
const result = Reflect.set(obj, prop, value);
|
|
48
|
-
|
|
49
|
-
onSet();
|
|
49
|
+
onSet == null ? void 0 : onSet();
|
|
50
50
|
return result;
|
|
51
51
|
}
|
|
52
52
|
});
|
|
@@ -54,74 +54,137 @@ function deepProxy(target, onSet) {
|
|
|
54
54
|
function useModel(rawData) {
|
|
55
55
|
const [, forceUpdate] = (0, import_react.useState)({});
|
|
56
56
|
const dataRef = (0, import_react.useRef)(rawData || {});
|
|
57
|
-
return (0, import_react.useMemo)(() => {
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
return (0, import_react.useMemo)(() => deepProxy(dataRef.current, () => forceUpdate({})), []);
|
|
58
|
+
}
|
|
59
|
+
function proxyRefs(target, parentComRefs, globalTodoPool) {
|
|
60
|
+
return new Proxy(target, {
|
|
61
|
+
get(obj, prop) {
|
|
62
|
+
if (prop === "__isProxy")
|
|
63
|
+
return true;
|
|
64
|
+
if (prop === "toJSON")
|
|
65
|
+
return () => obj;
|
|
66
|
+
if (typeof prop === "string" && prop.startsWith("u_") && obj[prop] === void 0) {
|
|
67
|
+
return obj[prop] = new Proxy({ __isShadow: true }, {
|
|
68
|
+
get(_, method) {
|
|
69
|
+
if (method === "__isShadow")
|
|
70
|
+
return true;
|
|
71
|
+
return (...args) => {
|
|
72
|
+
if (!(globalTodoPool instanceof Map))
|
|
73
|
+
return;
|
|
74
|
+
const instances = globalTodoPool.get(prop) || [];
|
|
75
|
+
if (!globalTodoPool.has(prop))
|
|
76
|
+
globalTodoPool.set(prop, instances);
|
|
77
|
+
const index = obj.$index ?? 0;
|
|
78
|
+
const todo = instances[index] || (instances[index] = {});
|
|
79
|
+
todo[method] = args;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return obj[prop];
|
|
85
|
+
},
|
|
86
|
+
set(obj, prop, value) {
|
|
87
|
+
const result = Reflect.set(obj, prop, value);
|
|
88
|
+
const isRealRef = typeof prop === "string" && !prop.startsWith("$") && (value == null ? void 0 : value.__isShadow) !== true;
|
|
89
|
+
if (isRealRef && (parentComRefs == null ? void 0 : parentComRefs.current)) {
|
|
90
|
+
try {
|
|
91
|
+
parentComRefs.current[prop] = value;
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
},
|
|
97
|
+
deleteProperty(obj, prop) {
|
|
98
|
+
const result = Reflect.deleteProperty(obj, prop);
|
|
99
|
+
const isRealRef = typeof prop === "string" && !prop.startsWith("$");
|
|
100
|
+
if (isRealRef && (parentComRefs == null ? void 0 : parentComRefs.current)) {
|
|
101
|
+
try {
|
|
102
|
+
delete parentComRefs.current[prop];
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
60
109
|
}
|
|
61
110
|
function useBindInputs(scope, id, initialHandlers) {
|
|
111
|
+
var _a, _b;
|
|
62
112
|
const handlersRef = (0, import_react.useRef)({ ...initialHandlers });
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
113
|
+
const { globalTodoInputs } = (0, import_ComContext.useAppContext)();
|
|
114
|
+
const parentSlot = (0, import_ComContext.useParentSlot)();
|
|
115
|
+
const index = ((_b = (_a = parentSlot == null ? void 0 : parentSlot.params) == null ? void 0 : _a.inputValues) == null ? void 0 : _b.index) ?? 0;
|
|
116
|
+
(0, import_react.useEffect)(() => {
|
|
117
|
+
return () => {
|
|
118
|
+
if (scope == null ? void 0 : scope.current) {
|
|
119
|
+
delete scope.current[id];
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}, [scope, id]);
|
|
66
123
|
return (0, import_react.useMemo)(() => {
|
|
67
124
|
const proxy = new Proxy({}, {
|
|
68
|
-
get: (
|
|
125
|
+
get: (target, pin) => {
|
|
126
|
+
if (pin === "__isShadow")
|
|
127
|
+
return false;
|
|
128
|
+
if (pin === "toJSON")
|
|
129
|
+
return () => target;
|
|
69
130
|
return (arg, ...args) => {
|
|
70
131
|
if (typeof arg === "function") {
|
|
71
132
|
handlersRef.current[pin] = arg;
|
|
133
|
+
const instances = globalTodoInputs == null ? void 0 : globalTodoInputs.get(id);
|
|
134
|
+
const todo = (instances == null ? void 0 : instances[index]) || (instances == null ? void 0 : instances[0]);
|
|
135
|
+
if (todo == null ? void 0 : todo[pin]) {
|
|
136
|
+
const pendingArgs = todo[pin];
|
|
137
|
+
if (pin === "_setData") {
|
|
138
|
+
arg(...pendingArgs);
|
|
139
|
+
} else {
|
|
140
|
+
(0, import_createReactiveInputHandler.createReactiveInputHandler)({ input: arg, value: pendingArgs[0], rels: {}, title: id });
|
|
141
|
+
}
|
|
142
|
+
delete todo[pin];
|
|
143
|
+
const hasTasks = instances == null ? void 0 : instances.some((inst) => inst && Object.keys(inst).length > 0);
|
|
144
|
+
if (!hasTasks)
|
|
145
|
+
globalTodoInputs.delete(id);
|
|
146
|
+
}
|
|
72
147
|
} else {
|
|
73
148
|
const handler = handlersRef.current[pin];
|
|
74
149
|
if (typeof handler === "function") {
|
|
75
|
-
|
|
76
|
-
return handler(arg, ...args);
|
|
77
|
-
}
|
|
78
|
-
return (0, import_createReactiveInputHandler.createReactiveInputHandler)({
|
|
79
|
-
input: handler,
|
|
80
|
-
value: arg,
|
|
81
|
-
rels: {},
|
|
82
|
-
// 这里可以扩展 output 关联
|
|
83
|
-
title: id
|
|
84
|
-
});
|
|
150
|
+
return pin === "_setData" ? handler(arg, ...args) : (0, import_createReactiveInputHandler.createReactiveInputHandler)({ input: handler, value: arg, rels: {}, title: id });
|
|
85
151
|
}
|
|
86
152
|
}
|
|
87
153
|
};
|
|
88
154
|
}
|
|
89
155
|
});
|
|
90
|
-
if (scope
|
|
156
|
+
if (scope == null ? void 0 : scope.current)
|
|
91
157
|
scope.current[id] = proxy;
|
|
158
|
+
if (initialHandlers) {
|
|
159
|
+
Object.keys(initialHandlers).forEach((pin) => proxy[pin](initialHandlers[pin]));
|
|
92
160
|
}
|
|
93
161
|
return proxy;
|
|
94
|
-
}, [scope, id]);
|
|
162
|
+
}, [scope, id, globalTodoInputs, index]);
|
|
95
163
|
}
|
|
96
164
|
function useBindEvents(props, context) {
|
|
97
165
|
return (0, import_react.useMemo)(() => {
|
|
98
|
-
const
|
|
166
|
+
const events = {};
|
|
99
167
|
Object.keys(props).forEach((key) => {
|
|
100
168
|
if (typeof props[key] === "function") {
|
|
101
169
|
const handler = props[key];
|
|
102
|
-
const wrapped = (
|
|
170
|
+
const wrapped = (original) => {
|
|
103
171
|
var _a, _b;
|
|
104
|
-
const value = ((_b = (_a = context == null ? void 0 : context.parentSlot) == null ? void 0 : _a.params) == null ? void 0 : _b.itemWrap) ? {
|
|
105
|
-
id: context.id,
|
|
106
|
-
name: context.name,
|
|
107
|
-
value: originalValue
|
|
108
|
-
} : originalValue;
|
|
172
|
+
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;
|
|
109
173
|
return handler(value);
|
|
110
174
|
};
|
|
111
175
|
wrapped.getConnections = () => [{ id: "default" }];
|
|
112
|
-
|
|
176
|
+
events[key] = wrapped;
|
|
113
177
|
}
|
|
114
178
|
});
|
|
115
|
-
return new Proxy(
|
|
179
|
+
return new Proxy(events, {
|
|
116
180
|
get(target, key) {
|
|
117
181
|
if (typeof key === "string" && key.startsWith("on")) {
|
|
118
|
-
if (target[key])
|
|
182
|
+
if (target[key])
|
|
119
183
|
return target[key];
|
|
120
|
-
|
|
121
|
-
const emptyFn = () => {
|
|
184
|
+
const fn = () => {
|
|
122
185
|
};
|
|
123
|
-
|
|
124
|
-
return
|
|
186
|
+
fn.getConnections = () => [];
|
|
187
|
+
return fn;
|
|
125
188
|
}
|
|
126
189
|
return target[key];
|
|
127
190
|
}
|
|
@@ -131,6 +194,7 @@ function useBindEvents(props, context) {
|
|
|
131
194
|
// Annotate the CommonJS export names for ESM import in node:
|
|
132
195
|
0 && (module.exports = {
|
|
133
196
|
deepProxy,
|
|
197
|
+
proxyRefs,
|
|
134
198
|
useBindEvents,
|
|
135
199
|
useBindInputs,
|
|
136
200
|
useModel
|
|
@@ -37,6 +37,11 @@ module.exports = __toCommonJS(slots_exports);
|
|
|
37
37
|
var import_react = __toESM(require("react"));
|
|
38
38
|
var import_ComContext = __toESM(require("./ComContext"));
|
|
39
39
|
var import_createReactiveInputHandler = require("../mybricks/createReactiveInputHandler");
|
|
40
|
+
var import_hooks = require("./hooks");
|
|
41
|
+
function createPenetratingComRefs(parentComRefs, globalTodoPool, index = 0) {
|
|
42
|
+
const localTarget = { $inputs: {}, $outputs: {}, $index: index };
|
|
43
|
+
return { current: (0, import_hooks.proxyRefs)(localTarget, parentComRefs, globalTodoPool) };
|
|
44
|
+
}
|
|
40
45
|
function SlotParamsBridge(props) {
|
|
41
46
|
var _a, _b;
|
|
42
47
|
const parentSlot = (0, import_ComContext.useParentSlot)();
|
|
@@ -71,6 +76,7 @@ function createChannelProxy(title) {
|
|
|
71
76
|
);
|
|
72
77
|
}
|
|
73
78
|
function useEnhancedSlots(rawSlots, id) {
|
|
79
|
+
const { comRefs: parentComRefs, globalTodoInputs } = (0, import_ComContext.useAppContext)();
|
|
74
80
|
const slotStoreRef = (0, import_react.useRef)({});
|
|
75
81
|
return (0, import_react.useMemo)(() => {
|
|
76
82
|
if (!rawSlots)
|
|
@@ -84,15 +90,16 @@ function useEnhancedSlots(rawSlots, id) {
|
|
|
84
90
|
_scopedComRefs: {},
|
|
85
91
|
_render: void 0,
|
|
86
92
|
render: (params) => {
|
|
87
|
-
var _a, _b, _c, _d;
|
|
93
|
+
var _a, _b, _c, _d, _e;
|
|
88
94
|
const r = state._render;
|
|
89
95
|
const rawScope = (params == null ? void 0 : params.key) ?? ((_a = params == null ? void 0 : params.inputValues) == null ? void 0 : _a.index) ?? ((_c = (_b = params == null ? void 0 : params.inputValues) == null ? void 0 : _b.itemData) == null ? void 0 : _c.id);
|
|
90
96
|
if (rawScope === void 0 || rawScope === null) {
|
|
91
97
|
return /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params, render: r });
|
|
92
98
|
}
|
|
93
99
|
const scopeId = `${id}.${slotKey}::${String(rawScope)}`;
|
|
94
|
-
const
|
|
95
|
-
|
|
100
|
+
const index = ((_d = params == null ? void 0 : params.inputValues) == null ? void 0 : _d.index) ?? 0;
|
|
101
|
+
const scopedComRefs = (_e = state._scopedComRefs)[scopeId] || (_e[scopeId] = createPenetratingComRefs(parentComRefs, globalTodoInputs, index));
|
|
102
|
+
return /* @__PURE__ */ import_react.default.createElement(ScopedComContextProvider, { comRefs: scopedComRefs, scopeId }, /* @__PURE__ */ import_react.default.createElement(SlotParamsBridge, { state, params, render: r }));
|
|
96
103
|
}
|
|
97
104
|
});
|
|
98
105
|
state._render = slotDef == null ? void 0 : slotDef.render;
|
|
@@ -105,7 +112,7 @@ function useEnhancedSlots(rawSlots, id) {
|
|
|
105
112
|
};
|
|
106
113
|
});
|
|
107
114
|
return nextSlots;
|
|
108
|
-
}, [rawSlots, id]);
|
|
115
|
+
}, [rawSlots, id, parentComRefs, globalTodoInputs]);
|
|
109
116
|
}
|
|
110
117
|
function ScopedComContextProvider(props) {
|
|
111
118
|
const parent = (0, import_ComContext.useAppContext)();
|
|
@@ -24,8 +24,10 @@ __export(useContext_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(useContext_exports);
|
|
25
25
|
var import_react = require("react");
|
|
26
26
|
var import_hooks = require("./hooks");
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
var GLOBAL_TODO_POOL = /* @__PURE__ */ new Map();
|
|
28
|
+
function useAppCreateContext(id) {
|
|
29
|
+
const globalTodoInputs = (0, import_react.useRef)(GLOBAL_TODO_POOL);
|
|
30
|
+
const comRefs = (0, import_react.useRef)((0, import_hooks.proxyRefs)({ $inputs: {}, $outputs: {} }, void 0, globalTodoInputs.current));
|
|
29
31
|
const $vars = (0, import_react.useRef)({});
|
|
30
32
|
const $fxs = (0, import_react.useRef)({});
|
|
31
33
|
const [popupState, setPopupState] = (0, import_react.useState)({
|
|
@@ -36,8 +38,7 @@ function useAppCreateContext() {
|
|
|
36
38
|
});
|
|
37
39
|
const appContext = (0, import_react.useRef)({
|
|
38
40
|
canvas: {
|
|
39
|
-
id
|
|
40
|
-
// 使用 data 中的 id
|
|
41
|
+
id
|
|
41
42
|
},
|
|
42
43
|
runtime: {
|
|
43
44
|
debug: false
|
|
@@ -57,6 +58,7 @@ function useAppCreateContext() {
|
|
|
57
58
|
comRefs,
|
|
58
59
|
$vars,
|
|
59
60
|
$fxs,
|
|
61
|
+
globalTodoInputs: globalTodoInputs.current,
|
|
60
62
|
appContext,
|
|
61
63
|
popupState,
|
|
62
64
|
setPopupState
|
|
@@ -109,11 +109,11 @@ var WithCom = (props) => {
|
|
|
109
109
|
style
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
return show || isPopup ? /* @__PURE__ */ import_react.default.createElement(import_components.View, { className, style: { ...style, ...dynamicStyle } }, jsx) : null;
|
|
112
|
+
return show || isPopup ? /* @__PURE__ */ import_react.default.createElement(import_components.View, { className, style: { ...style, ...dynamicStyle } }, jsx, props.children) : null;
|
|
113
113
|
};
|
|
114
|
-
var WithWrapper = (Component) => {
|
|
114
|
+
var WithWrapper = (id, Component) => {
|
|
115
115
|
return function WrappedComponent(props) {
|
|
116
|
-
const contextStore = (0, import_useContext.useAppCreateContext)();
|
|
116
|
+
const contextStore = (0, import_useContext.useAppCreateContext)(id);
|
|
117
117
|
const { setPopupState } = contextStore;
|
|
118
118
|
const isPopup = Component.isPopup;
|
|
119
119
|
(0, import_react.useEffect)(() => {
|
|
@@ -37,6 +37,7 @@ var path = __toESM(require("path"));
|
|
|
37
37
|
var import_fileNode = require("./utils/fileNode");
|
|
38
38
|
var import_commonDir = require("./utils/commonDir");
|
|
39
39
|
var import_tabBarImages = require("./utils/tabBarImages");
|
|
40
|
+
var import_pageImages = require("./utils/pageImages");
|
|
40
41
|
var import_appConfig = require("./utils/appConfig");
|
|
41
42
|
var import_genJSModules = require("../utils/logic/genJSModules");
|
|
42
43
|
var generateTaroProjectJson = (result) => {
|
|
@@ -60,6 +61,7 @@ var generateTaroProjectJson = (result) => {
|
|
|
60
61
|
const assetsDir = (0, import_fileNode.ensureDir)(srcDir, "src/assets");
|
|
61
62
|
const tabbarDir = (0, import_fileNode.ensureDir)(assetsDir, "src/assets/tabbar");
|
|
62
63
|
const imageFiles = assets.tabBarImages || [];
|
|
64
|
+
const pageImages = assets.pageImages || [];
|
|
63
65
|
const normalItems = files.filter((item) => item.type === "normal");
|
|
64
66
|
const generatedPages = normalItems.map((item) => {
|
|
65
67
|
var _a2;
|
|
@@ -90,8 +92,8 @@ ${fileContent}` : fileContent;
|
|
|
90
92
|
path: `src/pages/${pageName}/index.jsModules.ts`,
|
|
91
93
|
content: (0, import_genJSModules.genScopedJSModules)(
|
|
92
94
|
item.jsModules,
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
+
"@/core/mybricks/index",
|
|
96
|
+
"@/common/jsModulesRuntime"
|
|
95
97
|
)
|
|
96
98
|
});
|
|
97
99
|
}
|
|
@@ -125,8 +127,8 @@ ${item.content || ""}`;
|
|
|
125
127
|
path: `src/popupComponents/${popupId}/index.jsModules.ts`,
|
|
126
128
|
content: (0, import_genJSModules.genScopedJSModules)(
|
|
127
129
|
item.jsModules,
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
+
"@/core/mybricks/index",
|
|
131
|
+
"@/common/jsModulesRuntime"
|
|
130
132
|
)
|
|
131
133
|
});
|
|
132
134
|
}
|
|
@@ -143,6 +145,7 @@ ${item.content || ""}`;
|
|
|
143
145
|
(0, import_appConfig.updateAppConfig)(appConfigFile, normalItems, files);
|
|
144
146
|
}
|
|
145
147
|
(0, import_tabBarImages.handleTabBarImages)(tabbarDir, imageFiles);
|
|
148
|
+
(0, import_pageImages.handlePageImages)(assetsDir, pageImages);
|
|
146
149
|
const CUSTOM_TAB_BAR_CONFIG_PATH = "src/custom-tab-bar/mybricks/tabbar-config.ts";
|
|
147
150
|
const customTabBarItem = files.find((item) => item.type === "customTabBar");
|
|
148
151
|
if (customTabBarItem == null ? void 0 : customTabBarItem.content) {
|
|
@@ -23,7 +23,7 @@ __export(commonDir_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(commonDir_exports);
|
|
25
25
|
function handleCommonDir(commonDir, items) {
|
|
26
|
-
var _a;
|
|
26
|
+
var _a, _b;
|
|
27
27
|
commonDir.children = commonDir.children || [];
|
|
28
28
|
const jsModulesRuntimeItem = items.find((item) => item.type === "jsModulesRuntime");
|
|
29
29
|
if (jsModulesRuntimeItem) {
|
|
@@ -36,6 +36,17 @@ ${fileContent}` : fileContent;
|
|
|
36
36
|
content: fullContent
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
+
const globalItem = items.find((item) => item.type === "global");
|
|
40
|
+
if (globalItem) {
|
|
41
|
+
const importCode = ((_b = globalItem.importManager) == null ? void 0 : _b.toCode()) || "";
|
|
42
|
+
const fileContent = globalItem.content || "";
|
|
43
|
+
const fullContent = importCode ? `${importCode}
|
|
44
|
+
${fileContent}` : fileContent;
|
|
45
|
+
commonDir.children.push({
|
|
46
|
+
path: "src/common/global.ts",
|
|
47
|
+
content: fullContent
|
|
48
|
+
});
|
|
49
|
+
}
|
|
39
50
|
}
|
|
40
51
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
52
|
0 && (module.exports = {
|
|
@@ -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,36 @@
|
|
|
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/generate/utils/pageImages.ts
|
|
20
|
+
var pageImages_exports = {};
|
|
21
|
+
__export(pageImages_exports, {
|
|
22
|
+
handlePageImages: () => handlePageImages
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(pageImages_exports);
|
|
25
|
+
function handlePageImages(assetsDir, imageFiles) {
|
|
26
|
+
imageFiles.forEach((imageFile) => {
|
|
27
|
+
assetsDir.children.push({
|
|
28
|
+
path: imageFile.filePath,
|
|
29
|
+
content: imageFile.fileContent.toString("base64")
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
handlePageImages
|
|
36
|
+
});
|
package/dist/cjs/handleCom.js
CHANGED
|
@@ -38,6 +38,7 @@ var import_templates = require("./utils/templates/index");
|
|
|
38
38
|
var import_component = require("./utils/templates/component");
|
|
39
39
|
var import_renderManager = require("./utils/templates/renderManager");
|
|
40
40
|
var import_handleSlot = __toESM(require("./handleSlot"));
|
|
41
|
+
var import_handleDom = __toESM(require("./handleDom"));
|
|
41
42
|
var import_processComEvents = require("./processors/processComEvents");
|
|
42
43
|
var import_handleProcess = require("./utils/logic/handleProcess");
|
|
43
44
|
var COM_PROTOCOL = {
|
|
@@ -56,16 +57,31 @@ var handleCom = (com, config) => {
|
|
|
56
57
|
const { componentName, eventHandlers, comEventCode } = prepareComponent(com, config);
|
|
57
58
|
const { cssContent, rootStyle } = prepareStyles(com);
|
|
58
59
|
let accumulatedCssContent = cssContent;
|
|
60
|
+
if (com.child) {
|
|
61
|
+
rootStyle.position = "relative";
|
|
62
|
+
}
|
|
59
63
|
const { slotsCode, accumulatedCssContent: slotCss, eventCode, childrenResults } = processComSlots(com, config, accumulatedCssContent);
|
|
60
64
|
accumulatedCssContent = slotCss;
|
|
61
|
-
|
|
65
|
+
let childrenUi = "";
|
|
66
|
+
if (com.child) {
|
|
67
|
+
const childResult = (0, import_handleDom.default)(com.child, {
|
|
68
|
+
...config,
|
|
69
|
+
depth: config.depth + 1
|
|
70
|
+
});
|
|
71
|
+
childrenUi = childResult.ui;
|
|
72
|
+
if (childResult.cssContent) {
|
|
73
|
+
accumulatedCssContent += (accumulatedCssContent ? "\n" : "") + childResult.cssContent;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const ui = generateUiCode(com, config, componentName, rootStyle, comEventCode, slotsCode, eventHandlers, childrenUi);
|
|
77
|
+
const hasEvents = Object.keys(eventHandlers).length > 0;
|
|
62
78
|
return {
|
|
63
79
|
slots: [],
|
|
64
80
|
scopeSlots: [],
|
|
65
81
|
ui,
|
|
66
82
|
js: eventCode,
|
|
67
83
|
cssContent: accumulatedCssContent,
|
|
68
|
-
outputsConfig:
|
|
84
|
+
outputsConfig: hasEvents ? { [meta.id]: eventHandlers } : void 0,
|
|
69
85
|
childrenResults,
|
|
70
86
|
name: meta.name,
|
|
71
87
|
// 返回解析后的稳定名称
|
|
@@ -117,7 +133,13 @@ var processComSlots = (com, config, initialCss) => {
|
|
|
117
133
|
slotEntries.forEach(([slotId, slot], index) => {
|
|
118
134
|
var _a, _b, _c, _d;
|
|
119
135
|
const children = slot.comAry || slot.children || [];
|
|
136
|
+
const isLast = index === slotEntries.length - 1;
|
|
137
|
+
const slotIndent = (0, import_templates.indentation)(config.codeStyle.indent * (config.depth + 2));
|
|
120
138
|
if (children.length === 0) {
|
|
139
|
+
slotsCode += `${slotIndent}${slotId}: {
|
|
140
|
+
${slotIndent} render: () => null
|
|
141
|
+
${slotIndent}}${isLast ? "" : ","}
|
|
142
|
+
`;
|
|
121
143
|
return;
|
|
122
144
|
}
|
|
123
145
|
const slotLayout = (_a = com.props.data) == null ? void 0 : _a.layout;
|
|
@@ -127,6 +149,8 @@ var processComSlots = (com, config, initialCss) => {
|
|
|
127
149
|
depth: 1,
|
|
128
150
|
renderManager,
|
|
129
151
|
slotKey: slotId,
|
|
152
|
+
// 给 slot 根容器打标用(slot wrapper className)
|
|
153
|
+
parentComId: meta.id,
|
|
130
154
|
// 鸿蒙化:传递父容器的布局配置给插槽
|
|
131
155
|
layout: slotLayout
|
|
132
156
|
});
|
|
@@ -135,12 +159,10 @@ var processComSlots = (com, config, initialCss) => {
|
|
|
135
159
|
accumulatedCssContent += (accumulatedCssContent ? "\n" : "") + result.cssContent;
|
|
136
160
|
}
|
|
137
161
|
const renderId = `${meta.id}_${slotId}`;
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
const formattedContent = (0, import_templates.formatSlotContent)(result.ui, baseIndentSize, renderBodyIndent);
|
|
141
|
-
if (meta.def.namespace === "mybricks.taro.formContainer" && Array.isArray((_b = props.data) == null ? void 0 : _b.items) && result.childrenResults) {
|
|
162
|
+
const rawContent = result.ui;
|
|
163
|
+
if (meta.def.namespace === "mybricks.taro.formContainer" && Array.isArray((_b = props.data) == null ? void 0 : _b.items) && result.directChildren) {
|
|
142
164
|
const items = (_c = props.data) == null ? void 0 : _c.items;
|
|
143
|
-
result.
|
|
165
|
+
result.directChildren.forEach((childRes) => {
|
|
144
166
|
const itemConfig = items.find((it) => it.id === childRes.id);
|
|
145
167
|
if (itemConfig == null ? void 0 : itemConfig.comName) {
|
|
146
168
|
childRes.name = itemConfig.comName;
|
|
@@ -150,14 +172,15 @@ var processComSlots = (com, config, initialCss) => {
|
|
|
150
172
|
const logicCode = buildSlotLogicCode({
|
|
151
173
|
parentComId: meta.id,
|
|
152
174
|
slotKey: slotId,
|
|
153
|
-
children: result.
|
|
175
|
+
children: result.directChildren,
|
|
154
176
|
config
|
|
155
177
|
});
|
|
156
178
|
const description = `${meta.title || meta.id}的${slot.title || slotId}插槽`;
|
|
157
179
|
renderManager.register(
|
|
158
180
|
renderId,
|
|
159
|
-
|
|
160
|
-
result.
|
|
181
|
+
rawContent,
|
|
182
|
+
result.directChildren,
|
|
183
|
+
// 仅传入直接子组件,避免递归替换导致的结构破坏
|
|
161
184
|
logicCode,
|
|
162
185
|
slot.type,
|
|
163
186
|
slot.wrap || slot.itemWrap || ((_d = COM_PROTOCOL[meta.def.namespace]) == null ? void 0 : _d.useWrap),
|
|
@@ -166,12 +189,11 @@ var processComSlots = (com, config, initialCss) => {
|
|
|
166
189
|
if (result.childrenResults) {
|
|
167
190
|
allChildrenResults = allChildrenResults.concat(result.childrenResults);
|
|
168
191
|
}
|
|
169
|
-
const slotIndent = (0, import_templates.indentation)(config.codeStyle.indent * (config.depth + 2));
|
|
170
192
|
slotsCode += (0, import_component.genSlotRenderRef)({
|
|
171
193
|
slotId,
|
|
172
194
|
renderId,
|
|
173
195
|
indent: slotIndent,
|
|
174
|
-
isLast
|
|
196
|
+
isLast
|
|
175
197
|
});
|
|
176
198
|
});
|
|
177
199
|
return { slotsCode, accumulatedCssContent, eventCode, childrenResults: allChildrenResults };
|
|
@@ -210,7 +232,7 @@ var buildSlotLogicCode = (args) => {
|
|
|
210
232
|
`;
|
|
211
233
|
return code;
|
|
212
234
|
};
|
|
213
|
-
var generateUiCode = (com, config, componentName, rootStyle, comEventCode, slotsCode, eventHandlers) => {
|
|
235
|
+
var generateUiCode = (com, config, componentName, rootStyle, comEventCode, slotsCode, eventHandlers, childrenUi) => {
|
|
214
236
|
var _a, _b, _c, _d;
|
|
215
237
|
const { meta, props } = com;
|
|
216
238
|
const scene = config.getCurrentScene();
|
|
@@ -225,7 +247,8 @@ var generateUiCode = (com, config, componentName, rootStyle, comEventCode, slots
|
|
|
225
247
|
componentOutputs: (((_c = sceneCom == null ? void 0 : sceneCom.outputs) == null ? void 0 : _c.length) || 0) > 0 ? sceneCom.outputs : (((_d = meta.outputs) == null ? void 0 : _d.length) || 0) > 0 ? meta.outputs : void 0,
|
|
226
248
|
comEventCode,
|
|
227
249
|
slotsCode,
|
|
228
|
-
eventHandlers
|
|
250
|
+
eventHandlers,
|
|
251
|
+
childrenUi
|
|
229
252
|
},
|
|
230
253
|
{
|
|
231
254
|
codeStyle: config.codeStyle,
|
package/dist/cjs/handleDom.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ type HandleDomResult = {
|
|
|
14
14
|
slots: string[];
|
|
15
15
|
scopeSlots: string[];
|
|
16
16
|
cssContent: string;
|
|
17
|
+
directChildren?: any[];
|
|
18
|
+
childrenResults?: any[];
|
|
17
19
|
};
|
|
18
20
|
declare const handleDom: (dom: Dom, config: HandleDomConfig) => HandleDomResult;
|
|
19
21
|
export default handleDom;
|
package/dist/cjs/handleDom.js
CHANGED
|
@@ -26,8 +26,9 @@ var import_utils = require("./utils");
|
|
|
26
26
|
var import_processChildren = require("./utils/logic/processChildren");
|
|
27
27
|
var handleDom = (dom, config) => {
|
|
28
28
|
var _a;
|
|
29
|
-
const { props
|
|
29
|
+
const { props } = dom;
|
|
30
30
|
const domProps = props;
|
|
31
|
+
const children = (0, import_processChildren.normalizeChildren)(dom);
|
|
31
32
|
const childResults = (0, import_processChildren.processChildren)(children, {
|
|
32
33
|
...config,
|
|
33
34
|
depth: config.depth + 1
|
|
@@ -43,7 +44,9 @@ ${indent}</View>`;
|
|
|
43
44
|
js: childResults.js,
|
|
44
45
|
slots: childResults.slots,
|
|
45
46
|
scopeSlots: childResults.scopeSlots,
|
|
46
|
-
cssContent
|
|
47
|
+
cssContent,
|
|
48
|
+
directChildren: childResults.directChildren,
|
|
49
|
+
childrenResults: childResults.childrenResults
|
|
47
50
|
};
|
|
48
51
|
};
|
|
49
52
|
var handleDom_default = handleDom;
|
package/dist/cjs/handleGlobal.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(handleGlobal_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(handleGlobal_exports);
|
|
25
25
|
var import_utils = require("./utils");
|
|
26
26
|
var import_handleProcess = require("./utils/logic/handleProcess");
|
|
27
|
+
var import_string = require("./utils/common/string");
|
|
27
28
|
var handleGlobal = (params, config) => {
|
|
28
29
|
const { tojson, globalFxs, globalVars } = params;
|
|
29
30
|
const globalImportManager = new import_utils.ImportManager(config);
|
|
@@ -64,11 +65,12 @@ var handleGlobal = (params, config) => {
|
|
|
64
65
|
return tojson.global;
|
|
65
66
|
}
|
|
66
67
|
});
|
|
68
|
+
const varKey = (0, import_string.getSafeVarName)(com);
|
|
67
69
|
globalVarsRegisterChangeCode += `
|
|
68
|
-
${indent2}this.${
|
|
70
|
+
${indent2}this.${varKey}.registerChange((value: any) => {
|
|
69
71
|
${res}
|
|
70
72
|
${indent2}})`;
|
|
71
|
-
globalVarsInitCode += `${indent}${
|
|
73
|
+
globalVarsInitCode += `${indent}${varKey}: any = createVariable(${JSON.stringify(com.model.data.initValue || {})})
|
|
72
74
|
`;
|
|
73
75
|
});
|
|
74
76
|
let globalFxsInitCode = "";
|
package/dist/cjs/handleSlot.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ interface HandleSlotConfig extends BaseConfig {
|
|
|
12
12
|
hasPopups?: boolean;
|
|
13
13
|
/** handleCom 处理 slots 时的 slot key(如 item/content),用于识别 scope 入参 */
|
|
14
14
|
slotKey?: string;
|
|
15
|
+
/** 父组件 id(用于给插槽根容器打标 className) */
|
|
16
|
+
parentComId?: string;
|
|
15
17
|
}
|
|
16
18
|
declare const handleSlot: (ui: UI, config: HandleSlotConfig) => {
|
|
17
19
|
js: string;
|
|
@@ -20,6 +22,7 @@ declare const handleSlot: (ui: UI, config: HandleSlotConfig) => {
|
|
|
20
22
|
cssContent: string;
|
|
21
23
|
slots: any[];
|
|
22
24
|
scopeSlots: any[];
|
|
25
|
+
directChildren: any[];
|
|
23
26
|
childrenResults: any[];
|
|
24
27
|
};
|
|
25
28
|
export default handleSlot;
|