@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
@@ -6,63 +6,40 @@ export default (function (context) {
6
6
  var inputs = context.inputs;
7
7
  var outputs = context.outputs;
8
8
  (_inputs$showToast = inputs.showToast) === null || _inputs$showToast === void 0 || _inputs$showToast.call(inputs, function (val) {
9
- if (data !== null && data !== void 0 && data.dynamic) {
10
- // 动态输入
11
- try {
12
- var _ref, _val$duration, _data$duration, _ref2, _val$mask, _data$mask;
13
- var toastConfig = {
14
- title: typeof val === 'string' ? val : (val === null || val === void 0 ? void 0 : val.title) || data.title || '',
15
- duration: Number(val && _typeof(val) === 'object' ? (_ref = (_val$duration = val === null || val === void 0 ? void 0 : val.duration) !== null && _val$duration !== void 0 ? _val$duration : data.duration) !== null && _ref !== void 0 ? _ref : 1000 : (_data$duration = data.duration) !== null && _data$duration !== void 0 ? _data$duration : 1000),
16
- mask: val && _typeof(val) === 'object' ? (_ref2 = (_val$mask = val === null || val === void 0 ? void 0 : val.mask) !== null && _val$mask !== void 0 ? _val$mask : data.mask) !== null && _ref2 !== void 0 ? _ref2 : false : (_data$mask = data.mask) !== null && _data$mask !== void 0 ? _data$mask : false
17
- };
18
- if (val && _typeof(val) === 'object' && val.icon) {
19
- toastConfig.icon = val.icon;
20
- } else if (data.icon) {
21
- toastConfig.icon = data.icon;
22
- }
23
- if (val && _typeof(val) === 'object' && val.image) {
24
- toastConfig.image = val.image;
25
- } else if (data.image) {
26
- toastConfig.image = data.image;
27
- }
28
- Taro.showToast(toastConfig);
29
- if (data.asynchronous) {
30
- var _ref3, _val$duration2, _data$duration2;
31
- setTimeout(function () {
32
- outputs.afterShowToast(val);
33
- }, Number(val && _typeof(val) === 'object' ? (_ref3 = (_val$duration2 = val === null || val === void 0 ? void 0 : val.duration) !== null && _val$duration2 !== void 0 ? _val$duration2 : data.duration) !== null && _ref3 !== void 0 ? _ref3 : 1000 : (_data$duration2 = data.duration) !== null && _data$duration2 !== void 0 ? _data$duration2 : 1000));
34
- } else {
35
- outputs.afterShowToast(val);
36
- }
37
- } catch (error) {
38
- console.error('显示 Toast 失败:', error);
9
+ try {
10
+ // 构建 Toast 配置
11
+ var toastConfig = {
12
+ title: typeof val === 'string' ? val : (val === null || val === void 0 ? void 0 : val.title) || data.title || '',
13
+ duration: Number(_typeof(val) === 'object' && val !== null && val !== void 0 && val.duration ? val.duration : data.duration || 1000),
14
+ mask: _typeof(val) === 'object' && (val === null || val === void 0 ? void 0 : val.mask) !== undefined ? val.mask : data.mask || false
15
+ };
16
+
17
+ // 图标配置
18
+ if (_typeof(val) === 'object' && val !== null && val !== void 0 && val.icon) {
19
+ toastConfig.icon = val.icon;
20
+ } else if (data.icon) {
21
+ toastConfig.icon = data.icon;
39
22
  }
40
- } else {
41
- // 非动态输入
42
- try {
43
- var _data$mask2;
44
- var _toastConfig = {
45
- title: data.title || '',
46
- duration: Number(data.duration || 1000),
47
- mask: (_data$mask2 = data.mask) !== null && _data$mask2 !== void 0 ? _data$mask2 : false
48
- };
49
- if (data.icon) {
50
- _toastConfig.icon = data.icon;
51
- }
52
- if (data.image) {
53
- _toastConfig.image = data.image;
54
- }
55
- Taro.showToast(_toastConfig);
56
- if (data.asynchronous) {
57
- setTimeout(function () {
58
- outputs.afterShowToast(val);
59
- }, Number(data.duration || 1000));
60
- } else {
61
- outputs.afterShowToast(val);
62
- }
63
- } catch (error) {
64
- console.error('显示 Toast 失败:', error);
23
+
24
+ // 图片配置
25
+ if (_typeof(val) === 'object' && val !== null && val !== void 0 && val.image) {
26
+ toastConfig.image = val.image;
27
+ } else if (data.image) {
28
+ toastConfig.image = data.image;
65
29
  }
30
+ Taro.showToast(toastConfig);
31
+
32
+ // 处理输出回调
33
+ var triggerOutput = function triggerOutput() {
34
+ return outputs.afterShowToast(val);
35
+ };
36
+ if (data.asynchronous) {
37
+ setTimeout(triggerOutput, toastConfig.duration);
38
+ } else {
39
+ triggerOutput();
40
+ }
41
+ } catch (error) {
42
+ console.error('显示 Toast 失败:', error);
66
43
  }
67
44
  });
68
45
  });
@@ -0,0 +1,117 @@
1
+ // 检查浏览器是否支持Web Speech API
2
+ var speechSupported = typeof window !== 'undefined' && 'speechSynthesis' in window;
3
+ var currentUtterance = null;
4
+ export default (function (context) {
5
+ var _inputs$speak, _inputs$stop, _inputs$pause, _inputs$resume;
6
+ var data = context.data;
7
+ var inputs = context.inputs;
8
+ var outputs = context.outputs;
9
+ if (!speechSupported) {
10
+ console.warn('当前环境不支持语音合成功能');
11
+ }
12
+ (_inputs$speak = inputs.speak) === null || _inputs$speak === void 0 || _inputs$speak.call(inputs, function (val) {
13
+ try {
14
+ var text = (val === null || val === void 0 ? void 0 : val.text) || data.text;
15
+ var lang = (val === null || val === void 0 ? void 0 : val.lang) || data.lang || 'zh-CN';
16
+ var rate = (val === null || val === void 0 ? void 0 : val.rate) || data.rate || 1;
17
+ var pitch = (val === null || val === void 0 ? void 0 : val.pitch) || data.pitch || 1;
18
+ var volume = (val === null || val === void 0 ? void 0 : val.volume) || data.volume || 1;
19
+ if (!text) {
20
+ outputs.onFail('待合成的文本不能为空');
21
+ return;
22
+ }
23
+ if (!speechSupported) {
24
+ outputs.onFail('当前环境不支持语音合成功能');
25
+ return;
26
+ }
27
+
28
+ // 如果有正在播放的语音,先停止
29
+ if (currentUtterance && window.speechSynthesis.speaking) {
30
+ window.speechSynthesis.cancel();
31
+ }
32
+ currentUtterance = new SpeechSynthesisUtterance(text);
33
+ currentUtterance.lang = lang;
34
+ currentUtterance.rate = Math.max(0.1, Math.min(10, rate));
35
+ currentUtterance.pitch = Math.max(0, Math.min(2, pitch));
36
+ currentUtterance.volume = Math.max(0, Math.min(1, volume));
37
+ currentUtterance.onstart = function () {
38
+ outputs.onStart({
39
+ text: text,
40
+ lang: lang,
41
+ rate: rate,
42
+ pitch: pitch,
43
+ volume: volume
44
+ });
45
+ };
46
+ currentUtterance.onend = function () {
47
+ outputs.onEnd({
48
+ text: text,
49
+ lang: lang,
50
+ rate: rate,
51
+ pitch: pitch,
52
+ volume: volume
53
+ });
54
+ currentUtterance = null;
55
+ };
56
+ currentUtterance.onerror = function (event) {
57
+ outputs.onError({
58
+ error: event.error,
59
+ text: text,
60
+ message: '语音合成失败'
61
+ });
62
+ currentUtterance = null;
63
+ };
64
+ window.speechSynthesis.speak(currentUtterance);
65
+ outputs.onSuccess({
66
+ text: text,
67
+ lang: lang,
68
+ rate: rate,
69
+ pitch: pitch,
70
+ volume: volume
71
+ });
72
+ } catch (error) {
73
+ console.error('语音合成失败:', error);
74
+ outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '语音合成失败');
75
+ }
76
+ });
77
+ (_inputs$stop = inputs.stop) === null || _inputs$stop === void 0 || _inputs$stop.call(inputs, function () {
78
+ try {
79
+ if (speechSupported && currentUtterance) {
80
+ window.speechSynthesis.cancel();
81
+ currentUtterance = null;
82
+ outputs.onSuccess('已停止语音播放');
83
+ } else {
84
+ outputs.onFail('没有正在播放的语音');
85
+ }
86
+ } catch (error) {
87
+ console.error('停止语音失败:', error);
88
+ outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '停止语音失败');
89
+ }
90
+ });
91
+ (_inputs$pause = inputs.pause) === null || _inputs$pause === void 0 || _inputs$pause.call(inputs, function () {
92
+ try {
93
+ if (speechSupported && window.speechSynthesis.pause) {
94
+ window.speechSynthesis.pause();
95
+ outputs.onSuccess('已暂停语音播放');
96
+ } else {
97
+ outputs.onFail('当前环境不支持暂停功能');
98
+ }
99
+ } catch (error) {
100
+ console.error('暂停语音失败:', error);
101
+ outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '暂停语音失败');
102
+ }
103
+ });
104
+ (_inputs$resume = inputs.resume) === null || _inputs$resume === void 0 || _inputs$resume.call(inputs, function () {
105
+ try {
106
+ if (speechSupported && window.speechSynthesis.resume) {
107
+ window.speechSynthesis.resume();
108
+ outputs.onSuccess('已恢复语音播放');
109
+ } else {
110
+ outputs.onFail('当前环境不支持恢复功能');
111
+ }
112
+ } catch (error) {
113
+ console.error('恢复语音失败:', error);
114
+ outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '恢复语音失败');
115
+ }
116
+ });
117
+ });
@@ -0,0 +1,66 @@
1
+ // 防抖函数实现
2
+ function debounce(func, delay) {
3
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4
+ var timeoutId = null;
5
+ var lastExecTime = 0;
6
+ var _options$leading = options.leading,
7
+ leading = _options$leading === void 0 ? false : _options$leading,
8
+ _options$trailing = options.trailing,
9
+ trailing = _options$trailing === void 0 ? true : _options$trailing;
10
+ return function () {
11
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12
+ args[_key] = arguments[_key];
13
+ }
14
+ var currentTime = Date.now();
15
+ if (!timeoutId && leading) {
16
+ func.apply(null, args);
17
+ lastExecTime = currentTime;
18
+ }
19
+ if (timeoutId) {
20
+ clearTimeout(timeoutId);
21
+ }
22
+ timeoutId = setTimeout(function () {
23
+ if (trailing && (!leading || currentTime - lastExecTime >= delay)) {
24
+ func.apply(null, args);
25
+ }
26
+ timeoutId = null;
27
+ }, delay);
28
+ };
29
+ }
30
+ export default (function (context) {
31
+ var _inputs$debounce;
32
+ var data = context.data;
33
+ var inputs = context.inputs;
34
+ var outputs = context.outputs;
35
+ var debouncedFn = null;
36
+ (_inputs$debounce = inputs.debounce) === null || _inputs$debounce === void 0 || _inputs$debounce.call(inputs, function (val) {
37
+ try {
38
+ var delay = (val === null || val === void 0 ? void 0 : val.delay) || data.delay || 300;
39
+ var leading = (val === null || val === void 0 ? void 0 : val.leading) !== undefined ? val.leading : data.leading || false;
40
+ var trailing = (val === null || val === void 0 ? void 0 : val.trailing) !== undefined ? val.trailing : data.trailing || true;
41
+ if (!debouncedFn) {
42
+ debouncedFn = debounce(function () {
43
+ outputs.onExecute({
44
+ delay: delay,
45
+ leading: leading,
46
+ trailing: trailing,
47
+ timestamp: Date.now()
48
+ });
49
+ }, delay, {
50
+ leading: leading,
51
+ trailing: trailing
52
+ });
53
+ }
54
+
55
+ // 执行防抖函数
56
+ debouncedFn();
57
+ outputs.onComplete({
58
+ delay: delay,
59
+ leading: leading,
60
+ trailing: trailing
61
+ });
62
+ } catch (error) {
63
+ console.error('防抖执行失败:', error);
64
+ }
65
+ });
66
+ });
@@ -0,0 +1,47 @@
1
+ export default (function (context) {
2
+ var _inputs$delay, _inputs$cancel;
3
+ var data = context.data;
4
+ var inputs = context.inputs;
5
+ var outputs = context.outputs;
6
+ var timeoutId = null;
7
+ (_inputs$delay = inputs.delay) === null || _inputs$delay === void 0 || _inputs$delay.call(inputs, function (val) {
8
+ try {
9
+ var delay = (val === null || val === void 0 ? void 0 : val.delay) || data.delay || 1000;
10
+
11
+ // 清除之前的定时器
12
+ if (timeoutId) {
13
+ clearTimeout(timeoutId);
14
+ }
15
+ outputs.onStart({
16
+ delay: delay,
17
+ timestamp: Date.now()
18
+ });
19
+ timeoutId = setTimeout(function () {
20
+ outputs.onExecute({
21
+ delay: delay,
22
+ timestamp: Date.now()
23
+ });
24
+ timeoutId = null;
25
+ }, delay);
26
+ } catch (error) {
27
+ console.error('延迟执行失败:', error);
28
+ if (timeoutId) {
29
+ clearTimeout(timeoutId);
30
+ timeoutId = null;
31
+ }
32
+ }
33
+ });
34
+ (_inputs$cancel = inputs.cancel) === null || _inputs$cancel === void 0 || _inputs$cancel.call(inputs, function () {
35
+ try {
36
+ if (timeoutId) {
37
+ clearTimeout(timeoutId);
38
+ timeoutId = null;
39
+ outputs.onCancel('延迟任务已取消');
40
+ } else {
41
+ outputs.onCancel('没有正在执行的延迟任务');
42
+ }
43
+ } catch (error) {
44
+ console.error('取消延迟失败:', error);
45
+ }
46
+ });
47
+ });
@@ -0,0 +1,69 @@
1
+ // 节流函数实现
2
+ function throttle(func, delay) {
3
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4
+ var timeoutId = null;
5
+ var lastExecTime = 0;
6
+ var _options$leading = options.leading,
7
+ leading = _options$leading === void 0 ? true : _options$leading,
8
+ _options$trailing = options.trailing,
9
+ trailing = _options$trailing === void 0 ? true : _options$trailing;
10
+ return function () {
11
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12
+ args[_key] = arguments[_key];
13
+ }
14
+ var currentTime = Date.now();
15
+ if (currentTime - lastExecTime > delay) {
16
+ if (leading) {
17
+ func.apply(null, args);
18
+ lastExecTime = currentTime;
19
+ }
20
+ if (timeoutId) {
21
+ clearTimeout(timeoutId);
22
+ timeoutId = null;
23
+ }
24
+ } else if (trailing && !timeoutId) {
25
+ timeoutId = setTimeout(function () {
26
+ func.apply(null, args);
27
+ lastExecTime = Date.now();
28
+ timeoutId = null;
29
+ }, delay - (currentTime - lastExecTime));
30
+ }
31
+ };
32
+ }
33
+ export default (function (context) {
34
+ var _inputs$throttle;
35
+ var data = context.data;
36
+ var inputs = context.inputs;
37
+ var outputs = context.outputs;
38
+ var throttledFn = null;
39
+ (_inputs$throttle = inputs.throttle) === null || _inputs$throttle === void 0 || _inputs$throttle.call(inputs, function (val) {
40
+ try {
41
+ var interval = (val === null || val === void 0 ? void 0 : val.interval) || data.interval || 1000;
42
+ var leading = (val === null || val === void 0 ? void 0 : val.leading) !== undefined ? val.leading : data.leading || true;
43
+ var trailing = (val === null || val === void 0 ? void 0 : val.trailing) !== undefined ? val.trailing : data.trailing || true;
44
+ if (!throttledFn) {
45
+ throttledFn = throttle(function () {
46
+ outputs.onExecute({
47
+ interval: interval,
48
+ leading: leading,
49
+ trailing: trailing,
50
+ timestamp: Date.now()
51
+ });
52
+ }, interval, {
53
+ leading: leading,
54
+ trailing: trailing
55
+ });
56
+ }
57
+
58
+ // 执行节流函数
59
+ throttledFn();
60
+ outputs.onComplete({
61
+ interval: interval,
62
+ leading: leading,
63
+ trailing: trailing
64
+ });
65
+ } catch (error) {
66
+ console.error('节流执行失败:', error);
67
+ }
68
+ });
69
+ });
@@ -0,0 +1,34 @@
1
+ import Taro from '@tarojs/taro';
2
+ export default (function (context) {
3
+ var _inputs$vibrate;
4
+ var data = context.data;
5
+ var inputs = context.inputs;
6
+ var outputs = context.outputs;
7
+ (_inputs$vibrate = inputs.vibrate) === null || _inputs$vibrate === void 0 || _inputs$vibrate.call(inputs, function (val) {
8
+ try {
9
+ var type = (val === null || val === void 0 ? void 0 : val.type) || data.type || 'short';
10
+ if (type === 'long') {
11
+ Taro.vibrateLong({
12
+ success: function success() {
13
+ return outputs.onSuccess('长振动成功');
14
+ },
15
+ fail: function fail(err) {
16
+ return outputs.onFail(err.errMsg || '长振动失败');
17
+ }
18
+ });
19
+ } else {
20
+ Taro.vibrateShort({
21
+ success: function success() {
22
+ return outputs.onSuccess('短振动成功');
23
+ },
24
+ fail: function fail(err) {
25
+ return outputs.onFail(err.errMsg || '短振动失败');
26
+ }
27
+ });
28
+ }
29
+ } catch (error) {
30
+ console.error('设备振动失败:', error);
31
+ outputs.onFail((error === null || error === void 0 ? void 0 : error.message) || '设备振动失败');
32
+ }
33
+ });
34
+ });
@@ -1,3 +1,37 @@
1
+ // 显示提示消息
1
2
  export { default as mybricks_taro_showToast } from "./_ShowToast";
3
+ // 扫码
2
4
  export { default as mybricks_taro_scanQrcode } from "./_ScanQrcode";
3
- export { default as mybricks_taro_setStorage } from "./_SetStorage";
5
+ // 本地存储
6
+ export { default as mybricks_taro_setStorage } from "./_SetStorage";
7
+ export { default as mybricks_taro_getStorage } from "./_GetStorage";
8
+ export { default as mybricks_taro_removeStorage } from "./_RemoveStorage";
9
+ // 地理位置
10
+ export { default as mybricks_taro_getLocation } from "./_GetLocation";
11
+ // 设备功能
12
+ export { default as mybricks_taro_vibrate } from "./_Vibrate";
13
+ export { default as mybricks_taro_callPhone } from "./_CallPhone";
14
+ export { default as mybricks_taro_openCamera } from "./_OpenCamera";
15
+ // 系统功能
16
+ export { default as mybricks_taro_openUrl } from "./_OpenUrl";
17
+ export { default as mybricks_taro_share } from "./_Share";
18
+ export { default as mybricks_taro_getSystemInfo } from "./_GetSystemInfo";
19
+ // 数据处理
20
+ export { default as mybricks_taro_aesEncode } from "./_AesEncode";
21
+ export { default as mybricks_taro_format } from "./_Format";
22
+ // 文件和媒体
23
+ export { default as mybricks_taro_chooseFile } from "./_ChooseFile";
24
+ export { default as mybricks_taro_chooseMedia } from "./_ChooseMedia";
25
+ // 网络请求
26
+ export { default as mybricks_taro_connector } from "./_Connector";
27
+ export { default as mybricks_taro_connectorGlobalHeaders } from "./_ConnectorGlobalHeaders";
28
+ // 导航和路由
29
+ export { default as mybricks_taro_backTo } from "./_BackTo";
30
+ export { default as mybricks_taro_router } from "./_Router";
31
+ export { default as mybricks_taro_openPetalMap } from "./_OpenPetalMap";
32
+ // 语音和多媒体
33
+ export { default as mybricks_taro_textToSpeech } from "./_TextToSpeech";
34
+ // 定时器
35
+ export { default as mybricks_taro_timerDebounce } from "./_TimerDebounce";
36
+ export { default as mybricks_taro_timerDelay } from "./_TimerDelay";
37
+ export { default as mybricks_taro_timerThrottle } from "./_TimerThrottle";
@@ -1,5 +1,5 @@
1
1
  import { createContext, useContext } from 'react';
2
- export { page } from "./page";
2
+ export { pageRouter } from "./pageRouter";
3
3
  var ComContext = /*#__PURE__*/createContext(undefined);
4
4
  export function useAppContext() {
5
5
  var context = useContext(ComContext);
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { View } from '@tarojs/components';
3
+ import { useAppContext } from "./ComContext";
4
+ export var PopupRenderer = function PopupRenderer(_ref) {
5
+ var popupMap = _ref.popupMap;
6
+ var _useAppContext = useAppContext(),
7
+ popupState = _useAppContext.popupState;
8
+ var ActivePopup = popupState.visible && popupMap[popupState.name] ? popupMap[popupState.name] : null;
9
+ if (!ActivePopup) return null;
10
+ return /*#__PURE__*/React.createElement(View, {
11
+ className: "global-popup-container",
12
+ style: {
13
+ position: 'fixed',
14
+ top: 0,
15
+ left: 0,
16
+ right: 0,
17
+ bottom: 0,
18
+ zIndex: 999999,
19
+ pointerEvents: 'auto'
20
+ }
21
+ }, /*#__PURE__*/React.createElement(View, {
22
+ style: {
23
+ width: '100%',
24
+ height: '100%'
25
+ }
26
+ }, /*#__PURE__*/React.createElement(ActivePopup, null)));
27
+ };
@@ -1,7 +1,8 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
3
  import _typeof from "@babel/runtime/helpers/esm/typeof";
3
4
  import { useState, useRef, useMemo } from 'react';
4
- import { SUBJECT_SUBSCRIBE } from "../mybricks/constant";
5
+ import { createReactiveInputHandler } from "../mybricks/createReactiveInputHandler";
5
6
 
6
7
  /**
7
8
  * 深度代理,支持自动路径初始化和响应式更新(鸿蒙化处理方案)
@@ -18,12 +19,8 @@ export function deepProxy(target, onSet) {
18
19
  };
19
20
  var value = obj[prop];
20
21
 
21
- // 只有在访问不存在的对象属性时,才自动创建(实现类似 ensure 的效果)
22
- // 特意排除 MyBricks 内置的方法名,以便在生成代码中进行初始化判断
23
- var mybricksMethods = ['get', 'set', 'changed', 'reset', 'registerChange', 'call', 'apply', 'bind', 'push', 'pop'];
24
- if (value === undefined && typeof prop === 'string' && !mybricksMethods.includes(prop)) {
25
- value = obj[prop] = {};
26
- }
22
+ // 只代理已存在的对象属性,不自动创建空对象
23
+ // 避免访问不存在的属性(如 disabled)时污染原始数据
27
24
  if (_typeof(value) === 'object' && value !== null && !value.__isProxy) {
28
25
  obj[prop] = deepProxy(value, onSet);
29
26
  }
@@ -47,8 +44,13 @@ export function useModel(rawData) {
47
44
  });
48
45
  }, []);
49
46
  }
50
- export function useBindInputs(scope, id) {
51
- var handlersRef = useRef({});
47
+ export function useBindInputs(scope, id, initialHandlers) {
48
+ var handlersRef = useRef(_objectSpread({}, initialHandlers));
49
+
50
+ // 同步最新的 initialHandlers
51
+ if (initialHandlers) {
52
+ Object.assign(handlersRef.current, initialHandlers);
53
+ }
52
54
  return useMemo(function () {
53
55
  var proxy = new Proxy({}, {
54
56
  get: function get(_target, pin) {
@@ -60,14 +62,20 @@ export function useBindInputs(scope, id) {
60
62
  // 逻辑流触发输入
61
63
  var handler = handlersRef.current[pin];
62
64
  if (typeof handler === 'function') {
63
- if (arg && arg[SUBJECT_SUBSCRIBE]) {
64
- // 如果传入的是 Subject,自动订阅并触发回调
65
- arg[SUBJECT_SUBSCRIBE](function (val) {
66
- handler(val);
67
- });
68
- } else {
69
- handler(arg);
65
+ if (pin === '_setData') {
66
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
67
+ args[_key - 1] = arguments[_key];
68
+ }
69
+ return handler.apply(void 0, [arg].concat(args));
70
70
  }
71
+ // 构造 createReactiveInputHandler 需要的参数
72
+ return createReactiveInputHandler({
73
+ input: handler,
74
+ value: arg,
75
+ rels: {},
76
+ // 这里可以扩展 output 关联
77
+ title: id
78
+ });
71
79
  }
72
80
  }
73
81
  };
@@ -1,6 +1,8 @@
1
1
  export * from "./hooks";
2
2
  export { WithCom, WithWrapper } from "./with";
3
- export { page } from "./page";
3
+ export { PopupRenderer } from "./PopupRenderer";
4
+ export { pageRouter, router } from "./pageRouter";
5
+ export { popupRouter, subscribePopupRouter, closeActivePopupRouter } from "./popupRouter";
4
6
  export { useAppContext } from "./ComContext";
5
7
  export { createVariable, createFx, merge } from "../mybricks";
6
8
  export { SUBJECT_SUBSCRIBE, SUBJECT_VALUE } from "../mybricks/constant";
@@ -0,0 +1,69 @@
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
+ // @ts-ignore 运行时由宿主项目提供 @tarojs/taro
5
+ import Taro from '@tarojs/taro';
6
+ import { Page } from "../mybricks";
7
+
8
+ /**
9
+ * Taro 路由驱动 (纯粹版)
10
+ * 只负责处理真正的 Taro 页面跳转
11
+ */
12
+ var TaroRouter = /*#__PURE__*/function () {
13
+ function TaroRouter() {
14
+ _classCallCheck(this, TaroRouter);
15
+ _defineProperty(this, "paramsBackup", {});
16
+ }
17
+ _createClass(TaroRouter, [{
18
+ key: "getParams",
19
+ value: function getParams(name) {
20
+ var _instance$router;
21
+ var instance = Taro.getCurrentInstance();
22
+ var params = ((_instance$router = instance.router) === null || _instance$router === void 0 ? void 0 : _instance$router.params) || {};
23
+
24
+ // 备份参数,解决某些生命周期下 Taro 获取不到 params 的问题
25
+ if (!params.data && this.paramsBackup[name]) {
26
+ params = {
27
+ data: this.paramsBackup[name]
28
+ };
29
+ }
30
+ return {
31
+ value: params
32
+ };
33
+ }
34
+ }, {
35
+ key: "push",
36
+ value: function push(name, _ref) {
37
+ var value = _ref.value;
38
+ var url = "/pages/".concat(name, "/index");
39
+ var dataStr = value ? encodeURIComponent(JSON.stringify(value)) : '';
40
+ if (dataStr) {
41
+ this.paramsBackup[name] = dataStr;
42
+ }
43
+ Taro.navigateTo({
44
+ url: "".concat(url).concat(dataStr ? "?data=".concat(dataStr) : '')
45
+ });
46
+ }
47
+ }, {
48
+ key: "replace",
49
+ value: function replace(name, _ref2) {
50
+ var value = _ref2.value;
51
+ var url = "/pages/".concat(name, "/index");
52
+ var dataStr = value ? encodeURIComponent(JSON.stringify(value)) : '';
53
+ if (dataStr) {
54
+ this.paramsBackup[name] = dataStr;
55
+ }
56
+ Taro.redirectTo({
57
+ url: "".concat(url).concat(dataStr ? "?data=".concat(dataStr) : '')
58
+ });
59
+ }
60
+ }, {
61
+ key: "pop",
62
+ value: function pop() {
63
+ Taro.navigateBack();
64
+ }
65
+ }]);
66
+ return TaroRouter;
67
+ }();
68
+ export var router = new TaroRouter();
69
+ export var pageRouter = new Page(router);