UNPKG

18.7 kBTypeScriptView Raw
1/**
2 * vue tsx @tarojs/components 类型提示文件
3 *
4 * ## 如何使用?
5
6 * 请在醒目全局的类型文件中写入以下代码,覆盖默认的组件类型提示
7 * ```typescript
8 * export declare module '@tarojs/components' {
9 * export * from '@tarojs/components/types/index.vue3'
10 * }
11 * ```
12 */
13import * as CSS from 'csstype'
14import { DefineComponent, VNodeRef } from 'vue'
15
16import { AdProps } from './Ad'
17import { AdCustomProps } from './AdCustom'
18import { AudioProps } from './Audio'
19import { ButtonProps } from './Button'
20import { CameraProps } from './Camera'
21import { CanvasProps } from './Canvas'
22import { ChannelLiveProps } from './ChannelLive'
23import { ChannelVideoProps } from './ChannelVideo'
24import { CheckboxProps } from './Checkbox'
25import { CheckboxGroupProps } from './CheckboxGroup'
26import { StandardProps } from './common'
27import { CoverImageProps } from './CoverImage'
28import { CoverViewProps } from './CoverView'
29import { CustomWrapperProps } from './CustomWrapper'
30import { EditorProps } from './Editor'
31import { FormProps } from './Form'
32import { FunctionalPageNavigatorProps } from './FunctionalPageNavigator'
33import { GridViewProps } from './GridView'
34import { IconProps } from './Icon'
35import { ImageProps } from './Image'
36import { InputProps } from './Input'
37import { KeyboardAccessoryProps } from './KeyboardAccessory'
38import { LabelProps } from './Label'
39import { ListViewProps } from './ListView'
40import { LivePlayerProps } from './LivePlayer'
41import { LivePusherProps } from './LivePusher'
42import { MapProps } from './Map'
43import { MatchMediaProps } from './MatchMedia'
44import { MovableAreaProps } from './MovableArea'
45import { MovableViewProps } from './MovableView'
46import { NativeSlotProps } from './NativeSlot'
47import { NavigationBarProps } from './NavigationBar'
48import { NavigatorProps } from './Navigator'
49import { OfficialAccountProps } from './OfficialAccount'
50import { OpenDataProps } from './OpenData'
51import { PageContainerProps } from './PageContainer'
52import { PageMetaProps } from './PageMeta'
53import {
54 PickerDateProps, PickerMultiSelectorProps,
55 PickerRegionProps, PickerSelectorProps, PickerTimeProps
56} from './Picker'
57import { PickerViewProps } from './PickerView'
58import { PickerViewColumnProps } from './PickerViewColumn'
59import { ProgressProps } from './Progress'
60import { RadioProps } from './Radio'
61import { RadioGroupProps } from './RadioGroup'
62import { RichTextProps } from './RichText'
63import { RootPortalProps } from './RootPortal'
64import { ScrollViewProps } from './ScrollView'
65import { ShareElementProps } from './ShareElement'
66import { SliderProps } from './Slider'
67import { SlotProps } from './Slot'
68import { SnapshotProps } from './SnapShot'
69import { SpanProps } from './Span'
70import { StickyHeaderProps } from './StickyHeader'
71import { StickySectionProps } from './StickySection'
72import { SwiperProps } from './Swiper'
73import { SwiperItemProps } from './SwiperItem'
74import { SwitchProps } from './Switch'
75import { TextProps } from './Text'
76import { TextareaProps } from './Textarea'
77import { VideoProps } from './Video'
78import { ViewProps } from './View'
79import { VoipRoomProps } from './VoipRoom'
80import { WebViewProps } from './WebView'
81
82/** 因为react的事件是CamelCase而vue得是Camelcase, 所以需要转换 */
83type OnCamelCaseToOnCamelcase<T extends string> = T extends `on${infer Rest}`
84 ? `on${Capitalize<Lowercase<Rest>>}`
85 : T;
86
87type TransformCamelCase<T extends Record<string, any>> = {
88 [key in keyof T as OnCamelCaseToOnCamelcase<key>]: T[key]
89}
90
91/** 联合类型不能用omit(比如picker) */
92type DistributiveOmit<T, K extends keyof T> = T extends unknown ? TransformCamelCase<Omit<T, K>> : never
93
94interface SlimProps {
95 class?: any
96 style?: CSS.Properties<string | number>
97 innerHTML?: string
98}
99
100/** 转换 react 的类型到 vue */
101export type RemoveReactAttribute = 'className' | 'style' | 'key' | 'ref' | 'dangerouslySetInnerHTML'
102export type TransformReact2VueType<P extends StandardProps = Record<string, never>> = DistributiveOmit<P, RemoveReactAttribute> & SlimProps
103export type VueComponentType<P = Record<string, never>> = DefineComponent<TransformReact2VueType<P>>
104
105export * from './common'
106export * from './event'
107export * from './props'
108
109/** 视图容器 */
110export declare const Block: VueComponentType<StandardProps>
111export declare const CoverImage: VueComponentType<CoverImageProps>
112export declare const CoverView: VueComponentType<CoverViewProps>
113export declare const MatchMedia: VueComponentType<MatchMediaProps>
114export declare const MovableArea: VueComponentType<MovableAreaProps>
115export declare const MovableView: VueComponentType<MovableViewProps>
116export declare const PageContainer: VueComponentType<PageContainerProps>
117export declare const RootPortal: VueComponentType<RootPortalProps>
118export declare const ScrollView: VueComponentType<ScrollViewProps>
119export declare const Swiper: VueComponentType<SwiperProps>
120export declare const SwiperItem: VueComponentType<SwiperItemProps>
121export declare const View: VueComponentType<ViewProps>
122/** 基础内容 */
123export declare const Icon: VueComponentType<IconProps>
124export declare const Progress: VueComponentType<ProgressProps>
125export declare const RichText: VueComponentType<RichTextProps>
126export declare const Text: VueComponentType<TextProps>
127/** 表单组件 */
128export declare const Button: VueComponentType<ButtonProps>
129export declare const Checkbox: VueComponentType<CheckboxProps>
130export declare const CheckboxGroup: VueComponentType<CheckboxGroupProps>
131export declare const Editor: VueComponentType<EditorProps>
132export declare const Form: VueComponentType<FormProps>
133export declare const Input: VueComponentType<InputProps>
134export declare const KeyboardAccessory: VueComponentType<KeyboardAccessoryProps>
135export declare const Label: VueComponentType<LabelProps>
136export declare const Picker: VueComponentType<PickerMultiSelectorProps | PickerTimeProps | PickerDateProps | PickerRegionProps | PickerSelectorProps>
137export declare const PickerView: VueComponentType<PickerViewProps>
138export declare const PickerViewColumn: VueComponentType<PickerViewColumnProps>
139export declare const Radio: VueComponentType<RadioProps>
140export declare const RadioGroup: VueComponentType<RadioGroupProps>
141export declare const Slider: VueComponentType<SliderProps>
142export declare const Switch: VueComponentType<SwitchProps>
143export declare const Textarea: VueComponentType<TextareaProps>
144/** Skyline */
145export declare const GridView: VueComponentType<GridViewProps>
146export declare const ListView: VueComponentType<ListViewProps>
147export declare const Snapshot: VueComponentType<SnapshotProps>
148export declare const Span: VueComponentType<SpanProps>
149export declare const ShareElement: VueComponentType<ShareElementProps>
150export declare const StickyHeader: VueComponentType<StickyHeaderProps>
151export declare const StickySection: VueComponentType<StickySectionProps>
152/** 导航 */
153export declare const FunctionalPageNavigator: VueComponentType<FunctionalPageNavigatorProps>
154export declare const Navigator: VueComponentType<NavigatorProps>
155export declare const NavigationBar: VueComponentType<NavigationBarProps>
156/** 媒体组件 */
157export declare const Audio: VueComponentType<AudioProps>
158export declare const Camera: VueComponentType<CameraProps>
159export declare const ChannelLive: VueComponentType<ChannelLiveProps>
160export declare const ChannelVideo: VueComponentType<ChannelVideoProps>
161export declare const Image: VueComponentType<ImageProps>
162export declare const LivePlayer: VueComponentType<LivePlayerProps>
163export declare const LivePusher: VueComponentType<LivePusherProps>
164export declare const Video: VueComponentType<VideoProps>
165export declare const VoipRoom: VueComponentType<VoipRoomProps>
166/** 地图 */
167export declare const Map: VueComponentType<MapProps>
168/** 画布 */
169export declare const Canvas: VueComponentType<CanvasProps>
170/** 开放能力 */
171export declare const Ad: VueComponentType<AdProps>
172export declare const AdCustom: VueComponentType<AdCustomProps>
173export declare const OfficialAccount: VueComponentType<OfficialAccountProps>
174export declare const OpenData: VueComponentType<OpenDataProps>
175export declare const WebView: VueComponentType<WebViewProps>
176/** 配置节点 */
177export declare const PageMeta: VueComponentType<PageMetaProps>
178
179export declare const CustomWrapper: VueComponentType<CustomWrapperProps>
180export declare const Slot: VueComponentType<SlotProps>
181export declare const NativeSlot: VueComponentType<NativeSlotProps>
182
183export type ReservedProps = {
184 key?: string | number | symbol
185 ref?: VNodeRef
186 ref_for?: boolean
187 ref_key?: string
188}
189
190export type ElementAttrs<T> = T & ReservedProps
191
192declare global {
193 namespace JSX {
194 interface IntrinsicElements {
195 /** 视图容器 */
196 block: ElementAttrs<TransformReact2VueType<StandardProps>>
197 'taro-block-core': ElementAttrs<TransformReact2VueType<StandardProps>>
198 'cover-image': ElementAttrs<TransformReact2VueType<CoverImageProps>>
199 'taro-cover-image-core': ElementAttrs<TransformReact2VueType<CoverImageProps>>
200 'cover-view': ElementAttrs<TransformReact2VueType<CoverViewProps>>
201 'taro-cover-view-core': ElementAttrs<TransformReact2VueType<CoverViewProps>>
202 'match-media': ElementAttrs<TransformReact2VueType<MatchMediaProps>>
203 'taro-match-media-core': ElementAttrs<TransformReact2VueType<MatchMediaProps>>
204 'movable-area': ElementAttrs<TransformReact2VueType<MovableAreaProps>>
205 'taro-movable-area-core': ElementAttrs<TransformReact2VueType<MovableAreaProps>>
206 'movable-view': ElementAttrs<TransformReact2VueType<MovableViewProps>>
207 'taro-movable-view-core': ElementAttrs<TransformReact2VueType<MovableViewProps>>
208 'page-container': ElementAttrs<TransformReact2VueType<PageContainerProps>>
209 'taro-page-container-core': ElementAttrs<TransformReact2VueType<PageContainerProps>>
210 'root-portal': ElementAttrs<TransformReact2VueType<RootPortalProps>>
211 'taro-root-portal-core': ElementAttrs<TransformReact2VueType<RootPortalProps>>
212 'scroll-view': ElementAttrs<TransformReact2VueType<ScrollViewProps>>
213 'taro-scroll-view-core': ElementAttrs<TransformReact2VueType<ScrollViewProps>>
214 swiper: ElementAttrs<TransformReact2VueType<SwiperProps>>
215 'taro-swiper-core': ElementAttrs<TransformReact2VueType<SwiperProps>>
216 'swiper-item': ElementAttrs<TransformReact2VueType<SwiperItemProps>>
217 'taro-swiper-item-core': ElementAttrs<TransformReact2VueType<SwiperItemProps>>
218 view: ElementAttrs<TransformReact2VueType<ViewProps>>
219 'taro-view-core': ElementAttrs<TransformReact2VueType<ViewProps>>
220 /** 基础内容 */
221 icon: ElementAttrs<TransformReact2VueType<IconProps>>
222 'taro-icon-core': ElementAttrs<TransformReact2VueType<IconProps>>
223 progress: ElementAttrs<TransformReact2VueType<ProgressProps>>
224 'taro-progress-core': ElementAttrs<TransformReact2VueType<ProgressProps>>
225 'rich-text': ElementAttrs<TransformReact2VueType<RichTextProps>>
226 'taro-rich-text-core': ElementAttrs<TransformReact2VueType<RichTextProps>>
227 text: ElementAttrs<TransformReact2VueType<TextProps>>
228 'taro-text-core': ElementAttrs<TransformReact2VueType<TextProps>>
229 /** 表单组件 */
230 button: ElementAttrs<TransformReact2VueType<ButtonProps>>
231 'taro-button-core': ElementAttrs<TransformReact2VueType<ButtonProps>>
232 checkbox: ElementAttrs<TransformReact2VueType<CheckboxProps>>
233 'taro-checkbox-core': ElementAttrs<TransformReact2VueType<CheckboxProps>>
234 'checkbox-group': ElementAttrs<TransformReact2VueType<CheckboxGroupProps>>
235 'taro-checkbox-group-core': ElementAttrs<TransformReact2VueType<CheckboxGroupProps>>
236 editor: ElementAttrs<TransformReact2VueType<EditorProps>>
237 'taro-editor-core': ElementAttrs<TransformReact2VueType<EditorProps>>
238 form: ElementAttrs<TransformReact2VueType<FormProps>>
239 'taro-form-core': ElementAttrs<TransformReact2VueType<FormProps>>
240 input: ElementAttrs<TransformReact2VueType<InputProps>>
241 'taro-input-core': ElementAttrs<TransformReact2VueType<InputProps>>
242 'keyboard-accessory': ElementAttrs<TransformReact2VueType<KeyboardAccessoryProps>>
243 'taro-keyboard-accessory-core': ElementAttrs<TransformReact2VueType<KeyboardAccessoryProps>>
244 label: ElementAttrs<TransformReact2VueType<LabelProps>>
245 'taro-label-core': ElementAttrs<TransformReact2VueType<LabelProps>>
246 picker: ElementAttrs<TransformReact2VueType<PickerMultiSelectorProps | PickerTimeProps | PickerDateProps | PickerRegionProps | PickerSelectorProps>>
247 'taro-picker-core': ElementAttrs<TransformReact2VueType<PickerMultiSelectorProps | PickerTimeProps | PickerDateProps | PickerRegionProps | PickerSelectorProps>>
248 'picker-view': ElementAttrs<TransformReact2VueType<PickerViewProps>>
249 'taro-picker-view-core': ElementAttrs<TransformReact2VueType<PickerViewProps>>
250 'picker-view-column': ElementAttrs<TransformReact2VueType<PickerViewColumnProps>>
251 'taro-picker-view-column-core': ElementAttrs<TransformReact2VueType<PickerViewColumnProps>>
252 radio: ElementAttrs<TransformReact2VueType<RadioProps>>
253 'taro-radio-core': ElementAttrs<TransformReact2VueType<RadioProps>>
254 'radio-group': ElementAttrs<TransformReact2VueType<RadioGroupProps>>
255 'taro-radio-group-core': ElementAttrs<TransformReact2VueType<RadioGroupProps>>
256 slider: ElementAttrs<TransformReact2VueType<SliderProps>>
257 'taro-slider-core': ElementAttrs<TransformReact2VueType<SliderProps>>
258 switch: ElementAttrs<TransformReact2VueType<SwitchProps>>
259 'taro-switch-core': ElementAttrs<TransformReact2VueType<SwitchProps>>
260 textarea: ElementAttrs<TransformReact2VueType<TextareaProps>>
261 'taro-textarea-core': ElementAttrs<TransformReact2VueType<TextareaProps>>
262 /** Skyline */
263 'grid-view': ElementAttrs<TransformReact2VueType<GridViewProps>>
264 'taro-grid-view-core': ElementAttrs<TransformReact2VueType<GridViewProps>>
265 'list-view': ElementAttrs<TransformReact2VueType<ListViewProps>>
266 'taro-list-view-core': ElementAttrs<TransformReact2VueType<ListViewProps>>
267 'share-element': ElementAttrs<TransformReact2VueType<ShareElementProps>>
268 'taro-share-element-core': ElementAttrs<TransformReact2VueType<ShareElementProps>>
269 'snapshot': ElementAttrs<TransformReact2VueType<SnapshotProps>>
270 'taro-snapshot-core': ElementAttrs<TransformReact2VueType<SnapshotProps>>
271 'span': ElementAttrs<TransformReact2VueType<SpanProps>>
272 'taro-span-core': ElementAttrs<TransformReact2VueType<SpanProps>>
273 'sticky-header': ElementAttrs<TransformReact2VueType<StickyHeaderProps>>
274 'taro-sticky-header-core': ElementAttrs<TransformReact2VueType<StickyHeaderProps>>
275 'sticky-section': ElementAttrs<TransformReact2VueType<StickySectionProps>>
276 'taro-sticky-section-core': ElementAttrs<TransformReact2VueType<StickySectionProps>>
277 /** 导航 */
278 'functional-page-navigator': ElementAttrs<TransformReact2VueType<FunctionalPageNavigatorProps>>
279 'taro-functional-page-navigator-core': ElementAttrs<TransformReact2VueType<FunctionalPageNavigatorProps>>
280 navigator: ElementAttrs<TransformReact2VueType<NavigatorProps>>
281 'taro-navigator-core': ElementAttrs<TransformReact2VueType<NavigatorProps>>
282 'navigation-bar': ElementAttrs<TransformReact2VueType<NavigationBarProps>>
283 'taro-navigation-bar-core': ElementAttrs<TransformReact2VueType<NavigationBarProps>>
284 /** 媒体组件 */
285 audio: ElementAttrs<TransformReact2VueType<AudioProps>>
286 'taro-audio-core': ElementAttrs<TransformReact2VueType<AudioProps>>
287 camera: ElementAttrs<TransformReact2VueType<CameraProps>>
288 'taro-camera-core': ElementAttrs<TransformReact2VueType<CameraProps>>
289 'channel-live': ElementAttrs<TransformReact2VueType<ChannelLiveProps>>
290 'taro-channel-live-core': ElementAttrs<TransformReact2VueType<ChannelLiveProps>>
291 'channel-video': ElementAttrs<TransformReact2VueType<ChannelVideoProps>>
292 'taro-channel-video-core': ElementAttrs<TransformReact2VueType<ChannelVideoProps>>
293 image: ElementAttrs<TransformReact2VueType<ImageProps>>
294 'taro-image-core': ElementAttrs<TransformReact2VueType<ImageProps>>
295 'live-player': ElementAttrs<TransformReact2VueType<LivePlayerProps>>
296 'taro-live-player-core': ElementAttrs<TransformReact2VueType<LivePlayerProps>>
297 'live-pusher': ElementAttrs<TransformReact2VueType<LivePusherProps>>
298 'taro-live-pusher-core': ElementAttrs<TransformReact2VueType<LivePusherProps>>
299 video: ElementAttrs<TransformReact2VueType<VideoProps>>
300 'taro-video-core': ElementAttrs<TransformReact2VueType<VideoProps>>
301 'voip-room': ElementAttrs<TransformReact2VueType<VoipRoomProps>>
302 'taro-voip-room-core': ElementAttrs<TransformReact2VueType<VoipRoomProps>>
303 /** 地图 */
304 map: ElementAttrs<TransformReact2VueType<MapProps>>
305 'taro-map-core': ElementAttrs<TransformReact2VueType<MapProps>>
306 /** 画布 */
307 canvas: ElementAttrs<TransformReact2VueType<CanvasProps>>
308 'taro-canvas-core': ElementAttrs<TransformReact2VueType<CanvasProps>>
309 /** 开放能力 */
310 ad: ElementAttrs<TransformReact2VueType<AdProps>>
311 'taro-ad-core': ElementAttrs<TransformReact2VueType<AdProps>>
312 'ad-custom': ElementAttrs<TransformReact2VueType<AdCustomProps>>
313 'taro-ad-custom-core': ElementAttrs<TransformReact2VueType<AdCustomProps>>
314 'official-account': ElementAttrs<TransformReact2VueType<OfficialAccountProps>>
315 'taro-official-account-core': ElementAttrs<TransformReact2VueType<OfficialAccountProps>>
316 'open-data': ElementAttrs<TransformReact2VueType<OpenDataProps>>
317 'taro-open-data-core': ElementAttrs<TransformReact2VueType<OpenDataProps>>
318 'web-view': ElementAttrs<TransformReact2VueType<WebViewProps>>
319 'taro-web-view-core': ElementAttrs<TransformReact2VueType<WebViewProps>>
320 /** 配置节点 */
321 'page-meta': ElementAttrs<TransformReact2VueType<PageMetaProps>>
322 'taro-page-meta-core': ElementAttrs<TransformReact2VueType<PageMetaProps>>
323
324 'custom-wrapper': ElementAttrs<TransformReact2VueType<CustomWrapperProps>>
325 'taro-custom-wrapper-core': ElementAttrs<TransformReact2VueType<CustomWrapperProps>>
326 /** 为了不与vue3模板默认的slot冲突,增加 Record<string, any> */
327 'slot': ElementAttrs<TransformReact2VueType<SlotProps>> & Record<string, any>
328 'taro-slot-core': ElementAttrs<TransformReact2VueType<SlotProps>>
329 'native-slot': ElementAttrs<TransformReact2VueType<NativeSlotProps>>
330 'taro-native-slot-core': ElementAttrs<TransformReact2VueType<NativeSlotProps>>
331 }
332 }
333}