@mybricks/to-code-taro 1.2.6 → 1.2.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/package.json +1 -1
- package/dist/cjs/abstractEventTypeDef.d.ts +0 -11
- package/dist/cjs/abstractEventTypeDef.js +0 -93
- package/dist/cjs/generate/compressImages.d.ts +0 -16
- package/dist/cjs/generate/compressImages.js +0 -76
- package/dist/cjs/generate/generateTaroProjectJson.d.ts +0 -13
- package/dist/cjs/generate/generateTaroProjectJson.js +0 -225
- package/dist/cjs/generate/generateTaroTempalteJson.d.ts +0 -15
- package/dist/cjs/generate/generateTaroTempalteJson.js +0 -103
- package/dist/cjs/generate/utils/appConfig.d.ts +0 -21
- package/dist/cjs/generate/utils/appConfig.js +0 -57
- package/dist/cjs/generate/utils/commonDir.d.ts +0 -21
- package/dist/cjs/generate/utils/commonDir.js +0 -63
- package/dist/cjs/generate/utils/customTabBar.d.ts +0 -11
- package/dist/cjs/generate/utils/customTabBar.js +0 -73
- package/dist/cjs/generate/utils/fileNode.d.ts +0 -21
- package/dist/cjs/generate/utils/fileNode.js +0 -67
- package/dist/cjs/generate/utils/index.d.ts +0 -7
- package/dist/cjs/generate/utils/index.js +0 -29
- package/dist/cjs/generate/utils/pageImages.d.ts +0 -14
- package/dist/cjs/generate/utils/pageImages.js +0 -36
- package/dist/cjs/generate/utils/tabBarImages.d.ts +0 -14
- package/dist/cjs/generate/utils/tabBarImages.js +0 -36
- package/dist/cjs/handleCom.d.ts +0 -8
- package/dist/cjs/handleCom.js +0 -280
- package/dist/cjs/handleDom.d.ts +0 -21
- package/dist/cjs/handleDom.js +0 -52
- package/dist/cjs/handleExtension.d.ts +0 -10
- package/dist/cjs/handleExtension.js +0 -300
- package/dist/cjs/handleGlobal.d.ts +0 -11
- package/dist/cjs/handleGlobal.js +0 -191
- package/dist/cjs/handleModule.d.ts +0 -15
- package/dist/cjs/handleModule.js +0 -104
- package/dist/cjs/handleSlot.d.ts +0 -29
- package/dist/cjs/handleSlot.js +0 -153
- package/dist/cjs/index.d.ts +0 -4
- package/dist/cjs/index.js +0 -48
- package/dist/cjs/processors/processComEvents.d.ts +0 -9
- package/dist/cjs/processors/processComEvents.js +0 -163
- package/dist/cjs/processors/processModule.d.ts +0 -31
- package/dist/cjs/processors/processModule.js +0 -159
- package/dist/cjs/processors/processScene.d.ts +0 -32
- package/dist/cjs/processors/processScene.js +0 -198
- package/dist/cjs/processors/processSceneLogic.d.ts +0 -7
- package/dist/cjs/processors/processSceneLogic.js +0 -230
- package/dist/cjs/shims-taro.d.ts +0 -20
- package/dist/cjs/taro-template.json +0 -154
- package/dist/cjs/toCodeTaro.d.ts +0 -168
- package/dist/cjs/toCodeTaro.js +0 -326
- package/dist/cjs/utils/builder/buildResult.d.ts +0 -24
- package/dist/cjs/utils/builder/buildResult.js +0 -163
- package/dist/cjs/utils/common/ImportManager.d.ts +0 -26
- package/dist/cjs/utils/common/ImportManager.js +0 -123
- package/dist/cjs/utils/common/helper.d.ts +0 -12
- package/dist/cjs/utils/common/helper.js +0 -52
- package/dist/cjs/utils/common/object.d.ts +0 -5
- package/dist/cjs/utils/common/object.js +0 -58
- package/dist/cjs/utils/common/string.d.ts +0 -18
- package/dist/cjs/utils/common/string.js +0 -59
- package/dist/cjs/utils/config/content/converter.d.ts +0 -17
- package/dist/cjs/utils/config/content/converter.js +0 -84
- package/dist/cjs/utils/config/content/index.d.ts +0 -10
- package/dist/cjs/utils/config/content/index.js +0 -33
- package/dist/cjs/utils/config/content/pageConfig.d.ts +0 -10
- package/dist/cjs/utils/config/content/pageConfig.js +0 -80
- package/dist/cjs/utils/config/content/saveBase64Image.d.ts +0 -24
- package/dist/cjs/utils/config/content/saveBase64Image.js +0 -113
- package/dist/cjs/utils/config/content/tabBarConfig.d.ts +0 -28
- package/dist/cjs/utils/config/content/tabBarConfig.js +0 -74
- package/dist/cjs/utils/config/content/types.d.ts +0 -73
- package/dist/cjs/utils/config/content/types.js +0 -17
- package/dist/cjs/utils/config/content/validator.d.ts +0 -13
- package/dist/cjs/utils/config/content/validator.js +0 -67
- package/dist/cjs/utils/config/handlePageConfig.d.ts +0 -31
- package/dist/cjs/utils/config/handlePageConfig.js +0 -88
- package/dist/cjs/utils/context/buildContext.d.ts +0 -31
- package/dist/cjs/utils/context/buildContext.js +0 -76
- package/dist/cjs/utils/context/buildFrameMap.d.ts +0 -16
- package/dist/cjs/utils/context/buildFrameMap.js +0 -106
- package/dist/cjs/utils/context/buildGlobalData.d.ts +0 -13
- package/dist/cjs/utils/context/buildGlobalData.js +0 -58
- package/dist/cjs/utils/context/collectJSModules.d.ts +0 -41
- package/dist/cjs/utils/context/collectJSModules.js +0 -93
- package/dist/cjs/utils/context/createEventQueries.d.ts +0 -45
- package/dist/cjs/utils/context/createEventQueries.js +0 -99
- package/dist/cjs/utils/context/createProvider.d.ts +0 -21
- package/dist/cjs/utils/context/createProvider.js +0 -49
- package/dist/cjs/utils/index.d.ts +0 -10
- package/dist/cjs/utils/index.js +0 -60
- package/dist/cjs/utils/logic/convertNamespace.d.ts +0 -11
- package/dist/cjs/utils/logic/convertNamespace.js +0 -43
- package/dist/cjs/utils/logic/genJSModules.d.ts +0 -16
- package/dist/cjs/utils/logic/genJSModules.js +0 -114
- package/dist/cjs/utils/logic/handleProcess.d.ts +0 -9
- package/dist/cjs/utils/logic/handleProcess.js +0 -462
- package/dist/cjs/utils/logic/processChildren.d.ts +0 -26
- package/dist/cjs/utils/logic/processChildren.js +0 -121
- package/dist/cjs/utils/style/color.d.ts +0 -4
- package/dist/cjs/utils/style/color.js +0 -45
- package/dist/cjs/utils/style/converter.d.ts +0 -7
- package/dist/cjs/utils/style/converter.js +0 -175
- package/dist/cjs/utils/style/getComponentClassName.d.ts +0 -16
- package/dist/cjs/utils/style/getComponentClassName.js +0 -47
- package/dist/cjs/utils/style/pxtransform.d.ts +0 -4
- package/dist/cjs/utils/style/pxtransform.js +0 -62
- package/dist/cjs/utils/style/types.d.ts +0 -23
- package/dist/cjs/utils/style/types.js +0 -17
- package/dist/cjs/utils/templates/component.d.ts +0 -19
- package/dist/cjs/utils/templates/component.js +0 -86
- package/dist/cjs/utils/templates/index.d.ts +0 -32
- package/dist/cjs/utils/templates/index.js +0 -116
- package/dist/cjs/utils/templates/renderManager.d.ts +0 -18
- package/dist/cjs/utils/templates/renderManager.js +0 -152
- package/dist/cjs/utils/templates/scene.d.ts +0 -23
- package/dist/cjs/utils/templates/scene.js +0 -113
- package/dist/esm/abstractEventTypeDef.d.ts +0 -11
- package/dist/esm/abstractEventTypeDef.js +0 -63
- package/dist/esm/generate/compressImages.d.ts +0 -16
- package/dist/esm/generate/compressImages.js +0 -108
- package/dist/esm/generate/generateTaroProjectJson.d.ts +0 -13
- package/dist/esm/generate/generateTaroProjectJson.js +0 -228
- package/dist/esm/generate/generateTaroTempalteJson.d.ts +0 -15
- package/dist/esm/generate/generateTaroTempalteJson.js +0 -94
- package/dist/esm/generate/utils/appConfig.d.ts +0 -21
- package/dist/esm/generate/utils/appConfig.js +0 -49
- package/dist/esm/generate/utils/commonDir.d.ts +0 -21
- package/dist/esm/generate/utils/commonDir.js +0 -53
- package/dist/esm/generate/utils/customTabBar.d.ts +0 -11
- package/dist/esm/generate/utils/customTabBar.js +0 -52
- package/dist/esm/generate/utils/fileNode.d.ts +0 -21
- package/dist/esm/generate/utils/fileNode.js +0 -62
- package/dist/esm/generate/utils/index.d.ts +0 -7
- package/dist/esm/generate/utils/index.js +0 -8
- package/dist/esm/generate/utils/pageImages.d.ts +0 -14
- package/dist/esm/generate/utils/pageImages.js +0 -15
- package/dist/esm/generate/utils/tabBarImages.d.ts +0 -14
- package/dist/esm/generate/utils/tabBarImages.js +0 -15
- package/dist/esm/handleCom.d.ts +0 -8
- package/dist/esm/handleCom.js +0 -350
- package/dist/esm/handleDom.d.ts +0 -21
- package/dist/esm/handleDom.js +0 -26
- package/dist/esm/handleExtension.d.ts +0 -10
- package/dist/esm/handleExtension.js +0 -243
- package/dist/esm/handleGlobal.d.ts +0 -11
- package/dist/esm/handleGlobal.js +0 -157
- package/dist/esm/handleModule.d.ts +0 -15
- package/dist/esm/handleModule.js +0 -73
- package/dist/esm/handleSlot.d.ts +0 -29
- package/dist/esm/handleSlot.js +0 -215
- package/dist/esm/index.d.ts +0 -4
- package/dist/esm/index.js +0 -4
- package/dist/esm/processors/processComEvents.d.ts +0 -9
- package/dist/esm/processors/processComEvents.js +0 -170
- package/dist/esm/processors/processModule.d.ts +0 -31
- package/dist/esm/processors/processModule.js +0 -177
- package/dist/esm/processors/processScene.d.ts +0 -32
- package/dist/esm/processors/processScene.js +0 -234
- package/dist/esm/processors/processSceneLogic.d.ts +0 -7
- package/dist/esm/processors/processSceneLogic.js +0 -247
- package/dist/esm/shims-taro.d.ts +0 -20
- package/dist/esm/taro-template.json +0 -154
- package/dist/esm/toCodeTaro.d.ts +0 -168
- package/dist/esm/toCodeTaro.js +0 -367
- package/dist/esm/utils/builder/buildResult.d.ts +0 -24
- package/dist/esm/utils/builder/buildResult.js +0 -119
- package/dist/esm/utils/common/ImportManager.d.ts +0 -26
- package/dist/esm/utils/common/ImportManager.js +0 -131
- package/dist/esm/utils/common/helper.d.ts +0 -12
- package/dist/esm/utils/common/helper.js +0 -33
- package/dist/esm/utils/common/object.d.ts +0 -5
- package/dist/esm/utils/common/object.js +0 -32
- package/dist/esm/utils/common/string.d.ts +0 -18
- package/dist/esm/utils/common/string.js +0 -37
- package/dist/esm/utils/config/content/converter.d.ts +0 -17
- package/dist/esm/utils/config/content/converter.js +0 -106
- package/dist/esm/utils/config/content/index.d.ts +0 -10
- package/dist/esm/utils/config/content/index.js +0 -11
- package/dist/esm/utils/config/content/pageConfig.d.ts +0 -10
- package/dist/esm/utils/config/content/pageConfig.js +0 -43
- package/dist/esm/utils/config/content/saveBase64Image.d.ts +0 -24
- package/dist/esm/utils/config/content/saveBase64Image.js +0 -127
- package/dist/esm/utils/config/content/tabBarConfig.d.ts +0 -28
- package/dist/esm/utils/config/content/tabBarConfig.js +0 -89
- package/dist/esm/utils/config/content/types.d.ts +0 -73
- package/dist/esm/utils/config/content/types.js +0 -1
- package/dist/esm/utils/config/content/validator.d.ts +0 -13
- package/dist/esm/utils/config/content/validator.js +0 -64
- package/dist/esm/utils/config/handlePageConfig.d.ts +0 -31
- package/dist/esm/utils/config/handlePageConfig.js +0 -89
- package/dist/esm/utils/context/buildContext.d.ts +0 -31
- package/dist/esm/utils/context/buildContext.js +0 -65
- package/dist/esm/utils/context/buildFrameMap.d.ts +0 -16
- package/dist/esm/utils/context/buildFrameMap.js +0 -131
- package/dist/esm/utils/context/buildGlobalData.d.ts +0 -13
- package/dist/esm/utils/context/buildGlobalData.js +0 -44
- package/dist/esm/utils/context/collectJSModules.d.ts +0 -41
- package/dist/esm/utils/context/collectJSModules.js +0 -87
- package/dist/esm/utils/context/createEventQueries.d.ts +0 -45
- package/dist/esm/utils/context/createEventQueries.js +0 -99
- package/dist/esm/utils/context/createProvider.d.ts +0 -21
- package/dist/esm/utils/context/createProvider.js +0 -33
- package/dist/esm/utils/index.d.ts +0 -10
- package/dist/esm/utils/index.js +0 -12
- package/dist/esm/utils/logic/convertNamespace.d.ts +0 -11
- package/dist/esm/utils/logic/convertNamespace.js +0 -27
- package/dist/esm/utils/logic/genJSModules.d.ts +0 -16
- package/dist/esm/utils/logic/genJSModules.js +0 -33
- package/dist/esm/utils/logic/handleProcess.d.ts +0 -9
- package/dist/esm/utils/logic/handleProcess.js +0 -520
- package/dist/esm/utils/logic/processChildren.d.ts +0 -26
- package/dist/esm/utils/logic/processChildren.js +0 -101
- package/dist/esm/utils/style/color.d.ts +0 -4
- package/dist/esm/utils/style/color.js +0 -17
- package/dist/esm/utils/style/converter.d.ts +0 -7
- package/dist/esm/utils/style/converter.js +0 -175
- package/dist/esm/utils/style/getComponentClassName.d.ts +0 -16
- package/dist/esm/utils/style/getComponentClassName.js +0 -37
- package/dist/esm/utils/style/pxtransform.d.ts +0 -4
- package/dist/esm/utils/style/pxtransform.js +0 -54
- package/dist/esm/utils/style/types.d.ts +0 -23
- package/dist/esm/utils/style/types.js +0 -1
- package/dist/esm/utils/templates/component.d.ts +0 -19
- package/dist/esm/utils/templates/component.js +0 -55
- package/dist/esm/utils/templates/index.d.ts +0 -32
- package/dist/esm/utils/templates/index.js +0 -97
- package/dist/esm/utils/templates/renderManager.d.ts +0 -18
- package/dist/esm/utils/templates/renderManager.js +0 -145
- package/dist/esm/utils/templates/scene.d.ts +0 -23
- package/dist/esm/utils/templates/scene.js +0 -66
|
@@ -1,520 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
|
|
5
|
-
import { indentation } from "../common/helper";
|
|
6
|
-
import { getSafeVarName } from "../common/string";
|
|
7
|
-
import { genObjectCode } from "../common/object";
|
|
8
|
-
/**
|
|
9
|
-
* 判断是否是 JS 计算组件
|
|
10
|
-
*/
|
|
11
|
-
var isJsCalculationComponent = function isJsCalculationComponent(namespace) {
|
|
12
|
-
return namespace === "mybricks.taro._muilt-inputJs" || namespace === "mybricks.core-comlib.js-ai";
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 判断是否是 JS API 组件
|
|
17
|
-
*/
|
|
18
|
-
var isJsApiComponent = function isJsApiComponent(namespace, rtType) {
|
|
19
|
-
var jsCompNamespace = ['mybricks.taro.', 'mybricks.normal-pc.'];
|
|
20
|
-
return jsCompNamespace.some(function (_namespace) {
|
|
21
|
-
return namespace.startsWith(_namespace);
|
|
22
|
-
}) && (rtType === null || rtType === void 0 ? void 0 : rtType.match(/^js/gi)) !== null;
|
|
23
|
-
};
|
|
24
|
-
export var handleProcess = function handleProcess(event, config) {
|
|
25
|
-
var code = "";
|
|
26
|
-
var process = event.process;
|
|
27
|
-
var indent = indentation(config.codeStyle.indent * config.depth);
|
|
28
|
-
var indent2 = indentation(config.codeStyle.indent * (config.depth + 1));
|
|
29
|
-
|
|
30
|
-
// 检查是否有 JS 计算组件
|
|
31
|
-
var hasJsCalculationComponent = process.nodesDeclaration.some(function (_ref) {
|
|
32
|
-
var meta = _ref.meta;
|
|
33
|
-
return isJsCalculationComponent(meta.def.namespace);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// 如果有 JS 计算组件,导入已初始化的 jsModules
|
|
37
|
-
if (hasJsCalculationComponent) {
|
|
38
|
-
config.addParentDependencyImport({
|
|
39
|
-
packageName: "./index.jsModules",
|
|
40
|
-
dependencyNames: ["jsModules"],
|
|
41
|
-
importType: "named"
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 处理节点声明
|
|
46
|
-
process.nodesDeclaration.forEach(function (_ref2) {
|
|
47
|
-
var _config$getEventNodeN;
|
|
48
|
-
var meta = _ref2.meta,
|
|
49
|
-
props = _ref2.props;
|
|
50
|
-
if (meta.def.namespace.startsWith("mybricks.taro.module")) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 检查组件类型
|
|
55
|
-
var isJsCalc = isJsCalculationComponent(meta.def.namespace);
|
|
56
|
-
var isJsApi = isJsApiComponent(meta.def.namespace, meta.def.rtType);
|
|
57
|
-
var _config$getComponentM = config.getComponentMeta(meta),
|
|
58
|
-
importInfo = _config$getComponentM.importInfo,
|
|
59
|
-
name = _config$getComponentM.name,
|
|
60
|
-
callName = _config$getComponentM.callName;
|
|
61
|
-
var componentName = name;
|
|
62
|
-
if (isJsCalc) {
|
|
63
|
-
code += generateJsCalculationComponentCode({
|
|
64
|
-
meta: meta,
|
|
65
|
-
props: props,
|
|
66
|
-
componentName: componentName,
|
|
67
|
-
config: config,
|
|
68
|
-
event: event,
|
|
69
|
-
indent: indent,
|
|
70
|
-
indent2: indent2
|
|
71
|
-
});
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (isJsApi) {
|
|
75
|
-
code += generateJsApiComponentCode({
|
|
76
|
-
meta: meta,
|
|
77
|
-
props: props,
|
|
78
|
-
componentName: componentName,
|
|
79
|
-
callName: callName,
|
|
80
|
-
importInfo: importInfo,
|
|
81
|
-
config: config,
|
|
82
|
-
event: event,
|
|
83
|
-
indent: indent,
|
|
84
|
-
indent2: indent2
|
|
85
|
-
});
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
config.addParentDependencyImport({
|
|
89
|
-
packageName: importInfo.from,
|
|
90
|
-
dependencyNames: [importInfo.name],
|
|
91
|
-
importType: importInfo.type
|
|
92
|
-
});
|
|
93
|
-
var componentNameWithId = ((_config$getEventNodeN = config.getEventNodeName) === null || _config$getEventNodeN === void 0 ? void 0 : _config$getEventNodeN.call(config, {
|
|
94
|
-
com: meta,
|
|
95
|
-
scene: config.getCurrentScene(),
|
|
96
|
-
type: "declaration",
|
|
97
|
-
event: event
|
|
98
|
-
})) || "".concat(componentName, "_").concat(meta.id);
|
|
99
|
-
config.addParentDependencyImport({
|
|
100
|
-
packageName: config.getComponentPackageName(),
|
|
101
|
-
dependencyNames: ["useAppContext"],
|
|
102
|
-
importType: "named"
|
|
103
|
-
});
|
|
104
|
-
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, {
|
|
105
|
-
initialIndent: config.codeStyle.indent * (config.depth + 1),
|
|
106
|
-
indentSize: config.codeStyle.indent
|
|
107
|
-
}), ",") : "") + (props.inputs ? "\n".concat(indent2, "inputs: [").concat(props.inputs.map(function (input) {
|
|
108
|
-
return "\"".concat(input, "\"");
|
|
109
|
-
}).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, "outputs: [").concat(props.outputs.map(function (output) {
|
|
110
|
-
return "\"".concat(output, "\"");
|
|
111
|
-
}).join(", "), "],") : "") + "\n".concat(indent, "}, appContext)\n");
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// 处理节点调用
|
|
115
|
-
// 边遍历边构建映射:确保引用时只能看到已声明的变量
|
|
116
|
-
var outputToInputPinMap = new Map();
|
|
117
|
-
// 跟踪已声明的变量名,用于去重(同一组件+pin 多次调用时追加后缀)
|
|
118
|
-
var declaredVarCount = new Map();
|
|
119
|
-
process.nodesInvocation.forEach(function (props) {
|
|
120
|
-
var _props$nextParam, _config$getCallTempla, _props$meta$model;
|
|
121
|
-
var componentType = props.componentType,
|
|
122
|
-
category = props.category,
|
|
123
|
-
runType = props.runType;
|
|
124
|
-
var nextValue = getNextValue(props, config, event, outputToInputPinMap);
|
|
125
|
-
var isSameScope = checkIsSameScope(event, props);
|
|
126
|
-
var _getNextCode = getNextCode(props, config, isSameScope, event, declaredVarCount),
|
|
127
|
-
nextCode = _getNextCode.code,
|
|
128
|
-
declaredVarName = _getNextCode.varName;
|
|
129
|
-
|
|
130
|
-
// 声明后记录映射,供后续引用(存储完整变量名,支持去重后缀)
|
|
131
|
-
(_props$nextParam = props.nextParam) === null || _props$nextParam === void 0 || _props$nextParam.forEach(function (np) {
|
|
132
|
-
outputToInputPinMap.set("".concat(props.meta.id, "_").concat(np.id), declaredVarName);
|
|
133
|
-
});
|
|
134
|
-
if (code) {
|
|
135
|
-
code += "\n";
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// 优先尝试使用 config 提供的调用模板(解耦核心)
|
|
139
|
-
var callTemplate = (_config$getCallTempla = config.getCallTemplate) === null || _config$getCallTempla === void 0 ? void 0 : _config$getCallTempla.call(config, {
|
|
140
|
-
com: _objectSpread(_objectSpread({}, props.meta), {}, {
|
|
141
|
-
// 鸿蒙化:透传可能的场景 ID,增强识别能力
|
|
142
|
-
sceneId: ((_props$meta$model = props.meta.model) === null || _props$meta$model === void 0 || (_props$meta$model = _props$meta$model.data) === null || _props$meta$model === void 0 ? void 0 : _props$meta$model._sceneId) || props.meta.id
|
|
143
|
-
}),
|
|
144
|
-
pinId: props.id,
|
|
145
|
-
args: nextValue
|
|
146
|
-
});
|
|
147
|
-
if (callTemplate) {
|
|
148
|
-
if (callTemplate.import) {
|
|
149
|
-
config.addParentDependencyImport(callTemplate.import);
|
|
150
|
-
}
|
|
151
|
-
code += "".concat(indent, "/** ").concat(props.meta.title, " */\n").concat(indent).concat(nextCode).concat(callTemplate.code);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 路由/场景输出处理(默认策略)
|
|
156
|
-
if (componentType === "js") {
|
|
157
|
-
if (category === "scene") {
|
|
158
|
-
// [默认策略] 此处不再硬编码 commit/cancel,仅作为备选兜底
|
|
159
|
-
var _sceneId = props.meta.model.data._sceneId;
|
|
160
|
-
var operateName = props.meta.model.data.openType === "redirect" ? "replace" : "open";
|
|
161
|
-
code += "".concat(indent, "/** \u6253\u5F00 ").concat(props.meta.title, " */\n").concat(indent).concat(nextCode, "this.").concat(_sceneId, ".").concat(operateName, "(").concat(nextValue, ")");
|
|
162
|
-
} else if (category === "frameOutput") {
|
|
163
|
-
var _pinProxies;
|
|
164
|
-
var currentScene = config.getCurrentScene();
|
|
165
|
-
var pinProxy = currentScene === null || currentScene === void 0 || (_pinProxies = currentScene.pinProxies) === null || _pinProxies === void 0 ? void 0 : _pinProxies["".concat(props.meta.id, "-").concat(props.id)];
|
|
166
|
-
var method = (pinProxy === null || pinProxy === void 0 ? void 0 : pinProxy.pinId) || props.id;
|
|
167
|
-
var sceneId = (pinProxy === null || pinProxy === void 0 ? void 0 : pinProxy.frameId) || (currentScene === null || currentScene === void 0 ? void 0 : currentScene.id);
|
|
168
|
-
code += "".concat(indent, "/** ").concat(props.meta.title, " \u8F93\u51FA ").concat(method, " */\n").concat(indent).concat(nextCode, "this.").concat(sceneId, ".").concat(method, "(").concat(nextValue, ")");
|
|
169
|
-
} else if (category === "normal") {
|
|
170
|
-
var componentNameWithId = getComponentNameWithId(props, config, event);
|
|
171
|
-
code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode).concat(componentNameWithId, "(").concat(runType === "input" ? nextValue : "", ")");
|
|
172
|
-
} else if (category === "var") {
|
|
173
|
-
var _props$extData;
|
|
174
|
-
var varKey = getSafeVarName(props.meta);
|
|
175
|
-
// 处理 xpath:如 "/a" -> "a","/a/b" -> "a.b",用于读取变量的指定属性
|
|
176
|
-
var xpath = (_props$extData = props.extData) === null || _props$extData === void 0 ? void 0 : _props$extData.xpath;
|
|
177
|
-
var xpathArg = xpath ? ", \"".concat(xpath.replace(/^\//, "").replace(/\//g, "."), "\"") : "";
|
|
178
|
-
if (props.meta.global) {
|
|
179
|
-
config.addParentDependencyImport({
|
|
180
|
-
packageName: "../../common/global",
|
|
181
|
-
dependencyNames: ["globalVars"],
|
|
182
|
-
importType: "named"
|
|
183
|
-
});
|
|
184
|
-
code += "".concat(indent, "/** ").concat(props.title, " \u5168\u5C40\u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalVars.").concat(varKey, ".").concat(props.id, "(").concat(nextValue).concat(xpathArg, ")");
|
|
185
|
-
} else {
|
|
186
|
-
var currentProvider = getCurrentProvider({
|
|
187
|
-
isSameScope: isSameScope,
|
|
188
|
-
props: props
|
|
189
|
-
}, config);
|
|
190
|
-
code += "".concat(indent, "/** ").concat(props.title, " \u53D8\u91CF ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "$vars.current.").concat(varKey, ".").concat(props.id, "(").concat(nextValue).concat(xpathArg, ")");
|
|
191
|
-
}
|
|
192
|
-
} else if (category === "fx") {
|
|
193
|
-
if (props.meta.global) {
|
|
194
|
-
config.addParentDependencyImport({
|
|
195
|
-
packageName: "../../common/global",
|
|
196
|
-
dependencyNames: ["globalFxs"],
|
|
197
|
-
importType: "named"
|
|
198
|
-
});
|
|
199
|
-
code += "".concat(indent, "/** \u8C03\u7528\u5168\u5C40Fx ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "globalFxs.").concat(props.meta.ioProxy.id, "(").concat(nextValue).concat(nextValue ? ', ' : '', "appContext)");
|
|
200
|
-
} else {
|
|
201
|
-
var _currentProvider = getCurrentProvider({
|
|
202
|
-
isSameScope: isSameScope,
|
|
203
|
-
props: props
|
|
204
|
-
}, config);
|
|
205
|
-
code += "".concat(indent, "/** \u8C03\u7528Fx ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode, "$fxs.current.").concat(props.meta.ioProxy.id, "(").concat(nextValue, ")");
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
// UI 组件处理
|
|
210
|
-
if (props.type === "frameOutput") {
|
|
211
|
-
var _event$meta, _currentScene$coms;
|
|
212
|
-
// 帧输出:找到拥有该帧的组件,通过 $outputs 调用
|
|
213
|
-
var _currentScene = config.getCurrentScene();
|
|
214
|
-
var parentComId = event.comId || ((_event$meta = event.meta) === null || _event$meta === void 0 ? void 0 : _event$meta.parentComId);
|
|
215
|
-
var frameConEntry = Object.values(_currentScene.cons || {}).flat().find(function (con) {
|
|
216
|
-
if (con.type !== "frame" || con.pinId !== props.id) return false;
|
|
217
|
-
if (parentComId && con.comId) return con.comId === parentComId;
|
|
218
|
-
return true;
|
|
219
|
-
});
|
|
220
|
-
var comId = (frameConEntry === null || frameConEntry === void 0 ? void 0 : frameConEntry.comId) || props.meta.id;
|
|
221
|
-
var comTitle = ((_currentScene$coms = _currentScene.coms) === null || _currentScene$coms === void 0 || (_currentScene$coms = _currentScene$coms[comId]) === null || _currentScene$coms === void 0 ? void 0 : _currentScene$coms.title) || props.meta.title || comId;
|
|
222
|
-
code += "".concat(indent, "/** \u8C03\u7528 ").concat(comTitle, " \u7684 ").concat(props.title, " */") + "\n".concat(indent).concat(nextCode, "$outputs['").concat(comId, "'].").concat(props.id, "(").concat(nextValue, ")");
|
|
223
|
-
} else {
|
|
224
|
-
code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " \u7684 ").concat(props.title, " */") + "\n".concat(indent).concat(nextCode, "this.").concat(props.meta.id, ".").concat(props.id, "(").concat(nextValue, ")");
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
if (["fx", "extension-api", "extension-bus"].includes(event.type)) {
|
|
229
|
-
var returnCode = Object.entries(event.frameOutputs).reduce(function (pre, _ref3) {
|
|
230
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
231
|
-
_ref4$ = _ref4[1],
|
|
232
|
-
id = _ref4$.id,
|
|
233
|
-
outputs = _ref4$.outputs;
|
|
234
|
-
if (!outputs) {
|
|
235
|
-
return pre + "".concat(indent2).concat(id, ": undefined,\n");
|
|
236
|
-
} else {
|
|
237
|
-
var next = outputs.map(function (output) {
|
|
238
|
-
return getNextValueWithParam(output, config, event, outputToInputPinMap);
|
|
239
|
-
}).join(", ");
|
|
240
|
-
return pre + "".concat(indent2).concat(id, ": ").concat(next, ",\n");
|
|
241
|
-
}
|
|
242
|
-
}, "");
|
|
243
|
-
if (returnCode) {
|
|
244
|
-
code += "\n".concat(indent, "return {\n").concat(returnCode).concat(indent, "}");
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return code;
|
|
248
|
-
};
|
|
249
|
-
var checkIsSameScope = function checkIsSameScope(event, props) {
|
|
250
|
-
if (event.type === "com" && event.meta.parentComId === props.meta.parentComId && event.meta.frameId === props.meta.frameId) {
|
|
251
|
-
return true;
|
|
252
|
-
} else if (event.type === "slot" && event.comId === props.meta.parentComId && event.slotId === props.meta.frameId) {
|
|
253
|
-
return true;
|
|
254
|
-
} else if (event.type === "fx" && event.parentComId === props.meta.parentComId && event.parentSlotId === props.meta.frameId) {
|
|
255
|
-
return true;
|
|
256
|
-
}
|
|
257
|
-
return false;
|
|
258
|
-
};
|
|
259
|
-
var getComponentNameWithId = function getComponentNameWithId(props, config, event) {
|
|
260
|
-
// 检查是否是 JS 计算组件
|
|
261
|
-
if (isJsCalculationComponent(props.meta.def.namespace)) {
|
|
262
|
-
// JS 计算组件:使用 jsModules_${meta.id} 作为变量名
|
|
263
|
-
if (config.getEventNodeName) {
|
|
264
|
-
var componentName = config.getEventNodeName({
|
|
265
|
-
com: props.meta,
|
|
266
|
-
scene: config.getCurrentScene(),
|
|
267
|
-
event: event,
|
|
268
|
-
type: "declaration"
|
|
269
|
-
});
|
|
270
|
-
if (componentName) {
|
|
271
|
-
return componentName;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
return "jsModules_".concat(props.meta.id);
|
|
275
|
-
}
|
|
276
|
-
if (config.getEventNodeName) {
|
|
277
|
-
var _componentName = config.getEventNodeName({
|
|
278
|
-
com: props.meta,
|
|
279
|
-
scene: config.getCurrentScene(),
|
|
280
|
-
event: event,
|
|
281
|
-
type: "declaration"
|
|
282
|
-
});
|
|
283
|
-
if (_componentName) {
|
|
284
|
-
return _componentName;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
var _config$getComponentM2 = config.getComponentMeta(props.meta),
|
|
288
|
-
name = _config$getComponentM2.name;
|
|
289
|
-
// 确保变量名合法(将连字符替换为下划线)
|
|
290
|
-
var sanitizedName = name.replace(/-/g, '_');
|
|
291
|
-
return "".concat(sanitizedName, "_").concat(props.meta.id);
|
|
292
|
-
};
|
|
293
|
-
var getNextCode = function getNextCode(props, config, isSameScope, event, declaredVarCount) {
|
|
294
|
-
var nextParam = props.nextParam;
|
|
295
|
-
if (!nextParam.length) {
|
|
296
|
-
return {
|
|
297
|
-
code: "",
|
|
298
|
-
varName: ""
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
var componentNameWithId = getComponentNameWithId(props, config, event);
|
|
302
|
-
// 使用输入端口ID(props.id)来区分同一组件的不同调用
|
|
303
|
-
// 这样可以确保 trigger 和 cancel 两个输入端口生成不同的变量名
|
|
304
|
-
var pinId = props.id;
|
|
305
|
-
var sanitizedPinId = pinId.replace(/[^a-zA-Z0-9_]/g, '_');
|
|
306
|
-
var varName = "".concat(componentNameWithId, "_").concat(sanitizedPinId, "_result");
|
|
307
|
-
|
|
308
|
-
// 去重:同一变量名多次声明时追加后缀
|
|
309
|
-
var count = declaredVarCount.get(varName) || 0;
|
|
310
|
-
declaredVarCount.set(varName, count + 1);
|
|
311
|
-
if (count > 0) {
|
|
312
|
-
varName = "".concat(varName, "_").concat(count);
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
code: "const ".concat(varName, ": any = "),
|
|
316
|
-
varName: varName
|
|
317
|
-
};
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* frame-input:把「当前项/索引」这类 slot 输入,映射到 params.inputValues 上
|
|
322
|
-
* - 优先使用 pinValueProxies(连接线解析后的稳定映射):`${comId}-${inputPinId}` -> { pinId: 'itemData' | 'index' | ... }
|
|
323
|
-
* - 再次从父组件 frames[frameId].inputs 元数据中解析(结构化 pinAry)
|
|
324
|
-
* - 最后兜底返回 params?.inputValues(不崩溃)
|
|
325
|
-
*/
|
|
326
|
-
function getFrameInputValueExpr(meta, config, event) {
|
|
327
|
-
var _config$getCurrentSce, _meta$inputs, _pinValueProxies;
|
|
328
|
-
var scene = (_config$getCurrentSce = config.getCurrentScene) === null || _config$getCurrentSce === void 0 ? void 0 : _config$getCurrentSce.call(config);
|
|
329
|
-
|
|
330
|
-
// 1) pinValueProxies(最直接、最稳定:由 diagrams.conAry 解析而来)
|
|
331
|
-
var inputPinId = (meta === null || meta === void 0 || (_meta$inputs = meta.inputs) === null || _meta$inputs === void 0 ? void 0 : _meta$inputs[0]) || "getCurValue";
|
|
332
|
-
var proxyKey = "".concat(meta === null || meta === void 0 ? void 0 : meta.id, "-").concat(inputPinId);
|
|
333
|
-
var pinProxy = scene === null || scene === void 0 || (_pinValueProxies = scene.pinValueProxies) === null || _pinValueProxies === void 0 ? void 0 : _pinValueProxies[proxyKey];
|
|
334
|
-
var pinId = pinProxy === null || pinProxy === void 0 ? void 0 : pinProxy.pinId;
|
|
335
|
-
if (typeof pinId === "string" && pinId) {
|
|
336
|
-
var _config$getParams;
|
|
337
|
-
// 优先使用 getParams 映射(场景级输入:回调参数名如 data)
|
|
338
|
-
var paramsMap = (_config$getParams = config.getParams) === null || _config$getParams === void 0 ? void 0 : _config$getParams.call(config);
|
|
339
|
-
if (paramsMap !== null && paramsMap !== void 0 && paramsMap[pinId]) {
|
|
340
|
-
return paramsMap[pinId];
|
|
341
|
-
}
|
|
342
|
-
// fallback:插槽场景使用 params.inputValues
|
|
343
|
-
return "params?.inputValues?.[".concat(JSON.stringify(pinId), "]");
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
var getNextValue = function getNextValue(props, config, event, outputToInputPinMap) {
|
|
347
|
-
var paramSource = props.paramSource;
|
|
348
|
-
var nextValue = paramSource.map(function (param) {
|
|
349
|
-
var _param$meta, _param$meta2, _param$meta4;
|
|
350
|
-
if (param.type === "params") {
|
|
351
|
-
var params = config.getParams();
|
|
352
|
-
return params[param.id];
|
|
353
|
-
} else if (param.type === "constant") {
|
|
354
|
-
return JSON.stringify(param.value);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// frame-input:直接从 slot params 读取(不生成 frameInput_xxx_result 临时变量)
|
|
358
|
-
if (((_param$meta = param.meta) === null || _param$meta === void 0 || (_param$meta = _param$meta.def) === null || _param$meta === void 0 ? void 0 : _param$meta.namespace) === "mybricks.core-comlib.frame-input" && param.id === "return") {
|
|
359
|
-
return getFrameInputValueExpr(param.meta, config, event);
|
|
360
|
-
}
|
|
361
|
-
var componentNameWithId = getComponentNameWithId(param, config, event);
|
|
362
|
-
// 变量组件直接返回 Subject,不加 .id 后缀
|
|
363
|
-
if ((_param$meta2 = param.meta) !== null && _param$meta2 !== void 0 && (_param$meta2 = _param$meta2.def) !== null && _param$meta2 !== void 0 && (_param$meta2 = _param$meta2.namespace) !== null && _param$meta2 !== void 0 && _param$meta2.includes(".var")) {
|
|
364
|
-
var _param$meta3;
|
|
365
|
-
// 从 outputToInputPinMap 中查找完整变量名(已包含去重后缀)
|
|
366
|
-
var _key = "".concat((_param$meta3 = param.meta) === null || _param$meta3 === void 0 ? void 0 : _param$meta3.id, "_").concat(param.id);
|
|
367
|
-
var _fullVarName = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(_key);
|
|
368
|
-
if (_fullVarName) {
|
|
369
|
-
return _fullVarName;
|
|
370
|
-
}
|
|
371
|
-
return "".concat(componentNameWithId, "_result");
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// 从 outputToInputPinMap 中查找完整变量名(已包含去重后缀)
|
|
375
|
-
// key = `${componentId}_${outputPinId}`
|
|
376
|
-
var key = "".concat((_param$meta4 = param.meta) === null || _param$meta4 === void 0 ? void 0 : _param$meta4.id, "_").concat(param.id);
|
|
377
|
-
var fullVarName = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(key);
|
|
378
|
-
if (fullVarName) {
|
|
379
|
-
return "".concat(fullVarName, ".").concat(param.id);
|
|
380
|
-
}
|
|
381
|
-
return "".concat(componentNameWithId, "_result.").concat(param.id);
|
|
382
|
-
});
|
|
383
|
-
return nextValue.join(", ");
|
|
384
|
-
};
|
|
385
|
-
var getNextValueWithParam = function getNextValueWithParam(param, config, event, outputToInputPinMap) {
|
|
386
|
-
var _param$meta5, _param$meta6, _param$meta8;
|
|
387
|
-
if (param.type === "params") {
|
|
388
|
-
var params = config.getParams();
|
|
389
|
-
return params[param.id];
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// frame-input:直接从 slot params 读取(不生成 frameInput_xxx_result 临时变量)
|
|
393
|
-
if (((_param$meta5 = param.meta) === null || _param$meta5 === void 0 || (_param$meta5 = _param$meta5.def) === null || _param$meta5 === void 0 ? void 0 : _param$meta5.namespace) === "mybricks.core-comlib.frame-input" && param.id === "return") {
|
|
394
|
-
return getFrameInputValueExpr(param.meta, config, event);
|
|
395
|
-
}
|
|
396
|
-
var componentNameWithId = getComponentNameWithId(param, config, event);
|
|
397
|
-
// 变量组件直接返回 Subject
|
|
398
|
-
if ((_param$meta6 = param.meta) !== null && _param$meta6 !== void 0 && (_param$meta6 = _param$meta6.def) !== null && _param$meta6 !== void 0 && (_param$meta6 = _param$meta6.namespace) !== null && _param$meta6 !== void 0 && _param$meta6.includes(".var")) {
|
|
399
|
-
var _param$meta7;
|
|
400
|
-
var _key2 = "".concat((_param$meta7 = param.meta) === null || _param$meta7 === void 0 ? void 0 : _param$meta7.id, "_").concat(param.id);
|
|
401
|
-
var _fullVarName2 = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(_key2);
|
|
402
|
-
if (_fullVarName2) {
|
|
403
|
-
return _fullVarName2;
|
|
404
|
-
}
|
|
405
|
-
return "".concat(componentNameWithId, "_result");
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// 从 outputToInputPinMap 中查找完整变量名(已包含去重后缀)
|
|
409
|
-
var key = "".concat((_param$meta8 = param.meta) === null || _param$meta8 === void 0 ? void 0 : _param$meta8.id, "_").concat(param.id);
|
|
410
|
-
var fullVarName = outputToInputPinMap === null || outputToInputPinMap === void 0 ? void 0 : outputToInputPinMap.get(key);
|
|
411
|
-
if (fullVarName) {
|
|
412
|
-
return "".concat(fullVarName, ".").concat(param.id);
|
|
413
|
-
}
|
|
414
|
-
return "".concat(componentNameWithId, "_result.").concat(param.id);
|
|
415
|
-
};
|
|
416
|
-
var getCurrentProvider = function getCurrentProvider(params, config) {
|
|
417
|
-
var _config$getProviderNa, _config$getCurrentPro;
|
|
418
|
-
var providerMap = config.getProviderMap();
|
|
419
|
-
var isSameScope = params.isSameScope,
|
|
420
|
-
props = params.props;
|
|
421
|
-
var meta = props.meta;
|
|
422
|
-
var parentComId = meta.parentComId,
|
|
423
|
-
frameId = meta.frameId;
|
|
424
|
-
var providerName = ((_config$getProviderNa = config.getProviderName) === null || _config$getProviderNa === void 0 ? void 0 : _config$getProviderNa.call(config, {
|
|
425
|
-
com: meta,
|
|
426
|
-
scene: config.getCurrentScene()
|
|
427
|
-
})) || (!parentComId ? "slot_Index" : "slot_".concat(frameId[0].toUpperCase() + frameId.slice(1), "_").concat(parentComId));
|
|
428
|
-
var provider = providerMap === null || providerMap === void 0 ? void 0 : providerMap[providerName];
|
|
429
|
-
|
|
430
|
-
// 兜底:如果 provider 不存在(例如新架构未构建 slot provider),回退到当前 provider
|
|
431
|
-
var safeProvider = provider || ((_config$getCurrentPro = config.getCurrentProvider) === null || _config$getCurrentPro === void 0 ? void 0 : _config$getCurrentPro.call(config));
|
|
432
|
-
if (!isSameScope && safeProvider) {
|
|
433
|
-
var _config$addConsumer;
|
|
434
|
-
(_config$addConsumer = config.addConsumer) === null || _config$addConsumer === void 0 || _config$addConsumer.call(config, safeProvider);
|
|
435
|
-
}
|
|
436
|
-
return safeProvider;
|
|
437
|
-
};
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* 生成 JS 计算组件的代码
|
|
441
|
-
*/
|
|
442
|
-
var generateJsCalculationComponentCode = function generateJsCalculationComponentCode(params) {
|
|
443
|
-
var _config$getEventNodeN2;
|
|
444
|
-
var meta = params.meta,
|
|
445
|
-
props = params.props,
|
|
446
|
-
componentName = params.componentName,
|
|
447
|
-
config = params.config,
|
|
448
|
-
event = params.event,
|
|
449
|
-
indent = params.indent,
|
|
450
|
-
indent2 = params.indent2;
|
|
451
|
-
var componentNameWithId = ((_config$getEventNodeN2 = config.getEventNodeName) === null || _config$getEventNodeN2 === void 0 ? void 0 : _config$getEventNodeN2.call(config, {
|
|
452
|
-
com: meta,
|
|
453
|
-
scene: config.getCurrentScene(),
|
|
454
|
-
type: "declaration",
|
|
455
|
-
event: event
|
|
456
|
-
})) || "jsModules_".concat(meta.id);
|
|
457
|
-
|
|
458
|
-
// JS 计算组件的 data 只包含必要配置(如 runImmediate),不包含 fns、transformCode 等
|
|
459
|
-
var jsData = {};
|
|
460
|
-
if (props.data && 'runImmediate' in props.data) {
|
|
461
|
-
jsData.runImmediate = props.data.runImmediate;
|
|
462
|
-
}
|
|
463
|
-
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, {
|
|
464
|
-
initialIndent: config.codeStyle.indent * (config.depth + 1),
|
|
465
|
-
indentSize: config.codeStyle.indent
|
|
466
|
-
}), ",") : "") + (props.inputs ? "\n".concat(indent2, "inputs: [").concat(props.inputs.map(function (input) {
|
|
467
|
-
return "\"".concat(input, "\"");
|
|
468
|
-
}).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, "outputs: [").concat(props.outputs.map(function (output) {
|
|
469
|
-
return "\"".concat(output, "\"");
|
|
470
|
-
}).join(", "), "],") : "") + "\n".concat(indent, "}, appContext, '").concat(meta.id, "')\n");
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* 生成 JS API 组件的代码
|
|
475
|
-
*/
|
|
476
|
-
var generateJsApiComponentCode = function generateJsApiComponentCode(params) {
|
|
477
|
-
var _config$getEventNodeN3;
|
|
478
|
-
var meta = params.meta,
|
|
479
|
-
props = params.props,
|
|
480
|
-
componentName = params.componentName,
|
|
481
|
-
callName = params.callName,
|
|
482
|
-
importInfo = params.importInfo,
|
|
483
|
-
config = params.config,
|
|
484
|
-
event = params.event,
|
|
485
|
-
indent = params.indent,
|
|
486
|
-
indent2 = params.indent2;
|
|
487
|
-
|
|
488
|
-
// 导入 createJSHandle
|
|
489
|
-
config.addParentDependencyImport({
|
|
490
|
-
packageName: "@mybricks/taro-core",
|
|
491
|
-
dependencyNames: ["createJSHandle"],
|
|
492
|
-
importType: "named"
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
// 导入 JS API 组件
|
|
496
|
-
config.addParentDependencyImport({
|
|
497
|
-
packageName: importInfo.from,
|
|
498
|
-
dependencyNames: [importInfo.name],
|
|
499
|
-
importType: importInfo.type
|
|
500
|
-
});
|
|
501
|
-
var componentNameWithId = ((_config$getEventNodeN3 = config.getEventNodeName) === null || _config$getEventNodeN3 === void 0 ? void 0 : _config$getEventNodeN3.call(config, {
|
|
502
|
-
com: meta,
|
|
503
|
-
scene: config.getCurrentScene(),
|
|
504
|
-
type: "declaration",
|
|
505
|
-
event: event
|
|
506
|
-
})) || "".concat(componentName, "_").concat(meta.id);
|
|
507
|
-
config.addParentDependencyImport({
|
|
508
|
-
packageName: config.getComponentPackageName(),
|
|
509
|
-
dependencyNames: ["useAppContext"],
|
|
510
|
-
importType: "named"
|
|
511
|
-
});
|
|
512
|
-
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, {
|
|
513
|
-
initialIndent: config.codeStyle.indent * (config.depth + 2),
|
|
514
|
-
indentSize: config.codeStyle.indent
|
|
515
|
-
}), ",") : "") + (props.inputs ? "\n".concat(indent2, " inputs: [").concat(props.inputs.map(function (input) {
|
|
516
|
-
return "\"".concat(input, "\"");
|
|
517
|
-
}).join(", "), "],") : "") + (props.outputs ? "\n".concat(indent2, " outputs: [").concat(props.outputs.map(function (output) {
|
|
518
|
-
return "\"".concat(output, "\"");
|
|
519
|
-
}).join(", "), "],") : "") + "\n".concat(indent2, "},") + "\n".concat(indent2, "appContext") + "\n".concat(indent, "}, '").concat(meta.id, "')\n");
|
|
520
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { UI } from "../../toCodeTaro";
|
|
2
|
-
export type ChildResult = {
|
|
3
|
-
ui: string;
|
|
4
|
-
js: string;
|
|
5
|
-
cssContent: string;
|
|
6
|
-
slots: string[];
|
|
7
|
-
scopeSlots: string[];
|
|
8
|
-
/** 所有层级的后代组件结果 */
|
|
9
|
-
childrenResults?: any[];
|
|
10
|
-
/** 仅当前层级的直接子组件结果 */
|
|
11
|
-
directChildren?: any[];
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* 统一处理子节点(com, dom, module)
|
|
15
|
-
*/
|
|
16
|
-
export declare const processChildren: (children: UI["children"] | any[], config: any) => ChildResult;
|
|
17
|
-
/**
|
|
18
|
-
* 归一化子节点提取逻辑
|
|
19
|
-
* 兼容不同版本的 DSL 结构:
|
|
20
|
-
* 1. 数组直接返回
|
|
21
|
-
* 2. 包含 elements 的 DOM 包装层
|
|
22
|
-
* 3. 包含 layoutTemplate 的插槽
|
|
23
|
-
* 4. 包含 comAry 的传统插槽
|
|
24
|
-
* 5. 包含 children 的 Slot/Dom/Com 对象
|
|
25
|
-
*/
|
|
26
|
-
export declare function normalizeChildren(input: any): any[];
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
-
import handleCom from "../../handleCom";
|
|
4
|
-
import handleDom from "../../handleDom";
|
|
5
|
-
import handleModule from "../../handleModule";
|
|
6
|
-
/**
|
|
7
|
-
* 统一处理子节点(com, dom, module)
|
|
8
|
-
*/
|
|
9
|
-
export var processChildren = function processChildren(children, config) {
|
|
10
|
-
var uiCode = "";
|
|
11
|
-
var jsCode = "";
|
|
12
|
-
var cssContent = "";
|
|
13
|
-
var slots = [];
|
|
14
|
-
var scopeSlots = [];
|
|
15
|
-
var allChildrenResults = [];
|
|
16
|
-
var directChildren = [];
|
|
17
|
-
|
|
18
|
-
// 归一化处理子节点:兼容 comAry, children, elements, layoutTemplate
|
|
19
|
-
var normalizedChildren = normalizeChildren(children);
|
|
20
|
-
normalizedChildren.forEach(function (child) {
|
|
21
|
-
var result;
|
|
22
|
-
// 增加对 child.def 的判断,兼容 layoutTemplate 中的组件
|
|
23
|
-
if (child.type === "com" || child.def) {
|
|
24
|
-
result = handleCom(child, config);
|
|
25
|
-
} else if (child.type === "module") {
|
|
26
|
-
result = handleModule(child, config);
|
|
27
|
-
} else {
|
|
28
|
-
result = handleDom(child, config);
|
|
29
|
-
}
|
|
30
|
-
if (result) {
|
|
31
|
-
// 收集组件元数据
|
|
32
|
-
if (child.type === "com" || child.def) {
|
|
33
|
-
var _meta, _props, _meta2;
|
|
34
|
-
var comId = child.id || ((_meta = child.meta) === null || _meta === void 0 ? void 0 : _meta.id);
|
|
35
|
-
var childInfo = _objectSpread(_objectSpread({}, result), {}, {
|
|
36
|
-
id: comId,
|
|
37
|
-
// 优先使用 handleCom 解析出的稳定名称 (如 comName 别名)
|
|
38
|
-
name: result.name || child.name || ((_props = child.props) === null || _props === void 0 || (_props = _props.data) === null || _props === void 0 ? void 0 : _props.name) || ((_meta2 = child.meta) === null || _meta2 === void 0 ? void 0 : _meta2.title) || comId,
|
|
39
|
-
type: child.type || "com",
|
|
40
|
-
meta: child.meta,
|
|
41
|
-
props: child.props
|
|
42
|
-
});
|
|
43
|
-
directChildren.push(childInfo);
|
|
44
|
-
allChildrenResults.push(childInfo);
|
|
45
|
-
|
|
46
|
-
// 递归收集所有后代
|
|
47
|
-
if (result.childrenResults) {
|
|
48
|
-
allChildrenResults.push.apply(allChildrenResults, _toConsumableArray(result.childrenResults));
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
// 如果是 DOM 或 Module,也要收集它们内部可能包含的组件
|
|
52
|
-
if (result.childrenResults) {
|
|
53
|
-
allChildrenResults.push.apply(allChildrenResults, _toConsumableArray(result.childrenResults));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (result.ui) {
|
|
57
|
-
uiCode += (uiCode ? "\n" : "") + result.ui;
|
|
58
|
-
}
|
|
59
|
-
if (result.js) {
|
|
60
|
-
jsCode += result.js;
|
|
61
|
-
}
|
|
62
|
-
if (result.cssContent) {
|
|
63
|
-
cssContent += (cssContent ? "\n" : "") + result.cssContent;
|
|
64
|
-
}
|
|
65
|
-
if (result.slots) {
|
|
66
|
-
slots.push.apply(slots, _toConsumableArray(result.slots));
|
|
67
|
-
}
|
|
68
|
-
if (result.scopeSlots) {
|
|
69
|
-
scopeSlots.push.apply(scopeSlots, _toConsumableArray(result.scopeSlots));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
return {
|
|
74
|
-
ui: uiCode,
|
|
75
|
-
js: jsCode,
|
|
76
|
-
cssContent: cssContent,
|
|
77
|
-
slots: slots,
|
|
78
|
-
scopeSlots: scopeSlots,
|
|
79
|
-
directChildren: directChildren,
|
|
80
|
-
childrenResults: allChildrenResults
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* 归一化子节点提取逻辑
|
|
86
|
-
* 兼容不同版本的 DSL 结构:
|
|
87
|
-
* 1. 数组直接返回
|
|
88
|
-
* 2. 包含 elements 的 DOM 包装层
|
|
89
|
-
* 3. 包含 layoutTemplate 的插槽
|
|
90
|
-
* 4. 包含 comAry 的传统插槽
|
|
91
|
-
* 5. 包含 children 的 Slot/Dom/Com 对象
|
|
92
|
-
*/
|
|
93
|
-
export function normalizeChildren(input) {
|
|
94
|
-
if (!input) return [];
|
|
95
|
-
if (Array.isArray(input)) return input;
|
|
96
|
-
|
|
97
|
-
// 优先级顺序:elements -> layoutTemplate -> comAry -> children
|
|
98
|
-
var list = input.elements || input.layoutTemplate || input.comAry || input.children;
|
|
99
|
-
if (Array.isArray(list)) return list;
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 将 rgba 或 rgb 颜色转换为 hex 颜色
|
|
3
|
-
*/
|
|
4
|
-
export function colorToHex(color) {
|
|
5
|
-
if (!color || typeof color !== "string") return color;
|
|
6
|
-
if (!color.startsWith("rgb")) return color;
|
|
7
|
-
var match = color.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)$/);
|
|
8
|
-
if (!match) return color;
|
|
9
|
-
var r = parseInt(match[1]);
|
|
10
|
-
var g = parseInt(match[2]);
|
|
11
|
-
var b = parseInt(match[3]);
|
|
12
|
-
var toHex = function toHex(n) {
|
|
13
|
-
var hex = n.toString(16);
|
|
14
|
-
return hex.length === 1 ? "0" + hex : hex;
|
|
15
|
-
};
|
|
16
|
-
return "#".concat(toHex(r)).concat(toHex(g)).concat(toHex(b)).toLowerCase();
|
|
17
|
-
}
|