Skip to content

Commit

Permalink
chore: fix tsc for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Oct 22, 2024
1 parent 8c94377 commit 3f6f28b
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 45 deletions.
4 changes: 2 additions & 2 deletions docs/cypress/e2e/dark-mode.cypress.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ describe('Dark Mode', () => {
}

const assertTheme = (theme) =>
cy.get('html').then(html =>
cy.get('html').then((html) =>
expect(html.hasClass('dark')).to.equal(theme === 'dark'))

it('can toggle on and off', () => {
visitHome()
cy.get('html').then(html => {
cy.get('html').then((html) => {
if (html.hasClass('dark')) toggleTheme()
assertTheme('light')
})
Expand Down
2 changes: 1 addition & 1 deletion docs/cypress/e2e/docsearch.cypress.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('DocSearch', () => {
const searchModal = () =>
cy.get('.DocSearch-Modal')

const closeSearchModal = () =>{
const closeSearchModal = () => {
cy.get('body').type('{esc}')
searchModal().should('not.exist')
}
Expand Down
7 changes: 4 additions & 3 deletions docs/src/components/Iles.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script setup lang="ts">
const props = defineProps({
const { heading, small } = defineProps({
heading: { type: Boolean, default: false },
small: { type: Boolean, default: false },
noText: { type: Boolean, default: false },
})
const marginTop = props.heading ? '-mt-3 mx-1' : props.small ? '-mt-2.3 mx-0.5' : '-mt-4.8'
const size = props.small ? 'h-6' : 'h-10'
const marginTop = heading ? '-mt-3 mx-1' : small ? '-mt-2.3 mx-0.5' : '-mt-4.8'
const size = small ? 'h-6' : 'h-10'
</script>

<template>
Expand Down
6 changes: 3 additions & 3 deletions docs/src/components/NavBarLink.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
const props = defineProps({
const { href, external } = defineProps({
href: { type: String, default: undefined },
external: { type: Boolean, default: false },
text: { type: String, default: '' },
})
const route = useRoute()
let attrs = $computed(() => props.external ? { rel: 'noreferrer', target: '_blank' } : {})
let isActive = $computed(() => props.href && route.path.includes(props.href))
let attrs = $computed(() => external ? { rel: 'noreferrer', target: '_blank' } : {})
let isActive = $computed(() => href && route.path.includes(href))
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/NavBarLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div v-for="(item, index) in $site.nav" :key="item.text" class="item">
<NavBarLink :class="{ '<md:hidden': index > 1 }" :href="item.link" :text="item.text"/>
</div>
<NavBarLink aria-label="Follow on Twitter" class="text-2xl hover:text-primary-soft ml-6" :href="$site.twitter" external>
<NavBarLink aria-label="Follow on Twitter" class="text-xl hover:text-primary-soft ml-6" :href="$site.twitter" external>
<IconCarbonLogoTwitter/>
</NavBarLink>
<NavBarLink aria-label="Fork in GitHub" class="text-xl hover:text-primary-soft ml-2" :href="$site.github" external>
Expand Down
12 changes: 3 additions & 9 deletions docs/src/components/SidebarLink.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<script setup lang="ts">
import type { PropType } from 'vue'
import type { SideBarItem, SideBarGroup } from '~/logic/config'
import type { SideBarGroup } from '~/logic/config'
const props = defineProps({
item: {
type: Object as PropType<SideBarItem>,
required: true,
},
})
const { item } = defineProps<{ item: SideBarGroup }>()
let children = $computed(() => (props.item as SideBarGroup).children)
let children = $computed(() => item.children)
</script>

<template>
Expand Down
6 changes: 2 additions & 4 deletions docs/src/components/SidebarLinkItem.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<script setup lang="ts">
import { useAppConfig } from 'iles'
import { toRef } from 'vue'
import type { SideBarItem } from '~/logic/config'
import { joinUrl } from '~/logic/utils'
import { useActive } from '~/logic/sidebar'
const props = defineProps<{ item: SideBarItem; header?: boolean; table?: boolean }>()
const { item, header, table } = $(props)
const { item, header, table } = defineProps<{ item: SideBarItem; header?: boolean; table?: boolean }>()
const { base } = useAppConfig()
const active = $(useActive(toRef(props, 'item')))
const active = $(useActive(() => item))
const link = $computed(() => item.link && joinUrl(base, item.link))
const style = $computed(() => ([
Expand Down
8 changes: 4 additions & 4 deletions docs/src/components/TimeAgo.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script setup lang="ts">
import { watch, onBeforeUnmount } from 'vue'
const props = defineProps<{ date: Date }>()
let { date } = $(props)
const { date } = defineProps<{ date: Date }>()
let relativeTimeStr = $ref('')
let dateStr = $computed(() => date.toLocaleDateString('en-US', { day: 'numeric', month: 'long', year: 'numeric' }))
Expand All @@ -19,12 +18,13 @@ if (!import.meta.env.SSR) {
return date.toLocaleDateString('en-US', { day: 'numeric', month: 'long' })
}
const updateRelativeTimeStr = () =>
const updateRelativeTimeStr = () => {
relativeTimeStr = currentTime((Number(new Date()) - Number(date)) / (60 * 60 * 1000))
}
let activeInterval = setInterval(updateRelativeTimeStr, 60 * 1000)
onBeforeUnmount(() => clearInterval(activeInterval))
watch($$(date), updateRelativeTimeStr, { immediate: true })
watch(() => date, updateRelativeTimeStr, { immediate: true })
}
</script>

Expand Down
6 changes: 3 additions & 3 deletions docs/src/logic/sidebar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Ref, computed } from 'vue'
import { MaybeRefOrGetter, computed, toValue } from 'vue'

import type { Heading } from '@islands/headings'
import type { SideBarItem, SideBarGroup } from '~/logic/config'
Expand Down Expand Up @@ -37,11 +37,11 @@ export function useSideBar () {
})
}

export function useActive (itemRef: Ref<SideBarItem>) {
export function useActive (itemRef: MaybeRefOrGetter<SideBarItem>) {
const { route } = usePage()

return computed(() => {
const { link, ...item } = itemRef.value
const { link, ...item } = toValue(itemRef)

if (link === undefined)
return false
Expand Down
9 changes: 0 additions & 9 deletions docs/src/pages/guide/documents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,6 @@ export function usePosts () {
}
```

If you want to avoid using `value`, you can use [ref sugar] by wrapping it with `$()`:

```ts
export function usePosts () {
const posts = $(useDocuments('~/pages/posts'))
return computed(() => posts.sort(byDate))
}
```

## Comparison with `import.meta.glob`

- Significantly __faster__ than `import.meta.glob('./dir/*.mdx', { eager: true })`, as it serves a single file
Expand Down
4 changes: 2 additions & 2 deletions docs/src/pages/guide/rss.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ which are convenient to enable intellisense and type-checking for the feed optio
```ts
import type { FeedItem } from '@islands/feed'

const posts = $(useDocuments('~/pages/posts'))
const posts = useDocuments('~/pages/posts')

const items = posts.map<FeedItem>((post) => ({
const items = posts.value.map<FeedItem>((post) => ({
link: url + post.href,
date: post.date,
title: post.title,
Expand Down
5 changes: 4 additions & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"skipLibCheck": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"types": ["vite-plugin-pwa/client"],
"types": [
"@vue-macros/reactivity-transform/macros-global",
"vite-plugin-pwa/client"
],
"paths": {
"~/*": ["src/*"]
}
Expand Down
4 changes: 3 additions & 1 deletion playground/the-vue-point/src/components/BackLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const BackLink = ({ href, children }: { href: string, children: any }) =>
/** @jsxImportSource solid-js */

const BackLink = ({ href, children }: { href: string, children?: any }) =>
<a class="link" href={ href }>{ children }</a>

export default BackLink
2 changes: 1 addition & 1 deletion playground/the-vue-point/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let posts = $(getPosts())
<h2 class="text-2xl leading-8 font-bold tracking-tight">
<a class="text-gray-900" :href="post.href">{{ post.title }}</a>
</h2>
<div class="prose max-w-none text-gray-500">
<div class="max-w-none prose text-gray-500">
<component :is="post" excerpt/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion playground/the-vue-point/src/pages/posts/[page].vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defineProps<{
<h2 class="text-2xl leading-8 font-bold tracking-tight">
<a class="text-gray-900" :href="post.href">{{ post.title }}</a>
</h2>
<div class="prose max-w-none text-gray-500">
<div class="max-w-none prose text-gray-500">
<component :is="post" excerpt/>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions playground/the-vue-point/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"skipLibCheck": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"types": [
"@vue-macros/reactivity-transform/macros-global"
],
"paths": {
"~/*": ["src/*"]
}
Expand Down

0 comments on commit 3f6f28b

Please sign in to comment.