@mybricks/to-code-taro 1.1.7 → 1.1.8
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/generate/generateTaroProjectJson.js +45 -0
- package/dist/cjs/handleCom.js +1 -1
- package/dist/cjs/handleModule.js +6 -8
- package/dist/cjs/handleSlot.d.ts +1 -0
- package/dist/cjs/handleSlot.js +6 -3
- package/dist/cjs/processors/processModule.js +1 -0
- package/dist/cjs/processors/processSceneLogic.js +5 -1
- package/dist/cjs/toCodeTaro.js +89 -0
- package/dist/cjs/utils/logic/handleProcess.js +25 -17
- package/dist/cjs/utils/templates/component.js +1 -1
- package/dist/cjs/utils/templates/index.d.ts +2 -0
- package/dist/cjs/utils/templates/index.js +7 -2
- package/dist/cjs/utils/templates/renderManager.js +2 -2
- package/dist/cjs/utils/templates/scene.d.ts +1 -1
- package/dist/cjs/utils/templates/scene.js +4 -2
- package/dist/esm/generate/generateTaroProjectJson.js +41 -0
- package/dist/esm/handleCom.js +1 -1
- package/dist/esm/handleModule.js +5 -7
- package/dist/esm/handleSlot.d.ts +1 -0
- package/dist/esm/handleSlot.js +10 -7
- package/dist/esm/processors/processModule.js +1 -0
- package/dist/esm/processors/processSceneLogic.js +4 -2
- package/dist/esm/toCodeTaro.js +112 -0
- package/dist/esm/utils/logic/handleProcess.js +38 -17
- package/dist/esm/utils/templates/component.js +2 -2
- package/dist/esm/utils/templates/index.d.ts +2 -0
- package/dist/esm/utils/templates/index.js +5 -0
- package/dist/esm/utils/templates/renderManager.js +3 -3
- package/dist/esm/utils/templates/scene.d.ts +1 -1
- package/dist/esm/utils/templates/scene.js +4 -1
- package/package.json +1 -1
|
@@ -139,6 +139,51 @@ ${item.content || ""}`;
|
|
|
139
139
|
children: popupChildren
|
|
140
140
|
});
|
|
141
141
|
});
|
|
142
|
+
const compsDir = (0, import_fileNode.ensureDir)(srcDir, "src/comps");
|
|
143
|
+
const moduleScenes = files.filter((item) => item.type === "module" && item.meta);
|
|
144
|
+
const moduleExports = [];
|
|
145
|
+
moduleScenes.forEach((item) => {
|
|
146
|
+
var _a2;
|
|
147
|
+
const moduleId = item.meta.id;
|
|
148
|
+
const exportName = `C${String(moduleId).replace(/[^a-zA-Z0-9]/g, "_").toUpperCase()}`;
|
|
149
|
+
const importCode = ((_a2 = item.importManager) == null ? void 0 : _a2.toCode()) || "";
|
|
150
|
+
const fullContent = `${importCode}
|
|
151
|
+
${item.content || ""}`;
|
|
152
|
+
const moduleChildren = [
|
|
153
|
+
{
|
|
154
|
+
path: `src/comps/${moduleId}/index.tsx`,
|
|
155
|
+
content: fullContent
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
path: `src/comps/${moduleId}/index.global.less`,
|
|
159
|
+
content: item.cssContent || ""
|
|
160
|
+
}
|
|
161
|
+
];
|
|
162
|
+
if (item.jsModules && item.jsModules.length > 0) {
|
|
163
|
+
moduleChildren.push({
|
|
164
|
+
path: `src/comps/${moduleId}/index.jsModules.ts`,
|
|
165
|
+
content: (0, import_genJSModules.genScopedJSModules)(
|
|
166
|
+
item.jsModules,
|
|
167
|
+
"@/core/mybricks/index",
|
|
168
|
+
"@/common/jsModulesRuntime"
|
|
169
|
+
)
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
compsDir.children.push({
|
|
173
|
+
path: `src/comps/${moduleId}`,
|
|
174
|
+
content: null,
|
|
175
|
+
children: moduleChildren
|
|
176
|
+
});
|
|
177
|
+
moduleExports.push(
|
|
178
|
+
`export { default as ${exportName} } from "./${moduleId}/index";`
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
if (moduleExports.length > 0) {
|
|
182
|
+
compsDir.children.push({
|
|
183
|
+
path: "src/comps/Index.ts",
|
|
184
|
+
content: moduleExports.join("\n") + "\n"
|
|
185
|
+
});
|
|
186
|
+
}
|
|
142
187
|
const appConfigFile = (_a = srcDir.children) == null ? void 0 : _a.find(
|
|
143
188
|
(node) => node.path === "src/app.config.ts"
|
|
144
189
|
);
|
package/dist/cjs/handleCom.js
CHANGED
|
@@ -157,7 +157,7 @@ ${slotIndent}}${isLast ? "" : ","}
|
|
|
157
157
|
if (result.cssContent) {
|
|
158
158
|
accumulatedCssContent += (accumulatedCssContent ? "\n" : "") + result.cssContent;
|
|
159
159
|
}
|
|
160
|
-
const renderId = `${meta.id}_${slotId}
|
|
160
|
+
const renderId = slotEntries.length > 1 ? `${meta.id}_${slotId}` : meta.id;
|
|
161
161
|
const rawContent = result.ui;
|
|
162
162
|
if (meta.def.namespace === "mybricks.taro.formContainer" && Array.isArray((_g = props.data) == null ? void 0 : _g.items) && result.directChildren) {
|
|
163
163
|
const items = (_h = props.data) == null ? void 0 : _h.items;
|
package/dist/cjs/handleModule.js
CHANGED
|
@@ -25,11 +25,9 @@ module.exports = __toCommonJS(handleModule_exports);
|
|
|
25
25
|
var import_utils = require("./utils");
|
|
26
26
|
var import_handleProcess = require("./utils/logic/handleProcess");
|
|
27
27
|
var handleModule = (module2, config) => {
|
|
28
|
-
var _a, _b
|
|
28
|
+
var _a, _b;
|
|
29
29
|
const { events, moduleId, props } = module2;
|
|
30
|
-
const
|
|
31
|
-
const rawName = ((_a = config.getFileName) == null ? void 0 : _a.call(config, moduleId)) || moduleScene.title;
|
|
32
|
-
const name = (0, import_utils.firstCharToUpperCase)(rawName);
|
|
30
|
+
const name = `C${String(moduleId).replace(/[^a-zA-Z0-9]/g, "_").toUpperCase()}`;
|
|
33
31
|
let comEventCode = "";
|
|
34
32
|
const indent = (0, import_utils.indentation)(config.codeStyle.indent * (config.depth + 1));
|
|
35
33
|
Object.entries(events).forEach(([eventId, { diagramId }]) => {
|
|
@@ -66,7 +64,7 @@ ${indent}},
|
|
|
66
64
|
`;
|
|
67
65
|
});
|
|
68
66
|
config.addParentDependencyImport({
|
|
69
|
-
packageName: "
|
|
67
|
+
packageName: "@/comps/Index",
|
|
70
68
|
dependencyNames: [name],
|
|
71
69
|
importType: "named"
|
|
72
70
|
});
|
|
@@ -75,8 +73,8 @@ ${indent}},
|
|
|
75
73
|
currentProvider.coms.add(module2.meta.id);
|
|
76
74
|
currentProvider.controllers.add(module2.meta.id);
|
|
77
75
|
const resultStyle = (0, import_utils.convertComponentStyle)(module2.props.style);
|
|
78
|
-
const cssContent = (0, import_utils.convertStyleAryToCss)((
|
|
79
|
-
const componentController = ((
|
|
76
|
+
const cssContent = (0, import_utils.convertStyleAryToCss)((_a = props.style) == null ? void 0 : _a.styleAry, module2.meta.id);
|
|
77
|
+
const componentController = ((_b = config.getComponentController) == null ? void 0 : _b.call(config, {
|
|
80
78
|
com: module2.meta,
|
|
81
79
|
scene: config.getCurrentScene()
|
|
82
80
|
})) || `controller_${module2.meta.id}`;
|
|
@@ -90,7 +88,7 @@ ${indent3}data={${(0, import_utils.genObjectCode)(configs, {
|
|
|
90
88
|
initialIndent: initialIndent + config.codeStyle.indent * 2,
|
|
91
89
|
indentSize: config.codeStyle.indent
|
|
92
90
|
})}}` : "") + `
|
|
93
|
-
${indent3}controller={
|
|
91
|
+
${indent3}controller={comRefs.current.${componentController}}` + (comEventCode ? `
|
|
94
92
|
${indent3}onEvents={{${comEventCode.replace(/\n/g, "\n" + indent3)}}}` : "") + `
|
|
95
93
|
${indent2}/>`;
|
|
96
94
|
const ui = `${indentView}<View id="${module2.meta.id}" className="${module2.meta.id}" style={${JSON.stringify(resultStyle.root)}}>
|
package/dist/cjs/handleSlot.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface HandleSlotConfig extends BaseConfig {
|
|
|
9
9
|
renderManager?: RenderManager;
|
|
10
10
|
addJSModule?: (module: any) => void;
|
|
11
11
|
isPopup?: boolean;
|
|
12
|
+
isModule?: boolean;
|
|
12
13
|
hasPopups?: boolean;
|
|
13
14
|
/** handleCom 处理 slots 时的 slot key(如 item/content),用于识别 scope 入参 */
|
|
14
15
|
slotKey?: string;
|
package/dist/cjs/handleSlot.js
CHANGED
|
@@ -50,7 +50,7 @@ var handleSlot = (ui, config) => {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
const indent2 = (0, import_utils.indentation)(config.codeStyle.indent);
|
|
53
|
-
const envDefineCode = isRoot ? (0, import_scene.genRootDefineCode)(indent2, config.getUtilsPackageName()) : (0, import_scene.genSlotDefineCode)(indent2);
|
|
53
|
+
const envDefineCode = isRoot ? (0, import_scene.genRootDefineCode)(indent2, config.getUtilsPackageName(), false, config.isModule) : (0, import_scene.genSlotDefineCode)(indent2);
|
|
54
54
|
const renderManager = isRoot ? new import_renderManager.RenderManager() : config.renderManager || new import_renderManager.RenderManager();
|
|
55
55
|
const childResults = (0, import_processChildren.processChildren)(children, {
|
|
56
56
|
...config,
|
|
@@ -96,7 +96,9 @@ var setupImports = (addImport, config, isRoot) => {
|
|
|
96
96
|
addImport({ packageName: utilsPkg, dependencyNames, importType: "named" });
|
|
97
97
|
addImport({ packageName: comPkg, dependencyNames: ["useAppContext"], importType: "named" });
|
|
98
98
|
if (isRoot) {
|
|
99
|
-
|
|
99
|
+
if (!config.isModule) {
|
|
100
|
+
addImport({ packageName: "@/common/pageLife", dependencyNames: ["usePageLife"], importType: "named" });
|
|
101
|
+
}
|
|
100
102
|
if (config.hasPopups) {
|
|
101
103
|
addImport({ packageName: "@/common/popup", dependencyNames: ["POPUP_MAP", "POPUP_IDS"], importType: "named" });
|
|
102
104
|
}
|
|
@@ -126,7 +128,8 @@ var finalizeRootComponent = (ui, config, importManager, combinedJsCode, renderDe
|
|
|
126
128
|
var _a, _b, _c;
|
|
127
129
|
const fileName = ((_a = config.getFileName) == null ? void 0 : _a.call(config, ui.meta.slotId)) || ui.meta.title || "index";
|
|
128
130
|
const componentId = ((_b = ui.meta) == null ? void 0 : _b.id) || ui.id || ((_c = ui.meta) == null ? void 0 : _c.slotId) || "Index";
|
|
129
|
-
const
|
|
131
|
+
const prefix = config.isModule ? "C" : "P";
|
|
132
|
+
const componentName = `${prefix}${String(componentId).replace(/[^a-zA-Z0-9]/g, "_").toUpperCase()}`;
|
|
130
133
|
const componentCode = (0, import_scene.genComponentTemplate)({
|
|
131
134
|
componentId,
|
|
132
135
|
componentName,
|
|
@@ -64,6 +64,7 @@ var processModule = (params) => {
|
|
|
64
64
|
const eventQueries = (0, import_createEventQueries.createEventQueries)(event);
|
|
65
65
|
(0, import_handleSlot.default)(ui, {
|
|
66
66
|
...config,
|
|
67
|
+
isModule: true,
|
|
67
68
|
getCurrentScene: () => {
|
|
68
69
|
const originalScene = getSceneById(scene.id);
|
|
69
70
|
return { ...scene, ...originalScene, event };
|
|
@@ -84,7 +84,11 @@ ${indent} const run_${varName}_${pinId} = (value: any) => {
|
|
|
84
84
|
${process}
|
|
85
85
|
${indent} };`;
|
|
86
86
|
code += `
|
|
87
|
-
${indent} $vars.current.${varName}
|
|
87
|
+
${indent} $vars.current.${varName}.registerChange((changeValue: any) => {`;
|
|
88
|
+
code += `
|
|
89
|
+
${indent} changeValue[SUBJECT_SUBSCRIBE](run_${varName}_${pinId});`;
|
|
90
|
+
code += `
|
|
91
|
+
${indent} });`;
|
|
88
92
|
});
|
|
89
93
|
return code;
|
|
90
94
|
};
|
package/dist/cjs/toCodeTaro.js
CHANGED
|
@@ -45,6 +45,14 @@ var import_buildResult = require("./utils/builder/buildResult");
|
|
|
45
45
|
var import_processScene = require("./processors/processScene");
|
|
46
46
|
var import_processModule = require("./processors/processModule");
|
|
47
47
|
var toCodeTaro = (tojson, config) => {
|
|
48
|
+
if (tojson.modules) {
|
|
49
|
+
Object.values(tojson.modules).forEach((mod) => {
|
|
50
|
+
if (mod.json) {
|
|
51
|
+
tojson.scenes.push(mod.json);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
rebuildModuleFrames(tojson);
|
|
55
|
+
}
|
|
48
56
|
return getCode({ tojson, toCodejson: (0, import_toCode.default)(tojson) }, config);
|
|
49
57
|
};
|
|
50
58
|
var getCode = (params, config) => {
|
|
@@ -55,6 +63,14 @@ var getCode = (params, config) => {
|
|
|
55
63
|
const frameMap = (0, import_buildFrameMap.buildFrameMap)(tojson);
|
|
56
64
|
const getFrameById = (0, import_buildContext.createGetFrameById)(frameMap);
|
|
57
65
|
const sceneMap = (0, import_buildContext.buildSceneMap)(tojson.scenes);
|
|
66
|
+
if (tojson.modules) {
|
|
67
|
+
Object.values(tojson.modules).forEach((mod) => {
|
|
68
|
+
var _a;
|
|
69
|
+
if ((_a = mod.json) == null ? void 0 : _a.id) {
|
|
70
|
+
sceneMap[mod.json.id] = mod.json;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
58
74
|
const eventsMap = (0, import_buildContext.buildEventsMap)(tojson.frames);
|
|
59
75
|
const getSceneById = (0, import_buildContext.createGetSceneById)(sceneMap);
|
|
60
76
|
const getExtensionEventById = (0, import_buildContext.createGetExtensionEventById)(eventsMap);
|
|
@@ -227,6 +243,79 @@ var getCode = (params, config) => {
|
|
|
227
243
|
}
|
|
228
244
|
};
|
|
229
245
|
};
|
|
246
|
+
var rebuildModuleFrames = (tojson) => {
|
|
247
|
+
const modules = tojson.modules;
|
|
248
|
+
if (!modules)
|
|
249
|
+
return;
|
|
250
|
+
Object.values(modules).forEach((mod) => {
|
|
251
|
+
const moduleJson = mod.json;
|
|
252
|
+
if (!moduleJson)
|
|
253
|
+
return;
|
|
254
|
+
const frame = tojson.frames.find((f) => f.id === moduleJson.id);
|
|
255
|
+
if (!frame || Object.keys(frame.coms).length > 0)
|
|
256
|
+
return;
|
|
257
|
+
const coms = moduleJson.coms || {};
|
|
258
|
+
const cons = moduleJson.cons || {};
|
|
259
|
+
Object.values(coms).forEach((com) => {
|
|
260
|
+
var _a;
|
|
261
|
+
const outputEvents = (_a = com.model) == null ? void 0 : _a.outputEvents;
|
|
262
|
+
if (!outputEvents || Object.keys(outputEvents).length === 0)
|
|
263
|
+
return;
|
|
264
|
+
const comFrames = [];
|
|
265
|
+
Object.entries(outputEvents).forEach(([pinId, events]) => {
|
|
266
|
+
var _a2;
|
|
267
|
+
const activeEvent = Array.isArray(events) ? events.find((e) => e.active) : null;
|
|
268
|
+
if (!((_a2 = activeEvent == null ? void 0 : activeEvent.options) == null ? void 0 : _a2.id))
|
|
269
|
+
return;
|
|
270
|
+
const diagramId = activeEvent.options.id;
|
|
271
|
+
const consKey = `${com.id}-${pinId}`;
|
|
272
|
+
const connections = cons[consKey] || [];
|
|
273
|
+
const conAry = connections.map((con) => ({
|
|
274
|
+
id: con.id,
|
|
275
|
+
from: {
|
|
276
|
+
id: pinId,
|
|
277
|
+
title: activeEvent.options.title || pinId,
|
|
278
|
+
parent: { id: com.id, type: "com" }
|
|
279
|
+
},
|
|
280
|
+
to: {
|
|
281
|
+
id: con.pinId,
|
|
282
|
+
title: con.pinId,
|
|
283
|
+
parent: { id: con.comId, type: "com" }
|
|
284
|
+
},
|
|
285
|
+
startPinParentKey: con.startPinParentKey || con.frameKey,
|
|
286
|
+
finishPinParentKey: con.finishPinParentKey || con.targetFrameKey
|
|
287
|
+
}));
|
|
288
|
+
if (conAry.length === 0)
|
|
289
|
+
return;
|
|
290
|
+
comFrames.push({
|
|
291
|
+
id: `${com.id}_${pinId}_frame`,
|
|
292
|
+
title: activeEvent.options.title || `${com.title} > ${pinId}`,
|
|
293
|
+
type: "com",
|
|
294
|
+
coms: {},
|
|
295
|
+
autoRunComs: {},
|
|
296
|
+
inputs: [],
|
|
297
|
+
outputs: [],
|
|
298
|
+
frames: [],
|
|
299
|
+
diagrams: [{
|
|
300
|
+
id: diagramId,
|
|
301
|
+
title: activeEvent.options.title || `${com.title} > ${pinId}`,
|
|
302
|
+
starter: {
|
|
303
|
+
type: "com",
|
|
304
|
+
comId: com.id,
|
|
305
|
+
pinId
|
|
306
|
+
},
|
|
307
|
+
conAry,
|
|
308
|
+
runtimeBefore: [],
|
|
309
|
+
runtimeAfter: []
|
|
310
|
+
}]
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
if (comFrames.length > 0) {
|
|
314
|
+
frame.coms[com.id] = { id: com.id, frames: comFrames };
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
};
|
|
230
319
|
var transformConfig = (config) => {
|
|
231
320
|
if (!config.codeStyle) {
|
|
232
321
|
config.codeStyle = {
|
|
@@ -111,15 +111,15 @@ ${indent}}, appContext)
|
|
|
111
111
|
`;
|
|
112
112
|
});
|
|
113
113
|
const outputToInputPinMap = /* @__PURE__ */ new Map();
|
|
114
|
+
const declaredVarCount = /* @__PURE__ */ new Map();
|
|
114
115
|
process.nodesInvocation.forEach((props) => {
|
|
115
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
116
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
116
117
|
const { componentType, category, runType } = props;
|
|
117
118
|
const nextValue = getNextValue(props, config, event, outputToInputPinMap);
|
|
118
119
|
const isSameScope = checkIsSameScope(event, props);
|
|
119
|
-
const nextCode = getNextCode(props, config, isSameScope, event);
|
|
120
|
-
const inputPinId = props.id.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
120
|
+
const { code: nextCode, varName: declaredVarName } = getNextCode(props, config, isSameScope, event, declaredVarCount);
|
|
121
121
|
(_a = props.nextParam) == null ? void 0 : _a.forEach((np) => {
|
|
122
|
-
outputToInputPinMap.set(`${props.meta.id}_${np.id}`,
|
|
122
|
+
outputToInputPinMap.set(`${props.meta.id}_${np.id}`, declaredVarName);
|
|
123
123
|
});
|
|
124
124
|
if (code) {
|
|
125
125
|
code += "\n";
|
|
@@ -160,6 +160,8 @@ ${indent}${nextCode}this.${sceneId}.${method}(${nextValue})`;
|
|
|
160
160
|
${indent}${nextCode}${componentNameWithId}(${runType === "input" ? nextValue : ""})`;
|
|
161
161
|
} else if (category === "var") {
|
|
162
162
|
const varKey = (0, import_string.getSafeVarName)(props.meta);
|
|
163
|
+
const xpath = (_f = props.extData) == null ? void 0 : _f.xpath;
|
|
164
|
+
const xpathArg = xpath ? `, "${xpath.replace(/^\//, "").replace(/\//g, ".")}"` : "";
|
|
163
165
|
if (props.meta.global) {
|
|
164
166
|
config.addParentDependencyImport({
|
|
165
167
|
packageName: "../../common/global",
|
|
@@ -167,14 +169,14 @@ ${indent}${nextCode}${componentNameWithId}(${runType === "input" ? nextValue : "
|
|
|
167
169
|
importType: "named"
|
|
168
170
|
});
|
|
169
171
|
code += `${indent}/** ${props.title} 全局变量 ${props.meta.title} */
|
|
170
|
-
${indent}${nextCode}globalVars.${varKey}.${props.id}(${nextValue})`;
|
|
172
|
+
${indent}${nextCode}globalVars.${varKey}.${props.id}(${nextValue}${xpathArg})`;
|
|
171
173
|
} else {
|
|
172
174
|
const currentProvider = getCurrentProvider(
|
|
173
175
|
{ isSameScope, props },
|
|
174
176
|
config
|
|
175
177
|
);
|
|
176
178
|
code += `${indent}/** ${props.title} 变量 ${props.meta.title} */
|
|
177
|
-
${indent}${nextCode}this.$vars.${varKey}.${props.id}(${nextValue})`;
|
|
179
|
+
${indent}${nextCode}this.$vars.${varKey}.${props.id}(${nextValue}${xpathArg})`;
|
|
178
180
|
}
|
|
179
181
|
} else if (category === "fx") {
|
|
180
182
|
if (props.meta.global) {
|
|
@@ -197,7 +199,7 @@ ${indent}${nextCode}this.$fxs.${props.meta.ioProxy.id}(${nextValue})`;
|
|
|
197
199
|
} else {
|
|
198
200
|
if (props.type === "frameOutput") {
|
|
199
201
|
const currentScene = config.getCurrentScene();
|
|
200
|
-
const parentComId = event.comId || ((
|
|
202
|
+
const parentComId = event.comId || ((_g = event.meta) == null ? void 0 : _g.parentComId);
|
|
201
203
|
const frameConEntry = Object.values(currentScene.cons || {}).flat().find((con) => {
|
|
202
204
|
if (con.type !== "frame" || con.pinId !== props.id)
|
|
203
205
|
return false;
|
|
@@ -206,7 +208,7 @@ ${indent}${nextCode}this.$fxs.${props.meta.ioProxy.id}(${nextValue})`;
|
|
|
206
208
|
return true;
|
|
207
209
|
});
|
|
208
210
|
const comId = (frameConEntry == null ? void 0 : frameConEntry.comId) || props.meta.id;
|
|
209
|
-
const comTitle = ((
|
|
211
|
+
const comTitle = ((_i = (_h = currentScene.coms) == null ? void 0 : _h[comId]) == null ? void 0 : _i.title) || props.meta.title || comId;
|
|
210
212
|
code += `${indent}/** 调用 ${comTitle} 的 ${props.title} */
|
|
211
213
|
${indent}${nextCode}$outputs['${comId}'].${props.id}(${nextValue})`;
|
|
212
214
|
} else {
|
|
@@ -279,15 +281,21 @@ var getComponentNameWithId = (props, config, event) => {
|
|
|
279
281
|
const sanitizedName = name.replace(/-/g, "_");
|
|
280
282
|
return `${sanitizedName}_${props.meta.id}`;
|
|
281
283
|
};
|
|
282
|
-
var getNextCode = (props, config, isSameScope, event) => {
|
|
284
|
+
var getNextCode = (props, config, isSameScope, event, declaredVarCount) => {
|
|
283
285
|
const { nextParam } = props;
|
|
284
286
|
if (!nextParam.length) {
|
|
285
|
-
return "";
|
|
287
|
+
return { code: "", varName: "" };
|
|
286
288
|
}
|
|
287
289
|
const componentNameWithId = getComponentNameWithId(props, config, event);
|
|
288
290
|
const pinId = props.id;
|
|
289
291
|
const sanitizedPinId = pinId.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
290
|
-
|
|
292
|
+
let varName = `${componentNameWithId}_${sanitizedPinId}_result`;
|
|
293
|
+
const count = declaredVarCount.get(varName) || 0;
|
|
294
|
+
declaredVarCount.set(varName, count + 1);
|
|
295
|
+
if (count > 0) {
|
|
296
|
+
varName = `${varName}_${count}`;
|
|
297
|
+
}
|
|
298
|
+
return { code: `const ${varName}: any = `, varName };
|
|
291
299
|
};
|
|
292
300
|
function getFrameInputValueExpr(meta, config, event) {
|
|
293
301
|
var _a, _b, _c, _d;
|
|
@@ -320,16 +328,16 @@ var getNextValue = (props, config, event, outputToInputPinMap) => {
|
|
|
320
328
|
const componentNameWithId = getComponentNameWithId(param, config, event);
|
|
321
329
|
if ((_e = (_d = (_c = param.meta) == null ? void 0 : _c.def) == null ? void 0 : _d.namespace) == null ? void 0 : _e.includes(".var")) {
|
|
322
330
|
const key2 = `${(_f = param.meta) == null ? void 0 : _f.id}_${param.id}`;
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
return
|
|
331
|
+
const fullVarName2 = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key2);
|
|
332
|
+
if (fullVarName2) {
|
|
333
|
+
return fullVarName2;
|
|
326
334
|
}
|
|
327
335
|
return `${componentNameWithId}_result`;
|
|
328
336
|
}
|
|
329
337
|
const key = `${(_g = param.meta) == null ? void 0 : _g.id}_${param.id}`;
|
|
330
|
-
const
|
|
331
|
-
if (
|
|
332
|
-
return `${
|
|
338
|
+
const fullVarName = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key);
|
|
339
|
+
if (fullVarName) {
|
|
340
|
+
return `${fullVarName}.${param.id}`;
|
|
333
341
|
}
|
|
334
342
|
return `${componentNameWithId}_result.${param.id}`;
|
|
335
343
|
});
|
|
@@ -50,7 +50,7 @@ var genSlotRenderRef = ({
|
|
|
50
50
|
indent,
|
|
51
51
|
isLast
|
|
52
52
|
}) => {
|
|
53
|
-
const renderFunctionName = (0, import_index.
|
|
53
|
+
const renderFunctionName = (0, import_index.toSlotFunctionName)(renderId);
|
|
54
54
|
return `${indent}${slotId}: {
|
|
55
55
|
${indent} render: ${renderFunctionName},
|
|
56
56
|
${indent}}${isLast ? "" : ","}
|
|
@@ -6,6 +6,8 @@ export declare const firstCharToUpperCase: (str: string) => string;
|
|
|
6
6
|
export declare const formatSlotContent: (uiContent: string, baseIndentSize: number, renderBodyIndent: string) => string;
|
|
7
7
|
/** 将字符串转为大驼峰 */
|
|
8
8
|
export declare const toPascalCase: (str: string) => string;
|
|
9
|
+
/** 生成插槽渲染函数名:S${ID} (SCREAMING_SNAKE_CASE) */
|
|
10
|
+
export declare const toSlotFunctionName: (renderId: string) => string;
|
|
9
11
|
/** Taro/React UI 组件代码生成 */
|
|
10
12
|
export declare const getUiComponentCode: (params: {
|
|
11
13
|
componentName: string;
|
|
@@ -23,7 +23,8 @@ __export(templates_exports, {
|
|
|
23
23
|
formatSlotContent: () => formatSlotContent,
|
|
24
24
|
getUiComponentCode: () => getUiComponentCode,
|
|
25
25
|
indentation: () => import__.indentation,
|
|
26
|
-
toPascalCase: () => toPascalCase
|
|
26
|
+
toPascalCase: () => toPascalCase,
|
|
27
|
+
toSlotFunctionName: () => toSlotFunctionName
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(templates_exports);
|
|
29
30
|
var import__ = require("../index");
|
|
@@ -38,6 +39,9 @@ var formatSlotContent = (uiContent, baseIndentSize, renderBodyIndent) => {
|
|
|
38
39
|
var toPascalCase = (str) => {
|
|
39
40
|
return str.split(/[_-]/).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
40
41
|
};
|
|
42
|
+
var toSlotFunctionName = (renderId) => {
|
|
43
|
+
return `S${renderId.replace(/[^a-zA-Z0-9]/g, "_").toUpperCase()}`;
|
|
44
|
+
};
|
|
41
45
|
var formatData = (data, isRoot) => {
|
|
42
46
|
if (!data)
|
|
43
47
|
return {};
|
|
@@ -107,5 +111,6 @@ ${indent}/>`;
|
|
|
107
111
|
formatSlotContent,
|
|
108
112
|
getUiComponentCode,
|
|
109
113
|
indentation,
|
|
110
|
-
toPascalCase
|
|
114
|
+
toPascalCase,
|
|
115
|
+
toSlotFunctionName
|
|
111
116
|
});
|
|
@@ -49,7 +49,7 @@ var RenderManager = class {
|
|
|
49
49
|
const indent5 = (0, import_index.indentation)(indentSize * 4);
|
|
50
50
|
const indent6 = (0, import_index.indentation)(indentSize * 5);
|
|
51
51
|
this._renders.forEach(({ renderCode, children, logicCode, useWrap, description }, renderId) => {
|
|
52
|
-
const renderFunctionName = (0, import_index.
|
|
52
|
+
const renderFunctionName = (0, import_index.toSlotFunctionName)(renderId);
|
|
53
53
|
if (description) {
|
|
54
54
|
code += `${indent}/** ${description} */
|
|
55
55
|
`;
|
|
@@ -139,7 +139,7 @@ var RenderManager = class {
|
|
|
139
139
|
return new RegExp(escaped, "g");
|
|
140
140
|
}
|
|
141
141
|
genRenderRef(slotId, renderId, indent) {
|
|
142
|
-
const renderFunctionName = (0, import_index.
|
|
142
|
+
const renderFunctionName = (0, import_index.toSlotFunctionName)(renderId);
|
|
143
143
|
return `${indent}${slotId}: {
|
|
144
144
|
${indent} render: ${renderFunctionName},
|
|
145
145
|
${indent}},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** 生成响应式 data 管理器 */
|
|
2
2
|
export declare const genReactiveDataManager: (indent: string, utilsPackageName: string) => string;
|
|
3
3
|
/** 生成根组件定义代码 (useAppContext) */
|
|
4
|
-
export declare const genRootDefineCode: (indent: string, utilsPackageName: string, hasJsModules?: boolean) => string;
|
|
4
|
+
export declare const genRootDefineCode: (indent: string, utilsPackageName: string, hasJsModules?: boolean, isModule?: boolean) => string;
|
|
5
5
|
/** 生成普通插槽定义代码 */
|
|
6
6
|
export declare const genSlotDefineCode: (indent: string) => string;
|
|
7
7
|
/** 生成控制器初始化代码 */
|
|
@@ -30,11 +30,13 @@ module.exports = __toCommonJS(scene_exports);
|
|
|
30
30
|
var genReactiveDataManager = (indent, utilsPackageName) => {
|
|
31
31
|
return ``;
|
|
32
32
|
};
|
|
33
|
-
var genRootDefineCode = (indent, utilsPackageName, hasJsModules = false) => {
|
|
33
|
+
var genRootDefineCode = (indent, utilsPackageName, hasJsModules = false, isModule = false) => {
|
|
34
34
|
let code = `${indent}const {comRefs, $vars, $fxs, appContext} = useAppContext();
|
|
35
35
|
`;
|
|
36
|
-
|
|
36
|
+
if (!isModule) {
|
|
37
|
+
code += `${indent}usePageLife();
|
|
37
38
|
`;
|
|
39
|
+
}
|
|
38
40
|
if (hasJsModules) {
|
|
39
41
|
code += `${indent}const comModules = jsModules({ createJSHandle });
|
|
40
42
|
`;
|
|
@@ -129,6 +129,47 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
|
|
|
129
129
|
});
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
+
// --- 处理模块/区块场景 (module) ---
|
|
133
|
+
var compsDir = ensureDir(srcDir, "src/comps");
|
|
134
|
+
var moduleScenes = files.filter(function (item) {
|
|
135
|
+
return item.type === "module" && item.meta;
|
|
136
|
+
});
|
|
137
|
+
var moduleExports = [];
|
|
138
|
+
moduleScenes.forEach(function (item) {
|
|
139
|
+
var _item$importManager3;
|
|
140
|
+
var moduleId = item.meta.id;
|
|
141
|
+
var exportName = "C".concat(String(moduleId).replace(/[^a-zA-Z0-9]/g, "_").toUpperCase());
|
|
142
|
+
var importCode = ((_item$importManager3 = item.importManager) === null || _item$importManager3 === void 0 ? void 0 : _item$importManager3.toCode()) || "";
|
|
143
|
+
var fullContent = "".concat(importCode, "\n").concat(item.content || "");
|
|
144
|
+
var moduleChildren = [{
|
|
145
|
+
path: "src/comps/".concat(moduleId, "/index.tsx"),
|
|
146
|
+
content: fullContent
|
|
147
|
+
}, {
|
|
148
|
+
path: "src/comps/".concat(moduleId, "/index.global.less"),
|
|
149
|
+
content: item.cssContent || ""
|
|
150
|
+
}];
|
|
151
|
+
if (item.jsModules && item.jsModules.length > 0) {
|
|
152
|
+
moduleChildren.push({
|
|
153
|
+
path: "src/comps/".concat(moduleId, "/index.jsModules.ts"),
|
|
154
|
+
content: genScopedJSModules(item.jsModules, "@/core/mybricks/index", "@/common/jsModulesRuntime")
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
compsDir.children.push({
|
|
158
|
+
path: "src/comps/".concat(moduleId),
|
|
159
|
+
content: null,
|
|
160
|
+
children: moduleChildren
|
|
161
|
+
});
|
|
162
|
+
moduleExports.push("export { default as ".concat(exportName, " } from \"./").concat(moduleId, "/index\";"));
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// 生成 comps/Index.ts 汇总导出
|
|
166
|
+
if (moduleExports.length > 0) {
|
|
167
|
+
compsDir.children.push({
|
|
168
|
+
path: "src/comps/Index.ts",
|
|
169
|
+
content: moduleExports.join("\n") + "\n"
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
132
173
|
// 更新 app.config.ts (只传入 normalItems 作为真正的页面)
|
|
133
174
|
var appConfigFile = (_srcDir$children = srcDir.children) === null || _srcDir$children === void 0 ? void 0 : _srcDir$children.find(function (node) {
|
|
134
175
|
return node.path === "src/app.config.ts";
|
package/dist/esm/handleCom.js
CHANGED
|
@@ -194,7 +194,7 @@ var processComSlots = function processComSlots(com, config, initialCss) {
|
|
|
194
194
|
if (result.cssContent) {
|
|
195
195
|
accumulatedCssContent += (accumulatedCssContent ? "\n" : "") + result.cssContent;
|
|
196
196
|
}
|
|
197
|
-
var renderId = "".concat(meta.id, "_").concat(slotId);
|
|
197
|
+
var renderId = slotEntries.length > 1 ? "".concat(meta.id, "_").concat(slotId) : meta.id;
|
|
198
198
|
|
|
199
199
|
// 关键:不再预先 formatSlotContent,而是将原始 ui 传给 renderManager
|
|
200
200
|
// 这样 RenderManager 在内部进行精确字符串替换时才能匹配成功
|
package/dist/esm/handleModule.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
import { indentation, genObjectCode, convertComponentStyle, convertStyleAryToCss
|
|
4
|
+
import { indentation, genObjectCode, convertComponentStyle, convertStyleAryToCss } from "./utils";
|
|
5
5
|
import { handleProcess } from "./utils/logic/handleProcess";
|
|
6
6
|
var handleModule = function handleModule(module, config) {
|
|
7
|
-
var
|
|
7
|
+
var _props$style, _config$getComponentC;
|
|
8
8
|
var events = module.events,
|
|
9
9
|
moduleId = module.moduleId,
|
|
10
10
|
props = module.props;
|
|
11
|
-
var
|
|
12
|
-
var rawName = ((_config$getFileName = config.getFileName) === null || _config$getFileName === void 0 ? void 0 : _config$getFileName.call(config, moduleId)) || moduleScene.title;
|
|
13
|
-
var name = firstCharToUpperCase(rawName);
|
|
11
|
+
var name = "C".concat(String(moduleId).replace(/[^a-zA-Z0-9]/g, "_").toUpperCase());
|
|
14
12
|
var comEventCode = "";
|
|
15
13
|
var indent = indentation(config.codeStyle.indent * (config.depth + 1));
|
|
16
14
|
Object.entries(events).forEach(function (_ref) {
|
|
@@ -43,7 +41,7 @@ var handleModule = function handleModule(module, config) {
|
|
|
43
41
|
comEventCode += "".concat(indent).concat(eventId, ": (").concat(defaultValue, ": any) => {\n") + process + "\n".concat(indent, "},\n");
|
|
44
42
|
});
|
|
45
43
|
config.addParentDependencyImport({
|
|
46
|
-
packageName: "
|
|
44
|
+
packageName: "@/comps/Index",
|
|
47
45
|
dependencyNames: [name],
|
|
48
46
|
importType: "named"
|
|
49
47
|
});
|
|
@@ -64,7 +62,7 @@ var handleModule = function handleModule(module, config) {
|
|
|
64
62
|
var moduleCode = "".concat(indent2, "<").concat(name) + (config.verbose ? "\n".concat(indent3, "title=\"").concat(module.meta.title, "\"") : "") + (configs ? "\n".concat(indent3, "data={").concat(genObjectCode(configs, {
|
|
65
63
|
initialIndent: initialIndent + config.codeStyle.indent * 2,
|
|
66
64
|
indentSize: config.codeStyle.indent
|
|
67
|
-
}), "}") : "") + "\n".concat(indent3, "controller={
|
|
65
|
+
}), "}") : "") + "\n".concat(indent3, "controller={comRefs.current.").concat(componentController, "}") + (comEventCode ? "\n".concat(indent3, "onEvents={{").concat(comEventCode.replace(/\n/g, "\n" + indent3), "}}") : "") + "\n".concat(indent2, "/>");
|
|
68
66
|
var ui = "".concat(indentView, "<View id=\"").concat(module.meta.id, "\" className=\"").concat(module.meta.id, "\" style={").concat(JSON.stringify(resultStyle.root), "}>\n").concat(moduleCode, "\n").concat(indentView, "</View>");
|
|
69
67
|
return {
|
|
70
68
|
ui: ui,
|
package/dist/esm/handleSlot.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface HandleSlotConfig extends BaseConfig {
|
|
|
9
9
|
renderManager?: RenderManager;
|
|
10
10
|
addJSModule?: (module: any) => void;
|
|
11
11
|
isPopup?: boolean;
|
|
12
|
+
isModule?: boolean;
|
|
12
13
|
hasPopups?: boolean;
|
|
13
14
|
/** handleCom 处理 slots 时的 slot key(如 item/content),用于识别 scope 入参 */
|
|
14
15
|
slotKey?: string;
|
package/dist/esm/handleSlot.js
CHANGED
|
@@ -37,7 +37,7 @@ var handleSlot = function handleSlot(ui, config) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
var indent2 = indentation(config.codeStyle.indent);
|
|
40
|
-
var envDefineCode = isRoot ? genRootDefineCode(indent2, config.getUtilsPackageName()) : genSlotDefineCode(indent2);
|
|
40
|
+
var envDefineCode = isRoot ? genRootDefineCode(indent2, config.getUtilsPackageName(), false, config.isModule) : genSlotDefineCode(indent2);
|
|
41
41
|
|
|
42
42
|
// 2. 处理子节点
|
|
43
43
|
var renderManager = isRoot ? new RenderManager() : config.renderManager || new RenderManager();
|
|
@@ -114,11 +114,13 @@ var setupImports = function setupImports(addImport, config, isRoot) {
|
|
|
114
114
|
importType: "named"
|
|
115
115
|
});
|
|
116
116
|
if (isRoot) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
if (!config.isModule) {
|
|
118
|
+
addImport({
|
|
119
|
+
packageName: "@/common/pageLife",
|
|
120
|
+
dependencyNames: ["usePageLife"],
|
|
121
|
+
importType: "named"
|
|
122
|
+
});
|
|
123
|
+
}
|
|
122
124
|
if (config.hasPopups) {
|
|
123
125
|
addImport({
|
|
124
126
|
packageName: "@/common/popup",
|
|
@@ -175,7 +177,8 @@ var finalizeRootComponent = function finalizeRootComponent(ui, config, importMan
|
|
|
175
177
|
var _config$getFileName, _ui$meta, _ui$meta2;
|
|
176
178
|
var fileName = ((_config$getFileName = config.getFileName) === null || _config$getFileName === void 0 ? void 0 : _config$getFileName.call(config, ui.meta.slotId)) || ui.meta.title || "index";
|
|
177
179
|
var componentId = ((_ui$meta = ui.meta) === null || _ui$meta === void 0 ? void 0 : _ui$meta.id) || ui.id || ((_ui$meta2 = ui.meta) === null || _ui$meta2 === void 0 ? void 0 : _ui$meta2.slotId) || "Index";
|
|
178
|
-
var
|
|
180
|
+
var prefix = config.isModule ? "C" : "P";
|
|
181
|
+
var componentName = "".concat(prefix).concat(String(componentId).replace(/[^a-zA-Z0-9]/g, "_").toUpperCase());
|
|
179
182
|
var componentCode = genComponentTemplate({
|
|
180
183
|
componentId: componentId,
|
|
181
184
|
componentName: componentName,
|
|
@@ -50,6 +50,7 @@ export var processModule = function processModule(params) {
|
|
|
50
50
|
|
|
51
51
|
// 处理 Slot
|
|
52
52
|
handleSlot(ui, _objectSpread(_objectSpread({}, config), {}, {
|
|
53
|
+
isModule: true,
|
|
53
54
|
getCurrentScene: function getCurrentScene() {
|
|
54
55
|
var originalScene = getSceneById(scene.id);
|
|
55
56
|
return _objectSpread(_objectSpread(_objectSpread({}, scene), originalScene), {}, {
|
|
@@ -87,9 +87,11 @@ var processVarEvents = function processVarEvents(currentScene, config, addDepend
|
|
|
87
87
|
})).replace(/this\.\$vars\./g, "$vars.current.").replace(/this\.\$fxs\./g, "$fxs.current.").replace(/this\./g, "comRefs.current.").replace(/comRefs\.current\.([a-zA-Z0-9_]+)\.controller_/g, "comRefs.current.$1.").replace(/comRefs\.current\.slot_Index\./g, "comRefs.current.");
|
|
88
88
|
if (!process.trim()) return;
|
|
89
89
|
code += "\n".concat(indent, " /** \u53D8\u91CF ").concat(sanitizeBlockComment(com.title || varName), " \u7684 ").concat(pinId, " */");
|
|
90
|
-
//
|
|
90
|
+
// 使用 registerChange 订阅变量事件,确保有初始值时也能触发
|
|
91
91
|
code += "\n".concat(indent, " const run_").concat(varName, "_").concat(pinId, " = (value: any) => {\n").concat(process, "\n").concat(indent, " };");
|
|
92
|
-
code += "\n".concat(indent, " $vars.current.").concat(varName, ".
|
|
92
|
+
code += "\n".concat(indent, " $vars.current.").concat(varName, ".registerChange((changeValue: any) => {");
|
|
93
|
+
code += "\n".concat(indent, " changeValue[SUBJECT_SUBSCRIBE](run_").concat(varName, "_").concat(pinId, ");");
|
|
94
|
+
code += "\n".concat(indent, " });");
|
|
93
95
|
});
|
|
94
96
|
return code;
|
|
95
97
|
};
|
package/dist/esm/toCodeTaro.js
CHANGED
|
@@ -32,6 +32,16 @@ import { processModules } from "./processors/processModule";
|
|
|
32
32
|
* Taro 代码生成主函数
|
|
33
33
|
*/
|
|
34
34
|
var toCodeTaro = function toCodeTaro(tojson, config) {
|
|
35
|
+
// 将 modules 中的场景展开到 scenes 中,使 toCode 能识别并处理模块
|
|
36
|
+
if (tojson.modules) {
|
|
37
|
+
Object.values(tojson.modules).forEach(function (mod) {
|
|
38
|
+
if (mod.json) {
|
|
39
|
+
tojson.scenes.push(mod.json);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
// 预处理:从 modules.json 重建 frames 中模块的事件数据
|
|
43
|
+
rebuildModuleFrames(tojson);
|
|
44
|
+
}
|
|
35
45
|
return getCode({
|
|
36
46
|
tojson: tojson,
|
|
37
47
|
toCodejson: toCode(tojson)
|
|
@@ -60,6 +70,15 @@ var getCode = function getCode(params, config) {
|
|
|
60
70
|
|
|
61
71
|
// 构建场景和事件映射
|
|
62
72
|
var sceneMap = buildSceneMap(tojson.scenes);
|
|
73
|
+
// 将模块场景也加入 sceneMap,使 getSceneById 能查到模块
|
|
74
|
+
if (tojson.modules) {
|
|
75
|
+
Object.values(tojson.modules).forEach(function (mod) {
|
|
76
|
+
var _mod$json;
|
|
77
|
+
if ((_mod$json = mod.json) !== null && _mod$json !== void 0 && _mod$json.id) {
|
|
78
|
+
sceneMap[mod.json.id] = mod.json;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
63
82
|
var eventsMap = buildEventsMap(tojson.frames);
|
|
64
83
|
var getSceneById = createGetSceneById(sceneMap);
|
|
65
84
|
var getExtensionEventById = createGetExtensionEventById(eventsMap);
|
|
@@ -242,6 +261,99 @@ var getCode = function getCode(params, config) {
|
|
|
242
261
|
};
|
|
243
262
|
};
|
|
244
263
|
|
|
264
|
+
/**
|
|
265
|
+
* 预处理:从 modules.json 重建 frames 中模块的事件数据
|
|
266
|
+
*
|
|
267
|
+
* 背景:tojson.frames 中模块的 frame 可能是空壳(coms: {}, diagrams[0].conAry: []),
|
|
268
|
+
* 而完整的组件事件数据在 modules[moduleId].json 中(coms/cons/outputEvents)。
|
|
269
|
+
* toCode 的 handleFrame 需要 frame.coms 包含组件事件子 frames 才能生成事件代码。
|
|
270
|
+
*/
|
|
271
|
+
var rebuildModuleFrames = function rebuildModuleFrames(tojson) {
|
|
272
|
+
var modules = tojson.modules;
|
|
273
|
+
if (!modules) return;
|
|
274
|
+
Object.values(modules).forEach(function (mod) {
|
|
275
|
+
var moduleJson = mod.json;
|
|
276
|
+
if (!moduleJson) return;
|
|
277
|
+
var frame = tojson.frames.find(function (f) {
|
|
278
|
+
return f.id === moduleJson.id;
|
|
279
|
+
});
|
|
280
|
+
if (!frame || Object.keys(frame.coms).length > 0) return;
|
|
281
|
+
var coms = moduleJson.coms || {};
|
|
282
|
+
var cons = moduleJson.cons || {};
|
|
283
|
+
Object.values(coms).forEach(function (com) {
|
|
284
|
+
var _com$model2;
|
|
285
|
+
var outputEvents = (_com$model2 = com.model) === null || _com$model2 === void 0 ? void 0 : _com$model2.outputEvents;
|
|
286
|
+
if (!outputEvents || Object.keys(outputEvents).length === 0) return;
|
|
287
|
+
var comFrames = [];
|
|
288
|
+
Object.entries(outputEvents).forEach(function (_ref4) {
|
|
289
|
+
var _activeEvent$options;
|
|
290
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
291
|
+
pinId = _ref5[0],
|
|
292
|
+
events = _ref5[1];
|
|
293
|
+
var activeEvent = Array.isArray(events) ? events.find(function (e) {
|
|
294
|
+
return e.active;
|
|
295
|
+
}) : null;
|
|
296
|
+
if (!(activeEvent !== null && activeEvent !== void 0 && (_activeEvent$options = activeEvent.options) !== null && _activeEvent$options !== void 0 && _activeEvent$options.id)) return;
|
|
297
|
+
var diagramId = activeEvent.options.id;
|
|
298
|
+
var consKey = "".concat(com.id, "-").concat(pinId);
|
|
299
|
+
var connections = cons[consKey] || [];
|
|
300
|
+
var conAry = connections.map(function (con) {
|
|
301
|
+
return {
|
|
302
|
+
id: con.id,
|
|
303
|
+
from: {
|
|
304
|
+
id: pinId,
|
|
305
|
+
title: activeEvent.options.title || pinId,
|
|
306
|
+
parent: {
|
|
307
|
+
id: com.id,
|
|
308
|
+
type: "com"
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
to: {
|
|
312
|
+
id: con.pinId,
|
|
313
|
+
title: con.pinId,
|
|
314
|
+
parent: {
|
|
315
|
+
id: con.comId,
|
|
316
|
+
type: "com"
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
startPinParentKey: con.startPinParentKey || con.frameKey,
|
|
320
|
+
finishPinParentKey: con.finishPinParentKey || con.targetFrameKey
|
|
321
|
+
};
|
|
322
|
+
});
|
|
323
|
+
if (conAry.length === 0) return;
|
|
324
|
+
comFrames.push({
|
|
325
|
+
id: "".concat(com.id, "_").concat(pinId, "_frame"),
|
|
326
|
+
title: activeEvent.options.title || "".concat(com.title, " > ").concat(pinId),
|
|
327
|
+
type: "com",
|
|
328
|
+
coms: {},
|
|
329
|
+
autoRunComs: {},
|
|
330
|
+
inputs: [],
|
|
331
|
+
outputs: [],
|
|
332
|
+
frames: [],
|
|
333
|
+
diagrams: [{
|
|
334
|
+
id: diagramId,
|
|
335
|
+
title: activeEvent.options.title || "".concat(com.title, " > ").concat(pinId),
|
|
336
|
+
starter: {
|
|
337
|
+
type: "com",
|
|
338
|
+
comId: com.id,
|
|
339
|
+
pinId: pinId
|
|
340
|
+
},
|
|
341
|
+
conAry: conAry,
|
|
342
|
+
runtimeBefore: [],
|
|
343
|
+
runtimeAfter: []
|
|
344
|
+
}]
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
if (comFrames.length > 0) {
|
|
348
|
+
frame.coms[com.id] = {
|
|
349
|
+
id: com.id,
|
|
350
|
+
frames: comFrames
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
|
|
245
357
|
/**
|
|
246
358
|
* 初始化配置
|
|
247
359
|
*/
|
|
@@ -114,6 +114,8 @@ export var handleProcess = function handleProcess(event, config) {
|
|
|
114
114
|
// 处理节点调用
|
|
115
115
|
// 边遍历边构建映射:确保引用时只能看到已声明的变量
|
|
116
116
|
var outputToInputPinMap = new Map();
|
|
117
|
+
// 跟踪已声明的变量名,用于去重(同一组件+pin 多次调用时追加后缀)
|
|
118
|
+
var declaredVarCount = new Map();
|
|
117
119
|
process.nodesInvocation.forEach(function (props) {
|
|
118
120
|
var _props$nextParam, _config$getCallTempla, _props$meta$model;
|
|
119
121
|
var componentType = props.componentType,
|
|
@@ -121,12 +123,13 @@ export var handleProcess = function handleProcess(event, config) {
|
|
|
121
123
|
runType = props.runType;
|
|
122
124
|
var nextValue = getNextValue(props, config, event, outputToInputPinMap);
|
|
123
125
|
var isSameScope = checkIsSameScope(event, props);
|
|
124
|
-
var
|
|
126
|
+
var _getNextCode = getNextCode(props, config, isSameScope, event, declaredVarCount),
|
|
127
|
+
nextCode = _getNextCode.code,
|
|
128
|
+
declaredVarName = _getNextCode.varName;
|
|
125
129
|
|
|
126
|
-
//
|
|
127
|
-
var inputPinId = props.id.replace(/[^a-zA-Z0-9_]/g, '_');
|
|
130
|
+
// 声明后记录映射,供后续引用(存储完整变量名,支持去重后缀)
|
|
128
131
|
(_props$nextParam = props.nextParam) === null || _props$nextParam === void 0 || _props$nextParam.forEach(function (np) {
|
|
129
|
-
outputToInputPinMap.set("".concat(props.meta.id, "_").concat(np.id),
|
|
132
|
+
outputToInputPinMap.set("".concat(props.meta.id, "_").concat(np.id), declaredVarName);
|
|
130
133
|
});
|
|
131
134
|
if (code) {
|
|
132
135
|
code += "\n";
|
|
@@ -167,20 +170,24 @@ export var handleProcess = function handleProcess(event, config) {
|
|
|
167
170
|
var componentNameWithId = getComponentNameWithId(props, config, event);
|
|
168
171
|
code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode).concat(componentNameWithId, "(").concat(runType === "input" ? nextValue : "", ")");
|
|
169
172
|
} else if (category === "var") {
|
|
173
|
+
var _props$extData;
|
|
170
174
|
var varKey = getSafeVarName(props.meta);
|
|
175
|
+
// 处理 xpath:如 "/a" -> "a","/a/b" -> "a.b",用于读取变量的指定属性
|
|
176
|
+
var xpath = (_props$extData = props.extData) === null || _props$extData === void 0 ? void 0 : _props$extData.xpath;
|
|
177
|
+
var xpathArg = xpath ? ", \"".concat(xpath.replace(/^\//, "").replace(/\//g, "."), "\"") : "";
|
|
171
178
|
if (props.meta.global) {
|
|
172
179
|
config.addParentDependencyImport({
|
|
173
180
|
packageName: "../../common/global",
|
|
174
181
|
dependencyNames: ["globalVars"],
|
|
175
182
|
importType: "named"
|
|
176
183
|
});
|
|
177
|
-
code += "".concat(indent, "/** ").concat(props.title, " \u5168\u5C40\u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalVars.").concat(varKey, ".").concat(props.id, "(").concat(nextValue, ")");
|
|
184
|
+
code += "".concat(indent, "/** ").concat(props.title, " \u5168\u5C40\u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalVars.").concat(varKey, ".").concat(props.id, "(").concat(nextValue).concat(xpathArg, ")");
|
|
178
185
|
} else {
|
|
179
186
|
var currentProvider = getCurrentProvider({
|
|
180
187
|
isSameScope: isSameScope,
|
|
181
188
|
props: props
|
|
182
189
|
}, config);
|
|
183
|
-
code += "".concat(indent, "/** ").concat(props.title, " \u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "this.$vars.").concat(varKey, ".").concat(props.id, "(").concat(nextValue, ")");
|
|
190
|
+
code += "".concat(indent, "/** ").concat(props.title, " \u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "this.$vars.").concat(varKey, ".").concat(props.id, "(").concat(nextValue).concat(xpathArg, ")");
|
|
184
191
|
}
|
|
185
192
|
} else if (category === "fx") {
|
|
186
193
|
if (props.meta.global) {
|
|
@@ -283,17 +290,31 @@ var getComponentNameWithId = function getComponentNameWithId(props, config, even
|
|
|
283
290
|
var sanitizedName = name.replace(/-/g, '_');
|
|
284
291
|
return "".concat(sanitizedName, "_").concat(props.meta.id);
|
|
285
292
|
};
|
|
286
|
-
var getNextCode = function getNextCode(props, config, isSameScope, event) {
|
|
293
|
+
var getNextCode = function getNextCode(props, config, isSameScope, event, declaredVarCount) {
|
|
287
294
|
var nextParam = props.nextParam;
|
|
288
295
|
if (!nextParam.length) {
|
|
289
|
-
return
|
|
296
|
+
return {
|
|
297
|
+
code: "",
|
|
298
|
+
varName: ""
|
|
299
|
+
};
|
|
290
300
|
}
|
|
291
301
|
var componentNameWithId = getComponentNameWithId(props, config, event);
|
|
292
302
|
// 使用输入端口ID(props.id)来区分同一组件的不同调用
|
|
293
303
|
// 这样可以确保 trigger 和 cancel 两个输入端口生成不同的变量名
|
|
294
304
|
var pinId = props.id;
|
|
295
305
|
var sanitizedPinId = pinId.replace(/[^a-zA-Z0-9_]/g, '_');
|
|
296
|
-
|
|
306
|
+
var varName = "".concat(componentNameWithId, "_").concat(sanitizedPinId, "_result");
|
|
307
|
+
|
|
308
|
+
// 去重:同一变量名多次声明时追加后缀
|
|
309
|
+
var count = declaredVarCount.get(varName) || 0;
|
|
310
|
+
declaredVarCount.set(varName, count + 1);
|
|
311
|
+
if (count > 0) {
|
|
312
|
+
varName = "".concat(varName, "_").concat(count);
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
code: "const ".concat(varName, ": any = "),
|
|
316
|
+
varName: varName
|
|
317
|
+
};
|
|
297
318
|
};
|
|
298
319
|
|
|
299
320
|
/**
|
|
@@ -341,21 +362,21 @@ var getNextValue = function getNextValue(props, config, event, outputToInputPinM
|
|
|
341
362
|
// 变量组件直接返回 Subject,不加 .id 后缀
|
|
342
363
|
if ((_param$meta2 = param.meta) !== null && _param$meta2 !== void 0 && (_param$meta2 = _param$meta2.def) !== null && _param$meta2 !== void 0 && (_param$meta2 = _param$meta2.namespace) !== null && _param$meta2 !== void 0 && _param$meta2.includes(".var")) {
|
|
343
364
|
var _param$meta3;
|
|
344
|
-
// 从 outputToInputPinMap
|
|
365
|
+
// 从 outputToInputPinMap 中查找完整变量名(已包含去重后缀)
|
|
345
366
|
var _key = "".concat((_param$meta3 = param.meta) === null || _param$meta3 === void 0 ? void 0 : _param$meta3.id, "_").concat(param.id);
|
|
346
|
-
var
|
|
347
|
-
if (
|
|
348
|
-
return
|
|
367
|
+
var _fullVarName = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(_key);
|
|
368
|
+
if (_fullVarName) {
|
|
369
|
+
return _fullVarName;
|
|
349
370
|
}
|
|
350
371
|
return "".concat(componentNameWithId, "_result");
|
|
351
372
|
}
|
|
352
373
|
|
|
353
|
-
// 从 outputToInputPinMap
|
|
374
|
+
// 从 outputToInputPinMap 中查找完整变量名(已包含去重后缀)
|
|
354
375
|
// key = `${componentId}_${outputPinId}`
|
|
355
376
|
var key = "".concat((_param$meta4 = param.meta) === null || _param$meta4 === void 0 ? void 0 : _param$meta4.id, "_").concat(param.id);
|
|
356
|
-
var
|
|
357
|
-
if (
|
|
358
|
-
return "".concat(
|
|
377
|
+
var fullVarName = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(key);
|
|
378
|
+
if (fullVarName) {
|
|
379
|
+
return "".concat(fullVarName, ".").concat(param.id);
|
|
359
380
|
}
|
|
360
381
|
return "".concat(componentNameWithId, "_result.").concat(param.id);
|
|
361
382
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { indentation,
|
|
1
|
+
import { indentation, toSlotFunctionName } from "./index";
|
|
2
2
|
/** 生成组件 Inputs 映射代码 */
|
|
3
3
|
export var genComponentInputsCode = function genComponentInputsCode(indent, providerName, comId) {
|
|
4
4
|
return "".concat(indent, "inputs['").concat(comId, "'] = useBindInputs(controllers.current.").concat(providerName, ", '").concat(comId, "');\n");
|
|
@@ -21,7 +21,7 @@ export var genSlotRenderRef = function genSlotRenderRef(_ref) {
|
|
|
21
21
|
renderId = _ref.renderId,
|
|
22
22
|
indent = _ref.indent,
|
|
23
23
|
isLast = _ref.isLast;
|
|
24
|
-
var renderFunctionName =
|
|
24
|
+
var renderFunctionName = toSlotFunctionName(renderId);
|
|
25
25
|
return "".concat(indent).concat(slotId, ": {\n").concat(indent, " render: ").concat(renderFunctionName, ",\n").concat(indent, "}").concat(isLast ? '' : ',', "\n");
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -6,6 +6,8 @@ export declare const firstCharToUpperCase: (str: string) => string;
|
|
|
6
6
|
export declare const formatSlotContent: (uiContent: string, baseIndentSize: number, renderBodyIndent: string) => string;
|
|
7
7
|
/** 将字符串转为大驼峰 */
|
|
8
8
|
export declare const toPascalCase: (str: string) => string;
|
|
9
|
+
/** 生成插槽渲染函数名:S${ID} (SCREAMING_SNAKE_CASE) */
|
|
10
|
+
export declare const toSlotFunctionName: (renderId: string) => string;
|
|
9
11
|
/** Taro/React UI 组件代码生成 */
|
|
10
12
|
export declare const getUiComponentCode: (params: {
|
|
11
13
|
componentName: string;
|
|
@@ -23,6 +23,11 @@ export var toPascalCase = function toPascalCase(str) {
|
|
|
23
23
|
}).join("");
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
/** 生成插槽渲染函数名:S${ID} (SCREAMING_SNAKE_CASE) */
|
|
27
|
+
export var toSlotFunctionName = function toSlotFunctionName(renderId) {
|
|
28
|
+
return "S".concat(renderId.replace(/[^a-zA-Z0-9]/g, "_").toUpperCase());
|
|
29
|
+
};
|
|
30
|
+
|
|
26
31
|
/** 根节点data去除无用属性 */
|
|
27
32
|
var formatData = function formatData(data, isRoot) {
|
|
28
33
|
if (!data) return {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
-
import { indentation,
|
|
4
|
+
import { indentation, toSlotFunctionName } from "./index";
|
|
5
5
|
|
|
6
6
|
/** Render 函数管理器 */
|
|
7
7
|
export var RenderManager = /*#__PURE__*/function () {
|
|
@@ -50,7 +50,7 @@ export var RenderManager = /*#__PURE__*/function () {
|
|
|
50
50
|
logicCode = _ref.logicCode,
|
|
51
51
|
useWrap = _ref.useWrap,
|
|
52
52
|
description = _ref.description;
|
|
53
|
-
var renderFunctionName =
|
|
53
|
+
var renderFunctionName = toSlotFunctionName(renderId);
|
|
54
54
|
if (description) {
|
|
55
55
|
code += "".concat(indent, "/** ").concat(description, " */\n");
|
|
56
56
|
}
|
|
@@ -137,7 +137,7 @@ export var RenderManager = /*#__PURE__*/function () {
|
|
|
137
137
|
}, {
|
|
138
138
|
key: "genRenderRef",
|
|
139
139
|
value: function genRenderRef(slotId, renderId, indent) {
|
|
140
|
-
var renderFunctionName =
|
|
140
|
+
var renderFunctionName = toSlotFunctionName(renderId);
|
|
141
141
|
return "".concat(indent).concat(slotId, ": {\n").concat(indent, " render: ").concat(renderFunctionName, ",\n").concat(indent, "},\n");
|
|
142
142
|
}
|
|
143
143
|
}]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** 生成响应式 data 管理器 */
|
|
2
2
|
export declare const genReactiveDataManager: (indent: string, utilsPackageName: string) => string;
|
|
3
3
|
/** 生成根组件定义代码 (useAppContext) */
|
|
4
|
-
export declare const genRootDefineCode: (indent: string, utilsPackageName: string, hasJsModules?: boolean) => string;
|
|
4
|
+
export declare const genRootDefineCode: (indent: string, utilsPackageName: string, hasJsModules?: boolean, isModule?: boolean) => string;
|
|
5
5
|
/** 生成普通插槽定义代码 */
|
|
6
6
|
export declare const genSlotDefineCode: (indent: string) => string;
|
|
7
7
|
/** 生成控制器初始化代码 */
|
|
@@ -6,9 +6,12 @@ export var genReactiveDataManager = function genReactiveDataManager(indent, util
|
|
|
6
6
|
/** 生成根组件定义代码 (useAppContext) */
|
|
7
7
|
export var genRootDefineCode = function genRootDefineCode(indent, utilsPackageName) {
|
|
8
8
|
var hasJsModules = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
9
|
+
var isModule = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
9
10
|
// 使用 useAppContext 获取 comRefs / $vars / $fxs / appContext
|
|
10
11
|
var code = "".concat(indent, "const {comRefs, $vars, $fxs, appContext} = useAppContext();\n");
|
|
11
|
-
|
|
12
|
+
if (!isModule) {
|
|
13
|
+
code += "".concat(indent, "usePageLife();\n");
|
|
14
|
+
}
|
|
12
15
|
// 如果有 JS 计算组件,需要初始化 comModules
|
|
13
16
|
if (hasJsModules) {
|
|
14
17
|
code += "".concat(indent, "const comModules = jsModules({ createJSHandle });\n");
|