Compare commits

...

6 Commits

Author SHA1 Message Date
chenjiahan
8d6d65fa58 chore: bump lazyload and remove todo 2021-09-24 10:48:24 +08:00
chenjiahan
3aa3bbfa49 release: @vant/lazyload 1.3.0 2021-09-24 10:48:24 +08:00
chenjiahan
33d7aa8f1a perf(@vant/lazyload): reduce production log 2021-09-24 10:48:24 +08:00
chenjiahan
00b1568887 perf(@vant/lazyload): remove edge 15 polyfill 2021-09-24 10:48:24 +08:00
chenjiahan
3ad17abd52 types(@vant/lazyload): add $Lazyload typing 2021-09-24 10:48:24 +08:00
neverland
8fbeb6a9c3
types: fix $toast、$dialog、$notify typing (#9556)
* types: fix $toast、$dialog、$notify typing

* types: organize
2021-09-24 10:17:07 +08:00
23 changed files with 331 additions and 381 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@vant/lazyload",
"version": "1.2.0",
"version": "1.3.0",
"description": "This is a fork of vue-lazyload",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
@ -23,8 +23,7 @@
"devDependencies": {
"@babel/cli": "^7.12.8",
"@babel/core": "^7.12.9",
"release-it": "^14.2.2",
"vue": "^3.0.0"
"release-it": "^14.2.2"
},
"release-it": {
"git": {

View File

@ -1,70 +1,68 @@
import { h } from 'vue';
import { inBrowser } from './util';
export default (lazy) => {
return {
props: {
tag: {
type: String,
default: 'div',
export default (lazy) => ({
props: {
tag: {
type: String,
default: 'div',
},
},
emits: ['show'],
render() {
return h(
this.tag,
this.show && this.$slots.default ? this.$slots.default() : null
);
},
data() {
return {
el: null,
state: {
loaded: false,
},
rect: {},
show: false,
};
},
mounted() {
this.el = this.$el;
lazy.addLazyBox(this);
lazy.lazyLoadHandler();
},
beforeUnmount() {
lazy.removeComponent(this);
},
methods: {
getRect() {
this.rect = this.$el.getBoundingClientRect();
},
emits: ['show'],
render() {
return h(
this.tag,
this.show && this.$slots.default ? this.$slots.default() : null
checkInView() {
this.getRect();
return (
inBrowser &&
this.rect.top < window.innerHeight * lazy.options.preLoad &&
this.rect.bottom > 0 &&
this.rect.left < window.innerWidth * lazy.options.preLoad &&
this.rect.right > 0
);
},
data() {
return {
el: null,
state: {
loaded: false,
},
rect: {},
show: false,
};
load() {
this.show = true;
this.state.loaded = true;
this.$emit('show', this);
},
mounted() {
this.el = this.$el;
lazy.addLazyBox(this);
lazy.lazyLoadHandler();
destroy() {
return this.$destroy;
},
beforeUnmount() {
lazy.removeComponent(this);
},
methods: {
getRect() {
this.rect = this.$el.getBoundingClientRect();
},
checkInView() {
this.getRect();
return (
inBrowser &&
this.rect.top < window.innerHeight * lazy.options.preLoad &&
this.rect.bottom > 0 &&
this.rect.left < window.innerWidth * lazy.options.preLoad &&
this.rect.right > 0
);
},
load() {
this.show = true;
this.state.loaded = true;
this.$emit('show', this);
},
destroy() {
return this.$destroy;
},
},
};
};
},
});

View File

@ -1,107 +1,110 @@
import { inBrowser, loadImageAsync, noop } from './util';
export default (lazyManager) => {
return {
props: {
src: [String, Object],
tag: {
type: String,
default: 'img',
export default (lazyManager) => ({
props: {
src: [String, Object],
tag: {
type: String,
default: 'img',
},
},
render(h) {
return h(
this.tag,
{
attrs: {
src: this.renderSrc,
},
},
},
render(h) {
return h(
this.tag,
{
attrs: {
src: this.renderSrc,
},
},
this.$slots.default
);
},
data() {
return {
el: null,
options: {
src: '',
error: '',
loading: '',
attempt: lazyManager.options.attempt,
},
state: {
loaded: false,
error: false,
attempt: 0,
},
rect: {},
renderSrc: '',
};
},
watch: {
src() {
this.init();
lazyManager.addLazyBox(this);
lazyManager.lazyLoadHandler();
this.$slots.default
);
},
data() {
return {
el: null,
options: {
src: '',
error: '',
loading: '',
attempt: lazyManager.options.attempt,
},
},
created() {
state: {
loaded: false,
error: false,
attempt: 0,
},
rect: {},
renderSrc: '',
};
},
watch: {
src() {
this.init();
this.renderSrc = this.options.loading;
},
mounted() {
this.el = this.$el;
lazyManager.addLazyBox(this);
lazyManager.lazyLoadHandler();
},
beforeUnmount() {
lazyManager.removeComponent(this);
},
created() {
this.init();
this.renderSrc = this.options.loading;
},
mounted() {
this.el = this.$el;
lazyManager.addLazyBox(this);
lazyManager.lazyLoadHandler();
},
beforeUnmount() {
lazyManager.removeComponent(this);
},
methods: {
init() {
const { src, loading, error } = lazyManager._valueFormatter(this.src);
this.state.loaded = false;
this.options.src = src;
this.options.error = error;
this.options.loading = loading;
this.renderSrc = this.options.loading;
},
methods: {
init() {
const { src, loading, error } = lazyManager._valueFormatter(this.src);
this.state.loaded = false;
this.options.src = src;
this.options.error = error;
this.options.loading = loading;
this.renderSrc = this.options.loading;
},
getRect() {
this.rect = this.$el.getBoundingClientRect();
},
checkInView() {
this.getRect();
return (
inBrowser &&
this.rect.top < window.innerHeight * lazyManager.options.preLoad &&
this.rect.bottom > 0 &&
this.rect.left < window.innerWidth * lazyManager.options.preLoad &&
this.rect.right > 0
);
},
load(onFinish = noop) {
if (this.state.attempt > this.options.attempt - 1 && this.state.error) {
if (!lazyManager.options.silent)
console.log(
`VueLazyload log: ${this.options.src} tried too more than ${this.options.attempt} times`
);
onFinish();
return;
getRect() {
this.rect = this.$el.getBoundingClientRect();
},
checkInView() {
this.getRect();
return (
inBrowser &&
this.rect.top < window.innerHeight * lazyManager.options.preLoad &&
this.rect.bottom > 0 &&
this.rect.left < window.innerWidth * lazyManager.options.preLoad &&
this.rect.right > 0
);
},
load(onFinish = noop) {
if (this.state.attempt > this.options.attempt - 1 && this.state.error) {
if (
process.env.NODE_ENV !== 'production' &&
!lazyManager.options.silent
) {
console.log(
`[@vant/lazyload] ${this.options.src} tried too more than ${this.options.attempt} times`
);
}
const { src } = this.options;
loadImageAsync(
{ src },
({ src }) => {
this.renderSrc = src;
this.state.loaded = true;
},
() => {
this.state.attempt++;
this.renderSrc = this.options.error;
this.state.error = true;
}
);
},
onFinish();
return;
}
const { src } = this.options;
loadImageAsync(
{ src },
({ src }) => {
this.renderSrc = src;
this.state.loaded = true;
},
() => {
this.state.attempt++;
this.renderSrc = this.options.error;
this.state.error = true;
}
);
},
};
};
},
});

View File

@ -472,8 +472,14 @@ export default function () {
// value is object
if (isObject(value)) {
if (!value.src && !this.options.silent)
console.error('Vue Lazyload warning: miss src with ' + value);
if (
process.env.NODE_ENV !== 'production' &&
!value.src &&
!this.options.silent
) {
console.error('[@vant/lazyload] miss src with ' + value);
}
({ src } = value);
loading = value.loading || this.options.loading;
error = value.error || this.options.error;

View File

@ -140,9 +140,10 @@ export default class ReactiveListener {
// handler `loading image` load failed
cb();
this.state.loading = false;
if (!this.options.silent)
if (process.env.NODE_ENV !== 'production' && !this.options.silent)
console.warn(
`VueLazyload log: load failed with loading image(${this.loading})`
`[@vant/lazyload] load failed with loading image(${this.loading})`
);
}
);
@ -154,10 +155,12 @@ export default class ReactiveListener {
*/
load(onFinish = noop) {
if (this.attempt > this.options.attempt - 1 && this.state.error) {
if (!this.options.silent)
if (process.env.NODE_ENV !== 'production' && !this.options.silent) {
console.log(
`VueLazyload log: ${this.src} tried too more than ${this.options.attempt} times`
`[@vant/lazyload] ${this.src} tried too more than ${this.options.attempt} times`
);
}
onFinish();
return;
}

View File

@ -1,31 +1,10 @@
const inBrowser = typeof window !== 'undefined' && window !== null;
const inBrowser = typeof window !== 'undefined';
function checkIntersectionObserver() {
if (
inBrowser &&
'IntersectionObserver' in window &&
'IntersectionObserverEntry' in window &&
'intersectionRatio' in window.IntersectionObserverEntry.prototype
) {
// Minimal polyfill for Edge 15's lack of `isIntersecting`
// See: https://github.com/w3c/IntersectionObserver/issues/211
if (!('isIntersecting' in window.IntersectionObserverEntry.prototype)) {
Object.defineProperty(
window.IntersectionObserverEntry.prototype,
'isIntersecting',
{
get() {
return this.intersectionRatio > 0;
},
}
);
}
return true;
}
return false;
}
export const hasIntersectionObserver = checkIntersectionObserver();
export const hasIntersectionObserver =
inBrowser &&
'IntersectionObserver' in window &&
'IntersectionObserverEntry' in window &&
'intersectionRatio' in window.IntersectionObserverEntry.prototype;
export const modeType = {
event: 'event',
@ -86,7 +65,7 @@ function getBestSelectionFromSrcset(el, scale) {
return [tmpWidth, tmpSrc];
});
result.sort(function (a, b) {
result.sort((a, b) => {
if (a[0] < b[0]) {
return 1;
}
@ -236,17 +215,13 @@ const loadImageAsync = (item, resolve, reject) => {
};
};
const style = (el, prop) => {
return typeof getComputedStyle !== 'undefined'
const style = (el, prop) =>
typeof getComputedStyle !== 'undefined'
? getComputedStyle(el, null).getPropertyValue(prop)
: el.style[prop];
};
const overflow = (el) => {
return (
style(el, 'overflow') + style(el, 'overflow-y') + style(el, 'overflow-x')
);
};
const overflow = (el) =>
style(el, 'overflow') + style(el, 'overflow-y') + style(el, 'overflow-x');
const scrollParent = (el) => {
if (!inBrowser) return;

View File

@ -43,3 +43,13 @@ export declare type LazyloadOptions = {
export declare const Lazyload: {
install(app: App, options?: LazyloadOptions): void;
};
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$Lazyload: {
$on: (event: string, handler: Callback) => void;
$off: (event: string, handler?: Callback) => void;
$once: (event: string, handler: Callback) => void;
};
}
}

View File

@ -156,7 +156,7 @@
chalk "^2.0.0"
js-tokens "^4.0.0"
"@babel/parser@^7.12.0", "@babel/parser@^7.12.7":
"@babel/parser@^7.12.7":
version "7.12.7"
resolved "https://registry.npm.taobao.org/@babel/parser/download/@babel/parser-7.12.7.tgz?cache=0&sync_timestamp=1605906390839&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40babel%2Fparser%2Fdownload%2F%40babel%2Fparser-7.12.7.tgz#fee7b39fe809d0e73e5b25eecaf5780ef3d73056"
integrity sha1-/uezn+gJ0Oc+WyXuyvV4DvPXMFY=
@ -185,7 +185,7 @@
globals "^11.1.0"
lodash "^4.17.19"
"@babel/types@^7.10.4", "@babel/types@^7.11.0", "@babel/types@^7.12.0", "@babel/types@^7.12.1", "@babel/types@^7.12.5", "@babel/types@^7.12.7":
"@babel/types@^7.10.4", "@babel/types@^7.11.0", "@babel/types@^7.12.1", "@babel/types@^7.12.5", "@babel/types@^7.12.7":
version "7.12.7"
resolved "https://registry.npm.taobao.org/@babel/types/download/@babel/types-7.12.7.tgz?cache=0&sync_timestamp=1605906410175&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40babel%2Ftypes%2Fdownload%2F%40babel%2Ftypes-7.12.7.tgz#6039ff1e242640a29452c9ae572162ec9a8f5d13"
integrity sha1-YDn/HiQmQKKUUsmuVyFi7JqPXRM=
@ -397,54 +397,6 @@
dependencies:
"@types/node" "*"
"@vue/compiler-core@3.0.3":
version "3.0.3"
resolved "https://registry.npm.taobao.org/@vue/compiler-core/download/@vue/compiler-core-3.0.3.tgz?cache=0&sync_timestamp=1606319180904&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fcompiler-core%2Fdownload%2F%40vue%2Fcompiler-core-3.0.3.tgz#dbb4d5eb91f294038f0bed170a1c25f59f7dc74f"
integrity sha1-27TV65HylAOPC+0XChwl9Z99x08=
dependencies:
"@babel/parser" "^7.12.0"
"@babel/types" "^7.12.0"
"@vue/shared" "3.0.3"
estree-walker "^2.0.1"
source-map "^0.6.1"
"@vue/compiler-dom@3.0.3":
version "3.0.3"
resolved "https://registry.npm.taobao.org/@vue/compiler-dom/download/@vue/compiler-dom-3.0.3.tgz?cache=0&sync_timestamp=1606319180748&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fcompiler-dom%2Fdownload%2F%40vue%2Fcompiler-dom-3.0.3.tgz#582ba30bc82da8409868bc1153ff0e0e2be617e5"
integrity sha1-WCujC8gtqECYaLwRU/8ODivmF+U=
dependencies:
"@vue/compiler-core" "3.0.3"
"@vue/shared" "3.0.3"
"@vue/reactivity@3.0.3":
version "3.0.3"
resolved "https://registry.npm.taobao.org/@vue/reactivity/download/@vue/reactivity-3.0.3.tgz?cache=0&sync_timestamp=1606319193929&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Freactivity%2Fdownload%2F%40vue%2Freactivity-3.0.3.tgz#681ee01ceff9219bc4da6bbb7d9c97d452e44d1d"
integrity sha1-aB7gHO/5IZvE2mu7fZyX1FLkTR0=
dependencies:
"@vue/shared" "3.0.3"
"@vue/runtime-core@3.0.3":
version "3.0.3"
resolved "https://registry.npm.taobao.org/@vue/runtime-core/download/@vue/runtime-core-3.0.3.tgz?cache=0&sync_timestamp=1606319191469&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fruntime-core%2Fdownload%2F%40vue%2Fruntime-core-3.0.3.tgz#edab3c9ad122cf8afd034b174cd20c073fbf950a"
integrity sha1-7as8mtEiz4r9A0sXTNIMBz+/lQo=
dependencies:
"@vue/reactivity" "3.0.3"
"@vue/shared" "3.0.3"
"@vue/runtime-dom@3.0.3":
version "3.0.3"
resolved "https://registry.npm.taobao.org/@vue/runtime-dom/download/@vue/runtime-dom-3.0.3.tgz?cache=0&sync_timestamp=1606319176164&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fruntime-dom%2Fdownload%2F%40vue%2Fruntime-dom-3.0.3.tgz#5e3e5e5418b9defcac988d2be0cf65596fa2cc03"
integrity sha1-Xj5eVBi53vysmI0r4M9lWW+izAM=
dependencies:
"@vue/runtime-core" "3.0.3"
"@vue/shared" "3.0.3"
csstype "^2.6.8"
"@vue/shared@3.0.3":
version "3.0.3"
resolved "https://registry.npm.taobao.org/@vue/shared/download/@vue/shared-3.0.3.tgz?cache=0&sync_timestamp=1606319176262&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40vue%2Fshared%2Fdownload%2F%40vue%2Fshared-3.0.3.tgz#ef12ebff93a446df281e8a0fd765b5aea8e7745b"
integrity sha1-7xLr/5OkRt8oHooP12W1rqjndFs=
ansi-align@^3.0.0:
version "3.0.0"
resolved "https://registry.npm.taobao.org/ansi-align/download/ansi-align-3.0.0.tgz#b536b371cf687caaef236c18d3e21fe3797467cb"
@ -887,11 +839,6 @@ crypto-random-string@^2.0.0:
resolved "https://registry.npm.taobao.org/crypto-random-string/download/crypto-random-string-2.0.0.tgz?cache=0&sync_timestamp=1599137508676&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcrypto-random-string%2Fdownload%2Fcrypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5"
integrity sha1-7yp6lm7BEIM4g2m6oC6+rSKbMNU=
csstype@^2.6.8:
version "2.6.14"
resolved "https://registry.npm.taobao.org/csstype/download/csstype-2.6.14.tgz#004822a4050345b55ad4dcc00be1d9cf2f4296de"
integrity sha1-AEgipAUDRbVa1NzAC+HZzy9Clt4=
debug@4.3.1, debug@^4.1.0:
version "4.3.1"
resolved "https://registry.npm.taobao.org/debug/download/debug-4.3.1.tgz?cache=0&sync_timestamp=1606566568533&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fdebug%2Fdownload%2Fdebug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
@ -1040,11 +987,6 @@ escape-string-regexp@^1.0.5:
resolved "https://registry.npm.taobao.org/escape-string-regexp/download/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
estree-walker@^2.0.1:
version "2.0.1"
resolved "https://registry.npm.taobao.org/estree-walker/download/estree-walker-2.0.1.tgz#f8e030fb21cefa183b44b7ad516b747434e7a3e0"
integrity sha1-+OAw+yHO+hg7RLetUWt0dDTno+A=
execa@4.1.0, execa@^4.0.2:
version "4.1.0"
resolved "https://registry.npm.taobao.org/execa/download/execa-4.1.0.tgz?cache=0&sync_timestamp=1603884816920&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fexeca%2Fdownload%2Fexeca-4.1.0.tgz#4e5491ad1572f2f17a77d388c6c857135b22847a"
@ -2566,11 +2508,6 @@ source-map@^0.5.0, source-map@^0.5.6:
resolved "https://registry.npm.taobao.org/source-map/download/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
source-map@^0.6.1:
version "0.6.1"
resolved "https://registry.npm.taobao.org/source-map/download/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha1-dHIq8y6WFOnCh6jQu95IteLxomM=
split-string@^3.0.1, split-string@^3.0.2:
version "3.1.0"
resolved "https://registry.npm.taobao.org/split-string/download/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
@ -2817,15 +2754,6 @@ uuid@8.3.1:
resolved "https://registry.npm.taobao.org/uuid/download/uuid-8.3.1.tgz?cache=0&sync_timestamp=1605962427926&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fuuid%2Fdownload%2Fuuid-8.3.1.tgz#2ba2e6ca000da60fce5a196954ab241131e05a31"
integrity sha1-K6LmygANpg/OWhlpVKskETHgWjE=
vue@^3.0.0:
version "3.0.3"
resolved "https://registry.npm.taobao.org/vue/download/vue-3.0.3.tgz?cache=0&sync_timestamp=1606321342394&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue%2Fdownload%2Fvue-3.0.3.tgz#ad94a475e6ebbf3904673b6a0ae46e47b957bd72"
integrity sha1-rZSkdebrvzkEZztqCuRuR7lXvXI=
dependencies:
"@vue/compiler-dom" "3.0.3"
"@vue/runtime-dom" "3.0.3"
"@vue/shared" "3.0.3"
wcwidth@^1.0.1:
version "1.0.1"
resolved "https://registry.npm.taobao.org/wcwidth/download/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"

View File

@ -45,7 +45,7 @@
"license": "MIT",
"dependencies": {
"@vant/icons": "^1.7.1",
"@vant/lazyload": "^1.2.0",
"@vant/lazyload": "^1.3.0",
"@vant/popperjs": "^1.1.0",
"@vant/use": "^1.3.1"
},

View File

@ -21,12 +21,15 @@ import { Button } from '../button';
import { ActionBar } from '../action-bar';
import { ActionBarButton } from '../action-bar-button';
const [name, bem, t] = createNamespace('dialog');
// Types
import type {
DialogTheme,
DialogAction,
DialogMessage,
DialogMessageAlign,
} from './types';
export type DialogTheme = 'default' | 'round-button';
export type DialogAction = 'confirm' | 'cancel';
export type DialogMessage = string | (() => JSX.Element);
export type DialogMessageAlign = 'left' | 'center' | 'right';
const [name, bem, t] = createNamespace('dialog');
const popupKeys = [
...popupSharedPropKeys,

View File

@ -1,43 +1,8 @@
import { App, CSSProperties, TeleportProps } from 'vue';
import {
extend,
inBrowser,
withInstall,
Interceptor,
ComponentInstance,
} from '../utils';
import { App } from 'vue';
import { extend, inBrowser, withInstall, ComponentInstance } from '../utils';
import { mountComponent, usePopupState } from '../utils/mount-component';
import VanDialog, {
DialogTheme,
DialogAction,
DialogMessage,
DialogMessageAlign,
} from './Dialog';
export type DialogOptions = {
title?: string;
width?: string | number;
theme?: DialogTheme;
message?: DialogMessage;
overlay?: boolean;
teleport?: TeleportProps['to'];
className?: unknown;
allowHtml?: boolean;
lockScroll?: boolean;
transition?: string;
beforeClose?: Interceptor;
messageAlign?: DialogMessageAlign;
overlayClass?: string;
overlayStyle?: CSSProperties;
closeOnPopstate?: boolean;
cancelButtonText?: string;
showCancelButton?: boolean;
showConfirmButton?: boolean;
cancelButtonColor?: string;
confirmButtonText?: string;
confirmButtonColor?: string;
closeOnClickOverlay?: boolean;
};
import VanDialog from './Dialog';
import type { DialogAction, DialogOptions } from './types';
let instance: ComponentInstance;

View File

@ -1,6 +1,10 @@
import { Dialog, DialogOptions } from './function-call';
import type { DialogTheme, DialogMessage, DialogMessageAlign } from './Dialog';
import { Dialog } from './function-call';
export default Dialog;
export { Dialog };
export type { DialogTheme, DialogMessage, DialogOptions, DialogMessageAlign };
export type {
DialogTheme,
DialogMessage,
DialogOptions,
DialogMessageAlign,
} from './types';

View File

@ -0,0 +1,39 @@
import { Dialog } from './function-call';
import type { CSSProperties, TeleportProps } from 'vue';
import type { Interceptor } from '../utils';
export type DialogTheme = 'default' | 'round-button';
export type DialogAction = 'confirm' | 'cancel';
export type DialogMessage = string | (() => JSX.Element);
export type DialogMessageAlign = 'left' | 'center' | 'right';
export type DialogOptions = {
title?: string;
width?: string | number;
theme?: DialogTheme;
message?: DialogMessage;
overlay?: boolean;
teleport?: TeleportProps['to'];
className?: unknown;
allowHtml?: boolean;
lockScroll?: boolean;
transition?: string;
beforeClose?: Interceptor;
messageAlign?: DialogMessageAlign;
overlayClass?: string;
overlayStyle?: CSSProperties;
closeOnPopstate?: boolean;
cancelButtonText?: string;
showCancelButton?: boolean;
showConfirmButton?: boolean;
cancelButtonColor?: string;
confirmButtonText?: string;
confirmButtonColor?: string;
closeOnClickOverlay?: boolean;
};
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$dialog: typeof Dialog;
}
}

View File

@ -16,7 +16,6 @@ import {
inBrowser,
truthProp,
createNamespace,
ComponentInstance,
} from '../utils';
// Components
@ -59,8 +58,7 @@ export default defineComponent({
const loading = ref(true);
const imageRef = ref<HTMLElement>();
// TODO: types
const { $Lazyload } = getCurrentInstance()!.proxy as ComponentInstance;
const { $Lazyload } = getCurrentInstance()!.proxy!;
const style = computed(() => {
const style: CSSProperties = {};

View File

@ -2,11 +2,10 @@ import { PropType, defineComponent } from 'vue';
import { createNamespace, extend, unknownProp } from '../utils';
import { Popup } from '../popup';
import { popupSharedProps } from '../popup/shared';
import type { NotifyType } from './types';
const [name, bem] = createNamespace('notify');
export type NotifyType = 'primary' | 'success' | 'danger' | 'warning';
export default defineComponent({
name,

View File

@ -7,26 +7,12 @@ import {
ComponentInstance,
} from '../utils';
import { mountComponent, usePopupState } from '../utils/mount-component';
import VanNotify, { NotifyType } from './Notify';
import VanNotify from './Notify';
import type { NotifyMessage, NotifyOptions } from './types';
let timer: number;
let instance: ComponentInstance;
export type NotifyMessage = string | number;
export type NotifyOptions = {
type?: NotifyType;
color?: string;
message?: NotifyMessage;
duration?: number;
className?: unknown;
background?: string;
lockScroll?: boolean;
onClick?: (event: MouseEvent) => void;
onClose?: () => void;
onOpened?: () => void;
};
function parseOptions(message: NotifyMessage | NotifyOptions) {
return isObject(message) ? message : { message };
}

View File

@ -1,6 +1,5 @@
import { Notify, NotifyOptions } from './function-call';
import type { NotifyType } from './Notify';
import { Notify } from './function-call';
export default Notify;
export { Notify };
export type { NotifyType, NotifyOptions };
export type { NotifyType, NotifyOptions } from './types';

View File

@ -0,0 +1,24 @@
import { Notify } from './function-call';
export type NotifyMessage = string | number;
export type NotifyType = 'primary' | 'success' | 'danger' | 'warning';
export type NotifyOptions = {
type?: NotifyType;
color?: string;
message?: NotifyMessage;
duration?: number;
className?: unknown;
background?: string;
lockScroll?: boolean;
onClick?: (event: MouseEvent) => void;
onClose?: () => void;
onOpened?: () => void;
};
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$notify: typeof Notify;
}
}

View File

@ -16,10 +16,10 @@ import { Icon } from '../icon';
import { Popup } from '../popup';
import { Loading, LoadingType } from '../loading';
const [name, bem] = createNamespace('toast');
// Types
import type { ToastType, ToastPosition } from './types';
export type ToastType = 'text' | 'loading' | 'success' | 'fail' | 'html';
export type ToastPosition = 'top' | 'middle' | 'bottom';
const [name, bem] = createNamespace('toast');
export default defineComponent({
name,

View File

@ -1,4 +1,4 @@
import { ref, App, TeleportProps, getCurrentInstance, watch } from 'vue';
import { ref, App, getCurrentInstance, watch } from 'vue';
import {
extend,
isObject,
@ -7,31 +7,8 @@ import {
ComponentInstance,
} from '../utils';
import { mountComponent, usePopupState } from '../utils/mount-component';
import VanToast, { ToastType, ToastPosition } from './Toast';
import type { LoadingType } from '../loading';
export type ToastOptions = {
icon?: string;
type?: ToastType;
mask?: boolean;
message?: string | number;
onClose?: () => void;
onOpened?: () => void;
overlay?: boolean;
duration?: number;
teleport?: TeleportProps['to'];
iconSize?: number | string;
position?: ToastPosition;
className?: unknown;
transition?: string;
iconPrefix?: string;
loadingType?: LoadingType;
forbidClick?: boolean;
closeOnClick?: boolean;
overlayClass?: unknown;
overlayStyle?: Record<string, any>;
closeOnClickOverlay?: boolean;
};
import VanToast from './Toast';
import type { ToastType, ToastOptions } from './types';
const defaultOptions: ToastOptions = {
icon: '',

View File

@ -1,6 +1,5 @@
import { Toast, ToastOptions } from './function-call';
import type { ToastType, ToastPosition } from './Toast';
import { Toast } from './function-call';
export default Toast;
export { Toast };
export type { ToastType, ToastOptions, ToastPosition };
export type { ToastType, ToastOptions, ToastPosition } from './types';

View File

@ -0,0 +1,35 @@
import { Toast } from './function-call';
import type { TeleportProps } from 'vue';
import type { LoadingType } from '../loading';
export type ToastType = 'text' | 'loading' | 'success' | 'fail' | 'html';
export type ToastPosition = 'top' | 'middle' | 'bottom';
export type ToastOptions = {
icon?: string;
type?: ToastType;
mask?: boolean;
message?: string | number;
onClose?: () => void;
onOpened?: () => void;
overlay?: boolean;
duration?: number;
teleport?: TeleportProps['to'];
iconSize?: number | string;
position?: ToastPosition;
className?: unknown;
transition?: string;
iconPrefix?: string;
loadingType?: LoadingType;
forbidClick?: boolean;
closeOnClick?: boolean;
overlayClass?: unknown;
overlayStyle?: Record<string, any>;
closeOnClickOverlay?: boolean;
};
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$toast: typeof Toast;
}
}

View File

@ -1767,10 +1767,10 @@
resolved "https://registry.npmjs.org/@vant/icons/-/icons-1.7.1.tgz#49ae420302b5581e54e6894891e5a05bc76e9f87"
integrity sha512-66LPEq89w4kl258nALZcRNd14eUJC8VajvTJwvZKOaZawz6CUeVZ6ybhedTUhQhRjeA8SyWD7dFt4ALf33Sabw==
"@vant/lazyload@^1.2.0":
version "1.2.0"
resolved "https://registry.nlark.com/@vant/lazyload/download/@vant/lazyload-1.2.0.tgz#62e9779bd7844ad8f71c2ca2bf852e6147c7a86d"
integrity sha1-Yul3m9eEStj3HCyiv4UuYUfHqG0=
"@vant/lazyload@^1.3.0":
version "1.3.0"
resolved "https://registry.npmmirror.com/@vant/lazyload/download/@vant/lazyload-1.3.0.tgz?cache=0&sync_timestamp=1632451239649&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40vant%2Flazyload%2Fdownload%2F%40vant%2Flazyload-1.3.0.tgz#2a743339f271989dbf87f7a4c55c9fff7ebc774e"
integrity sha1-KnQzOfJxmJ2/h/ekxVyf/368d04=
"@vant/markdown-vetur@^2.2.0":
version "2.2.0"