@devite/nuxt-sanity 2.2.1 → 2.3.1
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
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<NuxtImg
|
|
3
3
|
v-if="imageAsset?._id"
|
|
4
|
+
provider="sanity"
|
|
4
5
|
densities="x1 x2"
|
|
5
6
|
:src="imageAsset._id"
|
|
6
7
|
:width="imageAsset.metadata.dimensions.width"
|
|
7
8
|
:height="imageAsset.metadata.dimensions.height"
|
|
8
9
|
:alt="imageAsset.altText"
|
|
9
10
|
:placeholder="loading === 'eager' ? undefined : imageAsset.metadata.lqip"
|
|
10
|
-
:loading="loading"
|
|
11
|
+
:loading="loading || 'lazy'"
|
|
11
12
|
:format="imageAsset.mimeType === 'image/svg+xml' ? undefined : 'webp'"
|
|
12
13
|
draggable="false"
|
|
13
14
|
/>
|
|
@@ -15,14 +16,22 @@
|
|
|
15
16
|
|
|
16
17
|
<script setup lang="ts">
|
|
17
18
|
import type { ImageAsset, Reference } from '@sanity/types'
|
|
18
|
-
import type { Ref } from 'vue'
|
|
19
19
|
import { resolveImageAssetById } from '../utils/resolveImageAssetById'
|
|
20
|
+
import { useLazyAsyncData, useAsyncData, useId } from '#imports'
|
|
20
21
|
|
|
21
|
-
const
|
|
22
|
-
asset?: ImageAsset | Reference
|
|
22
|
+
const props = defineProps<{
|
|
23
|
+
asset?: ImageAsset | Reference | null
|
|
23
24
|
loading?: 'eager' | 'lazy'
|
|
24
25
|
}>()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
|
|
27
|
+
const { data: imageAsset } = await (
|
|
28
|
+
props.loading !== 'eager' ? useLazyAsyncData : useAsyncData
|
|
29
|
+
)<ImageAsset | null>(
|
|
30
|
+
useId(),
|
|
31
|
+
async () =>
|
|
32
|
+
props.asset?._ref
|
|
33
|
+
? (await resolveImageAssetById((props.asset as Reference)._ref)).value
|
|
34
|
+
: ((props.asset || null) as ImageAsset | null),
|
|
35
|
+
{ watch: [props] },
|
|
36
|
+
)
|
|
28
37
|
</script>
|