@mybricks/to-code-taro 1.1.6 → 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.
Files changed (35) hide show
  1. package/dist/cjs/generate/generateTaroProjectJson.js +45 -0
  2. package/dist/cjs/generate/utils/appConfig.js +1 -2
  3. package/dist/cjs/handleCom.js +1 -1
  4. package/dist/cjs/handleModule.js +6 -8
  5. package/dist/cjs/handleSlot.d.ts +1 -0
  6. package/dist/cjs/handleSlot.js +7 -4
  7. package/dist/cjs/processors/processModule.js +1 -0
  8. package/dist/cjs/processors/processSceneLogic.js +5 -1
  9. package/dist/cjs/taro-template.json +1061 -1057
  10. package/dist/cjs/toCodeTaro.js +89 -0
  11. package/dist/cjs/utils/logic/handleProcess.js +30 -18
  12. package/dist/cjs/utils/templates/component.js +1 -1
  13. package/dist/cjs/utils/templates/index.d.ts +2 -0
  14. package/dist/cjs/utils/templates/index.js +8 -3
  15. package/dist/cjs/utils/templates/renderManager.js +2 -6
  16. package/dist/cjs/utils/templates/scene.d.ts +1 -1
  17. package/dist/cjs/utils/templates/scene.js +8 -6
  18. package/dist/esm/generate/generateTaroProjectJson.js +41 -0
  19. package/dist/esm/generate/utils/appConfig.js +1 -2
  20. package/dist/esm/handleCom.js +1 -1
  21. package/dist/esm/handleModule.js +5 -7
  22. package/dist/esm/handleSlot.d.ts +1 -0
  23. package/dist/esm/handleSlot.js +11 -8
  24. package/dist/esm/processors/processModule.js +1 -0
  25. package/dist/esm/processors/processSceneLogic.js +4 -2
  26. package/dist/esm/taro-template.json +1061 -1057
  27. package/dist/esm/toCodeTaro.js +112 -0
  28. package/dist/esm/utils/logic/handleProcess.js +45 -17
  29. package/dist/esm/utils/templates/component.js +2 -2
  30. package/dist/esm/utils/templates/index.d.ts +2 -0
  31. package/dist/esm/utils/templates/index.js +6 -1
  32. package/dist/esm/utils/templates/renderManager.js +3 -5
  33. package/dist/esm/utils/templates/scene.d.ts +1 -1
  34. package/dist/esm/utils/templates/scene.js +6 -3
  35. package/package.json +1 -1
@@ -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}`, inputPinId);
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 || ((_f = event.meta) == null ? void 0 : _f.parentComId);
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 = ((_h = (_g = currentScene.coms) == null ? void 0 : _g[comId]) == null ? void 0 : _h.title) || props.meta.title || comId;
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,24 +281,34 @@ 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
- return `const ${componentNameWithId}_${sanitizedPinId}_result: any = `;
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
- var _a, _b, _c;
301
+ var _a, _b, _c, _d;
294
302
  const scene = (_a = config.getCurrentScene) == null ? void 0 : _a.call(config);
295
303
  const inputPinId = ((_b = meta == null ? void 0 : meta.inputs) == null ? void 0 : _b[0]) || "getCurValue";
296
304
  const proxyKey = `${meta == null ? void 0 : meta.id}-${inputPinId}`;
297
305
  const pinProxy = (_c = scene == null ? void 0 : scene.pinValueProxies) == null ? void 0 : _c[proxyKey];
298
306
  const pinId = pinProxy == null ? void 0 : pinProxy.pinId;
299
307
  if (typeof pinId === "string" && pinId) {
308
+ const paramsMap = (_d = config.getParams) == null ? void 0 : _d.call(config);
309
+ if (paramsMap == null ? void 0 : paramsMap[pinId]) {
310
+ return paramsMap[pinId];
311
+ }
300
312
  return `params?.inputValues?.[${JSON.stringify(pinId)}]`;
301
313
  }
302
314
  }
@@ -316,16 +328,16 @@ var getNextValue = (props, config, event, outputToInputPinMap) => {
316
328
  const componentNameWithId = getComponentNameWithId(param, config, event);
317
329
  if ((_e = (_d = (_c = param.meta) == null ? void 0 : _c.def) == null ? void 0 : _d.namespace) == null ? void 0 : _e.includes(".var")) {
318
330
  const key2 = `${(_f = param.meta) == null ? void 0 : _f.id}_${param.id}`;
319
- const inputPinId2 = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key2);
320
- if (inputPinId2) {
321
- return `${componentNameWithId}_${inputPinId2}_result`;
331
+ const fullVarName2 = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key2);
332
+ if (fullVarName2) {
333
+ return fullVarName2;
322
334
  }
323
335
  return `${componentNameWithId}_result`;
324
336
  }
325
337
  const key = `${(_g = param.meta) == null ? void 0 : _g.id}_${param.id}`;
326
- const inputPinId = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key);
327
- if (inputPinId) {
328
- return `${componentNameWithId}_${inputPinId}_result.${param.id}`;
338
+ const fullVarName = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key);
339
+ if (fullVarName) {
340
+ return `${fullVarName}.${param.id}`;
329
341
  }
330
342
  return `${componentNameWithId}_result.${param.id}`;
331
343
  });
@@ -50,7 +50,7 @@ var genSlotRenderRef = ({
50
50
  indent,
51
51
  isLast
52
52
  }) => {
53
- const renderFunctionName = (0, import_index.toPascalCase)(`${renderId}_Render`);
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 {};
@@ -66,7 +70,7 @@ ${indent2}component={${componentName}}`;
66
70
  ui += `
67
71
  ${indent2}id='${meta.id}'`;
68
72
  ui += `
69
- ${indent2}className='${meta.id} mybricks_com'`;
73
+ ${indent2}className='mybricks_com ${meta.id}'`;
70
74
  if (meta.name) {
71
75
  ui += `
72
76
  ${indent2}name='${meta.name}'`;
@@ -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.toPascalCase)(`${renderId}_Render`);
52
+ const renderFunctionName = (0, import_index.toSlotFunctionName)(renderId);
53
53
  if (description) {
54
54
  code += `${indent}/** ${description} */
55
55
  `;
@@ -121,11 +121,7 @@ var RenderManager = class {
121
121
  code += `${indent}${indent3}params?.wrap?.(descriptors)
122
122
  `;
123
123
  } else {
124
- code += `${indent}${indent3}<>
125
- `;
126
124
  code += modifiedRenderCode.split("\n").map((line) => `${indent}${indent2}${line}`).join("\n") + "\n";
127
- code += `${indent}${indent3}</>
128
- `;
129
125
  }
130
126
  code += `${indent}${indent2});
131
127
  `;
@@ -143,7 +139,7 @@ var RenderManager = class {
143
139
  return new RegExp(escaped, "g");
144
140
  }
145
141
  genRenderRef(slotId, renderId, indent) {
146
- const renderFunctionName = (0, import_index.toPascalCase)(`${renderId}_Render`);
142
+ const renderFunctionName = (0, import_index.toSlotFunctionName)(renderId);
147
143
  return `${indent}${slotId}: {
148
144
  ${indent} render: ${renderFunctionName},
149
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
- code += `${indent}usePageLife();
36
+ if (!isModule) {
37
+ code += `${indent}usePageLife();
37
38
  `;
39
+ }
38
40
  if (hasJsModules) {
39
41
  code += `${indent}const comModules = jsModules({ createJSHandle });
40
42
  `;
@@ -75,11 +77,11 @@ function ${componentName}() {
75
77
  ${combinedJsCode}
76
78
  return (
77
79
  <PageScopeContext.Provider value={pageScopeRef}>
78
- <>
79
- ${uiResult.split("\n").map((line) => ` ${line}`).join("\n")}
80
+ ` + (hasPopups ? ` <>
81
+ ` : "") + `${uiResult.split("\n").map((line) => ` ${line}`).join("\n")}
80
82
  ` + (hasPopups ? ` <PopupRenderer popupMap={POPUP_MAP} />
81
- ` : "") + ` </>
82
- </PageScopeContext.Provider>
83
+ ` : "") + (hasPopups ? ` </>
84
+ ` : "") + ` </PageScopeContext.Provider>
83
85
  );
84
86
  }
85
87
 
@@ -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";
@@ -36,7 +36,6 @@ export function updateAppConfig(appConfigFile, normalItems, items) {
36
36
  if (entryPagePath) {
37
37
  content.entryPagePath = entryPagePath;
38
38
  }
39
- content.window = content.window || {};
40
39
 
41
40
  // 添加 TabBar 配置(从 items 中读取)
42
41
  var tabBarConfigItem = items.find(function (item) {
@@ -44,7 +43,7 @@ export function updateAppConfig(appConfigFile, normalItems, items) {
44
43
  });
45
44
  if (tabBarConfigItem !== null && tabBarConfigItem !== void 0 && tabBarConfigItem.content) {
46
45
  var tabBar = parseLooseObject("{".concat(tabBarConfigItem.content, "}"));
47
- Object.assign(content.window, tabBar);
46
+ Object.assign(content, tabBar);
48
47
  }
49
48
  appConfigFile.content = "export default defineAppConfig(".concat(JSON.stringify(content, null, 2), ")");
50
49
  }
@@ -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 在内部进行精确字符串替换时才能匹配成功
@@ -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, firstCharToUpperCase } from "./utils";
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 _config$getFileName, _props$style, _config$getComponentC;
7
+ var _props$style, _config$getComponentC;
8
8
  var events = module.events,
9
9
  moduleId = module.moduleId,
10
10
  props = module.props;
11
- var moduleScene = config.getSceneById(moduleId);
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: "../sections/Index",
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={this.").concat(currentProvider.name, ".").concat(componentController, "}") + (comEventCode ? "\n".concat(indent3, "onEvents={{").concat(comEventCode.replace(/\n/g, "\n" + indent3), "}}") : "") + "\n".concat(indent2, "/>");
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,
@@ -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;
@@ -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
- addImport({
118
- packageName: "@/common/pageLife",
119
- dependencyNames: ["usePageLife"],
120
- importType: "named"
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",
@@ -159,7 +161,7 @@ var generateSlotUi = function generateSlotUi(ui, props, childrenUi, childrenResu
159
161
  // 插槽根容器增强:加上可读的标识,便于用户定位/调试
160
162
  // - className: slot-<parentComId>
161
163
  var parentComId = config === null || config === void 0 ? void 0 : config.parentComId;
162
- var slotMarkClass = parentComId ? "slot-".concat(parentComId) : "";
164
+ var slotMarkClass = parentComId ? "mybricks_slot slot-".concat(parentComId) : "";
163
165
  var classNameStr = [rootClassName, slotMarkClass].filter(Boolean).join(" ");
164
166
  var classNameAttr = classNameStr ? " className='".concat(classNameStr, "'") : "";
165
167
 
@@ -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 componentName = "I".concat(String(componentId).replace(/[^a-zA-Z0-9]/g, "_"));
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
- // 订阅变量的 changed 事件
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, ".").concat(pinId, "?.()[SUBJECT_SUBSCRIBE](run_").concat(varName, "_").concat(pinId, ");");
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
  };