chore: move useRect to @vant/use

This commit is contained in:
chenjiahan 2020-10-05 11:22:30 +08:00
parent 6aa67b6df9
commit fd92564c27
15 changed files with 35 additions and 40 deletions

View File

@ -58,7 +58,7 @@
"dependencies": {
"@babel/runtime": "7.x",
"@vant/icons": "1.3.0",
"@vant/use": "^0.0.3",
"@vant/use": "^0.0.4",
"vue-lazyload": "1.2.3"
},
"peerDependencies": {

View File

@ -1,5 +1,11 @@
# 更新日志
### v0.0.4
`2020-10-05`
- 新增 `useRect` 方法
### v0.0.3
`2020-09-27`

View File

@ -16,7 +16,7 @@ import {
import { useToggle } from '@vant/use';
import { useRefs } from '../../composition/use-refs';
import { useExpose } from '../../composition/use-expose';
import { useRect, useHeight } from '../../composition/use-rect';
import { useRect, useHeight } from '../../composition/use-height';
// Components
import Day from './Day';

View File

@ -17,8 +17,8 @@ import {
} from './utils';
// Composition
import { useRect } from '@vant/use';
import { useRefs } from '../composition/use-refs';
import { useRect } from '../composition/use-rect';
import { useExpose } from '../composition/use-expose';
// Components

View File

@ -1,8 +1,5 @@
import { Ref, ref, unref, onMounted, nextTick } from 'vue';
export const useRect = (element: Element | Ref<Element>) => {
return unref(element).getBoundingClientRect();
};
import { useRect } from '@vant/use';
import { Ref, ref, onMounted, nextTick } from 'vue';
export const useHeight = (element: Element | Ref<Element>) => {
const height = ref();

View File

@ -1,4 +1,4 @@
import { useHeight } from './use-rect';
import { useHeight } from './use-height';
import type { Ref, VNode } from 'vue';
import type { BEM } from '../utils/create/bem';

View File

@ -5,12 +5,12 @@ import { createNamespace, isDef } from '../utils';
// Composition
import {
useRect,
useChildren,
useClickAway,
useScrollParent,
useEventListener,
} from '@vant/use';
import { useRect } from '../composition/use-rect';
const [createComponent, bem] = createNamespace('dropdown-menu');

View File

@ -7,7 +7,7 @@ import { INDEX_BAR_KEY } from '../index-bar';
// Composition
import { useParent } from '@vant/use';
import { useHeight } from '../composition/use-rect';
import { useHeight } from '../composition/use-height';
import { useExpose } from '../composition/use-expose';
const [createComponent, bem] = createNamespace('index-anchor');

View File

@ -13,8 +13,12 @@ import {
} from '../utils';
// Composition
import { useChildren, useScrollParent, useEventListener } from '@vant/use';
import { useRect } from '../composition/use-rect';
import {
useRect,
useChildren,
useScrollParent,
useEventListener,
} from '@vant/use';
import { useTouch } from '../composition/use-touch';
export const INDEX_BAR_KEY = 'vanIndexBar';

View File

@ -4,8 +4,7 @@ import { ref, watch, nextTick, onUpdated, onMounted } from 'vue';
import { isHidden, createNamespace } from '../utils';
// Composition
import { useScrollParent, useEventListener } from '@vant/use';
import { useRect } from '../composition/use-rect';
import { useRect, useScrollParent, useEventListener } from '@vant/use';
import { useExpose } from '../composition/use-expose';
// Components
@ -44,19 +43,6 @@ export default createComponent({
const placeholder = ref();
const scrollParent = useScrollParent(root);
const getScrollParentRect = () => {
const element = scrollParent.value;
if (element.getBoundingClientRect) {
return element.getBoundingClientRect();
}
const height = element.innerHeight;
return {
top: 0,
height,
bottom: height,
};
};
const check = () => {
nextTick(() => {
if (loading.value || props.finished || props.error) {
@ -64,7 +50,7 @@ export default createComponent({
}
const { offset, direction } = props;
const scrollParentRect = getScrollParentRect();
const scrollParentRect = useRect(scrollParent);
if (!scrollParentRect.height || isHidden(root)) {
return false;

View File

@ -2,8 +2,7 @@ import { ref, watch, reactive, nextTick, onActivated } from 'vue';
import { isDef, doubleRaf, createNamespace } from '../utils';
// Composition
import { useRect } from '../composition/use-rect';
import { useEventListener } from '@vant/use';
import { useRect, useEventListener } from '@vant/use';
// Components
import Icon from '../icon';

View File

@ -10,7 +10,7 @@ import {
import { deepClone } from '../utils/deep-clone';
// Composition
import { useRect } from '../composition/use-rect';
import { useRect } from '@vant/use';
import { useTouch } from '../composition/use-touch';
import { useLinkField } from '../composition/use-link-field';

View File

@ -5,8 +5,7 @@ import { range, createNamespace, preventDefault } from '../utils';
import { callInterceptor } from '../utils/interceptor';
// Composition
import { useClickAway } from '@vant/use';
import { useRect } from '../composition/use-rect';
import { useRect, useClickAway } from '@vant/use';
import { useTouch } from '../composition/use-touch';
import { useExpose } from '../composition/use-expose';

View File

@ -19,8 +19,12 @@ import {
} from '../utils';
// Composition
import { useChildren, useWindowSize, usePageVisibility } from '@vant/use';
import { useRect } from '../composition/use-rect';
import {
useRect,
useChildren,
useWindowSize,
usePageVisibility,
} from '@vant/use';
import { useTouch } from '../composition/use-touch';
import { useExpose } from '../composition/use-expose';

View File

@ -2175,10 +2175,10 @@
resolved "https://registry.yarnpkg.com/@vant/touch-emulator/-/touch-emulator-1.2.0.tgz#486300b23e57db9ce9231a04e0a0c621c68692d8"
integrity sha512-sJ97zU85zOq51qoi7+CpBEcOyH3CitjP1KC7/GQwqaurUJni+EP7/F9n0HMnAh8GXMjgtgDBNJ5z48x+coNKYQ==
"@vant/use@^0.0.3":
version "0.0.3"
resolved "https://registry.npmjs.org/@vant/use/-/use-0.0.3.tgz#e3043830206344442a22d302d556c2e36b492eb5"
integrity sha512-7B7tmc8OqkNlMsNzZrIBy2hE8pBvQexBdE74+xr8/HtLhFbVkiZeO+YsOmgYTrsnSEvACBreoIkFX2tjRjzdMw==
"@vant/use@^0.0.4":
version "0.0.4"
resolved "https://registry.npmjs.org/@vant/use/-/use-0.0.4.tgz#c02fb1b4cec53135efc85b1a7479ab186c0e5e73"
integrity sha512-beX+RH6SCyOIZ9nyod2nIK1/bNSPAAZoOvXQ2OZ0Dv9Dd55MyVnDTBZ1WCgE8Hf/PjgSOuIMp715ekEncSHoEg==
"@vue/babel-helper-vue-transform-on@^1.0.0-rc.2":
version "1.0.0-rc.2"