@mybricks/to-code-taro 1.1.7 → 1.2.1

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 (88) hide show
  1. package/dist/cjs/generate/generateTaroProjectJson.js +47 -2
  2. package/dist/cjs/handleCom.js +1 -1
  3. package/dist/cjs/handleModule.js +6 -8
  4. package/dist/cjs/handleSlot.d.ts +1 -0
  5. package/dist/cjs/handleSlot.js +6 -3
  6. package/dist/cjs/index.js +1 -0
  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 +6 -6008
  10. package/dist/cjs/toCodeTaro.js +89 -0
  11. package/dist/cjs/utils/logic/handleProcess.js +26 -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 +7 -2
  15. package/dist/cjs/utils/templates/renderManager.js +2 -2
  16. package/dist/cjs/utils/templates/scene.d.ts +1 -1
  17. package/dist/cjs/utils/templates/scene.js +4 -2
  18. package/dist/esm/generate/generateTaroProjectJson.js +43 -2
  19. package/dist/esm/handleCom.js +1 -1
  20. package/dist/esm/handleModule.js +5 -7
  21. package/dist/esm/handleSlot.d.ts +1 -0
  22. package/dist/esm/handleSlot.js +10 -7
  23. package/dist/esm/index.js +2 -1
  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 +6 -6008
  27. package/dist/esm/toCodeTaro.js +112 -0
  28. package/dist/esm/utils/logic/handleProcess.js +39 -18
  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 +5 -0
  32. package/dist/esm/utils/templates/renderManager.js +3 -3
  33. package/dist/esm/utils/templates/scene.d.ts +1 -1
  34. package/dist/esm/utils/templates/scene.js +4 -1
  35. package/package.json +2 -9
  36. package/README.md +0 -58
  37. package/dist/cjs/core/mybricks/MyBricksDescriptor.js +0 -213
  38. package/dist/cjs/core/mybricks/Subject.js +0 -119
  39. package/dist/cjs/core/mybricks/constant.js +0 -70
  40. package/dist/cjs/core/mybricks/context.js +0 -33
  41. package/dist/cjs/core/mybricks/createEnv.js +0 -39
  42. package/dist/cjs/core/mybricks/createJSHandle.js +0 -191
  43. package/dist/cjs/core/mybricks/createModuleEventsHandle.js +0 -49
  44. package/dist/cjs/core/mybricks/createReactiveInputHandler.js +0 -63
  45. package/dist/cjs/core/mybricks/event.js +0 -70
  46. package/dist/cjs/core/mybricks/index.js +0 -871
  47. package/dist/cjs/core/mybricks/log.js +0 -37
  48. package/dist/cjs/core/mybricks/utils.js +0 -69
  49. package/dist/cjs/core/mybricks/variables.js +0 -217
  50. package/dist/cjs/core/utils/ComContext.js +0 -51
  51. package/dist/cjs/core/utils/PopupRenderer.js +0 -63
  52. package/dist/cjs/core/utils/comRefResolver.js +0 -112
  53. package/dist/cjs/core/utils/event.js +0 -53
  54. package/dist/cjs/core/utils/hooks.js +0 -238
  55. package/dist/cjs/core/utils/index.js +0 -77
  56. package/dist/cjs/core/utils/pageRouter.js +0 -104
  57. package/dist/cjs/core/utils/pool.js +0 -63
  58. package/dist/cjs/core/utils/popupRouter.js +0 -98
  59. package/dist/cjs/core/utils/slots.js +0 -183
  60. package/dist/cjs/core/utils/tabbar.js +0 -56
  61. package/dist/cjs/core/utils/useContext.js +0 -112
  62. package/dist/cjs/core/utils/with.js +0 -109
  63. package/dist/esm/core/mybricks/MyBricksDescriptor.js +0 -232
  64. package/dist/esm/core/mybricks/Subject.js +0 -149
  65. package/dist/esm/core/mybricks/constant.js +0 -18
  66. package/dist/esm/core/mybricks/context.js +0 -5
  67. package/dist/esm/core/mybricks/createEnv.js +0 -9
  68. package/dist/esm/core/mybricks/createJSHandle.js +0 -189
  69. package/dist/esm/core/mybricks/createModuleEventsHandle.js +0 -26
  70. package/dist/esm/core/mybricks/createReactiveInputHandler.js +0 -40
  71. package/dist/esm/core/mybricks/event.js +0 -44
  72. package/dist/esm/core/mybricks/index.js +0 -952
  73. package/dist/esm/core/mybricks/log.js +0 -8
  74. package/dist/esm/core/mybricks/utils.js +0 -41
  75. package/dist/esm/core/mybricks/variables.js +0 -190
  76. package/dist/esm/core/utils/ComContext.js +0 -16
  77. package/dist/esm/core/utils/PopupRenderer.js +0 -27
  78. package/dist/esm/core/utils/comRefResolver.js +0 -134
  79. package/dist/esm/core/utils/event.js +0 -32
  80. package/dist/esm/core/utils/hooks.js +0 -287
  81. package/dist/esm/core/utils/index.js +0 -12
  82. package/dist/esm/core/utils/pageRouter.js +0 -112
  83. package/dist/esm/core/utils/pool.js +0 -52
  84. package/dist/esm/core/utils/popupRouter.js +0 -117
  85. package/dist/esm/core/utils/slots.js +0 -194
  86. package/dist/esm/core/utils/tabbar.js +0 -47
  87. package/dist/esm/core/utils/useContext.js +0 -100
  88. package/dist/esm/core/utils/with.js +0 -115
@@ -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,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
- 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
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 inputPinId2 = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key2);
324
- if (inputPinId2) {
325
- return `${componentNameWithId}_${inputPinId2}_result`;
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 inputPinId = outputToInputPinMap == null ? void 0 : outputToInputPinMap.get(key);
331
- if (inputPinId) {
332
- return `${componentNameWithId}_${inputPinId}_result.${param.id}`;
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
  });
@@ -411,7 +419,7 @@ var generateJsApiComponentCode = (params) => {
411
419
  indent2
412
420
  } = params;
413
421
  config.addParentDependencyImport({
414
- packageName: "@/core/mybricks/index",
422
+ packageName: "@mybricks/taro-core",
415
423
  dependencyNames: ["createJSHandle"],
416
424
  importType: "named"
417
425
  });
@@ -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 {};
@@ -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
  `;
@@ -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.toPascalCase)(`${renderId}_Render`);
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
- 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
  `;
@@ -84,7 +84,7 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
84
84
  if (item.jsModules && item.jsModules.length > 0) {
85
85
  pageChildren.push({
86
86
  path: "src/pages/".concat(pageName, "/index.jsModules.ts"),
87
- content: genScopedJSModules(item.jsModules, "@/core/mybricks/index", "@/common/jsModulesRuntime")
87
+ content: genScopedJSModules(item.jsModules, "@mybricks/taro-core", "@/common/jsModulesRuntime")
88
88
  });
89
89
  }
90
90
 
@@ -119,7 +119,7 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
119
119
  if (item.jsModules && item.jsModules.length > 0) {
120
120
  popupChildren.push({
121
121
  path: "src/popupComponents/".concat(popupId, "/index.jsModules.ts"),
122
- content: genScopedJSModules(item.jsModules, "@/core/mybricks/index", "@/common/jsModulesRuntime")
122
+ content: genScopedJSModules(item.jsModules, "@mybricks/taro-core", "@/common/jsModulesRuntime")
123
123
  });
124
124
  }
125
125
  popupComponentsDir.children.push({
@@ -129,6 +129,47 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
129
129
  });
130
130
  });
131
131
 
132
+ // --- 处理模块/区块场景 (module) ---
133
+ var componentsDir = ensureDir(srcDir, "src/components");
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/components/".concat(moduleId, "/index.tsx"),
146
+ content: fullContent
147
+ }, {
148
+ path: "src/components/".concat(moduleId, "/index.global.less"),
149
+ content: item.cssContent || ""
150
+ }];
151
+ if (item.jsModules && item.jsModules.length > 0) {
152
+ moduleChildren.push({
153
+ path: "src/components/".concat(moduleId, "/index.jsModules.ts"),
154
+ content: genScopedJSModules(item.jsModules, "@mybricks/taro-core", "@/common/jsModulesRuntime")
155
+ });
156
+ }
157
+ componentsDir.children.push({
158
+ path: "src/components/".concat(moduleId),
159
+ content: null,
160
+ children: moduleChildren
161
+ });
162
+ moduleExports.push("export { default as ".concat(exportName, " } from \"./").concat(moduleId, "/index\";"));
163
+ });
164
+
165
+ // 生成 components/Index.ts 汇总导出
166
+ if (moduleExports.length > 0) {
167
+ componentsDir.children.push({
168
+ path: "src/components/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";
@@ -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: "@/components/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",
@@ -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,
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { default as toCodeTaro } from "./toCodeTaro";
2
2
  export { default as generateTaroProjectJson } from "./generate/generateTaroProjectJson";
3
- export { default as generateTaroTempalteJson } from "./generate/generateTaroTempalteJson";
3
+ export { default as generateTaroTempalteJson } from "./generate/generateTaroTempalteJson";
4
+ console.log('222');
@@ -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
  };