@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
@@ -0,0 +1,116 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ import { Page } from "../mybricks";
5
+
6
+ /**
7
+ * 弹窗在 Taro 中被视为组件 兼容APP TODO
8
+ */
9
+ var PopupStore = /*#__PURE__*/function () {
10
+ function PopupStore() {
11
+ _classCallCheck(this, PopupStore);
12
+ _defineProperty(this, "activePopup", null);
13
+ _defineProperty(this, "listeners", new Set());
14
+ }
15
+ _createClass(PopupStore, [{
16
+ key: "subscribe",
17
+ value: /** 订阅弹窗状态变化 */
18
+ function subscribe(listener) {
19
+ var _this = this;
20
+ this.listeners.add(listener);
21
+ // 返回取消订阅函数
22
+ return function () {
23
+ _this.listeners.delete(listener);
24
+ };
25
+ }
26
+ }, {
27
+ key: "notify",
28
+ value: function notify() {
29
+ var _this2 = this;
30
+ this.listeners.forEach(function (l) {
31
+ return l(_this2.activePopup || {
32
+ visible: false,
33
+ name: '',
34
+ value: null,
35
+ controller: null
36
+ });
37
+ });
38
+ }
39
+
40
+ /** 获取弹窗参数 */
41
+ }, {
42
+ key: "getParams",
43
+ value: function getParams(name) {
44
+ if (this.activePopup && this.activePopup.name === name) {
45
+ return {
46
+ value: this.activePopup.value,
47
+ controller: this.activePopup.controller
48
+ };
49
+ }
50
+ return {
51
+ value: null
52
+ };
53
+ }
54
+
55
+ /** 获取当前激活的弹窗名称 */
56
+ }, {
57
+ key: "getActiveName",
58
+ value: function getActiveName() {
59
+ var _this$activePopup;
60
+ return (_this$activePopup = this.activePopup) === null || _this$activePopup === void 0 ? void 0 : _this$activePopup.name;
61
+ }
62
+
63
+ /** 打开弹窗 */
64
+ }, {
65
+ key: "push",
66
+ value: function push(name, _ref) {
67
+ var value = _ref.value,
68
+ controller = _ref.controller;
69
+ this.activePopup = {
70
+ visible: true,
71
+ name: name,
72
+ value: value,
73
+ controller: controller
74
+ };
75
+ this.notify();
76
+ }
77
+
78
+ /** 行为同 push */
79
+ }, {
80
+ key: "replace",
81
+ value: function replace(name, params) {
82
+ this.push(name, params);
83
+ }
84
+
85
+ /** 关闭弹窗 */
86
+ }, {
87
+ key: "pop",
88
+ value: function pop() {
89
+ this.activePopup = null;
90
+ this.notify();
91
+ }
92
+ }]);
93
+ return PopupStore;
94
+ }();
95
+ var popupStore = new PopupStore();
96
+
97
+ /**
98
+ * 订阅弹窗状态变化(统一入口,避免外部依赖内部实现细节)
99
+ */
100
+ export var subscribePopupRouter = function subscribePopupRouter(listener) {
101
+ return popupStore.subscribe(listener);
102
+ };
103
+
104
+ /** 弹窗控制器(命名与文件名保持一致) */
105
+ export var popupRouter = new Page(popupStore);
106
+
107
+ /**
108
+ * 关闭当前激活的弹窗(用于 TabBar 点击等场景)
109
+ * 不需要知道弹窗 id
110
+ */
111
+ export var closeActivePopupRouter = function closeActivePopupRouter() {
112
+ var name = popupStore.getActiveName();
113
+ if (!name) return;
114
+ // 走 Page.close,保证 close/commit/cancel 等控制器语义保持一致
115
+ popupRouter.close(name);
116
+ };
@@ -1,7 +1,17 @@
1
- import { useRef } from 'react';
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { useRef, useState } from 'react';
2
3
  import { deepProxy } from "./hooks";
3
4
  export function useAppCreateContext() {
4
5
  var comRefs = useRef(deepProxy({}));
6
+ var _useState = useState({
7
+ visible: false,
8
+ name: '',
9
+ value: null,
10
+ controller: null
11
+ }),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ popupState = _useState2[0],
14
+ setPopupState = _useState2[1];
5
15
  var appContext = {
6
16
  canvas: {
7
17
  id: "u_7VvVn" // 使用 data 中的 id
@@ -20,6 +30,8 @@ export function useAppCreateContext() {
20
30
  };
21
31
  return {
22
32
  comRefs: comRefs,
23
- appContext: appContext
33
+ appContext: appContext,
34
+ popupState: popupState,
35
+ setPopupState: setPopupState
24
36
  };
25
37
  }
@@ -1,12 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
5
  var _excluded = ["component", "id", "data", "className", "style"];
5
- import React, { useEffect, useState } from 'react';
6
+ import React, { useState, useEffect } from 'react';
6
7
  import { View } from '@tarojs/components';
7
- import { useModel, useBindInputs, useBindEvents } from "./index";
8
+ import { useModel, useBindInputs, useBindEvents, subscribePopupRouter, closeActivePopupRouter } from "./index";
8
9
  import { useAppCreateContext } from "./useContext";
9
10
  import ComContext, { useAppContext } from "./ComContext";
11
+ // @ts-ignore 运行时由宿主项目提供 @tarojs/taro
12
+ import { useTabItemTap } from '@tarojs/taro';
10
13
  export var WithCom = function WithCom(props) {
11
14
  var Component = props.component,
12
15
  _props$id = props.id,
@@ -20,34 +23,59 @@ export var WithCom = function WithCom(props) {
20
23
  appContext = _useAppContext.appContext;
21
24
  var env = appContext; //TODO: 需要根据实际情况修改
22
25
 
26
+ var isPopup = Component.isPopup;
23
27
  var _useState = useState(true),
24
28
  _useState2 = _slicedToArray(_useState, 2),
25
29
  show = _useState2[0],
26
30
  setShow = _useState2[1];
31
+ var _useState3 = useState({}),
32
+ _useState4 = _slicedToArray(_useState3, 2),
33
+ dynamicStyle = _useState4[0],
34
+ setDynamicStyle = _useState4[1];
27
35
 
28
- //默认事件注册
29
- useEffect(function () {
30
- comRefs.current[id].hide(function () {
31
- setShow(false);
32
- });
33
- comRefs.current[id].show(function () {
34
- setShow(true);
35
- });
36
- comRefs.current[id].showOrHide(function () {
37
- setShow(function (prev) {
38
- return !prev;
36
+ //数据模型
37
+ var _data = useModel(data || {});
38
+
39
+ // 内置通用能力
40
+ var handlers = {
41
+ _setStyle: function _setStyle(style) {
42
+ setDynamicStyle(function (prev) {
43
+ return _objectSpread(_objectSpread({}, prev), style);
39
44
  });
45
+ },
46
+ _setData: function _setData(path, value) {
47
+ var paths = path.split('.');
48
+ var current = _data;
49
+ for (var i = 0; i < paths.length - 1; i++) {
50
+ if (!current[paths[i]]) current[paths[i]] = {};
51
+ current = current[paths[i]];
52
+ }
53
+ current[paths[paths.length - 1]] = value;
54
+ }
55
+ };
56
+ if (!isPopup) {
57
+ Object.assign(handlers, {
58
+ show: function show() {
59
+ return setShow(true);
60
+ },
61
+ hide: function hide() {
62
+ return setShow(false);
63
+ },
64
+ showOrHide: function showOrHide() {
65
+ return setShow(function (prev) {
66
+ return !prev;
67
+ });
68
+ }
40
69
  });
41
- }, [comRefs]);
70
+ }
42
71
 
43
- //数据模型
44
- var _data = useModel(data || {});
45
- var inputProxy = useBindInputs(comRefs, id);
72
+ // 绑定输入,传入初始 handlers
73
+ var inputProxy = useBindInputs(comRefs, id, handlers);
46
74
  var eventProxy = useBindEvents(rest);
47
75
  comRefs.current[id] = inputProxy;
48
- return show ? /*#__PURE__*/React.createElement(View, {
76
+ return show || isPopup ? /*#__PURE__*/React.createElement(View, {
49
77
  className: className,
50
- style: style
78
+ style: _objectSpread(_objectSpread({}, style), dynamicStyle)
51
79
  }, /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
52
80
  inputs: inputProxy,
53
81
  outputs: eventProxy,
@@ -60,6 +88,21 @@ export var WithCom = function WithCom(props) {
60
88
  export var WithWrapper = function WithWrapper(Component) {
61
89
  return function WrappedComponent(props) {
62
90
  var contextStore = useAppCreateContext();
91
+ var setPopupState = contextStore.setPopupState;
92
+ var isPopup = Component.isPopup;
93
+
94
+ // 通过发布订阅模式解耦弹窗状态变化
95
+ useEffect(function () {
96
+ return subscribePopupRouter(function (state) {
97
+ return setPopupState(state);
98
+ });
99
+ }, [setPopupState]);
100
+
101
+ // 点击 TabBar 时自动关闭弹窗(自定义 TabBar 或原生 TabBar 点击均会触发)
102
+ useTabItemTap(function () {
103
+ if (isPopup) return;
104
+ closeActivePopupRouter();
105
+ });
63
106
  return /*#__PURE__*/React.createElement(ComContext.Provider, {
64
107
  value: contextStore
65
108
  }, /*#__PURE__*/React.createElement(Component, props));
@@ -88,7 +88,30 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
88
88
  // 一次性将所有生成的页面添加到 pages 目录
89
89
  (_pagesDir$children = pagesDir.children).push.apply(_pagesDir$children, _toConsumableArray(generatedPages));
90
90
 
91
- // 更新 app.config.ts
91
+ // --- 处理弹窗场景 (popup) ---
92
+ var popupComponentsDir = ensureDir(srcDir, "src/popupComponents");
93
+ var popupScenes = files.filter(function (item) {
94
+ return item.type === "popup" && item.meta;
95
+ });
96
+ popupScenes.forEach(function (item) {
97
+ var _item$importManager2;
98
+ var popupId = item.meta.id;
99
+ var importCode = ((_item$importManager2 = item.importManager) === null || _item$importManager2 === void 0 ? void 0 : _item$importManager2.toCode()) || "";
100
+ var fullContent = "".concat(importCode, "\n").concat(item.content || "");
101
+ popupComponentsDir.children.push({
102
+ path: "src/popupComponents/".concat(popupId),
103
+ content: null,
104
+ children: [{
105
+ path: "src/popupComponents/".concat(popupId, "/index.tsx"),
106
+ content: fullContent
107
+ }, {
108
+ path: "src/popupComponents/".concat(popupId, "/index.less"),
109
+ content: item.cssContent || ""
110
+ }]
111
+ });
112
+ });
113
+
114
+ // 更新 app.config.ts (只传入 normalItems 作为真正的页面)
92
115
  var appConfigFile = (_srcDir$children = srcDir.children) === null || _srcDir$children === void 0 ? void 0 : _srcDir$children.find(function (node) {
93
116
  return node.path === "src/app.config.ts";
94
117
  });
@@ -101,6 +124,17 @@ var generateTaroProjectJson = function generateTaroProjectJson(result) {
101
124
 
102
125
  // 处理 common 目录下的文件
103
126
  handleCommonDir(commonDir, files);
127
+
128
+ // 处理 popup 汇总文件 (type 为 popup 且无 meta)
129
+ var popupFile = files.find(function (f) {
130
+ return f.type === "popup" && !f.meta;
131
+ });
132
+ if (popupFile) {
133
+ commonDir.children.push({
134
+ path: "src/common/".concat(popupFile.name, ".ts"),
135
+ content: popupFile.content
136
+ });
137
+ }
104
138
  return templateJson;
105
139
  };
106
140
  export default generateTaroProjectJson;
@@ -8,6 +8,8 @@ interface HandleSlotConfig extends BaseConfig {
8
8
  checkIsRoot: () => boolean;
9
9
  renderManager?: RenderManager;
10
10
  addJSModule?: (module: any) => void;
11
+ isPopup?: boolean;
12
+ hasPopups?: boolean;
11
13
  }
12
14
  declare const handleSlot: (ui: UI, config: HandleSlotConfig) => {
13
15
  js: string;
@@ -57,8 +57,11 @@ var handleSlot = function handleSlot(ui, config) {
57
57
  * 设置基础导入
58
58
  */
59
59
  var setupImports = function setupImports(addImport, config, isRoot) {
60
- var utilsPkg = config.getUtilsPackageName();
61
- var comPkg = config.getComponentPackageName();
60
+ var importParams = {
61
+ isPopup: config.isPopup
62
+ };
63
+ var utilsPkg = config.getUtilsPackageName(importParams);
64
+ var comPkg = config.getComponentPackageName(importParams);
62
65
  addImport({
63
66
  packageName: "react",
64
67
  dependencyNames: ["useRef", "useEffect", "useState"],
@@ -69,9 +72,13 @@ var setupImports = function setupImports(addImport, config, isRoot) {
69
72
  dependencyNames: ["View"],
70
73
  importType: "named"
71
74
  });
75
+ var dependencyNames = ["WithCom", "WithWrapper"];
76
+ if (isRoot && config.hasPopups) {
77
+ dependencyNames.push("PopupRenderer");
78
+ }
72
79
  addImport({
73
80
  packageName: utilsPkg,
74
- dependencyNames: ["WithCom", "WithWrapper"],
81
+ dependencyNames: dependencyNames,
75
82
  importType: "named"
76
83
  });
77
84
  addImport({
@@ -80,6 +87,13 @@ var setupImports = function setupImports(addImport, config, isRoot) {
80
87
  importType: "named"
81
88
  });
82
89
  if (isRoot) {
90
+ if (config.hasPopups) {
91
+ addImport({
92
+ packageName: "../../common/popup",
93
+ dependencyNames: ["POPUP_MAP", "POPUP_IDS"],
94
+ importType: "named"
95
+ });
96
+ }
83
97
  addImport({
84
98
  packageName: "./index.less",
85
99
  dependencyNames: [],
@@ -116,7 +130,9 @@ var finalizeRootComponent = function finalizeRootComponent(ui, config, importMan
116
130
  var componentCode = genComponentTemplate({
117
131
  componentName: componentName,
118
132
  combinedJsCode: combinedJsCode,
119
- uiResult: uiResult
133
+ uiResult: uiResult,
134
+ isPopup: config.isPopup,
135
+ hasPopups: config.hasPopups
120
136
  });
121
137
  config.add({
122
138
  importManager: importManager,
@@ -7,6 +7,7 @@ import { handleProcess } from "../utils/logic/handleProcess";
7
7
  * 处理组件事件
8
8
  */
9
9
  export var processComEvents = function processComEvents(com, config) {
10
+ var _meta$def;
10
11
  var meta = com.meta,
11
12
  events = com.events;
12
13
  var comEventCode = "";
@@ -14,6 +15,7 @@ export var processComEvents = function processComEvents(com, config) {
14
15
  var eventConfig = {};
15
16
  var outputEvents = events || {};
16
17
  Object.entries(outputEvents).forEach(function (_ref) {
18
+ var _eventInfo$options, _eventInfo$options2;
17
19
  var _ref2 = _slicedToArray(_ref, 2),
18
20
  eventId = _ref2[0],
19
21
  eventInfo = _ref2[1];
@@ -41,8 +43,12 @@ export var processComEvents = function processComEvents(com, config) {
41
43
  };
42
44
  return;
43
45
  }
44
- if (type !== "defined" || !diagramId) return;
45
- var event = config.getEventByDiagramId(diagramId);
46
+ if (type !== "defined") return;
47
+
48
+ // 兼容:部分数据把 diagramId 放在 options.id(例如 test-data.json 的 outputEvents)
49
+ var resolvedDiagramId = diagramId || (eventInfo === null || eventInfo === void 0 || (_eventInfo$options = eventInfo.options) === null || _eventInfo$options === void 0 ? void 0 : _eventInfo$options.diagramId) || (eventInfo === null || eventInfo === void 0 || (_eventInfo$options2 = eventInfo.options) === null || _eventInfo$options2 === void 0 ? void 0 : _eventInfo$options2.id);
50
+ if (!resolvedDiagramId) return;
51
+ var event = config.getEventByDiagramId(resolvedDiagramId);
46
52
  if (!event) return;
47
53
  var paramName = "value";
48
54
  var process = handleProcess(event, _objectSpread(_objectSpread({}, config), {}, {
@@ -54,14 +60,18 @@ export var processComEvents = function processComEvents(com, config) {
54
60
  }
55
61
  })).replace(/this\./g, "comRefs.current.").replace(/comRefs\.current\.([a-zA-Z0-9_]+)\.controller_/g, "comRefs.current.$1.").replace(/comRefs\.current\.slot_Index\./g, "comRefs.current.");
56
62
  if (process.includes("pageParams")) {
63
+ var importParams = {
64
+ isPopup: config.isPopup
65
+ };
66
+ var controllerName = config.isPopup ? "popupRouter" : "pageRouter";
57
67
  config.addParentDependencyImport({
58
- packageName: config.getComponentPackageName(),
59
- dependencyNames: ["page", "SUBJECT_VALUE"],
68
+ packageName: config.getComponentPackageName(importParams),
69
+ dependencyNames: [controllerName, "SUBJECT_VALUE"],
60
70
  importType: "named"
61
71
  });
62
72
  var indent = indentation(config.codeStyle.indent * (config.depth + 3));
63
73
  // 使用 SUBJECT_VALUE 获取当前参数值,保持与 MyBricks 逻辑一致
64
- process = "".concat(indent, "const pageParams: any = page.getParams(\"").concat(config.getCurrentScene().id, "\")[SUBJECT_VALUE];\n").concat(process);
74
+ process = "".concat(indent, "const pageParams: any = ").concat(controllerName, ".getParams(\"").concat(config.getCurrentScene().id, "\")[SUBJECT_VALUE];\n").concat(process);
65
75
  }
66
76
  var handlerIndent = indentation(config.codeStyle.indent * (config.depth + 2));
67
77
  var handlerCode = "(".concat(paramName, ": any) => {\n").concat(process, "\n").concat(handlerIndent, "}");
@@ -74,6 +84,53 @@ export var processComEvents = function processComEvents(com, config) {
74
84
  connected: true
75
85
  };
76
86
  });
87
+
88
+ // 针对 mybricks.taro.popup 的特殊处理
89
+ if (((_meta$def = meta.def) === null || _meta$def === void 0 ? void 0 : _meta$def.namespace) === 'mybricks.taro.popup') {
90
+ var _config$getCurrentSce, _sceneCom$model;
91
+ if (!outputsConfig[meta.id]) {
92
+ outputsConfig[meta.id] = {};
93
+ }
94
+ var importParams = {
95
+ isPopup: config.isPopup
96
+ };
97
+ var sceneCom = (_config$getCurrentSce = config.getCurrentScene().coms) === null || _config$getCurrentSce === void 0 ? void 0 : _config$getCurrentSce[meta.id];
98
+ var popupData = (sceneCom === null || sceneCom === void 0 || (_sceneCom$model = sceneCom.model) === null || _sceneCom$model === void 0 ? void 0 : _sceneCom$model.data) || {};
99
+ var isTrue = function isTrue(v) {
100
+ return v === true || v === "true";
101
+ };
102
+
103
+ // 如果 onClose 没被连接,且 visibleClose=true(会渲染关闭按钮),才添加默认 close
104
+ // visibleClose=false 时,运行时不会触发 onClose(模板里只在 close 按钮点击时触发)
105
+ if (!eventConfig['onClose'] && isTrue(popupData.visibleClose)) {
106
+ config.addParentDependencyImport({
107
+ packageName: config.getComponentPackageName(importParams),
108
+ dependencyNames: ["popupRouter"],
109
+ importType: "named"
110
+ });
111
+ var handlerIndent = indentation(config.codeStyle.indent * (config.depth + 2));
112
+ var processIndent = indentation(config.codeStyle.indent * (config.depth + 3));
113
+ outputsConfig[meta.id]['onClose'] = "() => {\n".concat(processIndent, "popupRouter.close(\"").concat(config.getCurrentScene().id, "\");\n").concat(handlerIndent, "}");
114
+ eventConfig['onClose'] = {
115
+ connected: true
116
+ };
117
+ }
118
+
119
+ // 如果 onClickOverlay 没被连接,且组件配置了点击遮罩关闭
120
+ if (!eventConfig['onClickOverlay'] && isTrue(popupData.maskClose)) {
121
+ config.addParentDependencyImport({
122
+ packageName: config.getComponentPackageName(importParams),
123
+ dependencyNames: ["popupRouter"],
124
+ importType: "named"
125
+ });
126
+ var _handlerIndent = indentation(config.codeStyle.indent * (config.depth + 2));
127
+ var _processIndent = indentation(config.codeStyle.indent * (config.depth + 3));
128
+ outputsConfig[meta.id]['onClickOverlay'] = "() => {\n".concat(_processIndent, "popupRouter.close(\"").concat(config.getCurrentScene().id, "\");\n").concat(_handlerIndent, "}");
129
+ eventConfig['onClickOverlay'] = {
130
+ connected: true
131
+ };
132
+ }
133
+ }
77
134
  return {
78
135
  comEventCode: comEventCode,
79
136
  outputsConfig: outputsConfig,
@@ -12,7 +12,7 @@ import { collectJSModulesFromScene } from "../utils/context/collectJSModules";
12
12
  * 处理单个场景
13
13
  */
14
14
  export var processScene = function processScene(params) {
15
- var _config$getFileName;
15
+ var _config$getFileName, _originalScene$deps;
16
16
  var _params$scene = params.scene,
17
17
  scene = _params$scene.scene,
18
18
  ui = _params$scene.ui,
@@ -45,14 +45,22 @@ export var processScene = function processScene(params) {
45
45
  // 创建 FX Map
46
46
  var fxsMap = Object.assign({}, defaultFxsMap);
47
47
 
48
+ // 参考鸿蒙逻辑:如果场景中包含 popup 组件,则标记场景类型为 popup
49
+ var originalScene = getSceneById(scene.id);
50
+ var isPopup = (originalScene === null || originalScene === void 0 ? void 0 : originalScene.type) === 'popup' || (originalScene === null || originalScene === void 0 || (_originalScene$deps = originalScene.deps) === null || _originalScene$deps === void 0 ? void 0 : _originalScene$deps.some(function (dep) {
51
+ return dep.namespace === 'mybricks.taro.popup';
52
+ }));
53
+
48
54
  // 处理页面配置
49
- var pageConfigContent = pageConfigHandler.handle(scene);
55
+ var pageConfigContent = pageConfigHandler.handle(scene, isPopup);
50
56
 
51
57
  // 创建事件查询函数
52
58
  var eventQueries = createEventQueries(event);
53
59
 
54
60
  // 处理 Slot
55
61
  handleSlot(ui, _objectSpread(_objectSpread({}, config), {}, {
62
+ isPopup: isPopup,
63
+ // 标记当前场景是否为弹窗
56
64
  getCurrentScene: function getCurrentScene() {
57
65
  var originalScene = getSceneById(scene.id);
58
66
  return _objectSpread(_objectSpread(_objectSpread({}, scene), originalScene), {}, {
@@ -61,7 +69,7 @@ export var processScene = function processScene(params) {
61
69
  },
62
70
  add: function add(value) {
63
71
  params.addResult(_objectSpread(_objectSpread({}, value), {}, {
64
- type: scene.type ? scene.type : "normal",
72
+ type: isPopup ? "popup" : originalScene !== null && originalScene !== void 0 && originalScene.type ? originalScene.type : "normal",
65
73
  meta: scene,
66
74
  pageConfigContent: pageConfigContent
67
75
  }));
@@ -39,8 +39,11 @@ var processLogicalInit = function processLogicalInit(scene, config, addDependenc
39
39
  return com.def.namespace === "mybricks.core-comlib.var";
40
40
  });
41
41
  if (vars.length > 0) {
42
+ var importParams = {
43
+ isPopup: config.isPopup
44
+ };
42
45
  addDependencyImport({
43
- packageName: config.getUtilsPackageName(),
46
+ packageName: config.getUtilsPackageName(importParams),
44
47
  dependencyNames: ["createVariable"],
45
48
  importType: "named"
46
49
  });
@@ -58,8 +61,11 @@ var processLogicalInit = function processLogicalInit(scene, config, addDependenc
58
61
  // 2. 初始化 Fxs (使用 getFxEvents 获取 FX 列表)
59
62
  var fxEvents = config.getFxEvents();
60
63
  if (fxEvents.length > 0) {
64
+ var _importParams = {
65
+ isPopup: config.isPopup
66
+ };
61
67
  addDependencyImport({
62
- packageName: config.getUtilsPackageName(),
68
+ packageName: config.getUtilsPackageName(_importParams),
63
69
  dependencyNames: ["createFx"],
64
70
  importType: "named"
65
71
  });
@@ -146,13 +152,17 @@ var processSceneInputs = function processSceneInputs(currentScene, config, addDe
146
152
  if (process.trim()) {
147
153
  code += "\n".concat(indent, " inputs.").concat(input.id, " = (data: any) => {\n").concat(process, "\n").concat(indent, " };");
148
154
  if (input.id === "open") {
155
+ var importParams = {
156
+ isPopup: config.isPopup
157
+ };
158
+ var controllerName = config.isPopup ? "popupRouter" : "pageRouter";
149
159
  addDependencyImport({
150
- packageName: config.getComponentPackageName(),
151
- dependencyNames: ["page", "SUBJECT_SUBSCRIBE"],
160
+ packageName: config.getComponentPackageName(importParams),
161
+ dependencyNames: [controllerName, "SUBJECT_SUBSCRIBE"],
152
162
  importType: "named"
153
163
  });
154
164
  // 使用 SUBJECT_SUBSCRIBE 订阅,不修改 Subject.js
155
- code += "\n".concat(indent, " page.getParams()[SUBJECT_SUBSCRIBE]((val: any) => {\n").concat(indent, " if (val) inputs.open(val);\n").concat(indent, " });");
165
+ code += "\n".concat(indent, " ").concat(controllerName, ".getParams(\"").concat(currentScene.id, "\")[SUBJECT_SUBSCRIBE]((val: any) => {\n").concat(indent, " if (val) inputs.open(val);\n").concat(indent, " });");
156
166
  }
157
167
  }
158
168
  });
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 由于本仓库以生成代码为主,运行时依赖由宿主项目提供,
3
+ * 这里补充最小化的模块声明以避免编辑器/类型检查报错。
4
+ */
5
+
6
+ declare module '@tarojs/taro' {
7
+ const Taro: any;
8
+ export default Taro;
9
+ }
10
+
11
+ declare module '@tarojs/components' {
12
+ export const View: any;
13
+ export const Text: any;
14
+ export const Image: any;
15
+ export const Button: any;
16
+ const components: any;
17
+ export default components;
18
+ }
19
+
20
+