Skip to content

Commit

Permalink
fix(type): types additions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKonka committed Aug 21, 2024
1 parent f3ddb5b commit b7adffc
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
35 changes: 35 additions & 0 deletions packages/taro/types/api/base/weapp/life-cycle.d.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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) 的回调参数一致。
*
Expand All @@ -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
}
}
8 changes: 7 additions & 1 deletion packages/taro/types/api/ui/interaction.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 时,表示用户点击了确定按钮 */
Expand Down Expand Up @@ -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
Expand Down
38 changes: 35 additions & 3 deletions packages/taro/types/compile/config/mini.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +16,24 @@ interface Runtime {
enableMutationObserver?: boolean
}

interface PrerenderPageConfig {
/** 页面路径 */
path: string
/** 页面的路由参数,对应 `getCurrentInstance().router.params` */
params: Record<string, unknown>
}

/** 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<T extends CompilerTypes = CompilerWebpackTypes> {
/** 用于控制是否生成 js、css 对应的 sourceMap (默认值:watch 模式下为 true,否则为 false) */
enableSourceMap?: boolean
Expand Down Expand Up @@ -44,15 +63,28 @@ export interface IMiniAppConfig<T extends CompilerTypes = CompilerWebpackTypes>
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<RollupOutputOptions, 'chunkFileNames'> & OutputExt
? Pick<RollupOutputOptions, 'chunkFileNames'> & OutputExt
: Webpack.Configuration['output'] & OutputExt

/** 配置 postcss 相关插件 */
postcss?: IPostcssOption<'mini'>

/**预渲染
* https://docs.taro.zone/docs/prerender
*/
prerender?: {
match?: string | string[]
include?: Array<string | PrerenderPageConfig>
exclude?: string[]
mock?: Record<string, unknown>
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

Expand Down

0 comments on commit b7adffc

Please sign in to comment.