@mybricks/to-code-taro 1.0.0
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/abstractEventTypeDef.d.ts +11 -0
- package/dist/cjs/abstractEventTypeDef.js +93 -0
- package/dist/cjs/core/comlib/Index.js +45 -0
- package/dist/cjs/core/comlib/_ScanQrcode.js +60 -0
- package/dist/cjs/core/comlib/_SetStorage.js +76 -0
- package/dist/cjs/core/comlib/_ShowToast.js +96 -0
- package/dist/cjs/core/mybricks/MyBricksDescriptor.js +213 -0
- package/dist/cjs/core/mybricks/Subject.js +115 -0
- package/dist/cjs/core/mybricks/constant.js +70 -0
- package/dist/cjs/core/mybricks/context.js +33 -0
- package/dist/cjs/core/mybricks/createEnv.js +39 -0
- package/dist/cjs/core/mybricks/createJSHandle.js +150 -0
- package/dist/cjs/core/mybricks/createModuleEventsHandle.js +49 -0
- package/dist/cjs/core/mybricks/createReactiveInputHandler.js +63 -0
- package/dist/cjs/core/mybricks/event.js +70 -0
- package/dist/cjs/core/mybricks/index.js +871 -0
- package/dist/cjs/core/mybricks/log.js +38 -0
- package/dist/cjs/core/mybricks/utils.js +69 -0
- package/dist/cjs/core/mybricks/variables.js +217 -0
- package/dist/cjs/core/utils/ComContext.js +39 -0
- package/dist/cjs/core/utils/index.js +88 -0
- package/dist/cjs/core/utils/useContext.js +53 -0
- package/dist/cjs/core/utils/with.js +84 -0
- package/dist/cjs/generate/generateTaroProjectJson.d.ts +24 -0
- package/dist/cjs/generate/generateTaroProjectJson.js +101 -0
- package/dist/cjs/generate/generateTaroTempalteJson.d.ts +15 -0
- package/dist/cjs/generate/generateTaroTempalteJson.js +103 -0
- package/dist/cjs/generate/utils/appConfig.d.ts +21 -0
- package/dist/cjs/generate/utils/appConfig.js +47 -0
- package/dist/cjs/generate/utils/commonDir.d.ts +21 -0
- package/dist/cjs/generate/utils/commonDir.js +50 -0
- package/dist/cjs/generate/utils/fileNode.d.ts +17 -0
- package/dist/cjs/generate/utils/fileNode.js +57 -0
- package/dist/cjs/generate/utils/index.d.ts +7 -0
- package/dist/cjs/generate/utils/index.js +29 -0
- package/dist/cjs/generate/utils/tabBarImages.d.ts +14 -0
- package/dist/cjs/generate/utils/tabBarImages.js +36 -0
- package/dist/cjs/handleCom.d.ts +31 -0
- package/dist/cjs/handleCom.js +260 -0
- package/dist/cjs/handleDom.d.ts +19 -0
- package/dist/cjs/handleDom.js +86 -0
- package/dist/cjs/handleExtension.d.ts +10 -0
- package/dist/cjs/handleExtension.js +300 -0
- package/dist/cjs/handleGlobal.d.ts +21 -0
- package/dist/cjs/handleGlobal.js +155 -0
- package/dist/cjs/handleModule.d.ts +15 -0
- package/dist/cjs/handleModule.js +108 -0
- package/dist/cjs/handleSlot.d.ts +27 -0
- package/dist/cjs/handleSlot.js +197 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/taro-template.json +5370 -0
- package/dist/cjs/toCodeTaro.d.ts +130 -0
- package/dist/cjs/toCodeTaro.js +427 -0
- package/dist/cjs/utils/code/component.d.ts +19 -0
- package/dist/cjs/utils/code/component.js +85 -0
- package/dist/cjs/utils/code/index.d.ts +18 -0
- package/dist/cjs/utils/code/index.js +71 -0
- package/dist/cjs/utils/code/renderManager.d.ts +22 -0
- package/dist/cjs/utils/code/renderManager.js +80 -0
- package/dist/cjs/utils/code/scene.d.ts +19 -0
- package/dist/cjs/utils/code/scene.js +82 -0
- package/dist/cjs/utils/convertNamespace.d.ts +11 -0
- package/dist/cjs/utils/convertNamespace.js +43 -0
- package/dist/cjs/utils/genJSModules.d.ts +12 -0
- package/dist/cjs/utils/genJSModules.js +116 -0
- package/dist/cjs/utils/getComponentClassName.d.ts +16 -0
- package/dist/cjs/utils/getComponentClassName.js +47 -0
- package/dist/cjs/utils/handlePageConfig.d.ts +24 -0
- package/dist/cjs/utils/handlePageConfig.js +73 -0
- package/dist/cjs/utils/handleProcess.d.ts +9 -0
- package/dist/cjs/utils/handleProcess.js +370 -0
- package/dist/cjs/utils/index.d.ts +62 -0
- package/dist/cjs/utils/index.js +321 -0
- package/dist/cjs/utils/pageConfig/converter.d.ts +17 -0
- package/dist/cjs/utils/pageConfig/converter.js +83 -0
- package/dist/cjs/utils/pageConfig/index.d.ts +10 -0
- package/dist/cjs/utils/pageConfig/index.js +33 -0
- package/dist/cjs/utils/pageConfig/pageConfig.d.ts +10 -0
- package/dist/cjs/utils/pageConfig/pageConfig.js +87 -0
- package/dist/cjs/utils/pageConfig/saveBase64Image.d.ts +14 -0
- package/dist/cjs/utils/pageConfig/saveBase64Image.js +81 -0
- package/dist/cjs/utils/pageConfig/tabBarConfig.d.ts +13 -0
- package/dist/cjs/utils/pageConfig/tabBarConfig.js +74 -0
- package/dist/cjs/utils/pageConfig/types.d.ts +68 -0
- package/dist/cjs/utils/pageConfig/types.js +17 -0
- package/dist/cjs/utils/pageConfig/validator.d.ts +13 -0
- package/dist/cjs/utils/pageConfig/validator.js +67 -0
- package/dist/cjs/utils/pxtransform.d.ts +28 -0
- package/dist/cjs/utils/pxtransform.js +102 -0
- package/dist/esm/abstractEventTypeDef.d.ts +11 -0
- package/dist/esm/abstractEventTypeDef.js +63 -0
- package/dist/esm/core/comlib/Index.js +3 -0
- package/dist/esm/core/comlib/_ScanQrcode.js +27 -0
- package/dist/esm/core/comlib/_SetStorage.js +52 -0
- package/dist/esm/core/comlib/_ShowToast.js +68 -0
- package/dist/esm/core/mybricks/MyBricksDescriptor.js +232 -0
- package/dist/esm/core/mybricks/Subject.js +143 -0
- package/dist/esm/core/mybricks/constant.js +18 -0
- package/dist/esm/core/mybricks/context.js +5 -0
- package/dist/esm/core/mybricks/createEnv.js +9 -0
- package/dist/esm/core/mybricks/createJSHandle.js +138 -0
- package/dist/esm/core/mybricks/createModuleEventsHandle.js +26 -0
- package/dist/esm/core/mybricks/createReactiveInputHandler.js +40 -0
- package/dist/esm/core/mybricks/event.js +44 -0
- package/dist/esm/core/mybricks/index.js +952 -0
- package/dist/esm/core/mybricks/log.js +12 -0
- package/dist/esm/core/mybricks/utils.js +41 -0
- package/dist/esm/core/mybricks/variables.js +190 -0
- package/dist/esm/core/utils/ComContext.js +10 -0
- package/dist/esm/core/utils/index.js +57 -0
- package/dist/esm/core/utils/useContext.js +24 -0
- package/dist/esm/core/utils/with.js +67 -0
- package/dist/esm/generate/generateTaroProjectJson.d.ts +24 -0
- package/dist/esm/generate/generateTaroProjectJson.js +102 -0
- package/dist/esm/generate/generateTaroTempalteJson.d.ts +15 -0
- package/dist/esm/generate/generateTaroTempalteJson.js +94 -0
- package/dist/esm/generate/utils/appConfig.d.ts +21 -0
- package/dist/esm/generate/utils/appConfig.js +30 -0
- package/dist/esm/generate/utils/commonDir.d.ts +21 -0
- package/dist/esm/generate/utils/commonDir.js +36 -0
- package/dist/esm/generate/utils/fileNode.d.ts +17 -0
- package/dist/esm/generate/utils/fileNode.js +49 -0
- package/dist/esm/generate/utils/index.d.ts +7 -0
- package/dist/esm/generate/utils/index.js +8 -0
- package/dist/esm/generate/utils/tabBarImages.d.ts +14 -0
- package/dist/esm/generate/utils/tabBarImages.js +15 -0
- package/dist/esm/handleCom.d.ts +31 -0
- package/dist/esm/handleCom.js +297 -0
- package/dist/esm/handleDom.d.ts +19 -0
- package/dist/esm/handleDom.js +63 -0
- package/dist/esm/handleExtension.d.ts +10 -0
- package/dist/esm/handleExtension.js +243 -0
- package/dist/esm/handleGlobal.d.ts +21 -0
- package/dist/esm/handleGlobal.js +117 -0
- package/dist/esm/handleModule.d.ts +15 -0
- package/dist/esm/handleModule.js +78 -0
- package/dist/esm/handleSlot.d.ts +27 -0
- package/dist/esm/handleSlot.js +205 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/taro-template.json +5370 -0
- package/dist/esm/toCodeTaro.d.ts +130 -0
- package/dist/esm/toCodeTaro.js +452 -0
- package/dist/esm/utils/code/component.d.ts +19 -0
- package/dist/esm/utils/code/component.js +54 -0
- package/dist/esm/utils/code/index.d.ts +18 -0
- package/dist/esm/utils/code/index.js +51 -0
- package/dist/esm/utils/code/renderManager.d.ts +22 -0
- package/dist/esm/utils/code/renderManager.js +62 -0
- package/dist/esm/utils/code/scene.d.ts +19 -0
- package/dist/esm/utils/code/scene.js +47 -0
- package/dist/esm/utils/convertNamespace.d.ts +11 -0
- package/dist/esm/utils/convertNamespace.js +27 -0
- package/dist/esm/utils/genJSModules.d.ts +12 -0
- package/dist/esm/utils/genJSModules.js +44 -0
- package/dist/esm/utils/getComponentClassName.d.ts +16 -0
- package/dist/esm/utils/getComponentClassName.js +37 -0
- package/dist/esm/utils/handlePageConfig.d.ts +24 -0
- package/dist/esm/utils/handlePageConfig.js +68 -0
- package/dist/esm/utils/handleProcess.d.ts +9 -0
- package/dist/esm/utils/handleProcess.js +379 -0
- package/dist/esm/utils/index.d.ts +62 -0
- package/dist/esm/utils/index.js +345 -0
- package/dist/esm/utils/pageConfig/converter.d.ts +17 -0
- package/dist/esm/utils/pageConfig/converter.js +105 -0
- package/dist/esm/utils/pageConfig/index.d.ts +10 -0
- package/dist/esm/utils/pageConfig/index.js +11 -0
- package/dist/esm/utils/pageConfig/pageConfig.d.ts +10 -0
- package/dist/esm/utils/pageConfig/pageConfig.js +60 -0
- package/dist/esm/utils/pageConfig/saveBase64Image.d.ts +14 -0
- package/dist/esm/utils/pageConfig/saveBase64Image.js +105 -0
- package/dist/esm/utils/pageConfig/tabBarConfig.d.ts +13 -0
- package/dist/esm/utils/pageConfig/tabBarConfig.js +82 -0
- package/dist/esm/utils/pageConfig/types.d.ts +68 -0
- package/dist/esm/utils/pageConfig/types.js +1 -0
- package/dist/esm/utils/pageConfig/validator.d.ts +13 -0
- package/dist/esm/utils/pageConfig/validator.js +64 -0
- package/dist/esm/utils/pxtransform.d.ts +28 -0
- package/dist/esm/utils/pxtransform.js +121 -0
- package/package.json +74 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import { indentation, genObjectCode } from "./index";
|
|
4
|
+
/**
|
|
5
|
+
* 判断是否是 JS 计算组件
|
|
6
|
+
*/
|
|
7
|
+
var isJsCalculationComponent = function isJsCalculationComponent(namespace) {
|
|
8
|
+
return namespace === "mybricks.taro._muilt-inputJs" || namespace === "mybricks.core-comlib.js-ai";
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 判断是否是 JS API 组件
|
|
13
|
+
*/
|
|
14
|
+
var isJsApiComponent = function isJsApiComponent(namespace, rtType) {
|
|
15
|
+
return namespace.startsWith("mybricks.taro._") && (rtType === null || rtType === void 0 ? void 0 : rtType.match(/^js/gi)) !== null;
|
|
16
|
+
};
|
|
17
|
+
export var handleProcess = function handleProcess(event, config) {
|
|
18
|
+
var code = "";
|
|
19
|
+
var process = event.process;
|
|
20
|
+
var indent = indentation(config.codeStyle.indent * config.depth);
|
|
21
|
+
var indent2 = indentation(config.codeStyle.indent * (config.depth + 1));
|
|
22
|
+
|
|
23
|
+
// 检查是否有 JS 计算组件
|
|
24
|
+
var hasJsCalculationComponent = process.nodesDeclaration.some(function (_ref) {
|
|
25
|
+
var meta = _ref.meta;
|
|
26
|
+
return isJsCalculationComponent(meta.def.namespace);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 如果有 JS 计算组件,导入已初始化的 jsModules
|
|
30
|
+
if (hasJsCalculationComponent) {
|
|
31
|
+
config.addParentDependencyImport({
|
|
32
|
+
packageName: "../../common/index",
|
|
33
|
+
dependencyNames: ["jsModules"],
|
|
34
|
+
importType: "named"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 处理节点声明
|
|
39
|
+
process.nodesDeclaration.forEach(function (_ref2) {
|
|
40
|
+
var _config$getEventNodeN;
|
|
41
|
+
var meta = _ref2.meta,
|
|
42
|
+
props = _ref2.props;
|
|
43
|
+
if (meta.def.namespace.startsWith("mybricks.taro.module")) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 检查组件类型
|
|
48
|
+
var isJsCalc = isJsCalculationComponent(meta.def.namespace);
|
|
49
|
+
var isJsApi = isJsApiComponent(meta.def.namespace, meta.def.rtType);
|
|
50
|
+
var _config$getComponentM = config.getComponentMeta(meta),
|
|
51
|
+
importInfo = _config$getComponentM.importInfo,
|
|
52
|
+
name = _config$getComponentM.name,
|
|
53
|
+
callName = _config$getComponentM.callName;
|
|
54
|
+
var componentName = name;
|
|
55
|
+
if (isJsCalc) {
|
|
56
|
+
code += generateJsCalculationComponentCode({
|
|
57
|
+
meta: meta,
|
|
58
|
+
props: props,
|
|
59
|
+
componentName: componentName,
|
|
60
|
+
config: config,
|
|
61
|
+
event: event,
|
|
62
|
+
indent: indent,
|
|
63
|
+
indent2: indent2
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (isJsApi) {
|
|
68
|
+
code += generateJsApiComponentCode({
|
|
69
|
+
meta: meta,
|
|
70
|
+
props: props,
|
|
71
|
+
componentName: componentName,
|
|
72
|
+
callName: callName,
|
|
73
|
+
importInfo: importInfo,
|
|
74
|
+
config: config,
|
|
75
|
+
event: event,
|
|
76
|
+
indent: indent,
|
|
77
|
+
indent2: indent2
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
config.addParentDependencyImport({
|
|
82
|
+
packageName: importInfo.from,
|
|
83
|
+
dependencyNames: [importInfo.name],
|
|
84
|
+
importType: importInfo.type
|
|
85
|
+
});
|
|
86
|
+
var componentNameWithId = ((_config$getEventNodeN = config.getEventNodeName) === null || _config$getEventNodeN === void 0 ? void 0 : _config$getEventNodeN.call(config, {
|
|
87
|
+
com: meta,
|
|
88
|
+
scene: config.getCurrentScene(),
|
|
89
|
+
type: "declaration",
|
|
90
|
+
event: event
|
|
91
|
+
})) || "".concat(componentName, "_").concat(meta.id);
|
|
92
|
+
config.addParentDependencyImport({
|
|
93
|
+
packageName: config.getComponentPackageName(),
|
|
94
|
+
dependencyNames: ["useAppContext"],
|
|
95
|
+
importType: "named"
|
|
96
|
+
});
|
|
97
|
+
code += "".concat(indent, "/** ").concat(meta.title, " */") + "\n".concat(indent, "const ").concat(componentNameWithId, " = ").concat(callName || componentName, "({") + (config.verbose ? "\n".concat(indent2, "title: \"").concat(meta.title, "\",") : "") + (props.data ? "\n".concat(indent2, "data: ").concat(genObjectCode(props.data, {
|
|
98
|
+
initialIndent: config.codeStyle.indent * (config.depth + 1),
|
|
99
|
+
indentSize: config.codeStyle.indent
|
|
100
|
+
}), ",") : "") + (props.inputs ? "\n".concat(indent2, "inputs: [").concat(props.inputs.map(function (input) {
|
|
101
|
+
return "\"".concat(input, "\"");
|
|
102
|
+
}).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, "outputs: [").concat(props.outputs.map(function (output) {
|
|
103
|
+
return "\"".concat(output, "\"");
|
|
104
|
+
}).join(", "), "],") : "") + "\n".concat(indent, "}, appContext)\n");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// 处理节点调用
|
|
108
|
+
process.nodesInvocation.forEach(function (props) {
|
|
109
|
+
var componentType = props.componentType,
|
|
110
|
+
category = props.category,
|
|
111
|
+
runType = props.runType;
|
|
112
|
+
var nextValue = getNextValue(props, config, event);
|
|
113
|
+
var isSameScope = checkIsSameScope(event, props);
|
|
114
|
+
var nextCode = getNextCode(props, config, isSameScope, event);
|
|
115
|
+
if (code) {
|
|
116
|
+
code += "\n";
|
|
117
|
+
}
|
|
118
|
+
if (componentType === "js") {
|
|
119
|
+
if (category === "scene") {
|
|
120
|
+
var _config$getPageId;
|
|
121
|
+
config.addParentDependencyImport({
|
|
122
|
+
packageName: config.getComponentPackageName(),
|
|
123
|
+
dependencyNames: ["page"],
|
|
124
|
+
importType: "named"
|
|
125
|
+
});
|
|
126
|
+
var _sceneId = props.meta.model.data._sceneId;
|
|
127
|
+
var operateName = props.meta.model.data.openType === "redirect" ? "replace" : "open";
|
|
128
|
+
code += "".concat(indent, "/** \u6253\u5F00 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "page.").concat(operateName, "(\"").concat(((_config$getPageId = config.getPageId) === null || _config$getPageId === void 0 ? void 0 : _config$getPageId.call(config, _sceneId)) || _sceneId, "\", ").concat(nextValue, ")");
|
|
129
|
+
} else if (category === "normal") {
|
|
130
|
+
var componentNameWithId = getComponentNameWithId(props, config, event);
|
|
131
|
+
code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode).concat(componentNameWithId, "(").concat(runType === "input" ? nextValue : "", ")");
|
|
132
|
+
} else if (category === "var") {
|
|
133
|
+
if (props.meta.global) {
|
|
134
|
+
config.addParentDependencyImport({
|
|
135
|
+
packageName: config.getComponentPackageName(),
|
|
136
|
+
dependencyNames: ["globalVars"],
|
|
137
|
+
importType: "named"
|
|
138
|
+
});
|
|
139
|
+
code += "".concat(indent, "/** ").concat(props.title, " \u5168\u5C40\u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalVars.").concat(props.meta.title, ".").concat(props.id, "(").concat(nextValue, ")");
|
|
140
|
+
} else {
|
|
141
|
+
var currentProvider = getCurrentProvider({
|
|
142
|
+
isSameScope: isSameScope,
|
|
143
|
+
props: props
|
|
144
|
+
}, config);
|
|
145
|
+
code += "".concat(indent, "/** ").concat(props.title, " \u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "this.").concat(currentProvider.name, "_Vars.").concat(props.meta.title, ".").concat(props.id, "(").concat(nextValue, ")");
|
|
146
|
+
}
|
|
147
|
+
} else if (category === "fx") {
|
|
148
|
+
if (props.meta.global) {
|
|
149
|
+
config.addParentDependencyImport({
|
|
150
|
+
packageName: config.getComponentPackageName(),
|
|
151
|
+
dependencyNames: ["globalFxs"],
|
|
152
|
+
importType: "named"
|
|
153
|
+
});
|
|
154
|
+
code += "".concat(indent, "/** \u8C03\u7528\u5168\u5C40Fx ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalFxs.").concat(props.meta.ioProxy.id, "(").concat(nextValue, ")");
|
|
155
|
+
} else {
|
|
156
|
+
var _currentProvider = getCurrentProvider({
|
|
157
|
+
isSameScope: isSameScope,
|
|
158
|
+
props: props
|
|
159
|
+
}, config);
|
|
160
|
+
code += "".concat(indent, "/** \u8C03\u7528Fx ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "this.").concat(_currentProvider.name, "_Fxs.").concat(props.meta.ioProxy.id, "(").concat(nextValue, ")");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
var _config$getComponentC;
|
|
165
|
+
// UI 组件处理
|
|
166
|
+
var _currentProvider2 = getCurrentProvider({
|
|
167
|
+
isSameScope: isSameScope,
|
|
168
|
+
props: props
|
|
169
|
+
}, config);
|
|
170
|
+
_currentProvider2.controllers.add(props.meta.id);
|
|
171
|
+
var componentController = ((_config$getComponentC = config.getComponentController) === null || _config$getComponentC === void 0 ? void 0 : _config$getComponentC.call(config, {
|
|
172
|
+
com: props.meta,
|
|
173
|
+
scene: config.getCurrentScene()
|
|
174
|
+
})) || "controller_".concat(props.meta.id);
|
|
175
|
+
code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " \u7684 ").concat(props.title, " */") + "\n".concat(indent).concat(nextCode, "this.").concat(_currentProvider2.name, ".").concat(componentController, ".").concat(props.id, "(").concat(nextValue, ")");
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
if (["fx", "extension-api", "extension-bus"].includes(event.type)) {
|
|
179
|
+
var returnCode = Object.entries(event.frameOutputs).reduce(function (pre, _ref3) {
|
|
180
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
181
|
+
_ref4$ = _ref4[1],
|
|
182
|
+
id = _ref4$.id,
|
|
183
|
+
outputs = _ref4$.outputs;
|
|
184
|
+
if (!outputs) {
|
|
185
|
+
return pre + "".concat(indent2).concat(id, ": undefined,\n");
|
|
186
|
+
} else {
|
|
187
|
+
var next = outputs.map(function (output) {
|
|
188
|
+
return getNextValueWithParam(output, config, event);
|
|
189
|
+
}).join(", ");
|
|
190
|
+
return pre + "".concat(indent2).concat(id, ": ").concat(next, ",\n");
|
|
191
|
+
}
|
|
192
|
+
}, "");
|
|
193
|
+
if (returnCode) {
|
|
194
|
+
code += "\n".concat(indent, "return {\n").concat(returnCode).concat(indent, "}");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return code;
|
|
198
|
+
};
|
|
199
|
+
var checkIsSameScope = function checkIsSameScope(event, props) {
|
|
200
|
+
if (event.type === "com" && event.meta.parentComId === props.meta.parentComId && event.meta.frameId === props.meta.frameId) {
|
|
201
|
+
return true;
|
|
202
|
+
} else if (event.type === "slot" && event.comId === props.meta.parentComId && event.slotId === props.meta.frameId) {
|
|
203
|
+
return true;
|
|
204
|
+
} else if (event.type === "fx" && event.parentComId === props.meta.parentComId && event.parentSlotId === props.meta.frameId) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
};
|
|
209
|
+
var getComponentNameWithId = function getComponentNameWithId(props, config, event) {
|
|
210
|
+
// 检查是否是 JS 计算组件
|
|
211
|
+
if (isJsCalculationComponent(props.meta.def.namespace)) {
|
|
212
|
+
// JS 计算组件:使用 jsModules_${meta.id} 作为变量名
|
|
213
|
+
if (config.getEventNodeName) {
|
|
214
|
+
var componentName = config.getEventNodeName({
|
|
215
|
+
com: props.meta,
|
|
216
|
+
scene: config.getCurrentScene(),
|
|
217
|
+
event: event,
|
|
218
|
+
type: "declaration"
|
|
219
|
+
});
|
|
220
|
+
if (componentName) {
|
|
221
|
+
return componentName;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return "jsModules_".concat(props.meta.id);
|
|
225
|
+
}
|
|
226
|
+
if (config.getEventNodeName) {
|
|
227
|
+
var _componentName = config.getEventNodeName({
|
|
228
|
+
com: props.meta,
|
|
229
|
+
scene: config.getCurrentScene(),
|
|
230
|
+
event: event,
|
|
231
|
+
type: "declaration"
|
|
232
|
+
});
|
|
233
|
+
if (_componentName) {
|
|
234
|
+
return _componentName;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
var _config$getComponentM2 = config.getComponentMeta(props.meta),
|
|
238
|
+
name = _config$getComponentM2.name;
|
|
239
|
+
// 确保变量名合法(将连字符替换为下划线)
|
|
240
|
+
var sanitizedName = name.replace(/-/g, '_');
|
|
241
|
+
return "".concat(sanitizedName, "_").concat(props.meta.id);
|
|
242
|
+
};
|
|
243
|
+
var getNextCode = function getNextCode(props, config, isSameScope, event) {
|
|
244
|
+
var nextParam = props.nextParam;
|
|
245
|
+
if (!nextParam.length) {
|
|
246
|
+
return "";
|
|
247
|
+
}
|
|
248
|
+
var componentNameWithId = getComponentNameWithId(props, config, event);
|
|
249
|
+
return "const ".concat(componentNameWithId, "_result = ");
|
|
250
|
+
};
|
|
251
|
+
var getNextValue = function getNextValue(props, config, event) {
|
|
252
|
+
var paramSource = props.paramSource;
|
|
253
|
+
var nextValue = paramSource.map(function (param) {
|
|
254
|
+
if (param.type === "params") {
|
|
255
|
+
var params = config.getParams();
|
|
256
|
+
return params[param.id];
|
|
257
|
+
} else if (param.type === "constant") {
|
|
258
|
+
return JSON.stringify(param.value);
|
|
259
|
+
}
|
|
260
|
+
var componentNameWithId = getComponentNameWithId(param, config, event);
|
|
261
|
+
if (param.connectId) {
|
|
262
|
+
return "".concat(componentNameWithId, "_").concat(param.connectId, ".").concat(param.id);
|
|
263
|
+
}
|
|
264
|
+
return "".concat(componentNameWithId, "_result.").concat(param.id);
|
|
265
|
+
});
|
|
266
|
+
return nextValue.join(", ");
|
|
267
|
+
};
|
|
268
|
+
var getNextValueWithParam = function getNextValueWithParam(param, config, event) {
|
|
269
|
+
if (param.type === "params") {
|
|
270
|
+
var params = config.getParams();
|
|
271
|
+
return params[param.id];
|
|
272
|
+
}
|
|
273
|
+
var componentNameWithId = getComponentNameWithId(param, config, event);
|
|
274
|
+
if (param.connectId) {
|
|
275
|
+
return "".concat(componentNameWithId, "_").concat(param.connectId, ".").concat(param.id);
|
|
276
|
+
}
|
|
277
|
+
return "".concat(componentNameWithId, "_result.").concat(param.id);
|
|
278
|
+
};
|
|
279
|
+
var getCurrentProvider = function getCurrentProvider(params, config) {
|
|
280
|
+
var _config$getProviderNa;
|
|
281
|
+
var providerMap = config.getProviderMap();
|
|
282
|
+
var isSameScope = params.isSameScope,
|
|
283
|
+
props = params.props;
|
|
284
|
+
var meta = props.meta;
|
|
285
|
+
var parentComId = meta.parentComId,
|
|
286
|
+
frameId = meta.frameId;
|
|
287
|
+
var providerName = ((_config$getProviderNa = config.getProviderName) === null || _config$getProviderNa === void 0 ? void 0 : _config$getProviderNa.call(config, {
|
|
288
|
+
com: meta,
|
|
289
|
+
scene: config.getCurrentScene()
|
|
290
|
+
})) || (!parentComId ? "slot_Index" : "slot_".concat(frameId[0].toUpperCase() + frameId.slice(1), "_").concat(parentComId));
|
|
291
|
+
var provider = providerMap[providerName];
|
|
292
|
+
if (!isSameScope) {
|
|
293
|
+
config.addConsumer(provider);
|
|
294
|
+
}
|
|
295
|
+
return provider;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 生成 JS 计算组件的代码
|
|
300
|
+
*/
|
|
301
|
+
var generateJsCalculationComponentCode = function generateJsCalculationComponentCode(params) {
|
|
302
|
+
var _config$getEventNodeN2;
|
|
303
|
+
var meta = params.meta,
|
|
304
|
+
props = params.props,
|
|
305
|
+
componentName = params.componentName,
|
|
306
|
+
config = params.config,
|
|
307
|
+
event = params.event,
|
|
308
|
+
indent = params.indent,
|
|
309
|
+
indent2 = params.indent2;
|
|
310
|
+
var componentNameWithId = ((_config$getEventNodeN2 = config.getEventNodeName) === null || _config$getEventNodeN2 === void 0 ? void 0 : _config$getEventNodeN2.call(config, {
|
|
311
|
+
com: meta,
|
|
312
|
+
scene: config.getCurrentScene(),
|
|
313
|
+
type: "declaration",
|
|
314
|
+
event: event
|
|
315
|
+
})) || "jsModules_".concat(meta.id);
|
|
316
|
+
|
|
317
|
+
// JS 计算组件的 data 只包含必要配置(如 runImmediate),不包含 fns、transformCode 等
|
|
318
|
+
var jsData = {};
|
|
319
|
+
if (props.data && 'runImmediate' in props.data) {
|
|
320
|
+
jsData.runImmediate = props.data.runImmediate;
|
|
321
|
+
}
|
|
322
|
+
return "".concat(indent, "/** ").concat(meta.title, " */") + "\n".concat(indent, "const ").concat(componentNameWithId, " = jsModules.").concat(meta.id, "({") + (config.verbose ? "\n".concat(indent2, "title: \"").concat(meta.title, "\",") : "") + (Object.keys(jsData).length > 0 ? "\n".concat(indent2, "data: ").concat(genObjectCode(jsData, {
|
|
323
|
+
initialIndent: config.codeStyle.indent * (config.depth + 1),
|
|
324
|
+
indentSize: config.codeStyle.indent
|
|
325
|
+
}), ",") : "") + (props.inputs ? "\n".concat(indent2, "inputs: [").concat(props.inputs.map(function (input) {
|
|
326
|
+
return "\"".concat(input, "\"");
|
|
327
|
+
}).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, "outputs: [").concat(props.outputs.map(function (output) {
|
|
328
|
+
return "\"".concat(output, "\"");
|
|
329
|
+
}).join(", "), "],") : "") + "\n".concat(indent, "}, appContext)\n");
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* 生成 JS API 组件的代码
|
|
334
|
+
*/
|
|
335
|
+
var generateJsApiComponentCode = function generateJsApiComponentCode(params) {
|
|
336
|
+
var _config$getEventNodeN3;
|
|
337
|
+
var meta = params.meta,
|
|
338
|
+
props = params.props,
|
|
339
|
+
componentName = params.componentName,
|
|
340
|
+
callName = params.callName,
|
|
341
|
+
importInfo = params.importInfo,
|
|
342
|
+
config = params.config,
|
|
343
|
+
event = params.event,
|
|
344
|
+
indent = params.indent,
|
|
345
|
+
indent2 = params.indent2;
|
|
346
|
+
|
|
347
|
+
// 导入 createJSHandle
|
|
348
|
+
config.addParentDependencyImport({
|
|
349
|
+
packageName: "../../core/mybricks/index",
|
|
350
|
+
dependencyNames: ["createJSHandle"],
|
|
351
|
+
importType: "named"
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// 导入 JS API 组件
|
|
355
|
+
config.addParentDependencyImport({
|
|
356
|
+
packageName: importInfo.from,
|
|
357
|
+
dependencyNames: [importInfo.name],
|
|
358
|
+
importType: importInfo.type
|
|
359
|
+
});
|
|
360
|
+
var componentNameWithId = ((_config$getEventNodeN3 = config.getEventNodeName) === null || _config$getEventNodeN3 === void 0 ? void 0 : _config$getEventNodeN3.call(config, {
|
|
361
|
+
com: meta,
|
|
362
|
+
scene: config.getCurrentScene(),
|
|
363
|
+
type: "declaration",
|
|
364
|
+
event: event
|
|
365
|
+
})) || "".concat(componentName, "_").concat(meta.id);
|
|
366
|
+
config.addParentDependencyImport({
|
|
367
|
+
packageName: config.getComponentPackageName(),
|
|
368
|
+
dependencyNames: ["useAppContext"],
|
|
369
|
+
importType: "named"
|
|
370
|
+
});
|
|
371
|
+
return "".concat(indent, "/** ").concat(meta.title, " */") + "\n".concat(indent, "const ").concat(componentNameWithId, " = createJSHandle(").concat(callName || componentName, ", {") + "\n".concat(indent2, "props: {") + (config.verbose ? "\n".concat(indent2, " title: \"").concat(meta.title, "\",") : "") + (props.data ? "\n".concat(indent2, " data: ").concat(genObjectCode(props.data, {
|
|
372
|
+
initialIndent: config.codeStyle.indent * (config.depth + 2),
|
|
373
|
+
indentSize: config.codeStyle.indent
|
|
374
|
+
}), ",") : "") + (props.inputs ? "\n".concat(indent2, " inputs: [").concat(props.inputs.map(function (input) {
|
|
375
|
+
return "\"".concat(input, "\"");
|
|
376
|
+
}).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, " outputs: [").concat(props.outputs.map(function (output) {
|
|
377
|
+
return "\"".concat(output, "\"");
|
|
378
|
+
}).join(", "), "],") : "") + "\n".concat(indent2, "},") + "\n".concat(indent2, "appContext") + "\n".concat(indent, "})\n");
|
|
379
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ToTaroCodeConfig } from "../toCodeTaro";
|
|
2
|
+
export interface Style {
|
|
3
|
+
layout?: "smart" | "flex-column" | "flex-row" | {
|
|
4
|
+
display?: string;
|
|
5
|
+
position?: string;
|
|
6
|
+
flexDirection?: string;
|
|
7
|
+
alignItems?: string;
|
|
8
|
+
justifyContent?: string;
|
|
9
|
+
flexWrap?: string;
|
|
10
|
+
rowGap?: number;
|
|
11
|
+
columnGap?: number;
|
|
12
|
+
};
|
|
13
|
+
width?: string | number;
|
|
14
|
+
height?: string | number;
|
|
15
|
+
styleAry?: Array<{
|
|
16
|
+
selector: string;
|
|
17
|
+
css: Record<string, any>;
|
|
18
|
+
}>;
|
|
19
|
+
slots?: Record<string, {
|
|
20
|
+
layout?: string | object;
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}>;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
type ImportType = "default" | "named" | "module";
|
|
26
|
+
/** 导入依赖收集、解析 */
|
|
27
|
+
export declare class ImportManager {
|
|
28
|
+
private _config;
|
|
29
|
+
private _imports;
|
|
30
|
+
constructor(_config: ToTaroCodeConfig);
|
|
31
|
+
/** 添加依赖 */
|
|
32
|
+
addImport({ packageName, dependencyNames, importType, }: {
|
|
33
|
+
packageName: string;
|
|
34
|
+
dependencyNames: string[];
|
|
35
|
+
importType: ImportType;
|
|
36
|
+
}): void;
|
|
37
|
+
/** 依赖解析为code */
|
|
38
|
+
toCode(): string;
|
|
39
|
+
}
|
|
40
|
+
/** 将第一个字符转大写 */
|
|
41
|
+
export declare const firstCharToUpperCase: (str: string) => string;
|
|
42
|
+
/** 将第一个字符转小写 */
|
|
43
|
+
export declare const firstCharToLowerCase: (str: string) => string;
|
|
44
|
+
/** 缩进 */
|
|
45
|
+
export declare const indentation: (level: number) => string;
|
|
46
|
+
/** 驼峰转中划线 */
|
|
47
|
+
export declare const camelToKebab: (str: string) => string;
|
|
48
|
+
/** 中划线转驼峰 */
|
|
49
|
+
export declare const kebabToCamel: (str: string) => string;
|
|
50
|
+
/** 转换根节点样式 */
|
|
51
|
+
export declare const convertRootStyle: (style: Style) => Record<string, string | number>;
|
|
52
|
+
/** 转换组件样式为 Taro/React 样式 */
|
|
53
|
+
export declare const convertComponentStyle: (style: Style) => Record<string, Record<string, string | number>>;
|
|
54
|
+
/** 转换 styleAry 为 CSS 字符串 */
|
|
55
|
+
export declare const convertStyleAryToCss: (styleAry: any[], parentSelector?: string) => string;
|
|
56
|
+
/** 生成对象代码 */
|
|
57
|
+
export declare const genObjectCode: (object: any, config: {
|
|
58
|
+
initialIndent: number;
|
|
59
|
+
indentSize: number;
|
|
60
|
+
}) => string;
|
|
61
|
+
export { getUiComponentCode } from "./code";
|
|
62
|
+
export { getRootComponentClassName } from "./getComponentClassName";
|