chore: export some types (#8309)

This commit is contained in:
neverland 2021-03-08 17:14:55 +08:00 committed by GitHub
parent ae40d40c24
commit 8bae9ca0ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 68 additions and 26 deletions

View File

@ -5,3 +5,5 @@ const AddressEdit = withInstall<typeof _AddressEdit>(_AddressEdit);
export default AddressEdit;
export { AddressEdit };
export type { AddressEditInfo } from './AddressEdit';
export type { AddressEditSearchItem } from './AddressEditDetail';

View File

@ -1,8 +1,8 @@
import {
PropType,
CSSProperties,
ButtonHTMLAttributes,
defineComponent,
ButtonHTMLAttributes,
} from 'vue';
// Utils

View File

@ -5,3 +5,5 @@ const Calendar = withInstall<typeof _Calendar>(_Calendar);
export default Calendar;
export { Calendar };
export type { CalendarType } from './CalendarMonth';
export type { CalendarDayItem, CalendarDayType } from './CalendarDay';

View File

@ -5,3 +5,4 @@ const Cell = withInstall<typeof _Cell>(_Cell);
export default Cell;
export { Cell };
export type { CellArrowDirection } from './Cell';

View File

@ -5,3 +5,4 @@ const ContactCard = withInstall<typeof _ContactCard>(_ContactCard);
export default ContactCard;
export { ContactCard };
export type { ContactCardType } from './ContactCard';

View File

@ -5,3 +5,4 @@ const ContactList = withInstall<typeof _ContactList>(_ContactList);
export default ContactList;
export { ContactList };
export type { ContactListItem } from './ContactList';

View File

@ -5,3 +5,4 @@ const DatetimePicker = withInstall<typeof _DatetimePicker>(_DatetimePicker);
export default DatetimePicker;
export { DatetimePicker };
export type { DatetimePickerType } from './utils';

View File

@ -5,3 +5,4 @@ const Grid = withInstall<typeof _Grid>(_Grid);
export default Grid;
export { Grid };
export type { GridDirection } from './Grid';

View File

@ -5,3 +5,4 @@ const NoticeBar = withInstall<typeof _NoticeBar>(_NoticeBar);
export default NoticeBar;
export { NoticeBar };
export type { NoticeBarMode } from './NoticeBar';

View File

@ -5,3 +5,10 @@ const Picker = withInstall<typeof _Picker>(_Picker);
export default Picker;
export { Picker };
export type {
PickerColumn,
PickerOption,
PickerObjectColumn,
PickerObjectOption,
PickerToolbarPosition,
} from './Picker';

View File

@ -5,3 +5,9 @@ const Popover = withInstall<typeof _Popover>(_Popover);
export default Popover;
export { Popover };
export type {
PopoverTheme,
PopoverAction,
PopoverTrigger,
PopoverPlacement,
} from './Popover';

View File

@ -5,3 +5,4 @@ const Row = withInstall<typeof _Row>(_Row);
export default Row;
export { Row };
export type { RowAlign, RowJustify } from './Row';

View File

@ -5,3 +5,4 @@ const Search = withInstall<typeof _Search>(_Search);
export default Search;
export { Search };
export type { SearchShape } from './Search';

View File

@ -5,3 +5,4 @@ const Sticky = withInstall<typeof _Sticky>(_Sticky);
export default Sticky;
export { Sticky };
export type { StickyPosition } from './Sticky';

View File

@ -50,7 +50,7 @@ const [name, bem] = createNamespace('tabs');
export const TABS_KEY = Symbol(name);
export type TabType = 'line' | 'card';
export type TabsType = 'line' | 'card';
export type TabsProvide = {
props: {
@ -82,7 +82,7 @@ export default defineComponent({
titleActiveColor: String,
titleInactiveColor: String,
type: {
type: String as PropType<TabType>,
type: String as PropType<TabsType>,
default: 'line',
},
active: {

View File

@ -5,3 +5,4 @@ const Tabs = withInstall<typeof _Tabs>(_Tabs);
export default Tabs;
export { Tabs };
export type { TabsType } from './Tabs';

View File

@ -5,3 +5,4 @@ const TreeSelect = withInstall<typeof _TreeSelect>(_TreeSelect);
export default TreeSelect;
export { TreeSelect };
export type { TreeSelectItem, TreeSelectChild } from './TreeSelect';

View File

@ -9,9 +9,9 @@ import {
isOversize,
filterFiles,
isImageFile,
FileListItem,
readFileContent,
UploaderResultType,
UploaderFileListItem,
} from './utils';
// Composables
@ -38,7 +38,7 @@ export type UploaderBeforeRead = (
) => PromiseOrNot<File | File[] | undefined>;
export type UploaderAfterRead = (
items: FileListItem | FileListItem[],
items: UploaderFileListItem | UploaderFileListItem[],
detail: {
name: string | number;
index: number;
@ -68,7 +68,7 @@ export default defineComponent({
default: 'image/*',
},
modelValue: {
type: Array as PropType<FileListItem[]>,
type: Array as PropType<UploaderFileListItem[]>,
default: () => [],
},
maxSize: {
@ -131,7 +131,9 @@ export default defineComponent({
}
};
const onAfterRead = (items: FileListItem | FileListItem[]) => {
const onAfterRead = (
items: UploaderFileListItem | UploaderFileListItem[]
) => {
resetInput();
if (isOversize(items, props.maxSize)) {
@ -170,7 +172,11 @@ export default defineComponent({
files.map((file) => readFileContent(file, resultType))
).then((contents) => {
const fileList = (files as File[]).map((file, index) => {
const result: FileListItem = { file, status: '', message: '' };
const result: UploaderFileListItem = {
file,
status: '',
message: '',
};
if (contents[index]) {
result.content = contents[index] as string;
@ -183,7 +189,7 @@ export default defineComponent({
});
} else {
readFileContent(files, resultType).then((content) => {
const result: FileListItem = {
const result: UploaderFileListItem = {
file: files as File,
status: '',
message: '',
@ -237,7 +243,7 @@ export default defineComponent({
const onClosePreview = () => emit('close-preview');
const previewImage = (item: FileListItem) => {
const previewImage = (item: UploaderFileListItem) => {
if (props.previewFullImage) {
const imageFiles = props.modelValue.filter(isImageFile);
const images = imageFiles
@ -259,7 +265,7 @@ export default defineComponent({
}
};
const deleteFile = (item: FileListItem, index: number) => {
const deleteFile = (item: UploaderFileListItem, index: number) => {
const fileList = props.modelValue.slice(0);
fileList.splice(index, 1);
@ -267,7 +273,7 @@ export default defineComponent({
emit('delete', item, getDetail(index));
};
const renderPreviewItem = (item: FileListItem, index: number) => {
const renderPreviewItem = (item: UploaderFileListItem, index: number) => {
const needPickData = [
'imageFit',
'deletable',

View File

@ -1,7 +1,7 @@
import { PropType, defineComponent } from 'vue';
// Utils
import { bem, isImageFile, FileListItem } from './utils';
import { bem, isImageFile, UploaderFileListItem } from './utils';
import { isDef, getSizeStyle } from '../utils';
import { callInterceptor, Interceptor } from '../utils/interceptor';
@ -20,7 +20,7 @@ export default defineComponent({
previewSize: [Number, String],
beforeDelete: Function as PropType<Interceptor>,
item: {
type: Object as PropType<FileListItem>,
type: Object as PropType<UploaderFileListItem>,
required: true,
},
},

View File

@ -56,7 +56,7 @@
<script lang="ts">
import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate';
import { FileListItem } from '../utils';
import { UploaderFileListItem } from '../utils';
import Toast from '../../toast';
const i18n = {
@ -155,11 +155,11 @@ export default {
return true;
};
const afterRead = (file: FileListItem, detail: unknown) => {
const afterRead = (file: UploaderFileListItem, detail: unknown) => {
console.log(file, detail);
};
const afterReadFailed = (item: FileListItem) => {
const afterReadFailed = (item: UploaderFileListItem) => {
item.status = 'uploading';
item.message = t('uploading');
@ -169,7 +169,7 @@ export default {
}, 1000);
};
const onOversize = (file: FileListItem, detail: unknown) => {
const onOversize = (file: UploaderFileListItem, detail: unknown) => {
console.log(file, detail);
Toast(t('overSizeTip'));
};

View File

@ -5,3 +5,4 @@ const Uploader = withInstall<typeof _Uploader>(_Uploader);
export default Uploader;
export { Uploader };
export type { UploaderResultType, UploaderFileListItem } from './utils';

View File

@ -8,7 +8,7 @@ export { name, bem };
export type UploaderResultType = 'dataUrl' | 'text' | 'file';
export type FileListItem = {
export type UploaderFileListItem = {
url?: string;
file?: File;
content?: string;
@ -51,15 +51,18 @@ export function readFileContent(file: File, resultType: UploaderResultType) {
}
export function isOversize(
items: FileListItem | FileListItem[],
items: UploaderFileListItem | UploaderFileListItem[],
maxSize: number | string
): boolean {
return toArray(items).some((item) => item.file && item.file.size > maxSize);
}
export function filterFiles(items: FileListItem[], maxSize: number | string) {
const valid: FileListItem[] = [];
const invalid: FileListItem[] = [];
export function filterFiles(
items: UploaderFileListItem[],
maxSize: number | string
) {
const valid: UploaderFileListItem[] = [];
const invalid: UploaderFileListItem[] = [];
items.forEach((item) => {
if (item.file && item.file.size > maxSize) {
@ -78,7 +81,7 @@ export function isImageUrl(url: string): boolean {
return IMAGE_REGEXP.test(url);
}
export function isImageFile(item: FileListItem): boolean {
export function isImageFile(item: UploaderFileListItem): boolean {
// some special urls cannot be recognized
// user can add `isImage` flag to mark it as an image url
if (item.isImage) {

View File

@ -2,6 +2,10 @@ import { createBEM } from './bem';
import { createTranslate } from './translate';
export function createNamespace(name: string) {
name = 'van-' + name;
return [name, createBEM(name), createTranslate(name)] as const;
const prefixedName = `van-${name}`;
return [
prefixedName,
createBEM(prefixedName),
createTranslate(prefixedName),
] as const;
}