Skip to content

Commit

Permalink
Merge branch 'main' into pr/edumudu/2022
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 5, 2022
2 parents e2e62e4 + fbc8959 commit a947f34
Show file tree
Hide file tree
Showing 116 changed files with 2,098 additions and 933 deletions.
40 changes: 28 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
const { resolve } = require('path')

const restricted = [
'vue',
'@vue/composition-api',
'..',
'../..',
resolve(__dirname, 'packages/core/index.ts'),
resolve(__dirname, 'packages/shared/index.ts'),
{
name: 'vue-demi',
importNames: ['onMounted', 'onUnmounted'],
message: 'Use tryOnMounted and tryOnScopeDispose instead.',
},
]

module.exports = {
root: true,
env: {
Expand All @@ -19,18 +33,7 @@ module.exports = {
'no-restricted-imports': [
'error',
{
paths: [
'vue',
'@vue/composition-api',
'..',
'../..',
resolve(__dirname, 'packages/core/index.ts'),
{
name: 'vue-demi',
importNames: ['onMounted', 'onUnmounted'],
message: 'Use tryOnMounted and tryOnScopeDispose instead.',
},
],
paths: restricted,
},
],
'node/no-callback-literal': 'off',
Expand All @@ -40,6 +43,19 @@ module.exports = {
'import/no-named-as-default-member': 'off',
},
overrides: [
{
files: ['packages/shared/**/*.ts'],
rules: {
'no-restricted-imports': ['error',
{
paths: [
...restricted,
'@vueuse/shared',
],
},
],
},
},
{
files: ['**/*.md', '**/*.md/*.*', 'demo.vue', 'scripts/*.ts', '*.test.ts'],
rules: {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ packages/*/LICENSE
packages/contributing.md
packages/core/README.md
packages/public/badge-*
packages/*/index.mjs
playgrounds/*/pnpm-lock.yaml
types
4 changes: 4 additions & 0 deletions meta/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ export const packages: PackageManifest[] = [
external: [
'firebase',
'firebase/app',
'firebase/database',
'firebase/firestore',
],
globals: {
'firebase': 'firebase',
'firebase/app': 'firebase',
'firebase/database': 'firebase',
'firebase/firestore': 'firebase',
},
},
{
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vueuse/monorepo",
"version": "9.0.2",
"version": "9.1.1",
"private": true,
"packageManager": "pnpm@7.6.0",
"description": "Collection of essential Vue Composition Utilities",
Expand Down Expand Up @@ -50,10 +50,10 @@
"@vitest/ui": "^0.18.1",
"@vue/compiler-sfc": "^3.2.37",
"@vue/test-utils": "^2.0.2",
"@vueuse/core": "link:packages/core",
"@vueuse/integrations": "link:packages/integrations",
"@vueuse/math": "link:packages/math",
"@vueuse/shared": "link:packages/shared",
"@vueuse/core": "workspace:*",
"@vueuse/integrations": "workspace:*",
"@vueuse/math": "workspace:*",
"@vueuse/shared": "workspace:*",
"axios": "^0.27.2",
"bumpp": "^8.2.1",
"consola": "^2.15.3",
Expand Down
5 changes: 2 additions & 3 deletions packages/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Links = [
{ text: 'Add-ons', link: '/add-ons' },
{ text: 'Ecosystem', link: '/ecosystem' },
{ text: 'Export Size', link: '/export-size' },
{ text: 'Recent Updated', link: '/recent-updated' },
{ text: 'Recent Updated', link: '/functions.html#sort=updated' },
]

const DefaultSideBar = [
Expand Down Expand Up @@ -141,8 +141,6 @@ export default defineConfig({
'/ecosystem': DefaultSideBar,
'/guidelines': DefaultSideBar,
'/export-size': DefaultSideBar,
'/recent-updated': DefaultSideBar,

'/functions': FunctionsSideBar,
'/core/': FunctionsSideBar,
'/shared/': FunctionsSideBar,
Expand All @@ -151,6 +149,7 @@ export default defineConfig({
'/rxjs/': FunctionsSideBar,
'/integrations/': FunctionsSideBar,
'/firebase/': FunctionsSideBar,
'/math/': FunctionsSideBar,
},
},
head: [
Expand Down
13 changes: 9 additions & 4 deletions packages/.vitepress/theme/components/Changelog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
// @ts-expect-error virtual
import changelog from '/virtual-changelog'
import { computed } from 'vue'
import type { CommitInfo } from '../@vueuse/metadata'
import type { CommitInfo } from '@vueuse/metadata'
import { renderCommitMessage } from '../utils'
import { functions } from '@vueuse/metadata'
const props = defineProps<{ fn: string }>()
const info = computed(() => functions.find(i => i.name === props.fn))
const allCommits = changelog as CommitInfo[]
const names = computed(() => [props.fn, ...info.value.alias || []])
const commits = computed(() => {
const commits = allCommits.filter(c => c.version || c.functions?.includes(props.fn))
return commits.filter((i, idx) => {
if (i.version && (!commits[idx + 1] || commits[idx + 1]?.version))
const related = allCommits
.filter(c => c.version || c.functions?.some(i => names.value.includes(i)))
return related.filter((i, idx) => {
if (i.version && (!related[idx + 1] || related[idx + 1]?.version))
return false
return true
})
Expand Down
10 changes: 8 additions & 2 deletions packages/.vitepress/theme/components/FunctionBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ const link = computed(() => {
</script>

<template>
<div text="sm" flex="~ gap1" items-center>
<a v-bind="link" bg="gray-400/5" p="x-1.5 y-0.5" class="rounded items-center" flex="inline gap-1 none" my-auto>
<div
text="sm" flex="~ gap1" items-center
:class="fn.deprecated ? 'op80 saturate-0' : ''"
>
<a
v-bind="link" bg="gray-400/5" p="x-1.5 y-0.5" class="rounded items-center" flex="inline gap-1 none" my-auto
:class="fn.deprecated ? 'line-through !decoration-solid' : ''"
>
<span v-html="styledName(fn.name)" />
<i v-if="fn.external" i-carbon-launch class="opacity-80 text-xs" />
</a>
Expand Down
9 changes: 7 additions & 2 deletions packages/.vitepress/theme/components/FunctionInfo.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<script setup lang="ts">
import { useTimeAgo } from '@vueuse/core'
import { computed } from 'vue'
import { functions } from '../../../../packages/metadata/metadata'
import { functions } from '@vueuse/metadata'
import exportSizes from '../../../export-size.json'
const props = defineProps<{ fn: string }>()
const info = computed(() => functions.find(i => i.name === props.fn))
const format = (ts: number) => ago(-1, 'day')
const lastUpdated = useTimeAgo(new Date(info.value?.lastUpdated || 0))
const link = computed(() => `/functions\#category=${encodeURIComponent(info.value.category)}`)
const exportSize = exportSizes[info.value?.name]
const getFunctionLink = (fn: string) => {
const info = functions.find(i => i.name === fn)
return info?.docs.replace(/https?:\/\/vueuse\.org\//g, '/')
Expand All @@ -22,6 +23,10 @@ const getFunctionLink = (fn: string) => {
Category
</div>
<div><a :href="link">{{ info.category }}</a></div>
<div opacity="50">
Export Size
</div>
<div> {{ exportSize }}</div>
<template v-if="info.package !== 'core' && info.package !== 'shared'">
<div opacity="50">
Package
Expand Down
2 changes: 2 additions & 0 deletions packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export * from '../core/useOnline/component'
export * from '../core/usePageLeave/component'
export * from '../core/usePointer/component'
export * from '../core/usePreferredColorScheme/component'
export * from '../core/usePreferredContrast/component'
export * from '../core/usePreferredDark/component'
export * from '../core/usePreferredLanguages/component'
export * from '../core/usePreferredReducedMotion/component'
export * from '../core/useScreenSafeArea/component'
export * from '../core/useScroll/directive'
export * from '../core/useScrollLock/directive'
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vueuse/components",
"version": "9.0.2",
"version": "9.1.1",
"description": "Renderless components for VueUse",
"author": "Jacob Clevenger<https://github.com/wheatjs>",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/computedAsync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface AsyncComputedOptions {
*
* @default false
*/
lazy?: Boolean
lazy?: boolean

/**
* Ref passed to receive the updated of async evaluation
Expand Down
3 changes: 3 additions & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from './useBroadcastChannel'
export * from './useBrowserLocation'
export * from './useCached'
export * from './useClipboard'
export * from './useCloned'
export * from './useColorMode'
export * from './useConfirmDialog'
export * from './useCssVar'
Expand Down Expand Up @@ -81,8 +82,10 @@ export * from './usePermission'
export * from './usePointer'
export * from './usePointerSwipe'
export * from './usePreferredColorScheme'
export * from './usePreferredContrast'
export * from './usePreferredDark'
export * from './usePreferredLanguages'
export * from './usePreferredReducedMotion'
export * from './useRafFn'
export * from './useRefHistory'
export * from './useResizeObserver'
Expand Down
4 changes: 0 additions & 4 deletions packages/core/onKeyStroke/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ const translateY = ref(0)
onKeyStroke(['w', 'W', 'ArrowUp'], (e: KeyboardEvent) => {
translateY.value -= 10
e.preventDefault()
})
onKeyStroke(['s', 'S', 'ArrowDown'], (e: KeyboardEvent) => {
translateY.value += 10
e.preventDefault()
})
onKeyStroke(['a', 'A', 'ArrowLeft'], (e: KeyboardEvent) => {
translateX.value -= 10
e.preventDefault()
})
onKeyStroke(['d', 'D', 'ArrowRight'], (e: KeyboardEvent) => {
translateX.value += 10
e.preventDefault()
})
</script>

Expand Down
8 changes: 4 additions & 4 deletions packages/core/onLongPress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export function onLongPress(
) {
const elementRef = computed(() => unrefElement(target))

let timeout: number | null = null
let timeout: ReturnType<typeof setTimeout> | undefined

function clear() {
if (timeout != null) {
if (timeout) {
clearTimeout(timeout)
timeout = null
timeout = undefined
}
}

Expand All @@ -55,7 +55,7 @@ export function onLongPress(
timeout = setTimeout(
() => handler(ev),
options?.delay ?? DEFAULT_DELAY,
) as unknown as number
)
}

const listenerOptions: AddEventListenerOptions = {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vueuse/core",
"version": "9.0.2",
"version": "9.1.1",
"description": "Collection of essential Vue Composition Utilities",
"author": "Anthony Fu <https://github.com/antfu>",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/ssr-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface StorageLike {
}

/**
* @expiremental The API is not finalized yet. It might not follow semver.
* @experimental The API is not finalized yet. It might not follow semver.
*/
export interface SSRHandlersMap {
getDefaultStorage: () => StorageLike | undefined
Expand Down
17 changes: 8 additions & 9 deletions packages/core/useActiveElement/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed, ref } from 'vue-demi'
import { computedWithControl } from '@vueuse/shared'
import { useEventListener } from '../useEventListener'
import type { ConfigurableWindow } from '../_configurable'
import { defaultWindow } from '../_configurable'
Expand All @@ -11,16 +11,15 @@ import { defaultWindow } from '../_configurable'
*/
export function useActiveElement<T extends HTMLElement>(options: ConfigurableWindow = {}) {
const { window = defaultWindow } = options
const counter = ref(0)
const activeElement = computedWithControl(
() => null,
() => window?.document.activeElement as T | null | undefined,
)

if (window) {
useEventListener(window, 'blur', () => counter.value += 1, true)
useEventListener(window, 'focus', () => counter.value += 1, true)
useEventListener(window, 'blur', activeElement.trigger, true)
useEventListener(window, 'focus', activeElement.trigger, true)
}

return computed(() => {
// eslint-disable-next-line no-unused-expressions
counter.value
return window?.document.activeElement as T | null | undefined
})
return activeElement
}
6 changes: 5 additions & 1 deletion packages/core/useBreakpoints/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'
const breakpoints = useBreakpoints(breakpointsTailwind)
const smWidth = breakpointsTailwind.sm
const sm = breakpoints.smaller('sm')
const sme = breakpoints.smallerOrEqual('sm')
const md = breakpoints.between('sm', 'md')
const lg = breakpoints.between('md', 'lg')
const xl = breakpoints.between('lg', 'xl')
Expand All @@ -13,7 +16,8 @@ const xxxl = breakpoints['2xl']

<template>
<div class="font-mono">
<div> sm: <BooleanDisplay :value="sm" /></div>
<div> sm(&lt;{{ smWidth }}px): <BooleanDisplay :value="sm" /></div>
<div> sm(&lt;={{ smWidth }}px): <BooleanDisplay :value="sme" /></div>
<div> md: <BooleanDisplay :value="md" /></div>
<div> lg: <BooleanDisplay :value="lg" /></div>
<div> xl: <BooleanDisplay :value="xl" /></div>
Expand Down
5 changes: 4 additions & 1 deletion packages/core/useBreakpoints/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'

const breakpoints = useBreakpoints(breakpointsTailwind)

const smAndLarger = breakpoints.greater('sm')
const smAndLarger = breakpoints.greaterOrEqual('sm') // sm and larger
const largerThanSm = breakpoints.greater('sm') // only larger than sm
const lgAndSmaller = breakpoints.smallerOrEqual('lg') // lg and smaller
const smallerThanLg = breakpoints.smaller('lg') // only smaller than lg
```

```js
Expand Down

0 comments on commit a947f34

Please sign in to comment.