@mybricks/to-code-taro 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/cjs/core/comlib/_AesEncode.js +115 -0
  2. package/dist/cjs/core/comlib/_BackTo.js +80 -0
  3. package/dist/cjs/core/comlib/_CallPhone.js +58 -0
  4. package/dist/cjs/core/comlib/_ChooseFile.js +103 -0
  5. package/dist/cjs/core/comlib/_ChooseMedia.js +70 -0
  6. package/dist/cjs/core/comlib/_Connector.js +92 -0
  7. package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +79 -0
  8. package/dist/cjs/core/comlib/_Format.js +123 -0
  9. package/dist/cjs/core/comlib/_GetLocation.js +60 -0
  10. package/dist/cjs/core/comlib/_GetStorage.js +68 -0
  11. package/dist/cjs/core/comlib/_GetSystemInfo.js +62 -0
  12. package/dist/cjs/core/comlib/_OpenCamera.js +73 -0
  13. package/dist/cjs/core/comlib/_OpenPetalMap.js +49 -0
  14. package/dist/cjs/core/comlib/_OpenUrl.js +62 -0
  15. package/dist/cjs/core/comlib/_RemoveStorage.js +68 -0
  16. package/dist/cjs/core/comlib/_Router.js +100 -0
  17. package/dist/cjs/core/comlib/_ScanQrcode.js +9 -10
  18. package/dist/cjs/core/comlib/_SetStorage.js +10 -19
  19. package/dist/cjs/core/comlib/_Share.js +58 -0
  20. package/dist/cjs/core/comlib/_ShowToast.js +23 -50
  21. package/dist/cjs/core/comlib/_TextToSpeech.js +120 -0
  22. package/dist/cjs/core/comlib/_TimerDebounce.js +72 -0
  23. package/dist/cjs/core/comlib/_TimerDelay.js +63 -0
  24. package/dist/cjs/core/comlib/_TimerThrottle.js +75 -0
  25. package/dist/cjs/core/comlib/_Vibrate.js +60 -0
  26. package/dist/cjs/core/comlib/index.js +68 -2
  27. package/dist/cjs/core/utils/ComContext.js +3 -3
  28. package/dist/cjs/core/utils/PopupRenderer.js +63 -0
  29. package/dist/cjs/core/utils/hooks.js +16 -14
  30. package/dist/cjs/core/utils/index.js +15 -3
  31. package/dist/cjs/core/utils/{page.js → pageRouter.js} +28 -14
  32. package/dist/cjs/core/utils/popupRouter.js +98 -0
  33. package/dist/cjs/core/utils/useContext.js +9 -1
  34. package/dist/cjs/core/utils/with.js +37 -13
  35. package/dist/cjs/generate/generateTaroProjectJson.js +30 -0
  36. package/dist/cjs/handleSlot.d.ts +2 -0
  37. package/dist/cjs/handleSlot.js +19 -5
  38. package/dist/cjs/processors/processComEvents.js +47 -5
  39. package/dist/cjs/processors/processScene.js +9 -5
  40. package/dist/cjs/processors/processSceneLogic.js +9 -5
  41. package/dist/cjs/shims-taro.d.ts +20 -0
  42. package/dist/cjs/taro-template.json +493 -351
  43. package/dist/cjs/toCodeTaro.d.ts +1 -1
  44. package/dist/cjs/toCodeTaro.js +13 -1
  45. package/dist/cjs/utils/builder/buildResult.d.ts +1 -0
  46. package/dist/cjs/utils/builder/buildResult.js +26 -0
  47. package/dist/cjs/utils/config/handlePageConfig.d.ts +2 -1
  48. package/dist/cjs/utils/config/handlePageConfig.js +3 -2
  49. package/dist/cjs/utils/context/createEventQueries.js +1 -1
  50. package/dist/cjs/utils/logic/handleProcess.js +26 -5
  51. package/dist/cjs/utils/templates/scene.d.ts +3 -1
  52. package/dist/cjs/utils/templates/scene.js +16 -4
  53. package/dist/esm/core/comlib/_AesEncode.js +85 -0
  54. package/dist/esm/core/comlib/_BackTo.js +66 -0
  55. package/dist/esm/core/comlib/_CallPhone.js +30 -0
  56. package/dist/esm/core/comlib/_ChooseFile.js +81 -0
  57. package/dist/esm/core/comlib/_ChooseMedia.js +38 -0
  58. package/dist/esm/core/comlib/_Connector.js +60 -0
  59. package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +56 -0
  60. package/dist/esm/core/comlib/_Format.js +102 -0
  61. package/dist/esm/core/comlib/_GetLocation.js +26 -0
  62. package/dist/esm/core/comlib/_GetStorage.js +44 -0
  63. package/dist/esm/core/comlib/_GetSystemInfo.js +32 -0
  64. package/dist/esm/core/comlib/_OpenCamera.js +44 -0
  65. package/dist/esm/core/comlib/_OpenPetalMap.js +28 -0
  66. package/dist/esm/core/comlib/_OpenUrl.js +36 -0
  67. package/dist/esm/core/comlib/_RemoveStorage.js +42 -0
  68. package/dist/esm/core/comlib/_Router.js +113 -0
  69. package/dist/esm/core/comlib/_ScanQrcode.js +10 -11
  70. package/dist/esm/core/comlib/_SetStorage.js +13 -25
  71. package/dist/esm/core/comlib/_Share.js +28 -0
  72. package/dist/esm/core/comlib/_ShowToast.js +32 -55
  73. package/dist/esm/core/comlib/_TextToSpeech.js +117 -0
  74. package/dist/esm/core/comlib/_TimerDebounce.js +66 -0
  75. package/dist/esm/core/comlib/_TimerDelay.js +47 -0
  76. package/dist/esm/core/comlib/_TimerThrottle.js +69 -0
  77. package/dist/esm/core/comlib/_Vibrate.js +34 -0
  78. package/dist/esm/core/comlib/index.js +35 -1
  79. package/dist/esm/core/utils/ComContext.js +1 -1
  80. package/dist/esm/core/utils/PopupRenderer.js +27 -0
  81. package/dist/esm/core/utils/hooks.js +24 -16
  82. package/dist/esm/core/utils/index.js +3 -1
  83. package/dist/esm/core/utils/pageRouter.js +69 -0
  84. package/dist/esm/core/utils/popupRouter.js +116 -0
  85. package/dist/esm/core/utils/useContext.js +14 -2
  86. package/dist/esm/core/utils/with.js +62 -19
  87. package/dist/esm/generate/generateTaroProjectJson.js +35 -1
  88. package/dist/esm/handleSlot.d.ts +2 -0
  89. package/dist/esm/handleSlot.js +20 -4
  90. package/dist/esm/processors/processComEvents.js +62 -5
  91. package/dist/esm/processors/processScene.js +11 -3
  92. package/dist/esm/processors/processSceneLogic.js +15 -5
  93. package/dist/esm/shims-taro.d.ts +20 -0
  94. package/dist/esm/taro-template.json +493 -351
  95. package/dist/esm/toCodeTaro.d.ts +1 -1
  96. package/dist/esm/toCodeTaro.js +16 -1
  97. package/dist/esm/utils/builder/buildResult.d.ts +1 -0
  98. package/dist/esm/utils/builder/buildResult.js +21 -0
  99. package/dist/esm/utils/config/handlePageConfig.d.ts +2 -1
  100. package/dist/esm/utils/config/handlePageConfig.js +5 -1
  101. package/dist/esm/utils/context/createEventQueries.js +2 -1
  102. package/dist/esm/utils/logic/handleProcess.js +31 -4
  103. package/dist/esm/utils/templates/scene.d.ts +3 -1
  104. package/dist/esm/utils/templates/scene.js +13 -5
  105. package/package.json +4 -2
  106. package/dist/esm/core/utils/page.js +0 -50
@@ -24,7 +24,7 @@ export interface ToTaroCodeConfig {
24
24
  callName?: string;
25
25
  };
26
26
  getComponentPackageName: (props?: any) => string;
27
- getUtilsPackageName: () => string;
27
+ getUtilsPackageName: (props?: any) => string;
28
28
  getPageId?: (id: string) => string;
29
29
  getBus?: (namespace: string) => {
30
30
  title: string;
@@ -91,9 +91,23 @@ var getCode = function getCode(params, config) {
91
91
  var jsModulesCollector = createJSModulesCollector();
92
92
  var pageConfigHandler = new HandlePageConfig();
93
93
 
94
+ // 提前识别所有弹窗场景
95
+ var popupIds = new Set();
96
+ tojson.scenes.forEach(function (s) {
97
+ var _s$deps;
98
+ if (s.type === 'popup' || (_s$deps = s.deps) !== null && _s$deps !== void 0 && _s$deps.some(function (dep) {
99
+ return dep.namespace === 'mybricks.taro.popup';
100
+ })) {
101
+ popupIds.add(s.id);
102
+ }
103
+ });
104
+
94
105
  // ========== 第六步:处理场景 ==========
95
106
  processScenes(scenes, {
96
- config: config,
107
+ config: _objectSpread(_objectSpread({}, config), {}, {
108
+ // @ts-ignore
109
+ hasPopups: popupIds.size > 0
110
+ }),
97
111
  globalVarTypeDef: globalVarTypeDef,
98
112
  defaultFxsMap: defaultFxsMap,
99
113
  abstractEventTypeDefMap: abstractEventTypeDefMap,
@@ -128,6 +142,7 @@ var getCode = function getCode(params, config) {
128
142
  jsModulesMap: jsModulesCollector.getMap(),
129
143
  globalTabBarConfig: pageConfigHandler.getTabBarConfig(),
130
144
  tabBarImageFiles: pageConfigHandler.getTabBarImageFiles(),
145
+ popupIds: Array.from(popupIds),
131
146
  config: config
132
147
  });
133
148
  files.push.apply(files, _toConsumableArray(finalResultData.files));
@@ -9,6 +9,7 @@ interface BuildResultParams {
9
9
  jsModulesMap: JSModulesMap;
10
10
  globalTabBarConfig: string | null;
11
11
  tabBarImageFiles: any[];
12
+ popupIds: string[];
12
13
  config: ToTaroCodeConfig;
13
14
  }
14
15
  /**
@@ -14,6 +14,7 @@ export var buildFinalResults = function buildFinalResults(params) {
14
14
  jsModulesMap = params.jsModulesMap,
15
15
  globalTabBarConfig = params.globalTabBarConfig,
16
16
  tabBarImageFiles = params.tabBarImageFiles,
17
+ popupIds = params.popupIds,
17
18
  config = params.config;
18
19
  var files = [];
19
20
 
@@ -44,6 +45,26 @@ export var buildFinalResults = function buildFinalResults(params) {
44
45
  });
45
46
  }
46
47
 
48
+ // 生成弹窗汇总文件 (popup.ts)
49
+ if (popupIds.length > 0) {
50
+ var registryContent = "";
51
+ popupIds.forEach(function (id) {
52
+ registryContent += "import Scene_".concat(id, " from '../popupComponents/").concat(id, "/index';\n");
53
+ });
54
+ registryContent += "\nexport const POPUP_MAP: Record<string, any> = {\n";
55
+ popupIds.forEach(function (id) {
56
+ registryContent += " '".concat(id, "': Scene_").concat(id, ",\n");
57
+ });
58
+ registryContent += "};\n\n";
59
+ registryContent += "export const POPUP_IDS = ".concat(JSON.stringify(popupIds), ";\n");
60
+ files.push({
61
+ type: "popup",
62
+ content: registryContent,
63
+ importManager: new ImportManager(config),
64
+ name: "popup"
65
+ });
66
+ }
67
+
47
68
  // 添加 TabBar 配置项(如果存在)
48
69
  if (globalTabBarConfig) {
49
70
  files.push({
@@ -10,9 +10,10 @@ export declare class HandlePageConfig {
10
10
  /**
11
11
  * 处理页面配置(提取 systemPage 组件数据)
12
12
  * @param scene 场景数据
13
+ * @param isPopup 是否为弹窗场景
13
14
  * @returns 页面配置内容
14
15
  */
15
- handle(scene: ReturnType<typeof toCode>["scenes"][0]["scene"]): string | undefined;
16
+ handle(scene: ReturnType<typeof toCode>["scenes"][0]["scene"], isPopup?: boolean): string | undefined;
16
17
  /**
17
18
  * 获取全局 TabBar 配置
18
19
  */
@@ -1,3 +1,4 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
3
  import _createClass from "@babel/runtime/helpers/esm/createClass";
3
4
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
@@ -19,10 +20,12 @@ export var HandlePageConfig = /*#__PURE__*/function () {
19
20
  /**
20
21
  * 处理页面配置(提取 systemPage 组件数据)
21
22
  * @param scene 场景数据
23
+ * @param isPopup 是否为弹窗场景
22
24
  * @returns 页面配置内容
23
25
  */
24
26
  function handle(scene) {
25
27
  var _systemPageCom$model;
28
+ var isPopup = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
26
29
  // 提取 systemPage 组件数据,生成 pageConfigContent
27
30
  var pageConfigContent;
28
31
  var systemPageCom = Object.values(scene.coms || {}).find(function (com) {
@@ -30,7 +33,8 @@ export var HandlePageConfig = /*#__PURE__*/function () {
30
33
  return ((_com$def = com.def) === null || _com$def === void 0 ? void 0 : _com$def.namespace) === 'mybricks.taro.systemPage';
31
34
  });
32
35
  if (systemPageCom !== null && systemPageCom !== void 0 && (_systemPageCom$model = systemPageCom.model) !== null && _systemPageCom$model !== void 0 && _systemPageCom$model.data) {
33
- var systemPageData = systemPageCom.model.data;
36
+ var systemPageData = _objectSpread({}, systemPageCom.model.data);
37
+
34
38
  // 生成页面配置
35
39
  pageConfigContent = generatePageConfigContent(systemPageData);
36
40
 
@@ -65,8 +65,9 @@ export var createEventQueries = function createEventQueries(events) {
65
65
  getFxEvents: createGetFxEvents(events),
66
66
  getEffectEvent: createGetEffectEvent(events),
67
67
  getEventByDiagramId: function getEventByDiagramId(diagramId) {
68
+ // 兼容:部分 event 没有 diagramId 字段,而是直接用 id 存储 diagramId
68
69
  return events.find(function (event) {
69
- return event.diagramId === diagramId;
70
+ return event.diagramId === diagramId || event.id === diagramId;
70
71
  });
71
72
  },
72
73
  /** 获取场景/区块的输入项事件 */
@@ -119,15 +119,42 @@ export var handleProcess = function handleProcess(event, config) {
119
119
  }
120
120
  if (componentType === "js") {
121
121
  if (category === "scene") {
122
- var _config$getPageId;
122
+ var _targetScene$deps, _config$getPageId;
123
+ var _sceneId = props.meta.model.data._sceneId;
124
+ var targetScene = config.getSceneById(_sceneId);
125
+ var isPopup = (targetScene === null || targetScene === void 0 ? void 0 : targetScene.type) === 'popup' || (targetScene === null || targetScene === void 0 || (_targetScene$deps = targetScene.deps) === null || _targetScene$deps === void 0 ? void 0 : _targetScene$deps.some(function (dep) {
126
+ return dep.namespace === 'mybricks.taro.popup';
127
+ }));
128
+ var controllerName = isPopup ? "popupRouter" : "pageRouter";
123
129
  config.addParentDependencyImport({
124
130
  packageName: config.getComponentPackageName(),
125
- dependencyNames: ["page"],
131
+ dependencyNames: [controllerName],
126
132
  importType: "named"
127
133
  });
128
- var _sceneId = props.meta.model.data._sceneId;
129
134
  var operateName = props.meta.model.data.openType === "redirect" ? "replace" : "open";
130
- 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, ")");
135
+ code += "".concat(indent, "/** \u6253\u5F00 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode).concat(controllerName, ".").concat(operateName, "(\"").concat(((_config$getPageId = config.getPageId) === null || _config$getPageId === void 0 ? void 0 : _config$getPageId.call(config, _sceneId)) || _sceneId, "\", ").concat(nextValue, ")");
136
+ } else if (category === "frameOutput") {
137
+ var _pinProxies;
138
+ // 场景/弹窗输出(commit/cancel/apply/close)
139
+ var currentScene = config.getCurrentScene();
140
+ // pinProxies 的结构在不同数据/版本里不完全一致,这里按最小字段兼容
141
+ var pinProxy = currentScene === null || currentScene === void 0 || (_pinProxies = currentScene.pinProxies) === null || _pinProxies === void 0 ? void 0 : _pinProxies["".concat(props.meta.id, "-").concat(props.id)];
142
+ if (pinProxy !== null && pinProxy !== void 0 && pinProxy.frameId && pinProxy !== null && pinProxy !== void 0 && pinProxy.pinId) {
143
+ var method = pinProxy.pinId;
144
+ var _controllerName = config.isPopup ? "popupRouter" : "pageRouter";
145
+ config.addParentDependencyImport({
146
+ packageName: config.getComponentPackageName(),
147
+ dependencyNames: [_controllerName],
148
+ importType: "named"
149
+ });
150
+
151
+ // 仅支持 Page 内置的四种输出方法
152
+ if (["commit", "cancel", "apply", "close"].includes(method)) {
153
+ var sceneId = pinProxy.frameId || (currentScene === null || currentScene === void 0 ? void 0 : currentScene.id);
154
+ var argCode = nextValue ? ", ".concat(nextValue) : "";
155
+ code += "".concat(indent, "/** ").concat(props.meta.title, " \u8F93\u51FA ").concat(method, " */") + "\n".concat(indent).concat(nextCode).concat(_controllerName, ".").concat(method, "(\"").concat(sceneId, "\"").concat(argCode, ")");
156
+ }
157
+ }
131
158
  } else if (category === "normal") {
132
159
  var componentNameWithId = getComponentNameWithId(props, config, event);
133
160
  code += "".concat(indent, "/** \u8C03\u7528 ").concat(props.meta.title, " */") + "\n".concat(indent).concat(nextCode).concat(componentNameWithId, "(").concat(runType === "input" ? nextValue : "", ")");
@@ -7,13 +7,15 @@ export declare const genSlotDefineCode: (indent: string) => string;
7
7
  /** 生成控制器初始化代码 */
8
8
  export declare const genControllerInitCode: (indent: string, providerName: string) => string;
9
9
  /** 生成完整的函数组件模板 */
10
- export declare const genComponentTemplate: ({ componentName, combinedJsCode, uiResult, outputsConfig, scopeName, utilsPackageName, }: {
10
+ export declare const genComponentTemplate: ({ componentName, combinedJsCode, uiResult, outputsConfig, scopeName, utilsPackageName, isPopup, hasPopups, }: {
11
11
  componentName: string;
12
12
  combinedJsCode: string;
13
13
  uiResult: string;
14
14
  outputsConfig?: Record<string, Record<string, any>>;
15
15
  scopeName?: string;
16
16
  utilsPackageName?: string;
17
+ isPopup?: boolean;
18
+ hasPopups?: boolean;
17
19
  }) => string;
18
20
  /** 生成 useEffect 包装代码 */
19
21
  export declare const wrapInEffect: (indent: string, effectCode: string) => string;
@@ -33,12 +33,20 @@ export var genComponentTemplate = function genComponentTemplate(_ref) {
33
33
  uiResult = _ref.uiResult,
34
34
  outputsConfig = _ref.outputsConfig,
35
35
  scopeName = _ref.scopeName,
36
- utilsPackageName = _ref.utilsPackageName;
36
+ utilsPackageName = _ref.utilsPackageName,
37
+ _ref$isPopup = _ref.isPopup,
38
+ isPopup = _ref$isPopup === void 0 ? false : _ref$isPopup,
39
+ _ref$hasPopups = _ref.hasPopups,
40
+ hasPopups = _ref$hasPopups === void 0 ? false : _ref$hasPopups;
37
41
  // 使用 WithWrapper 作为高阶组件包裹根组件
38
- // 格式:export default WithWrapper(ComponentName)
39
- return "function ".concat(componentName, "() {\n") + "".concat(combinedJsCode, "\n") + " return (\n" + "".concat(uiResult.split('\n').map(function (line) {
40
- return " ".concat(line);
41
- }).join('\n'), "\n") + " );\n" + "}\n\n" + "export default WithWrapper(".concat(componentName, ")");
42
+ var code = "function ".concat(componentName, "() {\n") + "".concat(combinedJsCode, "\n") + " return (\n" + " <>\n" + "".concat(uiResult.split('\n').map(function (line) {
43
+ return " ".concat(line);
44
+ }).join('\n'), "\n") + (hasPopups ? " <PopupRenderer popupMap={POPUP_MAP} />\n" : "") + " </>\n" + " );\n" + "}\n\n";
45
+ if (isPopup) {
46
+ code += "(".concat(componentName, " as any).isPopup = true;\n\n");
47
+ }
48
+ code += "export default WithWrapper(".concat(componentName, ")");
49
+ return code;
42
50
  };
43
51
 
44
52
  /** 生成 useEffect 包装代码 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mybricks/to-code-taro",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "To code for Taro",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -39,7 +39,9 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "@babel/runtime": "^7.26.0",
42
- "@mybricks/to-code-react": "^0.0.5-next.160"
42
+ "@mybricks/to-code-react": "^0.0.5-next.160",
43
+ "@types/crypto-js": "^4.2.2",
44
+ "crypto-js": "^4.2.0"
43
45
  },
44
46
  "devDependencies": {
45
47
  "@types/node": "^20.0.0",
@@ -1,50 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import Taro from '@tarojs/taro';
4
- import { Page } from "../mybricks";
5
-
6
- /**
7
- * Taro 路由实现
8
- */
9
- var TaroRouter = /*#__PURE__*/function () {
10
- function TaroRouter() {
11
- _classCallCheck(this, TaroRouter);
12
- }
13
- _createClass(TaroRouter, [{
14
- key: "getParams",
15
- value: function getParams(name) {
16
- var _instance$router;
17
- var instance = Taro.getCurrentInstance();
18
- return {
19
- value: (_instance$router = instance.router) === null || _instance$router === void 0 ? void 0 : _instance$router.params
20
- };
21
- }
22
- }, {
23
- key: "push",
24
- value: function push(name, _ref) {
25
- var value = _ref.value;
26
- var url = "/pages/".concat(name, "/index");
27
- var queryString = value ? "?data=".concat(encodeURIComponent(JSON.stringify(value))) : '';
28
- Taro.navigateTo({
29
- url: url + queryString
30
- });
31
- }
32
- }, {
33
- key: "replace",
34
- value: function replace(name, _ref2) {
35
- var value = _ref2.value;
36
- var url = "/pages/".concat(name, "/index");
37
- var queryString = value ? "?data=".concat(encodeURIComponent(JSON.stringify(value))) : '';
38
- Taro.redirectTo({
39
- url: url + queryString
40
- });
41
- }
42
- }, {
43
- key: "pop",
44
- value: function pop() {
45
- Taro.navigateBack();
46
- }
47
- }]);
48
- return TaroRouter;
49
- }();
50
- export var page = new Page(new TaroRouter());