@mybricks/to-code-taro 1.1.4 → 1.1.6

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 (169) hide show
  1. package/dist/cjs/core/mybricks/Subject.js +9 -5
  2. package/dist/cjs/core/mybricks/createJSHandle.js +45 -4
  3. package/dist/cjs/core/utils/comRefResolver.js +112 -0
  4. package/dist/cjs/core/utils/event.js +53 -0
  5. package/dist/cjs/core/utils/hooks.js +76 -39
  6. package/dist/cjs/core/utils/index.js +6 -0
  7. package/dist/cjs/core/utils/pageRouter.js +34 -11
  8. package/dist/cjs/core/utils/pool.js +63 -0
  9. package/dist/cjs/core/utils/slots.js +59 -13
  10. package/dist/cjs/core/utils/tabbar.js +56 -0
  11. package/dist/cjs/core/utils/useContext.js +46 -4
  12. package/dist/cjs/core/utils/with.js +9 -34
  13. package/dist/cjs/generate/generateTaroProjectJson.js +11 -18
  14. package/dist/cjs/generate/utils/appConfig.d.ts +1 -1
  15. package/dist/cjs/generate/utils/appConfig.js +23 -12
  16. package/dist/cjs/generate/utils/commonDir.js +9 -0
  17. package/dist/cjs/generate/utils/customTabBar.d.ts +11 -0
  18. package/dist/cjs/generate/utils/customTabBar.js +73 -0
  19. package/dist/cjs/generate/utils/fileNode.d.ts +4 -0
  20. package/dist/cjs/generate/utils/fileNode.js +12 -2
  21. package/dist/cjs/handleCom.js +15 -16
  22. package/dist/cjs/handleGlobal.d.ts +1 -1
  23. package/dist/cjs/handleGlobal.js +6 -0
  24. package/dist/cjs/handleSlot.js +4 -9
  25. package/dist/cjs/processors/processScene.js +13 -1
  26. package/dist/cjs/processors/processSceneLogic.js +2 -6
  27. package/dist/cjs/taro-template.json +1318 -1016
  28. package/dist/cjs/toCodeTaro.d.ts +1 -2
  29. package/dist/cjs/toCodeTaro.js +2 -0
  30. package/dist/cjs/utils/builder/buildResult.d.ts +1 -0
  31. package/dist/cjs/utils/builder/buildResult.js +54 -2
  32. package/dist/cjs/utils/common/ImportManager.d.ts +7 -0
  33. package/dist/cjs/utils/common/ImportManager.js +19 -1
  34. package/dist/cjs/utils/context/buildContext.d.ts +7 -0
  35. package/dist/cjs/utils/context/buildContext.js +11 -0
  36. package/dist/cjs/utils/logic/genJSModules.js +2 -2
  37. package/dist/cjs/utils/logic/handleProcess.js +54 -12
  38. package/dist/cjs/utils/templates/renderManager.js +4 -2
  39. package/dist/esm/core/mybricks/Subject.js +11 -5
  40. package/dist/esm/core/mybricks/createJSHandle.js +57 -6
  41. package/dist/esm/core/utils/comRefResolver.js +134 -0
  42. package/dist/esm/core/utils/event.js +32 -0
  43. package/dist/esm/core/utils/hooks.js +114 -51
  44. package/dist/esm/core/utils/index.js +2 -0
  45. package/dist/esm/core/utils/pageRouter.js +56 -13
  46. package/dist/esm/core/utils/pool.js +52 -0
  47. package/dist/esm/core/utils/slots.js +82 -16
  48. package/dist/esm/core/utils/tabbar.js +47 -0
  49. package/dist/esm/core/utils/useContext.js +53 -4
  50. package/dist/esm/core/utils/with.js +19 -53
  51. package/dist/esm/generate/generateTaroProjectJson.js +14 -20
  52. package/dist/esm/generate/utils/appConfig.d.ts +1 -1
  53. package/dist/esm/generate/utils/appConfig.js +29 -9
  54. package/dist/esm/generate/utils/commonDir.js +13 -0
  55. package/dist/esm/generate/utils/customTabBar.d.ts +11 -0
  56. package/dist/esm/generate/utils/customTabBar.js +52 -0
  57. package/dist/esm/generate/utils/fileNode.d.ts +4 -0
  58. package/dist/esm/generate/utils/fileNode.js +13 -0
  59. package/dist/esm/handleCom.js +24 -21
  60. package/dist/esm/handleGlobal.d.ts +1 -1
  61. package/dist/esm/handleGlobal.js +6 -1
  62. package/dist/esm/handleSlot.js +6 -11
  63. package/dist/esm/processors/processScene.js +23 -3
  64. package/dist/esm/processors/processSceneLogic.js +3 -5
  65. package/dist/esm/taro-template.json +1318 -1016
  66. package/dist/esm/toCodeTaro.d.ts +1 -2
  67. package/dist/esm/toCodeTaro.js +4 -2
  68. package/dist/esm/utils/builder/buildResult.d.ts +1 -0
  69. package/dist/esm/utils/builder/buildResult.js +42 -3
  70. package/dist/esm/utils/common/ImportManager.d.ts +7 -0
  71. package/dist/esm/utils/common/ImportManager.js +42 -14
  72. package/dist/esm/utils/context/buildContext.d.ts +7 -0
  73. package/dist/esm/utils/context/buildContext.js +12 -0
  74. package/dist/esm/utils/logic/genJSModules.js +2 -2
  75. package/dist/esm/utils/logic/handleProcess.js +66 -12
  76. package/dist/esm/utils/templates/renderManager.js +4 -4
  77. package/package.json +1 -1
  78. package/dist/cjs/core/comlib/Index.js +0 -114
  79. package/dist/cjs/core/comlib/_AesEncode.js +0 -115
  80. package/dist/cjs/core/comlib/_BackTo.js +0 -80
  81. package/dist/cjs/core/comlib/_CallPhone.js +0 -58
  82. package/dist/cjs/core/comlib/_ChooseFile.js +0 -103
  83. package/dist/cjs/core/comlib/_ChooseMedia.js +0 -70
  84. package/dist/cjs/core/comlib/_Connector.js +0 -92
  85. package/dist/cjs/core/comlib/_ConnectorGlobalHeaders.js +0 -79
  86. package/dist/cjs/core/comlib/_Format.js +0 -123
  87. package/dist/cjs/core/comlib/_GetLocation.js +0 -60
  88. package/dist/cjs/core/comlib/_GetStorage.js +0 -68
  89. package/dist/cjs/core/comlib/_GetSystemInfo.js +0 -62
  90. package/dist/cjs/core/comlib/_Modal.js +0 -68
  91. package/dist/cjs/core/comlib/_OpenCamera.js +0 -73
  92. package/dist/cjs/core/comlib/_OpenPetalMap.js +0 -49
  93. package/dist/cjs/core/comlib/_OpenUrl.js +0 -62
  94. package/dist/cjs/core/comlib/_RemoveStorage.js +0 -68
  95. package/dist/cjs/core/comlib/_Router.js +0 -100
  96. package/dist/cjs/core/comlib/_ScanQrcode.js +0 -59
  97. package/dist/cjs/core/comlib/_SetStorage.js +0 -67
  98. package/dist/cjs/core/comlib/_Share.js +0 -58
  99. package/dist/cjs/core/comlib/_ShowToast.js +0 -69
  100. package/dist/cjs/core/comlib/_TextToSpeech.js +0 -120
  101. package/dist/cjs/core/comlib/_TimerDebounce.js +0 -72
  102. package/dist/cjs/core/comlib/_TimerDelay.js +0 -88
  103. package/dist/cjs/core/comlib/_TimerThrottle.js +0 -75
  104. package/dist/cjs/core/comlib/_Vibrate.js +0 -60
  105. package/dist/esm/abstractEventTypeDef.d.ts.map +0 -1
  106. package/dist/esm/core/comlib/Index.js +0 -39
  107. package/dist/esm/core/comlib/_AesEncode.js +0 -85
  108. package/dist/esm/core/comlib/_BackTo.js +0 -66
  109. package/dist/esm/core/comlib/_CallPhone.js +0 -30
  110. package/dist/esm/core/comlib/_ChooseFile.js +0 -81
  111. package/dist/esm/core/comlib/_ChooseMedia.js +0 -38
  112. package/dist/esm/core/comlib/_Connector.js +0 -60
  113. package/dist/esm/core/comlib/_ConnectorGlobalHeaders.js +0 -56
  114. package/dist/esm/core/comlib/_Format.js +0 -102
  115. package/dist/esm/core/comlib/_GetLocation.js +0 -26
  116. package/dist/esm/core/comlib/_GetStorage.js +0 -44
  117. package/dist/esm/core/comlib/_GetSystemInfo.js +0 -32
  118. package/dist/esm/core/comlib/_Modal.js +0 -51
  119. package/dist/esm/core/comlib/_OpenCamera.js +0 -44
  120. package/dist/esm/core/comlib/_OpenPetalMap.js +0 -28
  121. package/dist/esm/core/comlib/_OpenUrl.js +0 -36
  122. package/dist/esm/core/comlib/_RemoveStorage.js +0 -42
  123. package/dist/esm/core/comlib/_Router.js +0 -113
  124. package/dist/esm/core/comlib/_ScanQrcode.js +0 -26
  125. package/dist/esm/core/comlib/_SetStorage.js +0 -40
  126. package/dist/esm/core/comlib/_Share.js +0 -28
  127. package/dist/esm/core/comlib/_ShowToast.js +0 -45
  128. package/dist/esm/core/comlib/_TextToSpeech.js +0 -117
  129. package/dist/esm/core/comlib/_TimerDebounce.js +0 -66
  130. package/dist/esm/core/comlib/_TimerDelay.js +0 -79
  131. package/dist/esm/core/comlib/_TimerThrottle.js +0 -69
  132. package/dist/esm/core/comlib/_Vibrate.js +0 -34
  133. package/dist/esm/generate/generateTaroTempalteJson.d.ts.map +0 -1
  134. package/dist/esm/generate/utils/appConfig.d.ts.map +0 -1
  135. package/dist/esm/generate/utils/fileNode.d.ts.map +0 -1
  136. package/dist/esm/generate/utils/index.d.ts.map +0 -1
  137. package/dist/esm/generate/utils/pageImages.d.ts.map +0 -1
  138. package/dist/esm/generate/utils/tabBarImages.d.ts.map +0 -1
  139. package/dist/esm/handleExtension.d.ts.map +0 -1
  140. package/dist/esm/handleModule.d.ts.map +0 -1
  141. package/dist/esm/index.d.ts.map +0 -1
  142. package/dist/esm/processors/processComEvents.d.ts.map +0 -1
  143. package/dist/esm/processors/processModule.d.ts.map +0 -1
  144. package/dist/esm/processors/processScene.d.ts.map +0 -1
  145. package/dist/esm/processors/processSceneLogic.d.ts.map +0 -1
  146. package/dist/esm/toCodeTaro.d.ts.map +0 -1
  147. package/dist/esm/utils/builder/buildResult.d.ts.map +0 -1
  148. package/dist/esm/utils/common/ImportManager.d.ts.map +0 -1
  149. package/dist/esm/utils/common/helper.d.ts.map +0 -1
  150. package/dist/esm/utils/common/object.d.ts.map +0 -1
  151. package/dist/esm/utils/common/string.d.ts.map +0 -1
  152. package/dist/esm/utils/config/content/index.d.ts.map +0 -1
  153. package/dist/esm/utils/config/content/types.d.ts.map +0 -1
  154. package/dist/esm/utils/config/content/validator.d.ts.map +0 -1
  155. package/dist/esm/utils/config/handlePageConfig.d.ts.map +0 -1
  156. package/dist/esm/utils/context/buildContext.d.ts.map +0 -1
  157. package/dist/esm/utils/context/buildFrameMap.d.ts.map +0 -1
  158. package/dist/esm/utils/context/buildGlobalData.d.ts.map +0 -1
  159. package/dist/esm/utils/context/collectJSModules.d.ts.map +0 -1
  160. package/dist/esm/utils/context/createEventQueries.d.ts.map +0 -1
  161. package/dist/esm/utils/context/createProvider.d.ts.map +0 -1
  162. package/dist/esm/utils/index.d.ts.map +0 -1
  163. package/dist/esm/utils/logic/convertNamespace.d.ts.map +0 -1
  164. package/dist/esm/utils/logic/genJSModules.d.ts.map +0 -1
  165. package/dist/esm/utils/style/color.d.ts.map +0 -1
  166. package/dist/esm/utils/style/getComponentClassName.d.ts.map +0 -1
  167. package/dist/esm/utils/style/pxtransform.d.ts.map +0 -1
  168. package/dist/esm/utils/style/types.d.ts.map +0 -1
  169. package/dist/esm/utils/templates/component.d.ts.map +0 -1
@@ -31,16 +31,20 @@ var Subject = class {
31
31
  _empty = true;
32
32
  constructor(params = {}) {
33
33
  this._log = params.log;
34
+ this._subjectNextCache = {};
34
35
  return new Proxy(this, {
35
36
  get(target, prop) {
36
37
  if (prop in target) {
37
38
  return target[prop];
38
39
  }
39
- const subjectNext = new SubjectNext(prop);
40
- target[import_constant.SUBJECT_SUBSCRIBE]((value, extra) => {
41
- subjectNext[import_constant.SUBJECT_NEXT](value, extra);
42
- });
43
- return subjectNext;
40
+ if (!target._subjectNextCache[prop]) {
41
+ const subjectNext = new SubjectNext(prop);
42
+ target[import_constant.SUBJECT_SUBSCRIBE]((value, extra) => {
43
+ subjectNext[import_constant.SUBJECT_NEXT](value, extra);
44
+ });
45
+ target._subjectNextCache[prop] = subjectNext;
46
+ }
47
+ return target._subjectNextCache[prop];
44
48
  }
45
49
  });
46
50
  }
@@ -30,9 +30,34 @@ var import_createReactiveInputHandler = require("./createReactiveInputHandler");
30
30
  var validateJsMultipleInputs = (input) => {
31
31
  return input.match(/\./);
32
32
  };
33
- var createJSHandle = (fn, options) => {
34
- let controller;
33
+ var handleCache = /* @__PURE__ */ new Map();
34
+ var getFromCache = (handleKey) => {
35
+ if (!handleKey || !handleCache.has(handleKey))
36
+ return null;
37
+ const cached = handleCache.get(handleKey);
38
+ if (cached._rels) {
39
+ Object.values(cached._rels).forEach((subject) => {
40
+ var _a, _b;
41
+ (_b = (_a = subject._observers) == null ? void 0 : _a.clear) == null ? void 0 : _b.call(_a);
42
+ subject._values = [];
43
+ subject._empty = true;
44
+ });
45
+ }
46
+ return cached;
47
+ };
48
+ var setToCache = (handleKey, exe, rels, needsCache) => {
49
+ exe._rels = rels;
50
+ if (handleKey && needsCache) {
51
+ handleCache.set(handleKey, exe);
52
+ }
53
+ };
54
+ var createJSHandle = (fn, options, handleKey) => {
35
55
  const { props, appContext } = options;
56
+ const cached = getFromCache(handleKey);
57
+ if (cached)
58
+ return cached;
59
+ const needsCache = fn.__useCache === true;
60
+ let controller;
36
61
  const inputs = new Proxy({}, {
37
62
  getOwnPropertyDescriptor() {
38
63
  return {
@@ -71,17 +96,24 @@ var createJSHandle = (fn, options) => {
71
96
  inputs,
72
97
  outputs,
73
98
  logger: import_log.logger,
74
- env: appContext == null ? void 0 : appContext.env
99
+ env: appContext == null ? void 0 : appContext.env,
100
+ appContext
75
101
  });
76
102
  const isJsMultipleInputs = props.inputs[0] ? validateJsMultipleInputs(props.inputs[0]) : false;
103
+ const exeOutputsCache = {};
77
104
  const exeOutputs = new Proxy(
78
105
  {},
79
106
  {
80
107
  get(_, key) {
81
- return rels[key] || (rels[key] = new import_Subject.Subject({ log: `${import_constant.EXE_TITLE_MAP["output"]} ${props.title} | ${key}` }));
108
+ if (!exeOutputsCache[key]) {
109
+ const subject = rels[key] || (rels[key] = new import_Subject.Subject({ log: `${import_constant.EXE_TITLE_MAP["output"]} ${props.title} | ${key}` }));
110
+ exeOutputsCache[key] = subject;
111
+ }
112
+ return exeOutputsCache[key];
82
113
  }
83
114
  }
84
115
  );
116
+ const subscribedSubjects = /* @__PURE__ */ new Set();
85
117
  const exe = (...args) => {
86
118
  if (args.length) {
87
119
  if (isJsMultipleInputs) {
@@ -89,6 +121,10 @@ var createJSHandle = (fn, options) => {
89
121
  let valueAry = {};
90
122
  args.forEach((value, index) => {
91
123
  if (value == null ? void 0 : value[import_constant.SUBJECT_SUBSCRIBE]) {
124
+ if (subscribedSubjects.has(value)) {
125
+ return;
126
+ }
127
+ subscribedSubjects.add(value);
92
128
  value[import_constant.SUBJECT_SUBSCRIBE]((value2) => {
93
129
  (0, import_log.log)(`${import_constant.EXE_TITLE_MAP["input"]} ${props.title} | ${props.inputs[index]}`, JSON.stringify(value2));
94
130
  valueAry[props.inputs[index]] = value2;
@@ -119,6 +155,10 @@ var createJSHandle = (fn, options) => {
119
155
  } else {
120
156
  const value = args[0];
121
157
  if (value == null ? void 0 : value[import_constant.SUBJECT_SUBSCRIBE]) {
158
+ if (subscribedSubjects.has(value)) {
159
+ return exeOutputs;
160
+ }
161
+ subscribedSubjects.add(value);
122
162
  value[import_constant.SUBJECT_SUBSCRIBE]((value2) => {
123
163
  (0, import_log.log)(`${import_constant.EXE_TITLE_MAP["input"]} ${props.title} | ${props.inputs[0]}`, JSON.stringify(value2));
124
164
  (0, import_createReactiveInputHandler.createReactiveInputHandler)({
@@ -141,6 +181,7 @@ var createJSHandle = (fn, options) => {
141
181
  }
142
182
  return exeOutputs;
143
183
  };
184
+ setToCache(handleKey, exe, rels, needsCache);
144
185
  return exe;
145
186
  };
146
187
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,112 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/core/utils/comRefResolver.ts
20
+ var comRefResolver_exports = {};
21
+ __export(comRefResolver_exports, {
22
+ ComRefResolver: () => ComRefResolver
23
+ });
24
+ module.exports = __toCommonJS(comRefResolver_exports);
25
+ var import_pool = require("./pool");
26
+ var ComRefResolver = class {
27
+ constructor(registry, parent, todoPool, scopeIndex = 0) {
28
+ this.registry = registry;
29
+ this.parent = parent;
30
+ this.todoPool = todoPool;
31
+ this.scopeIndex = scopeIndex;
32
+ }
33
+ /**
34
+ * 获取组件引用
35
+ * @returns 真实引用或影子对象
36
+ */
37
+ get(id) {
38
+ var _a, _b;
39
+ if (this.registry[id] && !this.registry[id].__isShadow) {
40
+ return this.registry[id];
41
+ }
42
+ const parentRef = (_a = this.parent) == null ? void 0 : _a.findRealRef(id);
43
+ if (parentRef) {
44
+ return parentRef;
45
+ }
46
+ if ((_b = this.registry[id]) == null ? void 0 : _b.__isShadow) {
47
+ return this.registry[id];
48
+ }
49
+ return this.createShadowProxy(id);
50
+ }
51
+ /**
52
+ * 注册真实引用
53
+ */
54
+ set(id, ref) {
55
+ var _a;
56
+ this.registry[id] = ref;
57
+ (_a = this.parent) == null ? void 0 : _a.set(id, ref);
58
+ }
59
+ /**
60
+ * 删除引用
61
+ */
62
+ delete(id) {
63
+ var _a;
64
+ delete this.registry[id];
65
+ (_a = this.parent) == null ? void 0 : _a.delete(id);
66
+ }
67
+ /**
68
+ * 查找真实引用(仅用于父级链查找)
69
+ */
70
+ findRealRef(id) {
71
+ var _a;
72
+ const local = this.registry[id];
73
+ if (local && !local.__isShadow) {
74
+ return local;
75
+ }
76
+ return ((_a = this.parent) == null ? void 0 : _a.findRealRef(id)) ?? null;
77
+ }
78
+ /**
79
+ * 创建影子对象
80
+ * 关键:影子对象的方法被调用时,会动态查找真实引用
81
+ */
82
+ createShadowProxy(id) {
83
+ const resolver = this;
84
+ const registry = this.registry;
85
+ const todoPool = this.todoPool;
86
+ const scopeIndex = this.scopeIndex;
87
+ const shadow = new Proxy({ __isShadow: true }, {
88
+ get(_, method) {
89
+ if (method === "__isShadow")
90
+ return true;
91
+ return (...args) => {
92
+ const realRef = registry[id];
93
+ if (realRef && !realRef.__isShadow) {
94
+ if (typeof realRef[method] === "function") {
95
+ return realRef[method](...args);
96
+ }
97
+ return;
98
+ }
99
+ if (todoPool instanceof import_pool.TodoPool) {
100
+ todoPool.push(id, scopeIndex, method, args);
101
+ }
102
+ };
103
+ }
104
+ });
105
+ this.registry[id] = shadow;
106
+ return shadow;
107
+ }
108
+ };
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ ComRefResolver
112
+ });
@@ -0,0 +1,53 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/core/utils/event.ts
20
+ var event_exports = {};
21
+ __export(event_exports, {
22
+ EventEmitter: () => EventEmitter
23
+ });
24
+ module.exports = __toCommonJS(event_exports);
25
+ var EventEmitter = class {
26
+ constructor() {
27
+ this.eventsCache = {};
28
+ this.addEventListner = (evtName, listner) => {
29
+ if (!this.eventsCache[evtName]) {
30
+ this.eventsCache[evtName] = /* @__PURE__ */ new Set([listner]);
31
+ return;
32
+ }
33
+ this.eventsCache[evtName].add(listner);
34
+ };
35
+ this.removeEventListner = (evtName, listner) => {
36
+ if (this.eventsCache[evtName]) {
37
+ this.eventsCache[evtName].delete(listner);
38
+ }
39
+ };
40
+ this.dispatch = (evtName, detail) => {
41
+ if (!this.eventsCache[evtName]) {
42
+ return;
43
+ }
44
+ let hasPreventDefault = false;
45
+ (this.eventsCache[evtName] ?? []).forEach((listner) => listner(detail));
46
+ return hasPreventDefault;
47
+ };
48
+ }
49
+ };
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ EventEmitter
53
+ });
@@ -21,14 +21,16 @@ var hooks_exports = {};
21
21
  __export(hooks_exports, {
22
22
  deepProxy: () => deepProxy,
23
23
  proxyRefs: () => proxyRefs,
24
- useBindEvents: () => useBindEvents,
25
24
  useBindInputs: () => useBindInputs,
25
+ useBindOutputs: () => useBindOutputs,
26
+ useBuiltinHandlers: () => useBuiltinHandlers,
26
27
  useModel: () => useModel
27
28
  });
28
29
  module.exports = __toCommonJS(hooks_exports);
29
30
  var import_react = require("react");
30
31
  var import_createReactiveInputHandler = require("../mybricks/createReactiveInputHandler");
31
32
  var import_ComContext = require("./ComContext");
33
+ var import_comRefResolver = require("./comRefResolver");
32
34
  function deepProxy(target, onSet) {
33
35
  if (target === null || typeof target !== "object" || target.__isProxy)
34
36
  return target;
@@ -56,37 +58,31 @@ function useModel(rawData) {
56
58
  const dataRef = (0, import_react.useRef)(rawData || {});
57
59
  return (0, import_react.useMemo)(() => deepProxy(dataRef.current, () => forceUpdate({})), []);
58
60
  }
59
- function proxyRefs(target, parentComRefs, globalTodoPool) {
61
+ function proxyRefs(target, parentComRefs, todoPool) {
62
+ var _a;
63
+ const parentResolver = (_a = parentComRefs == null ? void 0 : parentComRefs.current) == null ? void 0 : _a.__resolver;
64
+ const scopeIndex = target.$index ?? 0;
65
+ const resolver = new import_comRefResolver.ComRefResolver(target, parentResolver, todoPool, scopeIndex);
66
+ target.__resolver = resolver;
60
67
  return new Proxy(target, {
61
68
  get(obj, prop) {
62
69
  if (prop === "__isProxy")
63
70
  return true;
71
+ if (prop === "__resolver")
72
+ return resolver;
64
73
  if (prop === "toJSON")
65
74
  return () => obj;
66
- if (typeof prop === "string" && prop.startsWith("u_") && obj[prop] === void 0) {
67
- return obj[prop] = new Proxy({ __isShadow: true }, {
68
- get(_, method) {
69
- if (method === "__isShadow")
70
- return true;
71
- return (...args) => {
72
- if (!(globalTodoPool instanceof Map))
73
- return;
74
- const instances = globalTodoPool.get(prop) || [];
75
- if (!globalTodoPool.has(prop))
76
- globalTodoPool.set(prop, instances);
77
- const index = obj.$index ?? 0;
78
- const todo = instances[index] || (instances[index] = {});
79
- todo[method] = args;
80
- };
81
- }
82
- });
75
+ if (typeof prop === "string" && prop.startsWith("u_")) {
76
+ return resolver.get(prop);
83
77
  }
84
78
  return obj[prop];
85
79
  },
86
80
  set(obj, prop, value) {
87
81
  const result = Reflect.set(obj, prop, value);
88
82
  const isRealRef = typeof prop === "string" && !prop.startsWith("$") && (value == null ? void 0 : value.__isShadow) !== true;
89
- if (isRealRef && (parentComRefs == null ? void 0 : parentComRefs.current)) {
83
+ if (isRealRef && typeof prop === "string" && prop.startsWith("u_")) {
84
+ resolver.set(prop, value);
85
+ } else if (isRealRef && (parentComRefs == null ? void 0 : parentComRefs.current)) {
90
86
  try {
91
87
  parentComRefs.current[prop] = value;
92
88
  } catch {
@@ -96,8 +92,9 @@ function proxyRefs(target, parentComRefs, globalTodoPool) {
96
92
  },
97
93
  deleteProperty(obj, prop) {
98
94
  const result = Reflect.deleteProperty(obj, prop);
99
- const isRealRef = typeof prop === "string" && !prop.startsWith("$");
100
- if (isRealRef && (parentComRefs == null ? void 0 : parentComRefs.current)) {
95
+ if (typeof prop === "string" && prop.startsWith("u_")) {
96
+ resolver.delete(prop);
97
+ } else if (typeof prop === "string" && !prop.startsWith("$") && (parentComRefs == null ? void 0 : parentComRefs.current)) {
101
98
  try {
102
99
  delete parentComRefs.current[prop];
103
100
  } catch {
@@ -110,7 +107,7 @@ function proxyRefs(target, parentComRefs, globalTodoPool) {
110
107
  function useBindInputs(scope, id, initialHandlers) {
111
108
  var _a, _b;
112
109
  const handlersRef = (0, import_react.useRef)({ ...initialHandlers });
113
- const { globalTodoInputs } = (0, import_ComContext.useAppContext)();
110
+ const { todoPool } = (0, import_ComContext.useAppContext)();
114
111
  const parentSlot = (0, import_ComContext.useParentSlot)();
115
112
  const index = ((_b = (_a = parentSlot == null ? void 0 : parentSlot.params) == null ? void 0 : _a.inputValues) == null ? void 0 : _b.index) ?? 0;
116
113
  (0, import_react.useEffect)(() => {
@@ -125,24 +122,20 @@ function useBindInputs(scope, id, initialHandlers) {
125
122
  get: (target, pin) => {
126
123
  if (pin === "__isShadow")
127
124
  return false;
125
+ if (pin === "__isLazyProxy")
126
+ return false;
128
127
  if (pin === "toJSON")
129
128
  return () => target;
130
129
  return (arg, ...args) => {
131
130
  if (typeof arg === "function") {
132
131
  handlersRef.current[pin] = arg;
133
- const instances = globalTodoInputs == null ? void 0 : globalTodoInputs.get(id);
134
- const todo = (instances == null ? void 0 : instances[index]) || (instances == null ? void 0 : instances[0]);
135
- if (todo == null ? void 0 : todo[pin]) {
136
- const pendingArgs = todo[pin];
132
+ const pendingArgs = todoPool == null ? void 0 : todoPool.pop(id, index, pin);
133
+ if (pendingArgs) {
137
134
  if (pin === "_setData") {
138
135
  arg(...pendingArgs);
139
136
  } else {
140
137
  (0, import_createReactiveInputHandler.createReactiveInputHandler)({ input: arg, value: pendingArgs[0], rels: {}, title: id });
141
138
  }
142
- delete todo[pin];
143
- const hasTasks = instances == null ? void 0 : instances.some((inst) => inst && Object.keys(inst).length > 0);
144
- if (!hasTasks)
145
- globalTodoInputs.delete(id);
146
139
  }
147
140
  } else {
148
141
  const handler = handlersRef.current[pin];
@@ -159,19 +152,44 @@ function useBindInputs(scope, id, initialHandlers) {
159
152
  Object.keys(initialHandlers).forEach((pin) => proxy[pin](initialHandlers[pin]));
160
153
  }
161
154
  return proxy;
162
- }, [scope, id, globalTodoInputs, index]);
155
+ }, [scope, id, todoPool, index]);
163
156
  }
164
- function useBindEvents(props, context) {
157
+ function useBuiltinHandlers(opts) {
158
+ const { data, setDynamicStyle, setShow, isPopup } = opts;
165
159
  return (0, import_react.useMemo)(() => {
160
+ const handlers = {
161
+ _setStyle: (style) => {
162
+ setDynamicStyle((prev) => ({ ...prev, ...style }));
163
+ },
164
+ _setData: (path, value) => {
165
+ const paths = path.split(".");
166
+ let current = data;
167
+ for (let i = 0; i < paths.length - 1; i++) {
168
+ if (!current[paths[i]])
169
+ current[paths[i]] = {};
170
+ current = current[paths[i]];
171
+ }
172
+ current[paths[paths.length - 1]] = value;
173
+ }
174
+ };
175
+ if (!isPopup) {
176
+ Object.assign(handlers, {
177
+ show: () => setShow(true),
178
+ hide: () => setShow(false),
179
+ showOrHide: () => setShow((prev) => !prev)
180
+ });
181
+ }
182
+ return handlers;
183
+ }, [data, setDynamicStyle, setShow, isPopup]);
184
+ }
185
+ function useBindOutputs(comRefs, id, props, enhancedSlots, context) {
186
+ var _a;
187
+ const eventProxy = (0, import_react.useMemo)(() => {
166
188
  const events = {};
167
189
  Object.keys(props).forEach((key) => {
168
190
  if (typeof props[key] === "function") {
169
191
  const handler = props[key];
170
- const wrapped = (original) => {
171
- var _a, _b;
172
- const value = ((_b = (_a = context == null ? void 0 : context.parentSlot) == null ? void 0 : _a.params) == null ? void 0 : _b.itemWrap) ? { id: context.id, name: context.name, value: original } : original;
173
- return handler(value);
174
- };
192
+ const wrapped = (original) => handler(original);
175
193
  wrapped.getConnections = () => [{ id: "default" }];
176
194
  events[key] = wrapped;
177
195
  }
@@ -190,12 +208,31 @@ function useBindEvents(props, context) {
190
208
  }
191
209
  });
192
210
  }, [props, context]);
211
+ if ((_a = comRefs == null ? void 0 : comRefs.current) == null ? void 0 : _a.$outputs) {
212
+ const slotOutputsList = Object.values(enhancedSlots || {}).map((slot) => slot == null ? void 0 : slot.outputs).filter(Boolean);
213
+ if (slotOutputsList.length > 0) {
214
+ comRefs.current.$outputs[id] = new Proxy({}, {
215
+ get(_, prop) {
216
+ for (const outputs of slotOutputsList) {
217
+ const fn = outputs[prop];
218
+ if (fn)
219
+ return fn;
220
+ }
221
+ return eventProxy[prop];
222
+ }
223
+ });
224
+ } else {
225
+ comRefs.current.$outputs[id] = eventProxy;
226
+ }
227
+ }
228
+ return eventProxy;
193
229
  }
194
230
  // Annotate the CommonJS export names for ESM import in node:
195
231
  0 && (module.exports = {
196
232
  deepProxy,
197
233
  proxyRefs,
198
- useBindEvents,
199
234
  useBindInputs,
235
+ useBindOutputs,
236
+ useBuiltinHandlers,
200
237
  useModel
201
238
  });
@@ -20,10 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/core/utils/index.ts
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
+ ComRefResolver: () => import_comRefResolver.ComRefResolver,
23
24
  PopupRenderer: () => import_PopupRenderer.PopupRenderer,
24
25
  SUBJECT_SUBSCRIBE: () => import_constant.SUBJECT_SUBSCRIBE,
25
26
  SUBJECT_VALUE: () => import_constant.SUBJECT_VALUE,
26
27
  SlotProvider: () => import_ComContext.SlotProvider,
28
+ TodoPool: () => import_pool.TodoPool,
27
29
  WithCom: () => import_with.WithCom,
28
30
  WithWrapper: () => import_with.WithWrapper,
29
31
  closeActivePopupRouter: () => import_popupRouter.closeActivePopupRouter,
@@ -39,6 +41,8 @@ __export(utils_exports, {
39
41
  });
40
42
  module.exports = __toCommonJS(utils_exports);
41
43
  __reExport(utils_exports, require("./hooks"), module.exports);
44
+ var import_pool = require("./pool");
45
+ var import_comRefResolver = require("./comRefResolver");
42
46
  var import_with = require("./with");
43
47
  var import_PopupRenderer = require("./PopupRenderer");
44
48
  var import_pageRouter = require("./pageRouter");
@@ -50,10 +54,12 @@ var import_constant = require("../mybricks/constant");
50
54
  __reExport(utils_exports, require("./slots"), module.exports);
51
55
  // Annotate the CommonJS export names for ESM import in node:
52
56
  0 && (module.exports = {
57
+ ComRefResolver,
53
58
  PopupRenderer,
54
59
  SUBJECT_SUBSCRIBE,
55
60
  SUBJECT_VALUE,
56
61
  SlotProvider,
62
+ TodoPool,
57
63
  WithCom,
58
64
  WithWrapper,
59
65
  closeActivePopupRouter,
@@ -34,6 +34,7 @@ __export(pageRouter_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(pageRouter_exports);
36
36
  var import_taro = __toESM(require("@tarojs/taro"));
37
+ var import_tabBar = __toESM(require("@/custom-tab-bar/tabBar.json"));
37
38
  var import_mybricks = require("../mybricks");
38
39
  var TaroRouter = class {
39
40
  constructor() {
@@ -42,35 +43,57 @@ var TaroRouter = class {
42
43
  getParams(name) {
43
44
  var _a;
44
45
  const instance = import_taro.default.getCurrentInstance();
45
- let params = ((_a = instance.router) == null ? void 0 : _a.params) || {};
46
+ const inputParams = ((_a = instance.router) == null ? void 0 : _a.params) || {};
47
+ let params = Object.keys(inputParams).length === 2 && inputParams.data && typeof inputParams.data === "string" ? inputParams : {
48
+ data: Object.keys(inputParams).length > 1 ? JSON.stringify({ ...inputParams, $taroTimestamp: void 0 }) : void 0,
49
+ $taroTimestamp: inputParams.$taroTimestamp
50
+ };
46
51
  if (!params.data && this.paramsBackup[name]) {
47
52
  params = { data: this.paramsBackup[name] };
48
53
  }
49
- return { value: params };
54
+ const paramsDataStr = params.data ? decodeURIComponent(params.data) : void 0;
55
+ let paramsData;
56
+ try {
57
+ paramsData = paramsDataStr ? JSON.parse(paramsDataStr) : void 0;
58
+ } catch (error) {
59
+ paramsData = paramsDataStr;
60
+ }
61
+ return { value: paramsData };
50
62
  }
51
63
  push(name, { value }) {
52
- const url = `/pages/${name}/index`;
53
- const dataStr = value ? encodeURIComponent(JSON.stringify(value)) : "";
54
- if (dataStr) {
55
- this.paramsBackup[name] = dataStr;
56
- }
57
- import_taro.default.navigateTo({
58
- url: `${url}${dataStr ? `?data=${dataStr}` : ""}`
59
- });
64
+ const path = `pages/${name}/index`;
65
+ const navigateType = this.isTabBarPage(path) ? "switchTab" : "navigateTo";
66
+ this.navigate(navigateType, name, { value });
60
67
  }
61
68
  replace(name, { value }) {
69
+ const path = `pages/${name}/index`;
70
+ const navigateType = this.isTabBarPage(path) ? "switchTab" : "redirectTo";
71
+ this.navigate(navigateType, name, { value });
72
+ }
73
+ navigate(type, name, { value }) {
62
74
  const url = `/pages/${name}/index`;
63
75
  const dataStr = value ? encodeURIComponent(JSON.stringify(value)) : "";
64
76
  if (dataStr) {
65
77
  this.paramsBackup[name] = dataStr;
66
78
  }
67
- import_taro.default.redirectTo({
79
+ import_taro.default[type]({
68
80
  url: `${url}${dataStr ? `?data=${dataStr}` : ""}`
69
81
  });
70
82
  }
71
83
  pop() {
72
84
  import_taro.default.navigateBack();
73
85
  }
86
+ /**
87
+ * 判断是否为标签栏页面
88
+ * @param pagePath 页面路径
89
+ * @returns 是否为标签栏页面
90
+ */
91
+ isTabBarPage(pagePath) {
92
+ var _a, _b, _c;
93
+ return (_c = (_b = (_a = import_tabBar.default) == null ? void 0 : _a.tabBar) == null ? void 0 : _b.list) == null ? void 0 : _c.some(
94
+ (item) => item.pagePath === pagePath
95
+ );
96
+ }
74
97
  };
75
98
  var router = new TaroRouter();
76
99
  var pageRouter = new import_mybricks.Page(router);
@@ -0,0 +1,63 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/core/utils/pool.ts
20
+ var pool_exports = {};
21
+ __export(pool_exports, {
22
+ TodoPool: () => TodoPool
23
+ });
24
+ module.exports = __toCommonJS(pool_exports);
25
+ var TodoPool = class {
26
+ constructor() {
27
+ this.pool = /* @__PURE__ */ new Map();
28
+ }
29
+ /** 存:记录待执行指令 */
30
+ push(id, index, method, args) {
31
+ if (!this.pool.has(id)) {
32
+ this.pool.set(id, /* @__PURE__ */ new Map());
33
+ }
34
+ const instances = this.pool.get(id);
35
+ if (!instances.has(index)) {
36
+ instances.set(index, {});
37
+ }
38
+ instances.get(index)[method] = args;
39
+ }
40
+ /** 取:获取并物理删除指令 */
41
+ pop(id, index, method) {
42
+ const instances = this.pool.get(id);
43
+ if (!instances)
44
+ return void 0;
45
+ const todo = instances.get(index);
46
+ if (todo && todo[method]) {
47
+ const args = todo[method];
48
+ delete todo[method];
49
+ if (Object.keys(todo).length === 0) {
50
+ instances.delete(index);
51
+ }
52
+ if (instances.size === 0) {
53
+ this.pool.delete(id);
54
+ }
55
+ return args;
56
+ }
57
+ return void 0;
58
+ }
59
+ };
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ TodoPool
63
+ });