@tarojs/taro 3.6.7 → 3.6.9-alpha.1

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.7",
3
+ "version": "3.6.9-alpha.1",
4
4
  "description": "Taro framework",
5
5
  "homepage": "https://github.com/nervjs/taro/tree/master/packages/taro#readme",
6
6
  "main": "index.js",
@@ -21,11 +21,15 @@
21
21
  "author": "O2Team",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@tarojs/api": "3.6.7",
25
- "@tarojs/runtime": "3.6.7"
24
+ "@tarojs/api": "3.6.9-alpha.1",
25
+ "@tarojs/runtime": "3.6.9-alpha.1"
26
26
  },
27
27
  "devDependencies": {
28
- "@tarojs/helper": "3.6.7"
28
+ "postcss": "^8.4.18",
29
+ "@tarojs/helper": "3.6.9-alpha.1"
30
+ },
31
+ "peerDependencies": {
32
+ "postcss": "^8.4.18"
29
33
  },
30
34
  "peerDependenciesMeta": {
31
35
  "@types/react": {
@@ -3,7 +3,7 @@ import Taro from '../../index'
3
3
  declare module '../../index' {
4
4
  interface TaroStatic {
5
5
  /** 判断小程序的 API,回调,参数,组件等是否在当前版本可用。
6
- * @supported weapp, tt
6
+ * @supported weapp, tt, h5
7
7
  * @example
8
8
  * ```tsx
9
9
  * Taro.canIUse('openBluetoothAdapter')
@@ -36,7 +36,7 @@ declare module '../../index' {
36
36
  ): boolean
37
37
 
38
38
  /** 判断能否使用 WebP 格式
39
- *
39
+ *
40
40
  * > 在小程序平台中仅在 android 和 devtools 设备时可用
41
41
  * @supported global
42
42
  */
@@ -259,7 +259,7 @@ declare module '../../../index' {
259
259
  */
260
260
  offAppHide(
261
261
  /** 小程序切后台事件的回调函数 */
262
- callback: (res: onAppHide.CallbackResult) => void,
262
+ callback: (res: onAppShow.CallbackResult) => void,
263
263
  ): void
264
264
  }
265
265
  }
@@ -75,12 +75,12 @@ declare module '../../index' {
75
75
 
76
76
  interface TaroStatic {
77
77
  /** 向系统日历添加重复事件
78
- * @supported weapp
78
+ * @supported weapp, h5
79
79
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/calendar/wx.addPhoneRepeatCalendar.html
80
80
  */
81
81
  addPhoneRepeatCalendar(option: addPhoneRepeatCalendar.Option): Promise<TaroGeneral.CallbackResult>
82
82
  /** 向系统日历添加事件
83
- * @supported weapp, tt
83
+ * @supported weapp, tt, h5
84
84
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/device/calendar/wx.addPhoneCalendar.html
85
85
  */
86
86
  addPhoneCalendar(option: addPhoneCalendar.Option): Promise<TaroGeneral.CallbackResult>
@@ -127,19 +127,30 @@ declare module '../../index' {
127
127
 
128
128
  namespace chooseImage {
129
129
  interface Option {
130
+ /** 最多可以选择的图片张数
131
+ * @default 9
132
+ * @supported weapp, alipay, swan, tt, h5, rn
133
+ */
134
+ count?: number
135
+ /** 所选的图片的尺寸
136
+ * @default ['original', 'compressed']
137
+ * @supported weapp, alipay, swan, tt, rn
138
+ */
139
+ sizeType?: Array<keyof sizeType>
140
+ /** 选择图片的来源
141
+ * @default ['album', 'camera']
142
+ * @supported weapp, alipay, swan, tt, h5, rn
143
+ */
144
+ sourceType?: Array<keyof sourceType>
130
145
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
131
146
  complete?: (res: TaroGeneral.CallbackResult) => void
132
- /** 最多可以选择的图片张数 */
133
- count?: number
134
147
  /** 接口调用失败的回调函数 */
135
148
  fail?: (res: TaroGeneral.CallbackResult) => void
136
- /** 所选的图片的尺寸 */
137
- sizeType?: Array<keyof sizeType>
138
- /** 选择图片的来源 */
139
- sourceType?: Array<keyof sourceType>
140
149
  /** 接口调用成功的回调函数 */
141
150
  success?: (result: SuccessCallbackResult) => void
142
- /** 用来上传的input元素ID(仅h5端)@supported h5 */
151
+ /** 用来上传的input元素ID(仅h5
152
+ * @supported h5
153
+ */
143
154
  imageId?: string
144
155
  }
145
156
  /** 图片的尺寸 */
@@ -301,7 +312,7 @@ declare module '../../index' {
301
312
 
302
313
  interface TaroStatic {
303
314
  /** 保存图片到系统相册。需要[用户授权](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html) scope.writePhotosAlbum
304
- * @supported weapp, rn, alipay, swan, tt
315
+ * @supported weapp, alipay, swan, tt, h5, rn
305
316
  * @example
306
317
  * ```tsx
307
318
  * Taro.saveImageToPhotosAlbum({
@@ -325,7 +336,7 @@ declare module '../../index' {
325
336
  previewMedia(option: previewMedia.Option): Promise<TaroGeneral.CallbackResult>
326
337
 
327
338
  /** 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。
328
- * @supported weapp, h5, rn, alipay, swan, tt
339
+ * @supported weapp, alipay, swan, tt, h5, rn
329
340
  * @example
330
341
  * ```tsx
331
342
  * Taro.previewImage({
@@ -338,7 +349,7 @@ declare module '../../index' {
338
349
  previewImage(option: previewImage.Option): Promise<TaroGeneral.CallbackResult>
339
350
 
340
351
  /** 获取图片信息。网络图片需先配置download域名才能生效。
341
- * @supported weapp, h5, rn, alipay, swan, tt
352
+ * @supported weapp, alipay, swan, tt, h5, rn
342
353
  * @example
343
354
  * ```tsx
344
355
  * Taro.getImageInfo({
@@ -377,7 +388,7 @@ declare module '../../index' {
377
388
  editImage(option: editImage.Option): Promise<editImage.SuccessCallbackResult>
378
389
 
379
390
  /** 压缩图片接口,可选压缩质量
380
- * @supported weapp, rn, tt
391
+ * @supported weapp, tt, rn
381
392
  * @example
382
393
  * ```tsx
383
394
  * Taro.compressImage({
@@ -408,7 +419,7 @@ declare module '../../index' {
408
419
 
409
420
  /**
410
421
  * 从本地相册选择图片或使用相机拍照。
411
- * @supported weapp, h5, rn, alipay, swan, tt
422
+ * @supported weapp, alipay, swan, tt, h5, rn
412
423
  * @example
413
424
  * ```tsx
414
425
  * Taro.chooseImage({
@@ -233,30 +233,42 @@ declare module '../../index' {
233
233
 
234
234
  namespace chooseVideo {
235
235
  interface Option {
236
- /** 默认拉起的是前置或者后置摄像头。部分 Android 手机下由于系统 ROM 不支持无法生效 */
236
+ /** 默认拉起的是前置或者后置摄像头。部分 Android 手机下由于系统 ROM 不支持无法生效
237
+ * @default "back"
238
+ * @supported weapp, h5
239
+ */
237
240
  camera?: keyof Camera
241
+ /** 是否压缩所选择的视频文件
242
+ * @default true
243
+ * @supported weapp
244
+ */
245
+ compressed?: boolean
246
+ /** 拍摄视频最长拍摄时间,单位秒
247
+ * @default 60
248
+ * @supported weapp
249
+ */
250
+ maxDuration?: number
251
+ /** 视频选择的来源
252
+ * @default ['album', 'camera']
253
+ * @supported weapp, h5
254
+ */
255
+ sourceType?: Array<keyof sourceType>
238
256
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
239
257
  complete?: (res: TaroGeneral.CallbackResult) => void
240
- /** 是否压缩所选择的视频文件 */
241
- compressed?: boolean
242
258
  /** 接口调用失败的回调函数 */
243
259
  fail?: (res: TaroGeneral.CallbackResult) => void
244
- /** 拍摄视频最长拍摄时间,单位秒 */
245
- maxDuration?: number
246
- /** 视频选择的来源 */
247
- sourceType?: Array<keyof sourceType>
248
260
  /** 接口调用成功的回调函数 */
249
261
  success?: (result: SuccessCallbackResult) => void
250
262
  }
251
263
  interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
264
+ /** 选定视频的临时文件路径 */
265
+ tempFilePath: string
252
266
  /** 选定视频的时间长度 */
253
267
  duration: number
254
- /** 返回选定视频的高度 */
255
- height: number
256
268
  /** 选定视频的数据量大小 */
257
269
  size: number
258
- /** 选定视频的临时文件路径 */
259
- tempFilePath: string
270
+ /** 返回选定视频的高度 */
271
+ height: number
260
272
  /** 返回选定视频的宽度 */
261
273
  width: number
262
274
  /** 调用结果 */
@@ -276,30 +288,53 @@ declare module '../../index' {
276
288
  }
277
289
  }
278
290
 
279
-
280
291
  namespace chooseMedia {
281
292
  interface Option {
282
- /** 最多可以选择的文件个数 */
293
+ /** 最多可以选择的文件个数
294
+ * @default 9
295
+ * @supported weapp, h5
296
+ */
283
297
  count?: number
284
- /** 文件类型 */
298
+ /** 文件类型
299
+ * @default ['image', 'video']
300
+ * @supported weapp, h5
301
+ */
285
302
  mediaType?: Array<keyof mediaType>
286
- /** 图片和视频选择的来源 */
303
+ /** 图片和视频选择的来源
304
+ * @default ['album', 'camera']
305
+ * @supported weapp, h5
306
+ */
287
307
  sourceType?: Array<keyof sourceType>
288
- /** 拍摄视频最长拍摄时间,单位秒。时间范围为 3s 至 30s 之间 */
308
+ /** 拍摄视频最长拍摄时间,单位秒。时间范围为 3s 至 60s 之间
309
+ * @default 10
310
+ * @supported weapp
311
+ */
289
312
  maxDuration?: number
290
- /** 仅对 mediaType 为 image 时有效,是否压缩所选文件 */
313
+ /** 是否压缩所选文件
314
+ * @default ['original', 'compressed']
315
+ * @supported weapp
316
+ */
291
317
  sizeType?: Array<'original' | 'compressed'>
292
- /** 仅在 sourceType 为 camera 时生效,使用前置或后置摄像头 */
318
+ /** 仅在 sourceType 为 camera 时生效,使用前置或后置摄像头
319
+ * @default "back"
320
+ * @supported weapp, h5
321
+ */
293
322
  camera?: string
323
+ /** 接口调用结束的回调函数(调用成功、失败都会执行) */
324
+ complete?: (res: TaroGeneral.CallbackResult) => void
294
325
  /** 接口调用失败的回调函数 */
295
326
  fail?: (res: TaroGeneral.CallbackResult) => void
296
327
  /** 接口调用成功的回调函数 */
297
328
  success?: (result: SuccessCallbackResult) => void
329
+ /** 用来上传的input元素ID
330
+ * @supported h5
331
+ */
332
+ mediaId?: string
298
333
  }
299
334
  interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
300
335
  /** 本地临时文件列表 */
301
336
  tempFiles: ChooseMedia[]
302
- /** 文件类型,有效值有 image 、video */
337
+ /** 文件类型,有效值有 image 、video、mix */
303
338
  type: string
304
339
  }
305
340
  /** 本地临时文件列表 */
@@ -316,6 +351,12 @@ declare module '../../index' {
316
351
  width: number
317
352
  /** 视频缩略图临时文件路径 */
318
353
  thumbTempFilePath: string
354
+ /** 选择的文件的类型 */
355
+ fileType: string
356
+ /** 原始的浏览器 File 对象
357
+ * @supported h5
358
+ */
359
+ originalFileObj?: File
319
360
  }
320
361
  interface mediaType {
321
362
  /** 只能拍摄视频或从相册选择视频 */
@@ -346,11 +387,11 @@ declare module '../../index' {
346
387
  * **Bug & Tip:**
347
388
  *
348
389
  * 1. `tip`: camera 参数在部分 Android 手机下由于系统 ROM 不支持无法生效
349
- * @supported weapp, rn
390
+ * @supported weapp, h5, rn
350
391
  * @example
351
392
  ```tsx
352
393
  * Taro.saveVideoToPhotosAlbum({
353
- * filePath: 'wxfile://xxx',
394
+ * filePath: 'file://xxx',
354
395
  * success: function (res) {
355
396
  * console.log(res.errMsg)
356
397
  * }
@@ -447,7 +488,7 @@ declare module '../../index' {
447
488
  compressVideo(option: compressVideo.Option): Promise<compressVideo.SuccessCallbackResult>
448
489
 
449
490
  /** 拍摄视频或从手机相册中选视频。
450
- * @supported weapp, rn
491
+ * @supported weapp, h5, rn
451
492
  * @example
452
493
  * ```tsx
453
494
  * Taro.chooseVideo({
@@ -464,7 +505,7 @@ declare module '../../index' {
464
505
  chooseVideo(option: chooseVideo.Option): Promise<chooseVideo.SuccessCallbackResult>
465
506
 
466
507
  /** 拍摄或从手机相册中选择图片或视频。
467
- * @supported weapp
508
+ * @supported weapp, h5
468
509
  * @example
469
510
  * ```tsx
470
511
  * Taro.chooseMedia({
@@ -60,58 +60,61 @@ declare module '../../index' {
60
60
  fail?: (res: TaroGeneral.CallbackResult) => void
61
61
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
62
62
  complete?: (res: TaroGeneral.CallbackResult) => void
63
- /** 设置 H5 端是否使用jsonp方式获取数据
63
+ /** 设置是否使用 jsonp 方式获取数据
64
64
  * @default false
65
65
  * @supported h5
66
66
  */
67
- jsonp?: boolean
68
- /** 设置 H5 端 jsonp 请求 url 是否需要被缓存
69
- * @default false
67
+ jsonp?: boolean | string
68
+ /** 设置 jsonp 请求 url 是否需要被缓存
70
69
  * @supported h5
71
70
  */
72
- jsonpCache?: boolean
73
- /** 设置 H5 端是否允许跨域请求
71
+ jsonpCache?: RequestCache
72
+ /** 设置是否允许跨域请求
74
73
  * @default "same-origin"
75
74
  * @supported h5
76
75
  */
77
76
  mode?: keyof CorsMode
78
- /** 设置 H5 端是否携带 Cookie
77
+ /** 设置是否携带 Cookie
79
78
  * @default "omit"
80
79
  * @supported h5
81
80
  */
82
81
  credentials?: keyof Credentials
83
- /** 设置 H5 端缓存模式
82
+ /** 设置缓存模式
84
83
  * @default "default"
85
84
  * @supported h5
86
85
  */
87
86
  cache?: keyof Cache
88
- /** 设置 H5 端请求重试次数
87
+ /** 设置请求重试次数
89
88
  * @default 2
90
89
  * @supported h5
91
90
  */
92
91
  retryTimes?: number
93
- /** 设置 H5 端请求的兜底接口
92
+ /** 设置请求的兜底接口
94
93
  * @supported h5
95
94
  */
96
95
  backup?: string | string[]
97
- /** 设置 H5 端请求响应的数据校验函数,若返回 false,则请求兜底接口,若无兜底接口,则报请求失败
96
+ /** 设置请求中止信号
97
+ * @supported h5
98
+ */
99
+ signal?: AbortSignal
100
+ /** 设置请求响应的数据校验函数,若返回 false,则请求兜底接口,若无兜底接口,则报请求失败
98
101
  * @supported h5
99
102
  */
100
103
  dataCheck?(): boolean
101
- /** 设置 H5 端请求是否使用缓存
104
+ /** 设置请求是否使用缓存
102
105
  * @default false
103
106
  * @supported h5
104
107
  */
105
108
  useStore?: boolean
106
- /** 设置 H5 端请求缓存校验的 key
109
+ /** 设置请求缓存校验的 key
107
110
  * @supported h5
108
111
  */
109
112
  storeCheckKey?: string
110
- /** 设置 H5 端请求缓存签名
113
+ /** 设置请求缓存签名
111
114
  * @supported h5
112
115
  */
113
116
  storeSign?: string
114
- /** 设置 H5 端请求校验函数,一般不需要设置
117
+ /** 设置请求校验函数,一般不需要设置
115
118
  * @supported h5
116
119
  */
117
120
  storeCheck?(): boolean
@@ -1,8 +1,9 @@
1
1
  import type Webpack from 'webpack'
2
2
  import type Chain from 'webpack-chain'
3
+ import { type Input } from 'postcss'
3
4
  import type { Compiler } from '../compiler'
4
5
  import type { IModifyWebpackChain } from '../hooks'
5
- import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from "./util"
6
+ import type { ICopyOptions, IOption, ISassOptions, TogglableOptions } from './util'
6
7
  import type { IH5Config } from './h5'
7
8
  import type { IMiniAppConfig } from './mini'
8
9
 
@@ -22,58 +23,114 @@ interface ILogger {
22
23
  export interface IProjectBaseConfig {
23
24
  isWatch?: boolean
24
25
  port?: number
26
+ /** 项目名称 */
25
27
  projectName?: string
28
+
29
+ /** 项目创建日期 */
26
30
  date?: string
27
- designWidth?: number | ((size?: string | number) => number)
31
+
32
+ /** 设计稿尺寸 */
33
+ designWidth?: number | ((size?: string | number | Input) => number)
34
+
35
+ /** 设计稿尺寸换算规则 */
28
36
  deviceRatio?: TaroGeneral.TDeviceRatio
37
+
29
38
  watcher?: any[]
39
+
40
+ /** 源码存放目录 (默认值:'src') */
30
41
  sourceRoot?: string
42
+
43
+ /** 代码编译后的生产目录 (默认值:'dist') */
31
44
  outputRoot?: string
45
+
46
+ /** 用于设置环境变量 (除了NODE_ENV以外,其他环境变量建议在根目录下的.env文件中) */
32
47
  env?: IOption
48
+
49
+ /** 用于配置目录别名,从而方便书写代码引用路径 */
33
50
  alias?: IOption
51
+
52
+ /** 用于配置一些全局变量供代码中进行使用(建议放在根目录下的.env文件中) */
34
53
  defineConstants?: IOption
54
+
55
+ /** 用于把文件从源码目录直接拷贝到编译后的生产目录 */
35
56
  copy?: ICopyOptions
57
+
58
+ /** 配置 JS 压缩工具 (默认 terser) */
36
59
  jsMinimizer?: 'terser' | 'esbuild'
60
+
61
+ /** 配置 CSS 压缩工具 (默认 csso) */
37
62
  cssMinimizer?: 'csso' | 'esbuild' | 'parcelCss'
63
+
64
+ /** 配置 csso 工具以压缩 CSS 代码 */
38
65
  csso?: TogglableOptions
66
+
67
+ /** 配置 terser 工具以压缩 JS 代码 */
39
68
  terser?: TogglableOptions
69
+
40
70
  esbuild?: Record<'minify', TogglableOptions>
71
+
41
72
  uglify?: TogglableOptions
73
+
74
+ /** 用于控制对 scss 代码的编译行为,默认使用 dart-sass,具体配置可以参考 https://www.npmjs.com/package/sass */
42
75
  sass?: ISassOptions
76
+
77
+ /** 配置 Taro 插件 */
43
78
  plugins?: PluginItem[]
79
+
80
+ /** 一个 preset 是一系列 Taro 插件的集合,配置语法同 plugins */
44
81
  presets?: PluginItem[]
82
+
83
+ /** 模板循环次数 */
45
84
  baseLevel?: number
46
- framework?: string
85
+
86
+ /** 使用的开发框架。可选值:react、preact、nerv、vue、vue3 */
87
+ framework?: 'react' | 'preact' | 'nerv' | 'vue' | 'vue3'
47
88
  frameworkExts?: string[]
89
+
90
+ /** 使用的编译工具。可选值:webpack4、webpack5 */
48
91
  compiler?: Compiler
92
+
93
+ /** Webpack5 持久化缓存配置。具体配置请参考 [WebpackConfig.cache](https://webpack.js.org/configuration/cache/#cache) */
49
94
  cache?: ICache
95
+
96
+ /** 控制 Taro 编译日志的输出方式 */
50
97
  logger?: ILogger
98
+
99
+ /** 用于控制是否生成 js、css 对应的 sourceMap */
51
100
  enableSourceMap?: boolean
101
+
52
102
  /**
53
103
  * 编译开始
54
104
  */
55
105
  onBuildStart?: (...args: any[]) => Promise<any>
106
+
56
107
  /**
57
108
  * 编译完成(启动项目后首次编译结束后会触发一次)
58
109
  */
59
110
  onBuildComplete?: (...args: any[]) => Promise<any>
111
+
60
112
  /**
61
113
  * 编译结束(保存代码每次编译结束后都会触发)
62
114
  */
63
- onBuildFinish?: (res: { error, stats, isWatch }) => Promise<any>
115
+ onBuildFinish?: (res: { error; stats; isWatch }) => Promise<any>
116
+
64
117
  /**
65
118
  * 修改编译过程中的页面组件配置
66
119
  */
67
120
  onCompilerMake?: (compilation: Webpack.Compilation, compiler: Webpack.Compiler, plugin: any) => Promise<any>
121
+
68
122
  onWebpackChainReady?: (webpackChain: Chain) => Promise<any>
123
+
69
124
  /**
70
125
  * 编译中修改 webpack 配置,在这个钩子中,你可以对 webpackChain 作出想要的调整,等同于配置 [`webpackChain`](./config-detail#miniwebpackchain)
71
126
  */
72
127
  modifyWebpackChain?: (chain: Chain, webpack: typeof Webpack, data: IModifyWebpackChain) => Promise<any>
128
+
73
129
  /**
74
130
  * 修改编译过程中的页面组件配置
75
131
  */
76
132
  modifyMiniConfigs?: (configMap: any) => Promise<any>
133
+
77
134
  /**
78
135
  * 修改编译后的结果
79
136
  */
@@ -81,11 +138,14 @@ export interface IProjectBaseConfig {
81
138
  }
82
139
 
83
140
  export interface IProjectConfig extends IProjectBaseConfig {
84
- ui?: {
85
- extraWatchFiles?: any[]
86
- }
141
+ /** 专属于小程序的配置 */
87
142
  mini?: IMiniAppConfig
143
+
144
+ /** 专属于 H5 的配置 */
88
145
  h5?: IH5Config
146
+
147
+ /** 专属于 RN 的配置 */
89
148
  rn?: IH5Config
149
+
90
150
  [key: string]: any
91
151
  }
@@ -154,6 +154,11 @@ declare module './index' {
154
154
  * @default: false
155
155
  */
156
156
  disableScroll?: boolean
157
+ /** 是否使用页面全局滚动,MPA下默认为全局滚动,SPA默认为局部滚动
158
+ * 只在H5生效
159
+ * @default: MPA:true SPA:false
160
+ */
161
+ usingWindowScroll?: boolean
157
162
  /** 禁止页面右滑手势返回
158
163
  *
159
164
  * **注意** 自微信客户端 7.0.5 开始,页面配置中的 disableSwipeBack 属性将不再生效,
@@ -360,7 +365,9 @@ declare module './index' {
360
365
  * @default false
361
366
  * @since 2.1.0
362
367
  */
363
- functionalPages?: boolean
368
+ functionalPages?: boolean | {
369
+ independent?: boolean
370
+ }
364
371
  /** 分包结构配置
365
372
  * @example
366
373
  * ```json