@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.
- package/dist/cjs/generate/generateTaroProjectJson.js +45 -0
- package/dist/cjs/generate/utils/appConfig.js +1 -2
- 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 +7 -4
- package/dist/cjs/processors/processModule.js +1 -0
- package/dist/cjs/processors/processSceneLogic.js +5 -1
- package/dist/cjs/taro-template.json +1061 -1057
- package/dist/cjs/toCodeTaro.js +89 -0
- package/dist/cjs/utils/logic/handleProcess.js +30 -18
- 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 +8 -3
- package/dist/cjs/utils/templates/renderManager.js +2 -6
- package/dist/cjs/utils/templates/scene.d.ts +1 -1
- package/dist/cjs/utils/templates/scene.js +8 -6
- package/dist/esm/generate/generateTaroProjectJson.js +41 -0
- package/dist/esm/generate/utils/appConfig.js +1 -2
- 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 +11 -8
- package/dist/esm/processors/processModule.js +1 -0
- package/dist/esm/processors/processSceneLogic.js +4 -2
- package/dist/esm/taro-template.json +1061 -1057
- package/dist/esm/toCodeTaro.js +112 -0
- package/dist/esm/utils/logic/handleProcess.js +45 -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 +6 -1
- package/dist/esm/utils/templates/renderManager.js +3 -5
- package/dist/esm/utils/templates/scene.d.ts +1 -1
- package/dist/esm/utils/templates/scene.js +6 -3
- 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
|
);
|
|
@@ -44,11 +44,10 @@ function updateAppConfig(appConfigFile, normalItems, items) {
|
|
|
44
44
|
if (entryPagePath) {
|
|
45
45
|
content.entryPagePath = entryPagePath;
|
|
46
46
|
}
|
|
47
|
-
content.window = content.window || {};
|
|
48
47
|
const tabBarConfigItem = items.find((item) => item.type === "tabBarConfig");
|
|
49
48
|
if (tabBarConfigItem == null ? void 0 : tabBarConfigItem.content) {
|
|
50
49
|
const tabBar = (0, import_fileNode.parseLooseObject)(`{${tabBarConfigItem.content}}`);
|
|
51
|
-
Object.assign(content
|
|
50
|
+
Object.assign(content, tabBar);
|
|
52
51
|
}
|
|
53
52
|
appConfigFile.content = `export default defineAppConfig(${JSON.stringify(content, null, 2)})`;
|
|
54
53
|
}
|
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
|
}
|
|
@@ -114,7 +116,7 @@ var generateSlotUi = (ui, props, childrenUi, childrenResults, config) => {
|
|
|
114
116
|
const styleCode = JSON.stringify((0, import_utils.convertRootStyle)({ ...mergedStyle, layout, ...layoutAdjustment }));
|
|
115
117
|
const rootClassName = (0, import_utils.getRootComponentClassName)(config.getCurrentScene(), config.checkIsRoot());
|
|
116
118
|
const parentComId = config == null ? void 0 : config.parentComId;
|
|
117
|
-
const slotMarkClass = parentComId ? `slot-${parentComId}` : "";
|
|
119
|
+
const slotMarkClass = parentComId ? `mybricks_slot slot-${parentComId}` : "";
|
|
118
120
|
const classNameStr = [rootClassName, slotMarkClass].filter(Boolean).join(" ");
|
|
119
121
|
const classNameAttr = classNameStr ? ` className='${classNameStr}'` : "";
|
|
120
122
|
const styleAttr = slotMarkClass ? `style={{...params.style || {}, ...${styleCode}}}` : `style={${styleCode}}`;
|
|
@@ -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
|
};
|