Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
package.lib.composables.router.mjs.map Maven / Gradle / Ivy
{"version":3,"file":"router.mjs","names":["computed","nextTick","onScopeDispose","resolveDynamicComponent","toRef","deepEqual","getCurrentInstance","hasEvent","IN_BROWSER","propsFactory","useRoute","vm","proxy","$route","useRouter","$router","useLink","props","attrs","RouterLink","isLink","href","to","isClickable","value","linkProps","routerLink","link","undefined","route","navigate","isActive","exact","isExactActive","query","makeRouterProps","String","replace","Boolean","Object","inTransition","useBackButton","router","cb","popped","removeBefore","removeAfter","window","addEventListener","onPopstate","beforeEach","from","next","setTimeout","afterEach","removeEventListener","e","state","replaced"],"sources":["../../src/composables/router.tsx"],"sourcesContent":["// Utilities\nimport {\n computed,\n nextTick,\n onScopeDispose,\n resolveDynamicComponent,\n toRef,\n} from 'vue'\nimport { deepEqual, getCurrentInstance, hasEvent, IN_BROWSER, propsFactory } from '@/util'\n\n// Types\nimport type { ComputedRef, PropType, Ref, SetupContext } from 'vue'\nimport type {\n RouterLink as _RouterLink,\n useLink as _useLink,\n NavigationGuardNext,\n RouteLocationNormalizedLoaded,\n RouteLocationRaw,\n Router,\n UseLinkOptions,\n} from 'vue-router'\nimport type { EventProp } from '@/util'\n\nexport function useRoute (): Ref {\n const vm = getCurrentInstance('useRoute')\n\n return computed(() => vm?.proxy?.$route)\n}\n\nexport function useRouter (): Router | undefined {\n return getCurrentInstance('useRouter')?.proxy?.$router\n}\n\nexport interface LinkProps {\n href: string | undefined\n replace: boolean | undefined\n to: RouteLocationRaw | undefined\n exact: boolean | undefined\n}\n\nexport interface LinkListeners {\n onClick?: EventProp | undefined\n onClickOnce?: EventProp | undefined\n}\n\nexport interface UseLink extends Omit>, 'href'> {\n isLink: ComputedRef\n isClickable: ComputedRef\n href: Ref\n}\n\nexport function useLink (props: LinkProps & LinkListeners, attrs: SetupContext['attrs']): UseLink {\n const RouterLink = resolveDynamicComponent('RouterLink') as typeof _RouterLink | string\n\n const isLink = computed(() => !!(props.href || props.to))\n const isClickable = computed(() => {\n return isLink?.value || hasEvent(attrs, 'click') || hasEvent(props, 'click')\n })\n\n if (typeof RouterLink === 'string' || !('useLink' in RouterLink)) {\n return {\n isLink,\n isClickable,\n href: toRef(props, 'href'),\n }\n }\n // vue-router useLink `to` prop needs to be reactive and useLink will crash if undefined\n const linkProps = computed(() => ({\n ...props,\n to: toRef(() => props.to || ''),\n }))\n\n const routerLink = RouterLink.useLink(linkProps.value as UseLinkOptions)\n // Actual link needs to be undefined when to prop is not used\n const link = computed(() => props.to ? routerLink : undefined)\n const route = useRoute()\n\n return {\n isLink,\n isClickable,\n route: link.value?.route,\n navigate: link.value?.navigate,\n isActive: computed(() => {\n if (!link.value) return false\n if (!props.exact) return link.value.isActive?.value ?? false\n if (!route.value) return link.value.isExactActive?.value ?? false\n\n return link.value.isExactActive?.value && deepEqual(link.value.route.value.query, route.value.query)\n }),\n href: computed(() => props.to ? link.value?.route.value.href : props.href),\n }\n}\n\nexport const makeRouterProps = propsFactory({\n href: String,\n replace: Boolean,\n to: [String, Object] as PropType,\n exact: Boolean,\n}, 'router')\n\nlet inTransition = false\nexport function useBackButton (router: Router | undefined, cb: (next: NavigationGuardNext) => void) {\n let popped = false\n let removeBefore: (() => void) | undefined\n let removeAfter: (() => void) | undefined\n\n if (IN_BROWSER) {\n nextTick(() => {\n window.addEventListener('popstate', onPopstate)\n removeBefore = router?.beforeEach((to, from, next) => {\n if (!inTransition) {\n setTimeout(() => popped ? cb(next) : next())\n } else {\n popped ? cb(next) : next()\n }\n inTransition = true\n })\n removeAfter = router?.afterEach(() => {\n inTransition = false\n })\n })\n onScopeDispose(() => {\n window.removeEventListener('popstate', onPopstate)\n removeBefore?.()\n removeAfter?.()\n })\n }\n\n function onPopstate (e: PopStateEvent) {\n if (e.state?.replaced) return\n\n popped = true\n setTimeout(() => (popped = false))\n }\n}\n"],"mappings":"AAAA;AAC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