@devite/nuxt-sanity 1.1.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +2 -2
- package/dist/runtime/components/SanityComponent.vue +7 -3
- package/dist/runtime/components/SanityImageAsset.vue +9 -8
- package/dist/runtime/components/SanityPage.vue +3 -5
- package/dist/runtime/utils/resolveImageAssetById.d.ts +2 -1
- package/dist/runtime/utils/resolveImageAssetById.js +1 -1
- package/package.json +8 -6
package/dist/module.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
<component
|
|
3
3
|
:is="component"
|
|
4
4
|
v-if="data"
|
|
5
|
-
|
|
5
|
+
ref="componentRef"
|
|
6
|
+
v-bind="{ ...$props, ...$attrs }"
|
|
6
7
|
>
|
|
7
8
|
<slot />
|
|
8
9
|
</component>
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
|
|
11
12
|
<script setup lang="ts">
|
|
12
13
|
import type { Component } from '@nuxt/schema'
|
|
13
|
-
import { computed, resolveComponent } from '#imports'
|
|
14
|
+
import { computed, ref, resolveComponent } from '#imports'
|
|
14
15
|
import { SanityLinkExternal, SanityLinkInternal, SanityRichText } from '#components'
|
|
15
16
|
|
|
16
17
|
const { data } = defineProps<{ data?: object }>()
|
|
@@ -24,7 +25,7 @@ const component = computed<Component>(() => {
|
|
|
24
25
|
case 'linkExternal':
|
|
25
26
|
return SanityLinkExternal
|
|
26
27
|
default:
|
|
27
|
-
if (data?.constructor.name === 'Array' && data.every(item => item._type === 'block'))
|
|
28
|
+
if (data?.constructor.name === 'Array' && data.every((item) => item._type === 'block'))
|
|
28
29
|
return SanityRichText
|
|
29
30
|
else if (type) {
|
|
30
31
|
const upperCamelCase = type.charAt(0).toUpperCase() + type.slice(1)
|
|
@@ -35,4 +36,7 @@ const component = computed<Component>(() => {
|
|
|
35
36
|
|
|
36
37
|
return null
|
|
37
38
|
})
|
|
39
|
+
|
|
40
|
+
const componentRef = ref<Component>()
|
|
41
|
+
defineExpose({ componentRef })
|
|
38
42
|
</script>
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<NuxtImg
|
|
3
|
-
v-if="
|
|
3
|
+
v-if="imageAsset?._id"
|
|
4
4
|
densities="x1 x2"
|
|
5
|
-
:src="
|
|
6
|
-
:width="
|
|
7
|
-
:height="
|
|
8
|
-
:alt="
|
|
9
|
-
:placeholder="
|
|
5
|
+
:src="imageAsset._id"
|
|
6
|
+
:width="imageAsset.metadata.dimensions.width"
|
|
7
|
+
:height="imageAsset.metadata.dimensions.height"
|
|
8
|
+
:alt="imageAsset.altText"
|
|
9
|
+
:placeholder="imageAsset.metadata.lqip"
|
|
10
10
|
:loading="loading"
|
|
11
|
-
:format="
|
|
11
|
+
:format="imageAsset.mimeType === 'image/svg+xml' ? undefined : 'webp'"
|
|
12
12
|
draggable="false"
|
|
13
13
|
/>
|
|
14
14
|
</template>
|
|
@@ -16,5 +16,6 @@
|
|
|
16
16
|
<script setup lang="ts">
|
|
17
17
|
import type { ImageAsset } from '@sanity/types'
|
|
18
18
|
|
|
19
|
-
const { loading = 'lazy' } = defineProps<{ asset
|
|
19
|
+
const { asset, loading = 'lazy' } = defineProps<{ asset?: ImageAsset, loading?: 'lazy' | 'eager' }>()
|
|
20
|
+
const imageAsset = asset?._ref ? await resolveImageAssetById(asset._ref) : asset
|
|
20
21
|
</script>
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
</template>
|
|
10
10
|
|
|
11
11
|
<script setup lang="ts">
|
|
12
|
-
import { useSanityQuery } from '@nuxtjs/sanity/runtime/composables'
|
|
12
|
+
import { useSanityQuery } from '@nuxtjs/sanity/runtime/composables/visual-editing'
|
|
13
13
|
import { groq } from '@nuxtjs/sanity/runtime/groq'
|
|
14
14
|
import type { ComputedRef } from 'vue'
|
|
15
15
|
import type { ImageAsset } from '@sanity/types'
|
|
@@ -18,15 +18,13 @@ import type { Page } from '../types/documents/Page'
|
|
|
18
18
|
import type { NotFound } from '../types/singletons/NotFound'
|
|
19
19
|
import type { GlobalSEO } from '../types/objects/global/GlobalSEO'
|
|
20
20
|
import { IMAGE_WITHOUT_PREVIEW_PROJECTION } from '../utils/projections'
|
|
21
|
-
import { useHead, useRoute, useRuntimeConfig, useSeoMeta } from '#
|
|
22
|
-
import { computed } from '#imports'
|
|
23
|
-
|
|
24
|
-
const { baseURL } = useRuntimeConfig().public
|
|
21
|
+
import { useHead, useRoute, useRuntimeConfig, useSeoMeta, computed } from '#imports'
|
|
25
22
|
|
|
26
23
|
const path = useRoute().fullPath
|
|
27
24
|
const groqFilter = path === '/' ? '_type == "home"' : `_type == "page" && slug.current == $slug`
|
|
28
25
|
const { data: sanityData } = await useSanityQuery<Home | Page | NotFound>(groq`*[(${groqFilter}) || _type == "notFound"][0] { _id, _type, title, modules, seo { _type, indexable, title, shortTitle, description, image ${IMAGE_WITHOUT_PREVIEW_PROJECTION} } }`, { slug: path.substring(1) })
|
|
29
26
|
|
|
27
|
+
const { baseURL } = useRuntimeConfig().public
|
|
30
28
|
const seo = computed(() => sanityData.value?.seo)
|
|
31
29
|
const url = computed(() => baseURL + (sanityData.value?.slug || '/'))
|
|
32
30
|
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { ImageAsset } from '@sanity/types';
|
|
2
|
-
|
|
2
|
+
import type { Ref } from '#imports';
|
|
3
|
+
export declare const resolveImageAssetById: (id: string) => Promise<Ref<ImageAsset | undefined>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useSanityQuery } from "@nuxtjs/sanity/runtime/composables";
|
|
2
2
|
import { IMAGE_ASSET_PROJECTION } from "./projections.js";
|
|
3
3
|
export const resolveImageAssetById = async (id) => {
|
|
4
|
-
return (await useSanityQuery(`*[_type == "sanity.imageAsset" && _id == $assetId][0] ${IMAGE_ASSET_PROJECTION}`, { assetId: id })).data
|
|
4
|
+
return (await useSanityQuery(`*[_type == "sanity.imageAsset" && _id == $assetId][0] ${IMAGE_ASSET_PROJECTION}`, { assetId: id })).data;
|
|
5
5
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devite/nuxt-sanity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Provides additional helper components and utilities for the Nuxt.js Sanity module",
|
|
5
5
|
"repository": "devite-io/nuxt-sanity",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,20 +22,22 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@nuxt/image": "^1.8.0",
|
|
25
26
|
"@nuxt/kit": "^3.13.2",
|
|
26
27
|
"@nuxtjs/sanity": "^1.12.1",
|
|
27
|
-
"@
|
|
28
|
+
"@portabletext/vue": "^1.0.11",
|
|
29
|
+
"@sanity/client": "^6.22.0",
|
|
30
|
+
"@sanity/types": "^3.59.0"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
|
-
"@nuxt/devtools": "^1.
|
|
33
|
+
"@nuxt/devtools": "^1.5.1",
|
|
31
34
|
"@nuxt/eslint-config": "^0.5.7",
|
|
32
35
|
"@nuxt/module-builder": "^0.8.4",
|
|
33
36
|
"@nuxt/schema": "^3.13.2",
|
|
34
37
|
"@nuxt/test-utils": "^3.14.2",
|
|
35
|
-
"@portabletext/vue": "^1.0.11",
|
|
36
38
|
"@types/node": "latest",
|
|
37
|
-
"changelogen": "^0.5.
|
|
38
|
-
"eslint": "^9.
|
|
39
|
+
"changelogen": "^0.5.7",
|
|
40
|
+
"eslint": "^9.11.1",
|
|
39
41
|
"nuxt": "^3.13.2",
|
|
40
42
|
"typescript": "latest",
|
|
41
43
|
"vitest": "^2.1.1",
|