@tarojs/taro-h5 3.5.0-beta.0 → 3.5.0-beta.3

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.
@@ -1,4 +1,35 @@
1
+ import Taro from '@tarojs/api';
2
+ import { parse } from 'query-string';
1
3
  import { temporarilyNotSupport } from '../../../utils';
4
+ import { CallbackManager } from '../../../utils/handler';
5
+ const appShowCallbackManager = new CallbackManager();
6
+ const appHideCallbackManager = new CallbackManager();
7
+ const getApp = () => {
8
+ var _a;
9
+ const path = (_a = Taro.Current.page) === null || _a === void 0 ? void 0 : _a.path;
10
+ return {
11
+ /** 小程序切前台的路径 */
12
+ path: path === null || path === void 0 ? void 0 : path.substring(0, path.indexOf('?')),
13
+ /** 小程序切前台的 query 参数 */
14
+ query: parse(location.search),
15
+ /** 来源信息。 */
16
+ referrerInfo: {},
17
+ /** 小程序切前台的[场景值](https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/scene.html) */
18
+ scene: 0,
19
+ /** shareTicket,详见[获取更多转发信息](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html) */
20
+ shareTicket: ''
21
+ };
22
+ };
23
+ const appShowListener = () => {
24
+ if (document.visibilityState !== 'hidden') {
25
+ appShowCallbackManager.trigger(getApp());
26
+ }
27
+ };
28
+ const appHideListener = () => {
29
+ if (document.visibilityState === 'hidden') {
30
+ appHideCallbackManager.trigger(getApp());
31
+ }
32
+ };
2
33
  // 应用级事件
3
34
  export const onUnhandledRejection = temporarilyNotSupport('onUnhandledRejection');
4
35
  export const onThemeChange = temporarilyNotSupport('onThemeChange');
@@ -6,13 +37,33 @@ export const onPageNotFound = temporarilyNotSupport('onPageNotFound');
6
37
  export const onError = temporarilyNotSupport('onError');
7
38
  export const onAudioInterruptionEnd = temporarilyNotSupport('onAudioInterruptionEnd');
8
39
  export const onAudioInterruptionBegin = temporarilyNotSupport('onAudioInterruptionBegin');
9
- export const onAppShow = temporarilyNotSupport('onAppShow');
10
- export const onAppHide = temporarilyNotSupport('onAppHide');
40
+ export const onAppShow = callback => {
41
+ appShowCallbackManager.add(callback);
42
+ if (appShowCallbackManager.count() === 1) {
43
+ window.addEventListener('visibilitychange', appShowListener);
44
+ }
45
+ };
46
+ export const onAppHide = callback => {
47
+ appHideCallbackManager.add(callback);
48
+ if (appHideCallbackManager.count() === 1) {
49
+ window.addEventListener('visibilitychange', appHideListener);
50
+ }
51
+ };
11
52
  export const offUnhandledRejection = temporarilyNotSupport('offUnhandledRejection');
12
53
  export const offThemeChange = temporarilyNotSupport('offThemeChange');
13
54
  export const offPageNotFound = temporarilyNotSupport('offPageNotFound');
14
55
  export const offError = temporarilyNotSupport('offError');
15
56
  export const offAudioInterruptionEnd = temporarilyNotSupport('offAudioInterruptionEnd');
16
57
  export const offAudioInterruptionBegin = temporarilyNotSupport('offAudioInterruptionBegin');
17
- export const offAppShow = temporarilyNotSupport('offAppShow');
18
- export const offAppHide = temporarilyNotSupport('offAppHide');
58
+ export const offAppShow = callback => {
59
+ appShowCallbackManager.remove(callback);
60
+ if (appShowCallbackManager.count() === 0) {
61
+ window.removeEventListener('visibilitychange', appShowListener);
62
+ }
63
+ };
64
+ export const offAppHide = callback => {
65
+ appHideCallbackManager.remove(callback);
66
+ if (appHideCallbackManager.count() === 0) {
67
+ window.removeEventListener('visibilitychange', appHideListener);
68
+ }
69
+ };
@@ -63,7 +63,7 @@ export class InnerAudioContext {
63
63
  get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
64
64
  set loop(e) { this.setProperty('loop', e); }
65
65
  get loop() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.loop) || false; }
66
- get paused() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) || true; }
66
+ get paused() { var _a, _b; return (_b = (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) !== null && _b !== void 0 ? _b : true; }
67
67
  set src(e) { this.setProperty('src', e); }
68
68
  get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
69
69
  set volume(e) { this.setProperty('volume', e); }
@@ -21,7 +21,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
21
21
  callbackManager.progressUpdate.trigger({
22
22
  progress: Math.round(loaded / total * 100),
23
23
  totalBytesSent: loaded,
24
- totalBytesExpectedToSent: total
24
+ totalBytesExpectedToSend: total
25
25
  });
26
26
  };
27
27
  xhr.onreadystatechange = () => {
package/dist/index.cjs.js CHANGED
@@ -83,12 +83,8 @@ function shouldBeObject(target) {
83
83
  };
84
84
  }
85
85
  function findDOM(inst) {
86
- const runtimeHooks = runtime.container.get(runtime.SERVICE_IDENTIFIER.Hooks);
87
- if (inst) {
88
- const find = runtimeHooks.getDOMNode;
89
- if (typeof find === 'function') {
90
- return find(inst);
91
- }
86
+ if (inst && runtime.hooks.isExist('getDOMNode')) {
87
+ return runtime.hooks.call('getDOMNode', inst);
92
88
  }
93
89
  const page = runtime.Current.page;
94
90
  const path = page === null || page === void 0 ? void 0 : page.path;
@@ -759,6 +755,34 @@ const getSystemInfo = (options = {}) => __awaiter(void 0, void 0, void 0, functi
759
755
  const updateWeChatApp = temporarilyNotSupport('updateWeChatApp');
760
756
  const getUpdateManager = temporarilyNotSupport('getUpdateManager');
761
757
 
758
+ const appShowCallbackManager = new CallbackManager();
759
+ const appHideCallbackManager = new CallbackManager();
760
+ const getApp$1 = () => {
761
+ var _a;
762
+ const path = (_a = Taro__default["default"].Current.page) === null || _a === void 0 ? void 0 : _a.path;
763
+ return {
764
+ /** 小程序切前台的路径 */
765
+ path: path === null || path === void 0 ? void 0 : path.substring(0, path.indexOf('?')),
766
+ /** 小程序切前台的 query 参数 */
767
+ query: queryString.parse(location.search),
768
+ /** 来源信息。 */
769
+ referrerInfo: {},
770
+ /** 小程序切前台的[场景值](https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/scene.html) */
771
+ scene: 0,
772
+ /** shareTicket,详见[获取更多转发信息](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html) */
773
+ shareTicket: ''
774
+ };
775
+ };
776
+ const appShowListener = () => {
777
+ if (document.visibilityState !== 'hidden') {
778
+ appShowCallbackManager.trigger(getApp$1());
779
+ }
780
+ };
781
+ const appHideListener = () => {
782
+ if (document.visibilityState === 'hidden') {
783
+ appHideCallbackManager.trigger(getApp$1());
784
+ }
785
+ };
762
786
  // 应用级事件
763
787
  const onUnhandledRejection = temporarilyNotSupport('onUnhandledRejection');
764
788
  const onThemeChange = temporarilyNotSupport('onThemeChange');
@@ -766,16 +790,36 @@ const onPageNotFound = temporarilyNotSupport('onPageNotFound');
766
790
  const onError = temporarilyNotSupport('onError');
767
791
  const onAudioInterruptionEnd = temporarilyNotSupport('onAudioInterruptionEnd');
768
792
  const onAudioInterruptionBegin = temporarilyNotSupport('onAudioInterruptionBegin');
769
- const onAppShow = temporarilyNotSupport('onAppShow');
770
- const onAppHide = temporarilyNotSupport('onAppHide');
793
+ const onAppShow = callback => {
794
+ appShowCallbackManager.add(callback);
795
+ if (appShowCallbackManager.count() === 1) {
796
+ window.addEventListener('visibilitychange', appShowListener);
797
+ }
798
+ };
799
+ const onAppHide = callback => {
800
+ appHideCallbackManager.add(callback);
801
+ if (appHideCallbackManager.count() === 1) {
802
+ window.addEventListener('visibilitychange', appHideListener);
803
+ }
804
+ };
771
805
  const offUnhandledRejection = temporarilyNotSupport('offUnhandledRejection');
772
806
  const offThemeChange = temporarilyNotSupport('offThemeChange');
773
807
  const offPageNotFound = temporarilyNotSupport('offPageNotFound');
774
808
  const offError = temporarilyNotSupport('offError');
775
809
  const offAudioInterruptionEnd = temporarilyNotSupport('offAudioInterruptionEnd');
776
810
  const offAudioInterruptionBegin = temporarilyNotSupport('offAudioInterruptionBegin');
777
- const offAppShow = temporarilyNotSupport('offAppShow');
778
- const offAppHide = temporarilyNotSupport('offAppHide');
811
+ const offAppShow = callback => {
812
+ appShowCallbackManager.remove(callback);
813
+ if (appShowCallbackManager.count() === 0) {
814
+ window.removeEventListener('visibilitychange', appShowListener);
815
+ }
816
+ };
817
+ const offAppHide = callback => {
818
+ appHideCallbackManager.remove(callback);
819
+ if (appHideCallbackManager.count() === 0) {
820
+ window.removeEventListener('visibilitychange', appHideListener);
821
+ }
822
+ };
779
823
 
780
824
  // 生命周期
781
825
  const getLaunchOptionsSync = temporarilyNotSupport('getLaunchOptionsSync');
@@ -2097,7 +2141,7 @@ class InnerAudioContext {
2097
2141
  get duration() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.duration) || 0; }
2098
2142
  set loop(e) { this.setProperty('loop', e); }
2099
2143
  get loop() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.loop) || false; }
2100
- get paused() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) || true; }
2144
+ get paused() { var _a, _b; return (_b = (_a = this.Instance) === null || _a === void 0 ? void 0 : _a.paused) !== null && _b !== void 0 ? _b : true; }
2101
2145
  set src(e) { this.setProperty('src', e); }
2102
2146
  get src() { var _a; return ((_a = this.Instance) === null || _a === void 0 ? void 0 : _a.src) || ''; }
2103
2147
  set volume(e) { this.setProperty('volume', e); }
@@ -2906,7 +2950,7 @@ const createUploadTask = ({ url, filePath, formData = {}, name, header, timeout,
2906
2950
  callbackManager.progressUpdate.trigger({
2907
2951
  progress: Math.round(loaded / total * 100),
2908
2952
  totalBytesSent: loaded,
2909
- totalBytesExpectedToSent: total
2953
+ totalBytesExpectedToSend: total
2910
2954
  });
2911
2955
  };
2912
2956
  xhr.onreadystatechange = () => {