@mybricks/to-code-taro 1.1.7 → 1.2.1

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 (88) hide show
  1. package/dist/cjs/generate/generateTaroProjectJson.js +47 -2
  2. package/dist/cjs/handleCom.js +1 -1
  3. package/dist/cjs/handleModule.js +6 -8
  4. package/dist/cjs/handleSlot.d.ts +1 -0
  5. package/dist/cjs/handleSlot.js +6 -3
  6. package/dist/cjs/index.js +1 -0
  7. package/dist/cjs/processors/processModule.js +1 -0
  8. package/dist/cjs/processors/processSceneLogic.js +5 -1
  9. package/dist/cjs/taro-template.json +6 -6008
  10. package/dist/cjs/toCodeTaro.js +89 -0
  11. package/dist/cjs/utils/logic/handleProcess.js +26 -18
  12. package/dist/cjs/utils/templates/component.js +1 -1
  13. package/dist/cjs/utils/templates/index.d.ts +2 -0
  14. package/dist/cjs/utils/templates/index.js +7 -2
  15. package/dist/cjs/utils/templates/renderManager.js +2 -2
  16. package/dist/cjs/utils/templates/scene.d.ts +1 -1
  17. package/dist/cjs/utils/templates/scene.js +4 -2
  18. package/dist/esm/generate/generateTaroProjectJson.js +43 -2
  19. package/dist/esm/handleCom.js +1 -1
  20. package/dist/esm/handleModule.js +5 -7
  21. package/dist/esm/handleSlot.d.ts +1 -0
  22. package/dist/esm/handleSlot.js +10 -7
  23. package/dist/esm/index.js +2 -1
  24. package/dist/esm/processors/processModule.js +1 -0
  25. package/dist/esm/processors/processSceneLogic.js +4 -2
  26. package/dist/esm/taro-template.json +6 -6008
  27. package/dist/esm/toCodeTaro.js +112 -0
  28. package/dist/esm/utils/logic/handleProcess.js +39 -18
  29. package/dist/esm/utils/templates/component.js +2 -2
  30. package/dist/esm/utils/templates/index.d.ts +2 -0
  31. package/dist/esm/utils/templates/index.js +5 -0
  32. package/dist/esm/utils/templates/renderManager.js +3 -3
  33. package/dist/esm/utils/templates/scene.d.ts +1 -1
  34. package/dist/esm/utils/templates/scene.js +4 -1
  35. package/package.json +2 -9
  36. package/README.md +0 -58
  37. package/dist/cjs/core/mybricks/MyBricksDescriptor.js +0 -213
  38. package/dist/cjs/core/mybricks/Subject.js +0 -119
  39. package/dist/cjs/core/mybricks/constant.js +0 -70
  40. package/dist/cjs/core/mybricks/context.js +0 -33
  41. package/dist/cjs/core/mybricks/createEnv.js +0 -39
  42. package/dist/cjs/core/mybricks/createJSHandle.js +0 -191
  43. package/dist/cjs/core/mybricks/createModuleEventsHandle.js +0 -49
  44. package/dist/cjs/core/mybricks/createReactiveInputHandler.js +0 -63
  45. package/dist/cjs/core/mybricks/event.js +0 -70
  46. package/dist/cjs/core/mybricks/index.js +0 -871
  47. package/dist/cjs/core/mybricks/log.js +0 -37
  48. package/dist/cjs/core/mybricks/utils.js +0 -69
  49. package/dist/cjs/core/mybricks/variables.js +0 -217
  50. package/dist/cjs/core/utils/ComContext.js +0 -51
  51. package/dist/cjs/core/utils/PopupRenderer.js +0 -63
  52. package/dist/cjs/core/utils/comRefResolver.js +0 -112
  53. package/dist/cjs/core/utils/event.js +0 -53
  54. package/dist/cjs/core/utils/hooks.js +0 -238
  55. package/dist/cjs/core/utils/index.js +0 -77
  56. package/dist/cjs/core/utils/pageRouter.js +0 -104
  57. package/dist/cjs/core/utils/pool.js +0 -63
  58. package/dist/cjs/core/utils/popupRouter.js +0 -98
  59. package/dist/cjs/core/utils/slots.js +0 -183
  60. package/dist/cjs/core/utils/tabbar.js +0 -56
  61. package/dist/cjs/core/utils/useContext.js +0 -112
  62. package/dist/cjs/core/utils/with.js +0 -109
  63. package/dist/esm/core/mybricks/MyBricksDescriptor.js +0 -232
  64. package/dist/esm/core/mybricks/Subject.js +0 -149
  65. package/dist/esm/core/mybricks/constant.js +0 -18
  66. package/dist/esm/core/mybricks/context.js +0 -5
  67. package/dist/esm/core/mybricks/createEnv.js +0 -9
  68. package/dist/esm/core/mybricks/createJSHandle.js +0 -189
  69. package/dist/esm/core/mybricks/createModuleEventsHandle.js +0 -26
  70. package/dist/esm/core/mybricks/createReactiveInputHandler.js +0 -40
  71. package/dist/esm/core/mybricks/event.js +0 -44
  72. package/dist/esm/core/mybricks/index.js +0 -952
  73. package/dist/esm/core/mybricks/log.js +0 -8
  74. package/dist/esm/core/mybricks/utils.js +0 -41
  75. package/dist/esm/core/mybricks/variables.js +0 -190
  76. package/dist/esm/core/utils/ComContext.js +0 -16
  77. package/dist/esm/core/utils/PopupRenderer.js +0 -27
  78. package/dist/esm/core/utils/comRefResolver.js +0 -134
  79. package/dist/esm/core/utils/event.js +0 -32
  80. package/dist/esm/core/utils/hooks.js +0 -287
  81. package/dist/esm/core/utils/index.js +0 -12
  82. package/dist/esm/core/utils/pageRouter.js +0 -112
  83. package/dist/esm/core/utils/pool.js +0 -52
  84. package/dist/esm/core/utils/popupRouter.js +0 -117
  85. package/dist/esm/core/utils/slots.js +0 -194
  86. package/dist/esm/core/utils/tabbar.js +0 -47
  87. package/dist/esm/core/utils/useContext.js +0 -100
  88. package/dist/esm/core/utils/with.js +0 -115
@@ -1,287 +0,0 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
- import _typeof from "@babel/runtime/helpers/esm/typeof";
6
- import { useState, useRef, useMemo, useEffect } from 'react';
7
- import { createReactiveInputHandler } from "../mybricks/createReactiveInputHandler";
8
- import { useAppContext, useParentSlot } from "./ComContext";
9
- import { ComRefResolver } from "./comRefResolver";
10
-
11
- /** 深度代理:支持响应式更新 */
12
- export function deepProxy(target, onSet) {
13
- if (target === null || _typeof(target) !== 'object' || target.__isProxy) return target;
14
- return new Proxy(target, {
15
- get: function get(obj, prop) {
16
- if (prop === '__isProxy') return true;
17
- if (prop === 'toJSON') return function () {
18
- return obj;
19
- };
20
- var value = obj[prop];
21
- if (_typeof(value) === 'object' && value !== null && !value.__isProxy) {
22
- obj[prop] = deepProxy(value, onSet);
23
- }
24
- return obj[prop];
25
- },
26
- set: function set(obj, prop, value) {
27
- var result = Reflect.set(obj, prop, value);
28
- onSet === null || onSet === void 0 || onSet();
29
- return result;
30
- }
31
- });
32
- }
33
-
34
- /** 状态 Hook:提供响应式数据能力 */
35
- export function useModel(rawData) {
36
- var _useState = useState({}),
37
- _useState2 = _slicedToArray(_useState, 2),
38
- forceUpdate = _useState2[1];
39
- var dataRef = useRef(rawData || {});
40
- return useMemo(function () {
41
- return deepProxy(dataRef.current, function () {
42
- return forceUpdate({});
43
- });
44
- }, []);
45
- }
46
-
47
- /**
48
- * 组件引用代理:
49
- * 1. 自动缓冲:访问未渲染组件时返回影子对象,缓冲后续指令
50
- * 2. 引用渗透:子作用域注册的真实引用自动同步至父级
51
- * 3. 自动同步清理:卸载时从作用域链中彻底移除,防止僵尸引用
52
- *
53
- * 使用 ComRefResolver 统一处理引用解析逻辑
54
- */
55
- export function proxyRefs(target, parentComRefs, todoPool) {
56
- var _parentComRefs$curren, _target$$index;
57
- // 创建解析器,链接父级解析器
58
- var parentResolver = parentComRefs === null || parentComRefs === void 0 || (_parentComRefs$curren = parentComRefs.current) === null || _parentComRefs$curren === void 0 ? void 0 : _parentComRefs$curren.__resolver;
59
- var scopeIndex = (_target$$index = target.$index) !== null && _target$$index !== void 0 ? _target$$index : 0;
60
- var resolver = new ComRefResolver(target, parentResolver, todoPool, scopeIndex);
61
-
62
- // 存储解析器引用,供子级使用
63
- target.__resolver = resolver;
64
- return new Proxy(target, {
65
- get: function get(obj, prop) {
66
- if (prop === '__isProxy') return true;
67
- if (prop === '__resolver') return resolver;
68
- if (prop === 'toJSON') return function () {
69
- return obj;
70
- };
71
-
72
- // u_ 开头的组件引用,统一由解析器处理
73
- if (typeof prop === 'string' && prop.startsWith('u_')) {
74
- return resolver.get(prop);
75
- }
76
- return obj[prop];
77
- },
78
- set: function set(obj, prop, value) {
79
- var result = Reflect.set(obj, prop, value);
80
-
81
- // 真实引用注册时,同步到解析器
82
- var isRealRef = typeof prop === 'string' && !prop.startsWith('$') && (value === null || value === void 0 ? void 0 : value.__isShadow) !== true;
83
- if (isRealRef && typeof prop === 'string' && prop.startsWith('u_')) {
84
- resolver.set(prop, value);
85
- } else if (isRealRef && parentComRefs !== null && parentComRefs !== void 0 && parentComRefs.current) {
86
- // 非 u_ 开头的属性,保持原有的父级渗透逻辑
87
- try {
88
- parentComRefs.current[prop] = value;
89
- } catch (_unused) {}
90
- }
91
- return result;
92
- },
93
- deleteProperty: function deleteProperty(obj, prop) {
94
- var result = Reflect.deleteProperty(obj, prop);
95
- if (typeof prop === 'string' && prop.startsWith('u_')) {
96
- resolver.delete(prop);
97
- } else if (typeof prop === 'string' && !prop.startsWith('$') && parentComRefs !== null && parentComRefs !== void 0 && parentComRefs.current) {
98
- try {
99
- delete parentComRefs.current[prop];
100
- } catch (_unused2) {}
101
- }
102
- return result;
103
- }
104
- });
105
- }
106
-
107
- /**
108
- * 组件输入绑定 Hook:
109
- * 1. 注册输入执行器
110
- * 2. 自动重放缓冲指令(精准索引匹配)
111
- * 3. 生命周期自动化:卸载时自动注销引用渗透路径
112
- */
113
- export function useBindInputs(scope, id, initialHandlers) {
114
- var _parentSlot$params$in, _parentSlot$params;
115
- var handlersRef = useRef(_objectSpread({}, initialHandlers));
116
- var _useAppContext = useAppContext(),
117
- todoPool = _useAppContext.todoPool;
118
- var parentSlot = useParentSlot();
119
- var index = (_parentSlot$params$in = parentSlot === null || parentSlot === void 0 || (_parentSlot$params = parentSlot.params) === null || _parentSlot$params === void 0 || (_parentSlot$params = _parentSlot$params.inputValues) === null || _parentSlot$params === void 0 ? void 0 : _parentSlot$params.index) !== null && _parentSlot$params$in !== void 0 ? _parentSlot$params$in : 0;
120
- useEffect(function () {
121
- return function () {
122
- if (scope !== null && scope !== void 0 && scope.current) {
123
- delete scope.current[id];
124
- }
125
- };
126
- }, [scope, id]);
127
- return useMemo(function () {
128
- var proxy = new Proxy({}, {
129
- get: function get(target, pin) {
130
- if (pin === '__isShadow') return false;
131
- if (pin === '__isLazyProxy') return false;
132
- if (pin === 'toJSON') return function () {
133
- return target;
134
- };
135
- return function (arg) {
136
- if (typeof arg === 'function') {
137
- handlersRef.current[pin] = arg;
138
-
139
- // 处理指令重放
140
- var pendingArgs = todoPool === null || todoPool === void 0 ? void 0 : todoPool.pop(id, index, pin);
141
- if (pendingArgs) {
142
- if (pin === '_setData') {
143
- arg.apply(void 0, _toConsumableArray(pendingArgs));
144
- } else {
145
- createReactiveInputHandler({
146
- input: arg,
147
- value: pendingArgs[0],
148
- rels: {},
149
- title: id
150
- });
151
- }
152
- }
153
- } else {
154
- var handler = handlersRef.current[pin];
155
- if (typeof handler === 'function') {
156
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
157
- args[_key - 1] = arguments[_key];
158
- }
159
- return pin === '_setData' ? handler.apply(void 0, [arg].concat(args)) : createReactiveInputHandler({
160
- input: handler,
161
- value: arg,
162
- rels: {},
163
- title: id
164
- });
165
- }
166
- }
167
- };
168
- }
169
- });
170
- if (scope !== null && scope !== void 0 && scope.current) scope.current[id] = proxy;
171
- if (initialHandlers) {
172
- Object.keys(initialHandlers).forEach(function (pin) {
173
- return proxy[pin](initialHandlers[pin]);
174
- });
175
- }
176
- return proxy;
177
- }, [scope, id, todoPool, index]);
178
- }
179
-
180
- /** 内置通用能力 Hook:_setStyle / _setData / show / hide / showOrHide */
181
- export function useBuiltinHandlers(opts) {
182
- var data = opts.data,
183
- setDynamicStyle = opts.setDynamicStyle,
184
- setShow = opts.setShow,
185
- isPopup = opts.isPopup;
186
- return useMemo(function () {
187
- var handlers = {
188
- _setStyle: function _setStyle(style) {
189
- setDynamicStyle(function (prev) {
190
- return _objectSpread(_objectSpread({}, prev), style);
191
- });
192
- },
193
- _setData: function _setData(path, value) {
194
- var paths = path.split('.');
195
- var current = data;
196
- for (var i = 0; i < paths.length - 1; i++) {
197
- if (!current[paths[i]]) current[paths[i]] = {};
198
- current = current[paths[i]];
199
- }
200
- current[paths[paths.length - 1]] = value;
201
- }
202
- };
203
- if (!isPopup) {
204
- Object.assign(handlers, {
205
- show: function show() {
206
- return setShow(true);
207
- },
208
- hide: function hide() {
209
- return setShow(false);
210
- },
211
- showOrHide: function showOrHide() {
212
- return setShow(function (prev) {
213
- return !prev;
214
- });
215
- }
216
- });
217
- }
218
- return handlers;
219
- }, [data, setDynamicStyle, setShow, isPopup]);
220
- }
221
-
222
- /**
223
- * 组件输出绑定 Hook(与 useBindInputs 对称)
224
- * - 从 props 提取事件函数,创建 eventProxy
225
- * - 合并 slot outputs,注册到 comRefs.current.$outputs[id]
226
- */
227
- export function useBindOutputs(comRefs, id, props, enhancedSlots, context) {
228
- var _comRefs$current;
229
- var eventProxy = useMemo(function () {
230
- var events = {};
231
- Object.keys(props).forEach(function (key) {
232
- if (typeof props[key] === 'function') {
233
- var handler = props[key];
234
- var wrapped = function wrapped(original) {
235
- return handler(original);
236
- };
237
- wrapped.getConnections = function () {
238
- return [{
239
- id: 'default'
240
- }];
241
- };
242
- events[key] = wrapped;
243
- }
244
- });
245
- return new Proxy(events, {
246
- get: function get(target, key) {
247
- if (typeof key === 'string' && key.startsWith('on')) {
248
- if (target[key]) return target[key];
249
- var fn = function fn() {};
250
- fn.getConnections = function () {
251
- return [];
252
- };
253
- return fn;
254
- }
255
- return target[key];
256
- }
257
- });
258
- }, [props, context]);
259
- if (comRefs !== null && comRefs !== void 0 && (_comRefs$current = comRefs.current) !== null && _comRefs$current !== void 0 && _comRefs$current.$outputs) {
260
- var slotOutputsList = Object.values(enhancedSlots || {}).map(function (slot) {
261
- return slot === null || slot === void 0 ? void 0 : slot.outputs;
262
- }).filter(Boolean);
263
- if (slotOutputsList.length > 0) {
264
- comRefs.current.$outputs[id] = new Proxy({}, {
265
- get: function get(_, prop) {
266
- var _iterator = _createForOfIteratorHelper(slotOutputsList),
267
- _step;
268
- try {
269
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
270
- var outputs = _step.value;
271
- var fn = outputs[prop];
272
- if (fn) return fn;
273
- }
274
- } catch (err) {
275
- _iterator.e(err);
276
- } finally {
277
- _iterator.f();
278
- }
279
- return eventProxy[prop];
280
- }
281
- });
282
- } else {
283
- comRefs.current.$outputs[id] = eventProxy;
284
- }
285
- }
286
- return eventProxy;
287
- }
@@ -1,12 +0,0 @@
1
- export * from "./hooks";
2
- export { TodoPool } from "./pool";
3
- export { ComRefResolver } from "./comRefResolver";
4
- export { WithCom, WithWrapper } from "./with";
5
- export { PopupRenderer } from "./PopupRenderer";
6
- export { pageRouter, router } from "./pageRouter";
7
- export { popupRouter, subscribePopupRouter, closeActivePopupRouter } from "./popupRouter";
8
- export { useAppContext, SlotProvider } from "./ComContext";
9
- export { useAppCreateContext } from "./useContext";
10
- export { createVariable, createFx, merge } from "../mybricks";
11
- export { SUBJECT_SUBSCRIBE, SUBJECT_VALUE } from "../mybricks/constant";
12
- export * from "./slots";
@@ -1,112 +0,0 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
- // @ts-ignore 运行时由宿主项目提供 @tarojs/taro
6
- import Taro from "@tarojs/taro";
7
- // @ts-ignore 运行时由宿主项目提供
8
- import tabBarConfig from "@/custom-tab-bar/tabBar.json";
9
- import { Page } from "../mybricks";
10
-
11
- /**
12
- * Taro 路由驱动 (纯粹版)
13
- * 只负责处理真正的 Taro 页面跳转
14
- */
15
- var TaroRouter = /*#__PURE__*/function () {
16
- function TaroRouter() {
17
- _classCallCheck(this, TaroRouter);
18
- _defineProperty(this, "paramsBackup", {});
19
- }
20
- _createClass(TaroRouter, [{
21
- key: "getParams",
22
- value: function getParams(name) {
23
- var _instance$router;
24
- var instance = Taro.getCurrentInstance();
25
- var inputParams = ((_instance$router = instance.router) === null || _instance$router === void 0 ? void 0 : _instance$router.params) || {};
26
-
27
- // 直接页面"打开",会有data包裹参数
28
- // 使用“跳转到”逻辑组件,会直接传递参数
29
- // TODO: 没有特殊字段和结构可以判断,现只能尽量加条件来判断
30
- var params = Object.keys(inputParams).length === 2 && inputParams.data && typeof inputParams.data === "string" ? inputParams : {
31
- data: Object.keys(inputParams).length > 1 ? JSON.stringify(_objectSpread(_objectSpread({}, inputParams), {}, {
32
- $taroTimestamp: undefined
33
- })) : undefined,
34
- $taroTimestamp: inputParams.$taroTimestamp
35
- };
36
-
37
- // 备份参数,解决某些生命周期下 Taro 获取不到 params 的问题
38
- if (!params.data && this.paramsBackup[name]) {
39
- params = {
40
- data: this.paramsBackup[name]
41
- };
42
- }
43
-
44
- // 解析真实参数
45
- var paramsDataStr = params.data ? decodeURIComponent(params.data) : undefined;
46
- var paramsData;
47
- try {
48
- paramsData = paramsDataStr ? JSON.parse(paramsDataStr) : undefined;
49
- } catch (error) {
50
- paramsData = paramsDataStr;
51
- }
52
- return {
53
- value: paramsData
54
- };
55
- }
56
- }, {
57
- key: "push",
58
- value: function push(name, _ref) {
59
- var value = _ref.value;
60
- var path = "pages/".concat(name, "/index");
61
- var navigateType = this.isTabBarPage(path) ? "switchTab" : "navigateTo";
62
- this.navigate(navigateType, name, {
63
- value: value
64
- });
65
- }
66
- }, {
67
- key: "replace",
68
- value: function replace(name, _ref2) {
69
- var value = _ref2.value;
70
- var path = "pages/".concat(name, "/index");
71
- var navigateType = this.isTabBarPage(path) ? "switchTab" : "redirectTo";
72
- this.navigate(navigateType, name, {
73
- value: value
74
- });
75
- }
76
- }, {
77
- key: "navigate",
78
- value: function navigate(type, name, _ref3) {
79
- var value = _ref3.value;
80
- var url = "/pages/".concat(name, "/index");
81
- var dataStr = value ? encodeURIComponent(JSON.stringify(value)) : "";
82
- if (dataStr) {
83
- this.paramsBackup[name] = dataStr;
84
- }
85
- Taro[type]({
86
- url: "".concat(url).concat(dataStr ? "?data=".concat(dataStr) : "")
87
- });
88
- }
89
- }, {
90
- key: "pop",
91
- value: function pop() {
92
- Taro.navigateBack();
93
- }
94
-
95
- /**
96
- * 判断是否为标签栏页面
97
- * @param pagePath 页面路径
98
- * @returns 是否为标签栏页面
99
- */
100
- }, {
101
- key: "isTabBarPage",
102
- value: function isTabBarPage(pagePath) {
103
- var _tabBarConfig$tabBar;
104
- return tabBarConfig === null || tabBarConfig === void 0 || (_tabBarConfig$tabBar = tabBarConfig.tabBar) === null || _tabBarConfig$tabBar === void 0 || (_tabBarConfig$tabBar = _tabBarConfig$tabBar.list) === null || _tabBarConfig$tabBar === void 0 ? void 0 : _tabBarConfig$tabBar.some(function (item) {
105
- return item.pagePath === pagePath;
106
- });
107
- }
108
- }]);
109
- return TaroRouter;
110
- }();
111
- export var router = new TaroRouter();
112
- export var pageRouter = new Page(router);
@@ -1,52 +0,0 @@
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
- /**
5
- * 待执行指令池
6
- * 结构:Map<组件ID, Map<索引, Record<方法名, 参数数组>>>
7
- */
8
- export var TodoPool = /*#__PURE__*/function () {
9
- function TodoPool() {
10
- _classCallCheck(this, TodoPool);
11
- _defineProperty(this, "pool", new Map());
12
- }
13
- _createClass(TodoPool, [{
14
- key: "push",
15
- value: /** 存:记录待执行指令 */
16
- function push(id, index, method, args) {
17
- if (!this.pool.has(id)) {
18
- this.pool.set(id, new Map());
19
- }
20
- var instances = this.pool.get(id);
21
- if (!instances.has(index)) {
22
- instances.set(index, {});
23
- }
24
- instances.get(index)[method] = args;
25
- }
26
-
27
- /** 取:获取并物理删除指令 */
28
- }, {
29
- key: "pop",
30
- value: function pop(id, index, method) {
31
- var instances = this.pool.get(id);
32
- if (!instances) return undefined;
33
- var todo = instances.get(index);
34
- if (todo && todo[method]) {
35
- var args = todo[method];
36
- delete todo[method];
37
-
38
- // 自动清理:如果当前索引下没指令了,删掉索引容器
39
- if (Object.keys(todo).length === 0) {
40
- instances.delete(index);
41
- }
42
- // 如果当前组件下没索引了,删掉整个 ID
43
- if (instances.size === 0) {
44
- this.pool.delete(id);
45
- }
46
- return args;
47
- }
48
- return undefined;
49
- }
50
- }]);
51
- return TodoPool;
52
- }();
@@ -1,117 +0,0 @@
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
- * 弹窗状态管理(解耦版)
8
- * 弹窗在 Taro 中被视为组件,不走路由栈
9
- */
10
- var PopupStore = /*#__PURE__*/function () {
11
- function PopupStore() {
12
- _classCallCheck(this, PopupStore);
13
- _defineProperty(this, "activePopup", null);
14
- _defineProperty(this, "listeners", new Set());
15
- }
16
- _createClass(PopupStore, [{
17
- key: "subscribe",
18
- value: /** 订阅弹窗状态变化 */
19
- function subscribe(listener) {
20
- var _this = this;
21
- this.listeners.add(listener);
22
- // 返回取消订阅函数
23
- return function () {
24
- _this.listeners.delete(listener);
25
- };
26
- }
27
- }, {
28
- key: "notify",
29
- value: function notify() {
30
- var _this2 = this;
31
- this.listeners.forEach(function (l) {
32
- return l(_this2.activePopup || {
33
- visible: false,
34
- name: '',
35
- value: null,
36
- controller: null
37
- });
38
- });
39
- }
40
-
41
- /** 获取弹窗参数 */
42
- }, {
43
- key: "getParams",
44
- value: function getParams(name) {
45
- if (this.activePopup && this.activePopup.name === name) {
46
- return {
47
- value: this.activePopup.value,
48
- controller: this.activePopup.controller
49
- };
50
- }
51
- return {
52
- value: null
53
- };
54
- }
55
-
56
- /** 获取当前激活的弹窗名称 */
57
- }, {
58
- key: "getActiveName",
59
- value: function getActiveName() {
60
- var _this$activePopup;
61
- return (_this$activePopup = this.activePopup) === null || _this$activePopup === void 0 ? void 0 : _this$activePopup.name;
62
- }
63
-
64
- /** 打开弹窗 */
65
- }, {
66
- key: "push",
67
- value: function push(name, _ref) {
68
- var value = _ref.value,
69
- controller = _ref.controller;
70
- this.activePopup = {
71
- visible: true,
72
- name: name,
73
- value: value,
74
- controller: controller
75
- };
76
- this.notify();
77
- }
78
-
79
- /** 行为同 push */
80
- }, {
81
- key: "replace",
82
- value: function replace(name, params) {
83
- this.push(name, params);
84
- }
85
-
86
- /** 关闭弹窗 */
87
- }, {
88
- key: "pop",
89
- value: function pop() {
90
- this.activePopup = null;
91
- this.notify();
92
- }
93
- }]);
94
- return PopupStore;
95
- }();
96
- var popupStore = new PopupStore();
97
-
98
- /**
99
- * 订阅弹窗状态变化(统一入口,避免外部依赖内部实现细节)
100
- */
101
- export var subscribePopupRouter = function subscribePopupRouter(listener) {
102
- return popupStore.subscribe(listener);
103
- };
104
-
105
- /** 弹窗控制器(命名与文件名保持一致) */
106
- export var popupRouter = new Page(popupStore);
107
-
108
- /**
109
- * 关闭当前激活的弹窗(用于 TabBar 点击等场景)
110
- * 不需要知道弹窗 id
111
- */
112
- export var closeActivePopupRouter = function closeActivePopupRouter() {
113
- var name = popupStore.getActiveName();
114
- if (!name) return;
115
- // 走 Page.close,保证 close/commit/cancel 等控制器语义保持一致
116
- popupRouter.close(name);
117
- };