From b7adffcf92433d45d5ea10732082be993bd22d14 Mon Sep 17 00:00:00 2001 From: konka <1094918@gmail.com> Date: Wed, 21 Aug 2024 22:49:55 +0800 Subject: [PATCH] fix(type): types additions #16325 #16328 --- .../taro/types/api/base/weapp/life-cycle.d.ts | 35 +++++++++++++++++ packages/taro/types/api/ui/interaction.d.ts | 8 +++- packages/taro/types/compile/config/mini.d.ts | 38 +++++++++++++++++-- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/packages/taro/types/api/base/weapp/life-cycle.d.ts b/packages/taro/types/api/base/weapp/life-cycle.d.ts index f2986b923d35..52782b465911 100644 --- a/packages/taro/types/api/base/weapp/life-cycle.d.ts +++ b/packages/taro/types/api/base/weapp/life-cycle.d.ts @@ -1,6 +1,21 @@ import Taro from '../../../index' declare module '../../../index' { + namespace onApiCategoryChange { + type Listener = (res: { apiCategory: keyof onApiCategoryChange.ApiCategory }) => void + + /** API 类别合法值 */ + interface ApiCategory { + /** 默认类别 */ + default + /** 原生功能化,视频号直播商品、商品橱窗等场景打开的小程序 */ + nativeFunctionalized + /** 仅浏览,朋友圈快照页等场景打开的小程序 */ + browseOnly + /** 内嵌,通过打开半屏小程序能力打开的小程序 */ + embedded + } + } namespace getLaunchOptionsSync { /** 启动参数 */ interface LaunchOptions { @@ -132,6 +147,20 @@ declare module '../../../index' { } interface TaroStatic { + /** + * 监听 API 类别变化事件 + * @param listener API 类别变化事件的监听函数 + * @supported weapp + * @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/life-cycle/wx.onApiCategoryChange.html + */ + onApiCategoryChange(listener: onApiCategoryChange.Listener): void + /** + * 移除 API 类别变化事件的监听函数 + * @param listener onApiCategoryChange 传入的监听函数。不传此参数则移除所有监听函数。 + * @supported weapp + * @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/life-cycle/wx.offApiCategoryChange.html + */ + offApiCategoryChange(listener?: onApiCategoryChange.Listener): void /** * 获取小程序启动时的参数。与 [`App.onLaunch`](https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html#onlaunchobject-object) 的回调参数一致。 * @@ -151,5 +180,11 @@ declare module '../../../index' { * @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/life-cycle/wx.getEnterOptionsSync.html */ getEnterOptionsSync(): getEnterOptionsSync.EnterOptions + /** + * 获取当前 API 类别 + * @supported weapp + * @see https://developers.weixin.qq.com/miniprogram/dev/api/base/app/life-cycle/wx.getApiCategory.html + */ + getApiCategory(): keyof onApiCategoryChange.ApiCategory } } diff --git a/packages/taro/types/api/ui/interaction.d.ts b/packages/taro/types/api/ui/interaction.d.ts index d5682a10554f..6c6928b0f5f5 100644 --- a/packages/taro/types/api/ui/interaction.d.ts +++ b/packages/taro/types/api/ui/interaction.d.ts @@ -50,9 +50,15 @@ declare module '../../index' { success?: (result: SuccessCallbackResult) => void /** 提示的标题 */ title?: string + /** 是否显示输入框 */ + editable?: boolean + /** 显示输入框时的提示文本 */ + placeholderText?: string } interface SuccessCallbackResult extends TaroGeneral.CallbackResult { + /** editable 为 true 时,用户输入的文本 */ + content: string /** 为 true 时,表示用户点击了取消(用于 Android 系统区分点击蒙层关闭还是点击取消按钮关闭) */ cancel: boolean /** 为 true 时,表示用户点击了确定按钮 */ @@ -256,7 +262,7 @@ declare module '../../index' { * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/interaction/wx.hideLoading.html */ - hideLoading(option?: hideLoading.Option): void /** 隐藏 loading 提示框 + hideLoading(option?: hideLoading.Option): void /** 隐藏 loading 提示框 /** 开启小程序页面返回询问对话框 * @supported weapp diff --git a/packages/taro/types/compile/config/mini.d.ts b/packages/taro/types/compile/config/mini.d.ts index d3cad4e908b6..b1d909700a1c 100644 --- a/packages/taro/types/compile/config/mini.d.ts +++ b/packages/taro/types/compile/config/mini.d.ts @@ -4,6 +4,7 @@ import type { IOption, IPostcssOption, IUrlLoaderOption } from './util' import type { OutputOptions as RollupOutputOptions } from 'rollup' import type { Compiler, CompilerTypes, CompilerWebpackTypes } from '../compiler' import type { OutputExt } from './project' +import type { Shortcuts } from '@tarojs/shared' interface Runtime { enableInnerHTML?: boolean @@ -15,6 +16,24 @@ interface Runtime { enableMutationObserver?: boolean } +interface PrerenderPageConfig { + /** 页面路径 */ + path: string + /** 页面的路由参数,对应 `getCurrentInstance().router.params` */ + params: Record +} + +/** DOM 树数据,Taro 通过遍历它动态渲染数据 */ +interface MiniData { + [Shortcuts.Childnodes]?: MiniData[] + [Shortcuts.NodeName]: string + [Shortcuts.Class]?: string + [Shortcuts.Style]?: string + [Shortcuts.Text]?: string + sid: string + uid?: string +} + export interface IMiniAppConfig { /** 用于控制是否生成 js、css 对应的 sourceMap (默认值:watch 模式下为 true,否则为 false) */ enableSourceMap?: boolean @@ -44,15 +63,28 @@ export interface IMiniAppConfig webpackChain?: (chain: Chain, webpack: typeof Webpack, PARSE_AST_TYPE: any) => void /** webpack 编译模式下,可用于修改、拓展 Webpack 的 output 选项,配置项参考[官方文档](https://webpack.js.org/configuration/output/) - * vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/) - */ + * vite 编译模式下,用于修改、扩展 rollup 的 output,目前仅适配 chunkFileNames 和 assetFileNames 两个配置,修改其他配置请使用 vite 插件进行修改。配置想参考[官方文档](https://rollupjs.org/configuration-options/) + */ output?: T extends 'vite' - ? Pick & OutputExt + ? Pick & OutputExt : Webpack.Configuration['output'] & OutputExt /** 配置 postcss 相关插件 */ postcss?: IPostcssOption<'mini'> + /**预渲染 + * https://docs.taro.zone/docs/prerender + */ + prerender?: { + match?: string | string[] + include?: Array + exclude?: string[] + mock?: Record + console?: boolean + transformData?: (data: MiniData, config: PrerenderPageConfig) => MiniData + transformXML?: (data: MiniData, config: PrerenderPageConfig, xml: string) => MiniData + } + /** [css-loader](https://github.com/webpack-contrib/css-loader) 的附加配置 */ cssLoaderOption?: IOption