@tarojs/taro 3.6.6-alpha.0 → 3.6.6-alpha.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro",
3
- "version": "3.6.6-alpha.0",
3
+ "version": "3.6.6-alpha.2",
4
4
  "description": "Taro framework",
5
5
  "homepage": "https://github.com/nervjs/taro/tree/master/packages/taro#readme",
6
6
  "main": "index.js",
@@ -21,8 +21,11 @@
21
21
  "author": "O2Team",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@tarojs/api": "3.6.6-alpha.0",
25
- "@tarojs/runtime": "3.6.6-alpha.0"
24
+ "@tarojs/api": "3.6.6-alpha.2",
25
+ "@tarojs/runtime": "3.6.6-alpha.2"
26
+ },
27
+ "devDependencies": {
28
+ "@tarojs/helper": "3.6.6-alpha.2"
26
29
  },
27
30
  "peerDependenciesMeta": {
28
31
  "@types/react": {
@@ -37,8 +40,5 @@
37
40
  "vue": {
38
41
  "optional": true
39
42
  }
40
- },
41
- "scripts": {
42
- "test": "echo \"Error: run tests from root\" && exit 1"
43
43
  }
44
44
  }
@@ -26,7 +26,7 @@ declare module '../../index' {
26
26
  * @supported weapp
27
27
  * @example
28
28
  * ```tsx
29
- * Taro.getRandomValues({
29
+ * Taro.getUserCryptoManager().getRandomValues({
30
30
  * length: 6 // 生成 6 个字节长度的随机数,
31
31
  * success: res => {
32
32
  * console.log(Taro.arrayBufferToBase64(res.randomValues)) // 转换为 base64 字符串后打印
@@ -35,7 +35,7 @@ declare module '../../index' {
35
35
  * ```
36
36
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/base/crypto/UserCryptoManager.getRandomValues.html
37
37
  */
38
- getRandomValues(option: UserCryptoManager.getRandomValues.Option): Promise<UserCryptoManager.getRandomValues.SuccessCallbackResult>
38
+ getRandomValues(option: UserCryptoManager.getRandomValues.Option): void
39
39
  }
40
40
 
41
41
  namespace UserCryptoManager {
@@ -66,7 +66,7 @@ declare module '../../index' {
66
66
  /** 整数,生成随机数的字节数,最大 1048576 */
67
67
  length: number
68
68
  /** 接口调用成功的回调函数 */
69
- success?: (res: TaroGeneral.CallbackResult) => void
69
+ success?: (res: SuccessCallbackResult) => void
70
70
  /** 接口调用失败的回调函数 */
71
71
  fail?: (res: TaroGeneral.CallbackResult) => void
72
72
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
@@ -86,5 +86,19 @@ declare module '../../index' {
86
86
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/base/crypto/wx.getUserCryptoManager.html
87
87
  */
88
88
  getUserCryptoManager(): UserCryptoManager
89
+
90
+ /** 获取密码学安全随机数
91
+ * @supported weapp
92
+ * @example
93
+ * ```tsx
94
+ * Taro.getRandomValues({
95
+ * length: 6 // 生成 6 个字节长度的随机数
96
+ * }).then(res => {
97
+ * console.log(Taro.arrayBufferToBase64(res.randomValues)) // 转换为 base64 字符串后打印
98
+ * })
99
+ * ```
100
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/base/crypto/UserCryptoManager.getRandomValues.html
101
+ */
102
+ getRandomValues(option: UserCryptoManager.getRandomValues.Option): Promise<UserCryptoManager.getRandomValues.SuccessCallbackResult>
89
103
  }
90
104
  }
@@ -0,0 +1,203 @@
1
+ import React from 'react'
2
+
3
+ import Taro from '../index'
4
+
5
+ declare module '../index' {
6
+ namespace getAppInfo {
7
+ /** 应用信息 */
8
+ interface AppInfo {
9
+ platform: string
10
+ taroVersion: string
11
+ designWidth: number | ((size?: string | number) => number)
12
+ }
13
+ }
14
+
15
+ namespace getCurrentInstance {
16
+ interface Current {
17
+ app: AppInstance | null
18
+ router: RouterInfo | null
19
+ page: PageInstance | null
20
+ onReady: string
21
+ onHide: string
22
+ onShow: string
23
+ preloadData?: Record<any, any>
24
+ /**
25
+ * RN 私有对象navigationRef,用于使用底层接口控制路由
26
+ */
27
+ rnNavigationRef?: React.RefObject<any>
28
+ }
29
+ }
30
+
31
+ namespace setGlobalDataPlugin {
32
+ /** Vue3 插件,用于设置 `getApp()` 中的全局变量 */
33
+ interface Plugin {
34
+ install (app: any, data: any): void
35
+ }
36
+ }
37
+
38
+ /** @ignore */
39
+ interface TARO_ENV_TYPE {
40
+ [TaroGeneral.ENV_TYPE.WEAPP]: TaroGeneral.ENV_TYPE.WEAPP
41
+ [TaroGeneral.ENV_TYPE.WEB]: TaroGeneral.ENV_TYPE.WEB
42
+ [TaroGeneral.ENV_TYPE.RN]: TaroGeneral.ENV_TYPE.RN
43
+ [TaroGeneral.ENV_TYPE.SWAN]: TaroGeneral.ENV_TYPE.SWAN
44
+ [TaroGeneral.ENV_TYPE.ALIPAY]: TaroGeneral.ENV_TYPE.ALIPAY
45
+ [TaroGeneral.ENV_TYPE.TT]: TaroGeneral.ENV_TYPE.TT
46
+ [TaroGeneral.ENV_TYPE.QQ]: TaroGeneral.ENV_TYPE.QQ
47
+ [TaroGeneral.ENV_TYPE.JD]: TaroGeneral.ENV_TYPE.JD
48
+ }
49
+
50
+ namespace interceptorify {
51
+ type promiseifyApi<T, R> = (requestParams: T) => Promise<R>
52
+ interface InterceptorifyChain<T, R> {
53
+ requestParams: T
54
+ proceed: promiseifyApi<T, R>
55
+ }
56
+ type InterceptorifyInterceptor<T, R> = (chain: InterceptorifyChain<T, R>) => Promise<R>
57
+ interface Interceptorify<T, R> {
58
+ request(requestParams: T): Promise<R>
59
+ addInterceptor( interceptor: InterceptorifyInterceptor<T, R>): void
60
+ cleanInterceptors(): void
61
+ }
62
+ }
63
+
64
+ interface TaroStatic {
65
+ /** @ignore */
66
+ Events: {
67
+ new (): TaroGeneral.Events
68
+ }
69
+
70
+ /** 事件中心
71
+ * @supported global
72
+ */
73
+ eventCenter: TaroGeneral.Events
74
+
75
+ /** @ignore */
76
+ ENV_TYPE: TARO_ENV_TYPE
77
+
78
+ /** 获取环境变量
79
+ * @supported global
80
+ */
81
+ getEnv(): TaroGeneral.ENV_TYPE
82
+
83
+ /** 尺寸转换
84
+ * @supported global
85
+ */
86
+ pxTransform(size: number, designWidth?: number): string
87
+
88
+ /** 尺寸转换初始化
89
+ * @supported global
90
+ */
91
+ initPxTransform(config: {
92
+ baseFontSize?: number
93
+ deviceRatio?: TaroGeneral.TDeviceRatio
94
+ designWidth?: number | ((size?: string | number) => number)
95
+ targetUnit?: string
96
+ unitPrecision?: number
97
+ }): void
98
+
99
+ /** @ignore */
100
+ initAppInfo(appInfo: getAppInfo.AppInfo): void
101
+
102
+ /** 小程序获取和 Taro 相关的 App 信息
103
+ * @supported weapp, alipay, jd, qq, swan, tt, h5
104
+ */
105
+ getAppInfo(): getAppInfo.AppInfo
106
+
107
+ /** 小程序引用插件 JS 接口
108
+ * @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
109
+ */
110
+ requirePlugin(pluginName: string): any
111
+
112
+ /** 获取当前页面实例
113
+ * @supported global
114
+ */
115
+ getCurrentInstance(): getCurrentInstance.Current
116
+
117
+ /** @ignore */
118
+ Current: getCurrentInstance.Current
119
+
120
+ /** Vue3 插件,用于设置 `getApp()` 中的全局变量
121
+ * @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
122
+ * @example
123
+ * ```js
124
+ * // 使用插件
125
+ * const App = createApp(...)
126
+ * App.use(setGlobalDataPlugin, {
127
+ * xxx: 999
128
+ * })
129
+ * // 获取全局变量
130
+ * Taro.getApp().xxx
131
+ * ```
132
+ */
133
+ setGlobalDataPlugin: setGlobalDataPlugin.Plugin
134
+
135
+ /** 获取自定义 TabBar 对应的 React 或 Vue 组件实例
136
+ * @supported weapp
137
+ * @param page 小程序页面对象,可以通过 Taro.getCurrentInstance().page 获取
138
+ */
139
+ getTabBar<T>(page: getCurrentInstance.Current['page']): T | undefined
140
+
141
+ /** 获取当前页面渲染引擎类型
142
+ * @supported weapp
143
+ */
144
+ getRenderer(): 'webview' | 'skyline'
145
+
146
+ /**
147
+ * 包裹 promiseify api 的洋葱圈模型
148
+ * @supported global
149
+ * @param promiseifyApi
150
+ * @example
151
+ * ```tsx
152
+ * // 创建实例
153
+ * const modalInterceptorify = interceptorify(taro.showModal)
154
+ * // 添加拦截器
155
+ * modalInterceptorify.addInterceptor(async function (chain) {
156
+ * const res = await chain.proceed({
157
+ * ...chain.requestParams,
158
+ * title: 'interceptor1'
159
+ * })
160
+ * return res
161
+ * })
162
+ * modalInterceptorify.addInterceptor(async function (chain) {
163
+ * const res = await chain.proceed({
164
+ * ...chain.requestParams,
165
+ * content: 'interceptor2'
166
+ * })
167
+ * return res
168
+ * })
169
+ * // 使用
170
+ * modalInterceptorify.request({})
171
+ * ```
172
+ * @example
173
+ * ```tsx
174
+ * // 创建实例
175
+ * const fetchDataInterceptorify = interceptorify(taro.request)
176
+ * // 添加拦截器
177
+ * fetchDataInterceptorify.addInterceptor(async function (chain) {
178
+ * taro.showLoading({
179
+ * title: 'Loading...'
180
+ * })
181
+ * const res = await chain.proceed(chain.requestParams)
182
+ * taro.hideLoading()
183
+ * return res
184
+ * })
185
+ * fetchDataInterceptorify.addInterceptor(async function (chain) {
186
+ * const params = chain.requestParams
187
+ * const res = await chain.proceed({
188
+ * url: 'http://httpbin.org' + params.url,
189
+ * })
190
+ * return res.data
191
+ * })
192
+ * // 使用
193
+ * fetchDataInterceptorify.request({
194
+ * url: '/ip'
195
+ * }).then((res) => {
196
+ * // log my ip
197
+ * console.log(res.origin)
198
+ * })
199
+ * ```
200
+ */
201
+ interceptorify<T, R>(promiseifyApi: interceptorify.promiseifyApi<T, R>): interceptorify.Interceptorify<T, R>
202
+ }
203
+ }
@@ -1,6 +1,6 @@
1
- import Taro from './index'
1
+ import Taro from '../index'
2
2
 
3
- declare module './index' {
3
+ declare module '../index' {
4
4
  interface TaroStatic {
5
5
  /**
6
6
  * 页面展示时的回调。
@@ -46,7 +46,7 @@ declare module './index' {
46
46
 
47
47
  /**
48
48
  * 当前是 tab 页时,tab 被点击时的回调。
49
- * @supported weapp, rn
49
+ * @supported weapp, h5, rn
50
50
  */
51
51
  useTabItemTap(callback: (payload: TabItemTapObject) => void): void
52
52
 
@@ -1,4 +1,4 @@
1
- import type swc from '@swc/core'
1
+ import type { swc } from '@tarojs/helper'
2
2
  import type Webpack from 'webpack'
3
3
 
4
4
  type CompilerTypes = 'webpack4' | 'webpack5'
@@ -24,7 +24,7 @@ export interface IProjectBaseConfig {
24
24
  port?: number
25
25
  projectName?: string
26
26
  date?: string
27
- designWidth?: number | ((size: number) => number)
27
+ designWidth?: number | ((size?: string | number) => number)
28
28
  deviceRatio?: TaroGeneral.TDeviceRatio
29
29
  watcher?: any[]
30
30
  sourceRoot?: string
package/types/index.d.ts CHANGED
@@ -108,13 +108,13 @@
108
108
  * │ │ └── interaction.d.ts 界面 -> 交互 API
109
109
  * │ ├── worker
110
110
  * │ │ └── index.d.ts Worker API
111
- * │ └── wxml
112
- * │ └── index.d.ts WXML API
111
+ * │ ├── wxml
112
+ * │└── index.d.ts WXML API
113
+ * │ ├── taro.extend.d.ts Taro 扩展 API 类型定义
114
+ * │ └── taro.hooks.d.ts Taro Hooks 类型定义
113
115
  * ├── index.d.ts 此文件
114
116
  * ├── taro.component.d.ts Taro Component 类型定义
115
- * ├── taro.config.d.ts Taro 小程序 App 与 Window 设置类型定义
116
- * ├── taro.extend.d.ts Taro 扩展 API 类型定义
117
- * ├── taro.hooks.d.ts Taro Hooks 类型定义
117
+ * ├── taro.config.d.ts Taro 小程序 App 与 Window 设置类型定义
118
118
  * └── taro.lifecycle.d.ts Taro 生命周期类型定义
119
119
  */
120
120
 
@@ -123,8 +123,6 @@
123
123
  /// <reference path="taro.api.d.ts" />
124
124
  /// <reference path="taro.component.d.ts" />
125
125
  /// <reference path="taro.config.d.ts" />
126
- /// <reference path="taro.extend.d.ts" />
127
- /// <reference path="taro.hooks.d.ts" />
128
126
  /// <reference path="taro.lifecycle.d.ts" />
129
127
 
130
128
  /// <reference types="@tarojs/plugin-platform-alipay/types/shims-alipay" />
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * 微信端能力
4
4
  * original code from: https://github.com/wx-minapp/minapp-wx/blob/master/typing/wx.d.ts
5
- * Lincenced under MIT license: https://github.com/qiu8310/minapp/issues/69
5
+ * Licensed under MIT license: https://github.com/qiu8310/minapp/issues/69
6
6
  * thanks for the great work by @qiu8310 👍👍👍
7
7
  *
8
8
  */
@@ -110,3 +110,6 @@
110
110
  /// <reference path="api/alipay/index.d.ts" />
111
111
  /// <reference path="api/qq/index.d.ts" />
112
112
  /// <reference path="api/swan/index.d.ts" />
113
+
114
+ /// <reference path="api/taro.extend.d.ts" />
115
+ /// <reference path="api/taro.hooks.d.ts" />
@@ -1,7 +1,7 @@
1
1
  import React from 'react'
2
2
  import Vue from 'vue'
3
3
 
4
- import Taro, { Config } from './index'
4
+ import Taro from './index'
5
5
 
6
6
  declare module './index' {
7
7
  // ref: packages/taro-runtime/src/current.ts
@@ -1,122 +0,0 @@
1
- import React from 'react'
2
-
3
- import Taro from './index'
4
-
5
- declare module './index' {
6
- type MessageType = 'info' | 'success' | 'error' | 'warning'
7
-
8
- interface AtMessageOptions {
9
- message: string
10
- type?: MessageType
11
- duration?: number
12
- }
13
-
14
- interface AppInfo {
15
- platform: string,
16
- taroVersion: string
17
- designWidth: number
18
- }
19
-
20
- interface RequestParams<T=any> extends request.Option<T, any> {
21
- [propName: string]: any
22
- }
23
-
24
- interface Current {
25
- app: AppInstance | null
26
- router: RouterInfo | null
27
- page: PageInstance | null
28
- onReady: string
29
- onHide: string
30
- onShow: string
31
- preloadData?: Record<any, any>
32
- /**
33
- * RN 私有对象navigationRef,用于使用底层接口控制路由
34
- */
35
- rnNavigationRef?: React.RefObject<any>
36
- }
37
-
38
- interface SetGlobalDataPlugin {
39
- install (app: any, data: any): void
40
- }
41
-
42
- interface TARO_ENV_TYPE {
43
- [TaroGeneral.ENV_TYPE.WEAPP]: TaroGeneral.ENV_TYPE.WEAPP
44
- [TaroGeneral.ENV_TYPE.WEB]: TaroGeneral.ENV_TYPE.WEB
45
- [TaroGeneral.ENV_TYPE.RN]: TaroGeneral.ENV_TYPE.RN
46
- [TaroGeneral.ENV_TYPE.SWAN]: TaroGeneral.ENV_TYPE.SWAN
47
- [TaroGeneral.ENV_TYPE.ALIPAY]: TaroGeneral.ENV_TYPE.ALIPAY
48
- [TaroGeneral.ENV_TYPE.TT]: TaroGeneral.ENV_TYPE.TT
49
- [TaroGeneral.ENV_TYPE.QQ]: TaroGeneral.ENV_TYPE.QQ
50
- [TaroGeneral.ENV_TYPE.JD]: TaroGeneral.ENV_TYPE.JD
51
- }
52
-
53
- interface TaroStatic {
54
- Events: {
55
- new (): TaroGeneral.Events
56
- }
57
-
58
- /** 事件中心
59
- * @supported global
60
- */
61
- eventCenter: TaroGeneral.Events
62
-
63
- ENV_TYPE: TARO_ENV_TYPE
64
-
65
- /** 获取环境变量
66
- * @supported global
67
- */
68
- getEnv(): TaroGeneral.ENV_TYPE
69
-
70
- /** 尺寸转换
71
- * @supported global
72
- */
73
- pxTransform(size: number, designWidth?: number): string
74
-
75
- /** 尺寸转换初始化
76
- * @supported global
77
- */
78
- initPxTransform(config: {
79
- baseFontSize?: number
80
- deviceRatio?: TaroGeneral.TDeviceRatio
81
- designWidth?: number
82
- targetUnit?: string
83
- unitPrecision?: number
84
- }): void
85
-
86
- initAppInfo(appInfo: AppInfo): void
87
-
88
- getAppInfo(): AppInfo
89
-
90
- /** 小程序引用插件 JS 接口
91
- * @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
92
- */
93
- requirePlugin(pluginName: string): any
94
-
95
- /** 获取当前页面实例
96
- * @supported global
97
- */
98
- getCurrentInstance(): Current
99
- Current: Current
100
-
101
- /** Vue3 插件,用于设置 `getApp()` 中的全局变量
102
- * @supported weapp, alipay, h5, rn, jd, qq, swan, tt, quickapp
103
- * @example
104
- * ```js
105
- * // 使用插件
106
- * const App = createApp(...)
107
- * App.use(setGlobalDataPlugin, {
108
- * xxx: 999
109
- * })
110
- * // 获取全局变量
111
- * Taro.getApp().xxx
112
- * ```
113
- */
114
- setGlobalDataPlugin: SetGlobalDataPlugin
115
-
116
- /** 获取自定义 TabBar 对应的 React 或 Vue 组件实例
117
- * @supported weapp
118
- * @param page 小程序页面对象,可以通过 Taro.getCurrentInstance().page 获取
119
- */
120
- getTabBar<T>(page: Current['page']): T | undefined
121
- }
122
- }