@tarojs/taro-h5 3.4.0-beta.0 → 3.4.0

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 (306) hide show
  1. package/dist/api/ad/index.js +4 -0
  2. package/dist/api/ai/facial.js +5 -0
  3. package/dist/api/ai/index.js +2 -0
  4. package/dist/api/ai/visual.js +3 -0
  5. package/dist/api/alipay/index.js +3 -0
  6. package/dist/api/base/crypto.js +3 -0
  7. package/dist/api/base/debug.js +4 -0
  8. package/dist/api/base/index.js +17 -0
  9. package/dist/api/base/performance.js +4 -0
  10. package/dist/api/base/system/index.js +2 -0
  11. package/dist/api/base/system/info.js +57 -0
  12. package/dist/api/base/system/network.js +63 -0
  13. package/dist/api/base/update.js +4 -0
  14. package/dist/api/base/weapp/app-event.js +18 -0
  15. package/dist/api/base/weapp/life-cycle.js +4 -0
  16. package/dist/api/canvas/CanvasContext.js +191 -0
  17. package/dist/api/canvas/canvasGetImageData.js +25 -0
  18. package/dist/api/canvas/canvasPutImageData.js +22 -0
  19. package/dist/api/canvas/canvasToTempFilePath.js +22 -0
  20. package/dist/api/canvas/createCanvasContext.js +16 -0
  21. package/dist/api/canvas/index.js +8 -0
  22. package/dist/api/cloud/index.js +17 -0
  23. package/dist/api/data-analysis/index.js +5 -0
  24. package/dist/api/device/accelerometer.js +83 -0
  25. package/dist/api/device/accessibility.js +3 -0
  26. package/dist/api/device/battery.js +4 -0
  27. package/dist/api/device/bluetooth-ble.js +18 -0
  28. package/dist/api/device/bluetooth-peripheral.js +5 -0
  29. package/dist/api/device/bluetooth.js +15 -0
  30. package/dist/api/device/calendar.js +4 -0
  31. package/dist/api/device/clipboard.js +65 -0
  32. package/dist/api/device/compass.js +64 -0
  33. package/dist/api/device/contact.js +4 -0
  34. package/dist/api/device/crypto.js +3 -0
  35. package/dist/api/device/gyroscope.js +6 -0
  36. package/dist/api/device/iBeacon.js +9 -0
  37. package/dist/api/device/index.js +22 -0
  38. package/dist/api/device/keyboard.js +6 -0
  39. package/dist/api/device/memory.js +4 -0
  40. package/dist/api/device/motion.js +81 -0
  41. package/dist/api/device/nfc.js +9 -0
  42. package/dist/api/device/phone.js +24 -0
  43. package/dist/api/device/scan.js +6 -0
  44. package/dist/api/device/screen.js +8 -0
  45. package/dist/api/device/vibrate.js +35 -0
  46. package/dist/api/device/wifi.js +12 -0
  47. package/dist/api/ext/index.js +4 -0
  48. package/dist/api/files/index.js +10 -0
  49. package/dist/api/framework/index.js +7 -0
  50. package/dist/api/index.js +24 -0
  51. package/dist/api/location/chooseLocation.js +93 -0
  52. package/dist/api/location/index.js +13 -0
  53. package/dist/api/location/style.css +79 -0
  54. package/dist/api/media/audio/index.js +88 -0
  55. package/dist/api/media/background-audio.js +11 -0
  56. package/dist/api/media/camera.js +3 -0
  57. package/dist/api/media/editor.js +18 -0
  58. package/dist/api/media/image/chooseImage.js +74 -0
  59. package/dist/api/media/image/getImageInfo.js +31 -0
  60. package/dist/api/media/image/index.js +9 -0
  61. package/dist/api/media/image/previewImage.js +67 -0
  62. package/dist/api/media/index.js +13 -0
  63. package/dist/api/media/live.js +4 -0
  64. package/dist/api/media/map.js +3 -0
  65. package/dist/api/media/media-recorder.js +3 -0
  66. package/dist/api/media/recorder.js +5 -0
  67. package/dist/api/media/video/index.js +74 -0
  68. package/dist/api/media/video-decoder.js +3 -0
  69. package/dist/api/media/video-processing.js +3 -0
  70. package/dist/api/media/voip.js +16 -0
  71. package/dist/api/navigate/index.js +6 -0
  72. package/dist/api/network/download.js +124 -0
  73. package/dist/api/network/index.js +7 -0
  74. package/dist/api/network/mdns.js +12 -0
  75. package/dist/api/network/request/index.js +125 -0
  76. package/dist/api/network/tcp.js +3 -0
  77. package/dist/api/network/udp.js +3 -0
  78. package/dist/api/network/upload.js +151 -0
  79. package/dist/api/network/utils.js +65 -0
  80. package/dist/api/network/websocket/index.js +70 -0
  81. package/dist/api/network/websocket/socketTask.js +63 -0
  82. package/dist/api/open-api/account.js +3 -0
  83. package/dist/api/open-api/address.js +3 -0
  84. package/dist/api/open-api/authorize.js +4 -0
  85. package/dist/api/open-api/card.js +4 -0
  86. package/dist/api/open-api/channels-live.js +8 -0
  87. package/dist/api/open-api/customer-service.js +3 -0
  88. package/dist/api/open-api/facial.js +6 -0
  89. package/dist/api/open-api/favorites.js +4 -0
  90. package/dist/api/open-api/group.js +3 -0
  91. package/dist/api/open-api/index.js +18 -0
  92. package/dist/api/open-api/invoice.js +4 -0
  93. package/dist/api/open-api/license-plate.js +3 -0
  94. package/dist/api/open-api/login.js +5 -0
  95. package/dist/api/open-api/red-package.js +3 -0
  96. package/dist/api/open-api/settings.js +4 -0
  97. package/dist/api/open-api/soter.js +5 -0
  98. package/dist/api/open-api/subscribe-message.js +3 -0
  99. package/dist/api/open-api/user-info.js +4 -0
  100. package/dist/api/open-api/werun.js +4 -0
  101. package/dist/api/payment/index.js +4 -0
  102. package/dist/api/route/index.js +3 -0
  103. package/dist/api/share/index.js +12 -0
  104. package/dist/api/storage/background-fetch.js +6 -0
  105. package/dist/api/storage/index.js +157 -0
  106. package/dist/api/swan/index.js +26 -0
  107. package/dist/api/taro.js +47 -0
  108. package/dist/api/ui/animation/index.js +284 -0
  109. package/dist/api/ui/background.js +4 -0
  110. package/dist/api/ui/custom-component.js +3 -0
  111. package/dist/api/ui/fonts.js +3 -0
  112. package/dist/api/ui/index.js +12 -0
  113. package/dist/api/ui/interaction/actionSheet.js +188 -0
  114. package/dist/api/ui/interaction/index.js +268 -0
  115. package/dist/api/ui/interaction/modal.js +207 -0
  116. package/dist/api/ui/interaction/toast.js +195 -0
  117. package/dist/api/ui/menu.js +3 -0
  118. package/dist/api/ui/navigation-bar/index.js +42 -0
  119. package/dist/api/ui/pull-down-refresh.js +26 -0
  120. package/dist/api/ui/scroll/index.js +83 -0
  121. package/dist/api/ui/sticky.js +3 -0
  122. package/dist/api/ui/tab-bar.js +282 -0
  123. package/dist/api/ui/window.js +31 -0
  124. package/dist/api/utils/handler.js +80 -0
  125. package/dist/api/utils/index.js +148 -0
  126. package/dist/api/worker/index.js +3 -0
  127. package/dist/api/wxml/index.js +6 -0
  128. package/dist/api/wxml/nodesRef.js +42 -0
  129. package/dist/api/wxml/selectorQuery.js +201 -0
  130. package/dist/index.cjs.js +7852 -11638
  131. package/dist/index.js +4 -0
  132. package/dist/taroApis.js +1 -1
  133. package/dist/types/type.js +2 -0
  134. package/package.json +14 -16
  135. package/src/api/ad/index.ts +5 -0
  136. package/src/api/ai/facial.ts +6 -0
  137. package/src/api/ai/index.ts +2 -0
  138. package/src/api/ai/visual.ts +4 -0
  139. package/src/api/alipay/index.ts +4 -0
  140. package/src/api/base/crypto.ts +4 -0
  141. package/src/api/base/debug.ts +5 -0
  142. package/src/api/base/index.ts +23 -0
  143. package/src/api/base/performance.ts +5 -0
  144. package/src/api/base/system/index.ts +2 -0
  145. package/src/api/base/system/info.ts +64 -0
  146. package/src/api/base/system/network.ts +70 -0
  147. package/src/api/base/update.ts +5 -0
  148. package/src/api/base/weapp/app-event.ts +19 -0
  149. package/src/api/base/weapp/life-cycle.ts +5 -0
  150. package/src/api/canvas/CanvasContext.ts +233 -0
  151. package/src/api/canvas/canvasGetImageData.ts +27 -0
  152. package/src/api/canvas/canvasPutImageData.ts +24 -0
  153. package/src/api/canvas/canvasToTempFilePath.ts +24 -0
  154. package/src/api/canvas/createCanvasContext.ts +18 -0
  155. package/src/api/canvas/index.ts +10 -0
  156. package/src/api/cloud/index.ts +27 -0
  157. package/src/api/data-analysis/index.ts +6 -0
  158. package/src/api/device/accelerometer.ts +87 -0
  159. package/src/api/device/accessibility.ts +4 -0
  160. package/src/api/device/battery.ts +5 -0
  161. package/src/api/device/bluetooth-ble.ts +19 -0
  162. package/src/api/device/bluetooth-peripheral.ts +6 -0
  163. package/src/api/device/bluetooth.ts +16 -0
  164. package/src/api/device/calendar.ts +5 -0
  165. package/src/api/device/clipboard.ts +67 -0
  166. package/src/api/device/compass.ts +67 -0
  167. package/src/api/device/contact.ts +5 -0
  168. package/src/api/device/crypto.ts +4 -0
  169. package/src/api/device/gyroscope.ts +7 -0
  170. package/src/api/device/iBeacon.ts +10 -0
  171. package/src/api/device/index.ts +22 -0
  172. package/src/api/device/keyboard.ts +7 -0
  173. package/src/api/device/memory.ts +5 -0
  174. package/src/api/device/motion.ts +85 -0
  175. package/src/api/device/nfc.ts +10 -0
  176. package/src/api/device/phone.ts +30 -0
  177. package/src/api/device/scan.ts +7 -0
  178. package/src/api/device/screen.ts +9 -0
  179. package/src/api/device/vibrate.ts +36 -0
  180. package/src/api/device/wifi.ts +13 -0
  181. package/src/api/ext/index.ts +5 -0
  182. package/src/api/files/index.ts +11 -0
  183. package/src/api/framework/index.ts +10 -0
  184. package/src/api/index.ts +25 -0
  185. package/src/api/location/chooseLocation.ts +106 -0
  186. package/src/api/location/index.ts +19 -0
  187. package/src/api/location/style.css +8 -8
  188. package/src/api/media/audio/index.ts +105 -0
  189. package/src/api/media/background-audio.ts +12 -0
  190. package/src/api/media/camera.ts +4 -0
  191. package/src/api/media/editor.ts +29 -0
  192. package/src/api/media/image/chooseImage.ts +78 -0
  193. package/src/api/media/image/getImageInfo.ts +35 -0
  194. package/src/api/media/image/index.ts +13 -0
  195. package/src/api/media/image/previewImage.ts +80 -0
  196. package/src/api/media/index.ts +13 -0
  197. package/src/api/media/live.ts +5 -0
  198. package/src/api/media/map.ts +4 -0
  199. package/src/api/media/media-recorder.ts +4 -0
  200. package/src/api/media/recorder.ts +6 -0
  201. package/src/api/media/video/index.ts +82 -0
  202. package/src/api/media/video-decoder.ts +4 -0
  203. package/src/api/media/video-processing.ts +4 -0
  204. package/src/api/media/voip.ts +17 -0
  205. package/src/api/navigate/index.ts +7 -0
  206. package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -27
  207. package/src/api/network/index.ts +7 -0
  208. package/src/api/network/mdns.ts +13 -0
  209. package/src/api/{request/index.js → network/request/index.ts} +9 -6
  210. package/src/api/network/tcp.ts +4 -0
  211. package/src/api/network/udp.ts +4 -0
  212. package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -32
  213. package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
  214. package/src/api/network/websocket/index.ts +88 -0
  215. package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
  216. package/src/api/open-api/account.ts +4 -0
  217. package/src/api/open-api/address.ts +4 -0
  218. package/src/api/open-api/authorize.ts +5 -0
  219. package/src/api/open-api/card.ts +5 -0
  220. package/src/api/open-api/channels-live.ts +9 -0
  221. package/src/api/open-api/customer-service.ts +4 -0
  222. package/src/api/open-api/facial.ts +7 -0
  223. package/src/api/open-api/favorites.ts +5 -0
  224. package/src/api/open-api/group.ts +4 -0
  225. package/src/api/open-api/index.ts +18 -0
  226. package/src/api/open-api/invoice.ts +5 -0
  227. package/src/api/open-api/license-plate.ts +4 -0
  228. package/src/api/open-api/login.ts +6 -0
  229. package/src/api/open-api/red-package.ts +4 -0
  230. package/src/api/open-api/settings.ts +5 -0
  231. package/src/api/open-api/soter.ts +6 -0
  232. package/src/api/open-api/subscribe-message.ts +4 -0
  233. package/src/api/open-api/user-info.ts +5 -0
  234. package/src/api/open-api/werun.ts +5 -0
  235. package/src/api/payment/index.ts +5 -0
  236. package/src/api/route/index.ts +10 -0
  237. package/src/api/share/index.ts +13 -0
  238. package/src/api/storage/background-fetch.ts +7 -0
  239. package/src/api/storage/index.ts +181 -0
  240. package/src/api/swan/index.ts +31 -0
  241. package/src/{taro/index.js → api/taro.ts} +89 -104
  242. package/src/api/{createAnimation/index.js → ui/animation/index.ts} +52 -41
  243. package/src/api/ui/background.ts +5 -0
  244. package/src/api/ui/custom-component.ts +4 -0
  245. package/src/api/ui/fonts.ts +4 -0
  246. package/src/api/ui/index.ts +12 -0
  247. package/src/api/ui/interaction/actionSheet.ts +212 -0
  248. package/src/api/{interactive/index.js → ui/interaction/index.ts} +95 -77
  249. package/src/api/ui/interaction/modal.ts +237 -0
  250. package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
  251. package/src/api/ui/menu.ts +4 -0
  252. package/src/api/ui/navigation-bar/index.ts +52 -0
  253. package/src/api/ui/pull-down-refresh.ts +27 -0
  254. package/src/api/ui/scroll/index.ts +85 -0
  255. package/src/api/ui/sticky.ts +4 -0
  256. package/src/api/ui/tab-bar.ts +326 -0
  257. package/src/api/ui/window.ts +37 -0
  258. package/src/api/utils/handler.ts +105 -0
  259. package/src/api/utils/{index.js → index.ts} +36 -115
  260. package/src/api/worker/index.ts +4 -0
  261. package/src/api/wxml/index.ts +9 -0
  262. package/src/api/wxml/nodesRef.ts +56 -0
  263. package/src/api/wxml/selectorQuery.ts +219 -0
  264. package/src/index.ts +6 -0
  265. package/src/types/api.d.ts +4 -0
  266. package/src/types/define.d.ts +2 -0
  267. package/{types → src/types}/index.d.ts +0 -0
  268. package/{types → src/types}/type.ts +1 -1
  269. package/src/api/accelerometer/index.js +0 -105
  270. package/src/api/audio/index.js +0 -137
  271. package/src/api/canvas/canvasGetImageData.js +0 -44
  272. package/src/api/canvas/canvasPutImageData.js +0 -45
  273. package/src/api/canvas/canvasToTempFilePath.js +0 -49
  274. package/src/api/canvas/createCanvasContext.js +0 -340
  275. package/src/api/canvas/index.js +0 -4
  276. package/src/api/clipboard/index.js +0 -113
  277. package/src/api/compass/index.js +0 -99
  278. package/src/api/createSelectorQuery/index.js +0 -193
  279. package/src/api/deviceMotion/index.js +0 -105
  280. package/src/api/fileTransfer/index.js +0 -2
  281. package/src/api/image/chooseImage.js +0 -87
  282. package/src/api/image/getImageInfo.js +0 -74
  283. package/src/api/image/index.js +0 -7
  284. package/src/api/image/previewImage.js +0 -94
  285. package/src/api/index.js +0 -29
  286. package/src/api/interactive/actionSheet.js +0 -214
  287. package/src/api/interactive/modal.js +0 -256
  288. package/src/api/location/chooseLocation.js +0 -143
  289. package/src/api/location/index.js +0 -5
  290. package/src/api/navigationBar/index.js +0 -57
  291. package/src/api/open/index.js +0 -5
  292. package/src/api/others/index.js +0 -43
  293. package/src/api/pullDownRefresh/index.js +0 -51
  294. package/src/api/scroll/index.js +0 -99
  295. package/src/api/storage/index.js +0 -211
  296. package/src/api/system/index.js +0 -9
  297. package/src/api/system/info.js +0 -36
  298. package/src/api/system/network.js +0 -68
  299. package/src/api/tabBar/index.js +0 -402
  300. package/src/api/unsupportedApi/index.js +0 -278
  301. package/src/api/vibrate/index.js +0 -49
  302. package/src/api/video/index.js +0 -87
  303. package/src/api/webSocket/index.js +0 -103
  304. package/src/api/window/index.js +0 -38
  305. package/src/index.cjs.js +0 -11
  306. package/src/index.js +0 -6
@@ -0,0 +1,188 @@
1
+ import { inlineStyle, setTransform } from '../../utils';
2
+ const noop = function () { };
3
+ export default class ActionSheet {
4
+ constructor() {
5
+ this.options = {
6
+ itemList: [],
7
+ itemColor: '#000000',
8
+ success: noop,
9
+ fail: noop,
10
+ complete: noop
11
+ };
12
+ this.style = {
13
+ maskStyle: {
14
+ position: 'fixed',
15
+ 'z-index': '1000',
16
+ top: '0',
17
+ right: '0',
18
+ left: '0',
19
+ bottom: '0',
20
+ background: 'rgba(0,0,0,0.6)'
21
+ },
22
+ actionSheetStyle: {
23
+ 'z-index': '4999',
24
+ position: 'fixed',
25
+ left: '0',
26
+ bottom: '0',
27
+ '-webkit-transform': 'translate(0, 100%)',
28
+ transform: 'translate(0, 100%)',
29
+ width: '100%',
30
+ 'line-height': '1.6',
31
+ background: '#EFEFF4',
32
+ '-webkit-transition': '-webkit-transform .3s',
33
+ transition: 'transform .3s'
34
+ },
35
+ menuStyle: {
36
+ 'background-color': '#FCFCFD'
37
+ },
38
+ cellStyle: {
39
+ position: 'relative',
40
+ padding: '10px 0',
41
+ 'text-align': 'center',
42
+ 'font-size': '18px'
43
+ },
44
+ cancelStyle: {
45
+ 'margin-top': '6px',
46
+ padding: '10px 0',
47
+ 'text-align': 'center',
48
+ 'font-size': '18px',
49
+ color: '#000000',
50
+ 'background-color': '#FCFCFD'
51
+ }
52
+ };
53
+ this.lastConfig = {};
54
+ }
55
+ create(options = {}) {
56
+ return new Promise((resolve) => {
57
+ // style
58
+ const { maskStyle, actionSheetStyle, menuStyle, cellStyle, cancelStyle } = this.style;
59
+ // configuration
60
+ const config = {
61
+ ...this.options,
62
+ ...options
63
+ };
64
+ this.lastConfig = config;
65
+ // wrapper
66
+ this.el = document.createElement('div');
67
+ this.el.className = 'taro__actionSheet';
68
+ this.el.style.opacity = '0';
69
+ this.el.style.transition = 'opacity 0.2s linear';
70
+ // mask
71
+ const mask = document.createElement('div');
72
+ mask.setAttribute('style', inlineStyle(maskStyle));
73
+ // actionSheet
74
+ this.actionSheet = document.createElement('div');
75
+ this.actionSheet.setAttribute('style', inlineStyle(actionSheetStyle));
76
+ // menu
77
+ this.menu = document.createElement('div');
78
+ this.menu.setAttribute('style', inlineStyle({
79
+ ...menuStyle,
80
+ color: config.itemColor
81
+ }));
82
+ // cells
83
+ this.cells = config.itemList.map((item, index) => {
84
+ const cell = document.createElement('div');
85
+ cell.className = 'taro-actionsheet__cell';
86
+ cell.setAttribute('style', inlineStyle(cellStyle));
87
+ cell.textContent = item;
88
+ cell.dataset.tapIndex = `${index}`;
89
+ cell.onclick = e => {
90
+ this.hide();
91
+ const target = e.currentTarget;
92
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
93
+ resolve(index);
94
+ };
95
+ return cell;
96
+ });
97
+ // cancel
98
+ this.cancel = document.createElement('div');
99
+ this.cancel.setAttribute('style', inlineStyle(cancelStyle));
100
+ this.cancel.textContent = '取消';
101
+ // result
102
+ this.cells.forEach(item => this.menu.appendChild(item));
103
+ this.actionSheet.appendChild(this.menu);
104
+ this.actionSheet.appendChild(this.cancel);
105
+ this.el.appendChild(mask);
106
+ this.el.appendChild(this.actionSheet);
107
+ // callbacks
108
+ const cb = () => {
109
+ this.hide();
110
+ resolve('cancel');
111
+ };
112
+ mask.onclick = cb;
113
+ this.cancel.onclick = cb;
114
+ // show immediately
115
+ document.body.appendChild(this.el);
116
+ setTimeout(() => {
117
+ this.el.style.opacity = '1';
118
+ setTransform(this.actionSheet, 'translate(0, 0)');
119
+ }, 0);
120
+ });
121
+ }
122
+ show(options = {}) {
123
+ return new Promise((resolve) => {
124
+ const config = {
125
+ ...this.options,
126
+ ...options
127
+ };
128
+ this.lastConfig = config;
129
+ if (this.hideOpacityTimer)
130
+ clearTimeout(this.hideOpacityTimer);
131
+ if (this.hideDisplayTimer)
132
+ clearTimeout(this.hideDisplayTimer);
133
+ // itemColor
134
+ if (config.itemColor)
135
+ this.menu.style.color = config.itemColor;
136
+ // cells
137
+ const { cellStyle } = this.style;
138
+ config.itemList.forEach((item, index) => {
139
+ let cell;
140
+ if (this.cells[index]) {
141
+ // assign new content
142
+ cell = this.cells[index];
143
+ }
144
+ else {
145
+ // create new cell
146
+ cell = document.createElement('div');
147
+ cell.className = 'taro-actionsheet__cell';
148
+ cell.setAttribute('style', inlineStyle(cellStyle));
149
+ cell.dataset.tapIndex = `${index}`;
150
+ this.cells.push(cell);
151
+ this.menu.appendChild(cell);
152
+ }
153
+ cell.textContent = item;
154
+ cell.onclick = e => {
155
+ this.hide();
156
+ const target = e.currentTarget;
157
+ const index = Number(target === null || target === void 0 ? void 0 : target.dataset.tapIndex) || 0;
158
+ resolve(index);
159
+ };
160
+ });
161
+ const cellsLen = this.cells.length;
162
+ const itemListLen = config.itemList.length;
163
+ if (cellsLen > itemListLen) {
164
+ for (let i = itemListLen; i < cellsLen; i++) {
165
+ this.menu.removeChild(this.cells[i]);
166
+ }
167
+ this.cells.splice(itemListLen);
168
+ }
169
+ // show
170
+ this.el.style.display = 'block';
171
+ setTimeout(() => {
172
+ this.el.style.opacity = '1';
173
+ setTransform(this.actionSheet, 'translate(0, 0)');
174
+ }, 0);
175
+ });
176
+ }
177
+ hide() {
178
+ if (this.hideOpacityTimer)
179
+ clearTimeout(this.hideOpacityTimer);
180
+ if (this.hideDisplayTimer)
181
+ clearTimeout(this.hideDisplayTimer);
182
+ this.hideOpacityTimer = setTimeout(() => {
183
+ this.el.style.opacity = '0';
184
+ setTransform(this.actionSheet, 'translate(0, 100%)');
185
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
186
+ }, 0);
187
+ }
188
+ }
@@ -0,0 +1,268 @@
1
+ import Taro from '@tarojs/api';
2
+ import { getParameterError, temporarilyNotSupport } from '../../utils';
3
+ import { MethodHandler } from '../../utils/handler';
4
+ import Toast from './toast';
5
+ import Modal from './modal';
6
+ import ActionSheet from './actionSheet';
7
+ // 交互
8
+ let status = 'default';
9
+ // inject necessary style
10
+ function init(doc) {
11
+ if (status === 'ready')
12
+ return;
13
+ const taroStyle = doc.createElement('style');
14
+ taroStyle.textContent = '@font-face{font-weight:normal;font-style:normal;font-family:"taro";src:url("data:application/x-font-ttf;charset=utf-8;base64, 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") format("truetype");}@-webkit-keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}@keyframes taroLoading{0%{-webkit-transform:rotate3d(0, 0, 1, 0deg);}100%{-webkit-transform:rotate3d(0, 0, 1, 360deg);transform:rotate3d(0, 0, 1, 360deg);}}.taro-modal__foot:after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);} .taro-model__btn:active {background-color: #EEEEEE}.taro-model__btn:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;width: 1px;bottom: 0;border-left: 1px solid #D5D5D6;color: #D5D5D6;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleX(0.5);transform: scaleX(0.5);}.taro-actionsheet__cell:not(:first-child):after {content: "";position: absolute;left: 0;top: 0;right: 0;height: 1px;border-top: 1px solid #e5e5e5;color: #e5e5e5;-webkit-transform-origin: 0 0;transform-origin: 0 0;-webkit-transform: scaleY(0.5);transform: scaleY(0.5);}';
15
+ doc.querySelector('head').appendChild(taroStyle);
16
+ status = 'ready';
17
+ }
18
+ const toast = new Toast();
19
+ const modal = new Modal();
20
+ const actionSheet = new ActionSheet();
21
+ const showToast = (options = { title: '' }) => {
22
+ init(document);
23
+ options = Object.assign({
24
+ title: '',
25
+ icon: 'success',
26
+ image: '',
27
+ duration: 1500,
28
+ mask: false
29
+ }, options);
30
+ const { success, fail, complete } = options;
31
+ const handle = new MethodHandler({ name: 'showToast', success, fail, complete });
32
+ if (typeof options.title !== 'string') {
33
+ return handle.fail({
34
+ errMsg: getParameterError({
35
+ para: 'title',
36
+ correct: 'String',
37
+ wrong: options.title
38
+ })
39
+ });
40
+ }
41
+ if (typeof options.duration !== 'number') {
42
+ return handle.fail({
43
+ errMsg: getParameterError({
44
+ para: 'duration',
45
+ correct: 'Number',
46
+ wrong: options.duration
47
+ })
48
+ });
49
+ }
50
+ if (options.image && typeof options.image !== 'string')
51
+ options.image = '';
52
+ options.mask = !!options.mask;
53
+ let errMsg = '';
54
+ if (!toast.el) {
55
+ errMsg = toast.create(options, 'toast');
56
+ }
57
+ else {
58
+ errMsg = toast.show(options, 'toast');
59
+ }
60
+ return handle.success({ errMsg });
61
+ };
62
+ const hideToast = ({ success, fail, complete } = {}) => {
63
+ const handle = new MethodHandler({ name: 'hideToast', success, fail, complete });
64
+ if (!toast.el)
65
+ return handle.success();
66
+ toast.hide(0, 'toast');
67
+ return handle.success();
68
+ };
69
+ const showLoading = (options = { title: '' }) => {
70
+ init(document);
71
+ options = Object.assign({
72
+ title: '',
73
+ mask: false
74
+ }, options);
75
+ const { success, fail, complete } = options;
76
+ const handle = new MethodHandler({ name: 'showLoading', success, fail, complete });
77
+ const config = {
78
+ icon: 'loading',
79
+ image: '',
80
+ duration: -1
81
+ };
82
+ options = Object.assign({}, options, config);
83
+ if (typeof options.title !== 'string') {
84
+ return handle.fail({
85
+ errMsg: getParameterError({
86
+ para: 'title',
87
+ correct: 'String',
88
+ wrong: options.title
89
+ })
90
+ });
91
+ }
92
+ options.mask = !!options.mask;
93
+ let errMsg = '';
94
+ if (!toast.el) {
95
+ errMsg = toast.create(options, 'loading');
96
+ }
97
+ else {
98
+ errMsg = toast.show(options, 'loading');
99
+ }
100
+ return handle.success({ errMsg });
101
+ };
102
+ const hideLoading = ({ success, fail, complete } = {}) => {
103
+ const handle = new MethodHandler({ name: 'hideLoading', success, fail, complete });
104
+ if (!toast.el)
105
+ return handle.success();
106
+ toast.hide(0, 'loading');
107
+ return handle.success();
108
+ };
109
+ const showModal = async (options = {}) => {
110
+ init(document);
111
+ options = Object.assign({
112
+ title: '',
113
+ content: '',
114
+ showCancel: true,
115
+ cancelText: '取消',
116
+ cancelColor: '#000000',
117
+ confirmText: '确定',
118
+ confirmColor: '#3CC51F'
119
+ }, options);
120
+ const { success, fail, complete } = options;
121
+ const handle = new MethodHandler({ name: 'showModal', success, fail, complete });
122
+ if (typeof options.title !== 'string') {
123
+ return handle.fail({
124
+ errMsg: getParameterError({
125
+ para: 'title',
126
+ correct: 'String',
127
+ wrong: options.title
128
+ })
129
+ });
130
+ }
131
+ if (typeof options.content !== 'string') {
132
+ return handle.fail({
133
+ errMsg: getParameterError({
134
+ para: 'content',
135
+ correct: 'String',
136
+ wrong: options.content
137
+ })
138
+ });
139
+ }
140
+ if (typeof options.cancelText !== 'string') {
141
+ return handle.fail({
142
+ errMsg: getParameterError({
143
+ para: 'cancelText',
144
+ correct: 'String',
145
+ wrong: options.cancelText
146
+ })
147
+ });
148
+ }
149
+ if (options.cancelText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
150
+ return handle.fail({
151
+ errMsg: 'cancelText length should not larger then 4 Chinese characters'
152
+ });
153
+ }
154
+ if (typeof options.confirmText !== 'string') {
155
+ return handle.fail({
156
+ errMsg: getParameterError({
157
+ para: 'confirmText',
158
+ correct: 'String',
159
+ wrong: options.confirmText
160
+ })
161
+ });
162
+ }
163
+ if (options.confirmText.replace(/[\u0391-\uFFE5]/g, 'aa').length > 8) {
164
+ return handle.fail({
165
+ errMsg: 'confirmText length should not larger then 4 Chinese characters'
166
+ });
167
+ }
168
+ if (typeof options.cancelColor !== 'string') {
169
+ return handle.fail({
170
+ errMsg: getParameterError({
171
+ para: 'cancelColor',
172
+ correct: 'String',
173
+ wrong: options.cancelColor
174
+ })
175
+ });
176
+ }
177
+ if (typeof options.confirmColor !== 'string') {
178
+ return handle.fail({
179
+ errMsg: getParameterError({
180
+ para: 'confirmColor',
181
+ correct: 'String',
182
+ wrong: options.confirmColor
183
+ })
184
+ });
185
+ }
186
+ options.showCancel = !!options.showCancel;
187
+ let result = '';
188
+ if (!modal.el) {
189
+ result = await modal.create(options);
190
+ }
191
+ else {
192
+ result = await modal.show(options);
193
+ }
194
+ const res = { cancel: !1, confirm: !1 };
195
+ res[result] = !0;
196
+ return handle.success(res);
197
+ };
198
+ function hideModal() {
199
+ if (!modal.el)
200
+ return;
201
+ modal.hide();
202
+ }
203
+ const showActionSheet = async (options = { itemList: [] }) => {
204
+ init(document);
205
+ options = Object.assign({
206
+ itemColor: '#000000',
207
+ itemList: []
208
+ }, options);
209
+ const { success, fail, complete } = options;
210
+ const handle = new MethodHandler({ name: 'showActionSheet', success, fail, complete });
211
+ // list item String
212
+ if (!Array.isArray(options.itemList)) {
213
+ return handle.fail({
214
+ errMsg: getParameterError({
215
+ para: 'itemList',
216
+ correct: 'Array',
217
+ wrong: options.itemList
218
+ })
219
+ });
220
+ }
221
+ if (options.itemList.length < 1) {
222
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should have at least 1 item' });
223
+ }
224
+ if (options.itemList.length > 6) {
225
+ return handle.fail({ errMsg: 'parameter error: parameter.itemList should not be large than 6' });
226
+ }
227
+ for (let i = 0; i < options.itemList.length; i++) {
228
+ if (typeof options.itemList[i] !== 'string') {
229
+ return handle.fail({
230
+ errMsg: getParameterError({
231
+ para: `itemList[${i}]`,
232
+ correct: 'String',
233
+ wrong: options.itemList[i]
234
+ })
235
+ });
236
+ }
237
+ }
238
+ if (typeof options.itemColor !== 'string') {
239
+ return handle.fail({
240
+ errMsg: getParameterError({
241
+ para: 'itemColor',
242
+ correct: 'String',
243
+ wrong: options.itemColor
244
+ })
245
+ });
246
+ }
247
+ let result = '';
248
+ if (!actionSheet.el) {
249
+ result = await actionSheet.create(options);
250
+ }
251
+ else {
252
+ result = await actionSheet.show(options);
253
+ }
254
+ if (typeof result === 'string') {
255
+ return handle.fail(({ errMsg: result }));
256
+ }
257
+ else {
258
+ return handle.success(({ tapIndex: result }));
259
+ }
260
+ };
261
+ Taro.eventCenter.on('__taroRouterChange', () => {
262
+ hideToast();
263
+ hideLoading();
264
+ hideModal();
265
+ });
266
+ const enableAlertBeforeUnload = temporarilyNotSupport('enableAlertBeforeUnload');
267
+ const disableAlertBeforeUnload = temporarilyNotSupport('disableAlertBeforeUnload');
268
+ export { showToast, showModal, showLoading, showActionSheet, hideToast, hideLoading, enableAlertBeforeUnload, disableAlertBeforeUnload };
@@ -0,0 +1,207 @@
1
+ import { inlineStyle } from '../../utils';
2
+ export default class Modal {
3
+ constructor() {
4
+ this.options = {
5
+ title: '',
6
+ content: '',
7
+ showCancel: true,
8
+ cancelText: '取消',
9
+ cancelColor: '#000000',
10
+ confirmText: '确定',
11
+ confirmColor: '#3CC51F'
12
+ };
13
+ this.style = {
14
+ maskStyle: {
15
+ position: 'fixed',
16
+ 'z-index': '1000',
17
+ top: '0',
18
+ right: '0',
19
+ left: '0',
20
+ bottom: '0',
21
+ background: 'rgba(0,0,0,0.6)'
22
+ },
23
+ modalStyle: {
24
+ 'z-index': '4999',
25
+ position: 'fixed',
26
+ top: '50%',
27
+ left: '50%',
28
+ transform: 'translate(-50%, -50%)',
29
+ width: '80%',
30
+ 'max-width': '300px',
31
+ 'border-radius': '3px',
32
+ 'text-align': 'center',
33
+ 'line-height': '1.6',
34
+ overflow: 'hidden',
35
+ background: '#FFFFFF'
36
+ },
37
+ titleStyle: {
38
+ padding: '20px 24px 9px',
39
+ 'font-size': '18px'
40
+ },
41
+ textStyle: {
42
+ padding: '0 24px 12px',
43
+ 'min-height': '40px',
44
+ 'font-size': '15px',
45
+ 'line-height': '1.3',
46
+ color: '#808080'
47
+ },
48
+ footStyle: {
49
+ position: 'relative',
50
+ 'line-height': '48px',
51
+ 'font-size': '18px',
52
+ display: 'flex'
53
+ },
54
+ btnStyle: {
55
+ position: 'relative',
56
+ '-webkit-box-flex': '1',
57
+ '-webkit-flex': '1',
58
+ flex: '1'
59
+ }
60
+ };
61
+ }
62
+ create(options = {}) {
63
+ return new Promise((resolve) => {
64
+ // style
65
+ const { maskStyle, modalStyle, titleStyle, textStyle, footStyle, btnStyle } = this.style;
66
+ // configuration
67
+ const config = {
68
+ ...this.options,
69
+ ...options
70
+ };
71
+ // wrapper
72
+ this.el = document.createElement('div');
73
+ this.el.className = 'taro__modal';
74
+ this.el.style.opacity = '0';
75
+ this.el.style.transition = 'opacity 0.2s linear';
76
+ // mask
77
+ const mask = document.createElement('div');
78
+ mask.className = 'taro-modal__mask';
79
+ mask.setAttribute('style', inlineStyle(maskStyle));
80
+ // modal
81
+ const modal = document.createElement('div');
82
+ modal.className = 'taro-modal__content';
83
+ modal.setAttribute('style', inlineStyle(modalStyle));
84
+ // title
85
+ const titleCSS = config.title ? titleStyle : {
86
+ ...titleStyle,
87
+ display: 'none'
88
+ };
89
+ this.title = document.createElement('div');
90
+ this.title.className = 'taro-modal__title';
91
+ this.title.setAttribute('style', inlineStyle(titleCSS));
92
+ this.title.textContent = config.title;
93
+ // text
94
+ const textCSS = config.title ? textStyle : {
95
+ ...textStyle,
96
+ padding: '40px 20px 26px',
97
+ color: '#353535'
98
+ };
99
+ this.text = document.createElement('div');
100
+ this.text.className = 'taro-modal__text';
101
+ this.text.setAttribute('style', inlineStyle(textCSS));
102
+ this.text.textContent = config.content;
103
+ // foot
104
+ const foot = document.createElement('div');
105
+ foot.className = 'taro-modal__foot';
106
+ foot.setAttribute('style', inlineStyle(footStyle));
107
+ // cancel button
108
+ const cancelCSS = {
109
+ ...btnStyle,
110
+ color: config.cancelColor,
111
+ display: config.showCancel ? 'block' : 'none'
112
+ };
113
+ this.cancel = document.createElement('div');
114
+ this.cancel.className = 'taro-model__btn taro-model__cancel';
115
+ this.cancel.setAttribute('style', inlineStyle(cancelCSS));
116
+ this.cancel.textContent = config.cancelText;
117
+ this.cancel.onclick = () => {
118
+ this.hide();
119
+ resolve('cancel');
120
+ };
121
+ // confirm button
122
+ this.confirm = document.createElement('div');
123
+ this.confirm.className = 'taro-model__btn taro-model__confirm';
124
+ this.confirm.setAttribute('style', inlineStyle(btnStyle));
125
+ this.confirm.style.color = config.confirmColor;
126
+ this.confirm.textContent = config.confirmText;
127
+ this.confirm.onclick = () => {
128
+ this.hide();
129
+ resolve('confirm');
130
+ };
131
+ // result
132
+ foot.appendChild(this.cancel);
133
+ foot.appendChild(this.confirm);
134
+ modal.appendChild(this.title);
135
+ modal.appendChild(this.text);
136
+ modal.appendChild(foot);
137
+ this.el.appendChild(mask);
138
+ this.el.appendChild(modal);
139
+ // show immediately
140
+ document.body.appendChild(this.el);
141
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
142
+ });
143
+ }
144
+ show(options = {}) {
145
+ return new Promise((resolve) => {
146
+ const config = {
147
+ ...this.options,
148
+ ...options
149
+ };
150
+ if (this.hideOpacityTimer)
151
+ clearTimeout(this.hideOpacityTimer);
152
+ if (this.hideDisplayTimer)
153
+ clearTimeout(this.hideDisplayTimer);
154
+ // title & text
155
+ const { textStyle } = this.style;
156
+ if (config.title) {
157
+ this.title.textContent = config.title;
158
+ // none => block
159
+ this.title.style.display = 'block';
160
+ this.text.setAttribute('style', inlineStyle(textStyle));
161
+ }
162
+ else {
163
+ // block => none
164
+ this.title.style.display = 'none';
165
+ const textCSS = {
166
+ ...textStyle,
167
+ padding: '40px 20px 26px',
168
+ color: '#353535'
169
+ };
170
+ this.text.setAttribute('style', inlineStyle(textCSS));
171
+ }
172
+ this.text.textContent = config.content || '';
173
+ // showCancel
174
+ this.cancel.style.display = config.showCancel ? 'block' : 'none';
175
+ // cancelText
176
+ this.cancel.textContent = config.cancelText || '';
177
+ // cancelColor
178
+ this.cancel.style.color = config.cancelColor || '';
179
+ // confirmText
180
+ this.confirm.textContent = config.confirmText || '';
181
+ // confirmColor
182
+ this.confirm.style.color = config.confirmColor || '';
183
+ // cbs
184
+ this.cancel.onclick = () => {
185
+ this.hide();
186
+ resolve('cancel');
187
+ };
188
+ this.confirm.onclick = () => {
189
+ this.hide();
190
+ resolve('confirm');
191
+ };
192
+ // show
193
+ this.el.style.display = 'block';
194
+ setTimeout(() => { this.el.style.opacity = '1'; }, 0);
195
+ });
196
+ }
197
+ hide() {
198
+ if (this.hideOpacityTimer)
199
+ clearTimeout(this.hideOpacityTimer);
200
+ if (this.hideDisplayTimer)
201
+ clearTimeout(this.hideDisplayTimer);
202
+ this.hideOpacityTimer = setTimeout(() => {
203
+ this.el.style.opacity = '0';
204
+ this.hideDisplayTimer = setTimeout(() => { this.el.style.display = 'none'; }, 200);
205
+ }, 0);
206
+ }
207
+ }