@devite/nuxt-sanity 2.3.0 → 2.3.2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "configKey": "sanity",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
package/dist/module.mjs CHANGED
@@ -3,7 +3,7 @@ import { defineNuxtModule, createResolver, addPlugin, addServerHandler, addImpor
3
3
  import defu from 'defu';
4
4
 
5
5
  const name = "@devite/nuxt-sanity";
6
- const version = "2.3.0";
6
+ const version = "2.3.2";
7
7
 
8
8
  const module = defineNuxtModule({
9
9
  meta: {
@@ -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,22 +16,30 @@
15
16
 
16
17
  <script setup lang="ts">
17
18
  import type { ImageAsset, Reference } from '@sanity/types'
19
+ import { ref, watch } from 'vue'
18
20
  import { resolveImageAssetById } from '../utils/resolveImageAssetById'
19
- import { useLazyAsyncData, useAsyncData, useId } from '#imports'
20
21
 
21
22
  const props = defineProps<{
22
23
  asset?: ImageAsset | Reference | null
23
24
  loading?: 'eager' | 'lazy'
24
25
  }>()
26
+ const imageAsset = ref<ImageAsset | null>(null)
27
+ let unwatchFunc = undefined as (() => void) | undefined
25
28
 
26
- const { data: imageAsset } = (
27
- props.loading !== 'eager' ? useLazyAsyncData : useAsyncData
28
- )<ImageAsset | null>(
29
- useId(),
30
- async () =>
31
- props.asset?._ref
32
- ? (await resolveImageAssetById((props.asset as Reference)._ref)).value
33
- : ((props.asset || null) as ImageAsset | null),
34
- { watch: [props] },
35
- )
29
+ async function resolveImageAsset() {
30
+ if (props.asset?._ref) {
31
+ const assetRef = await resolveImageAssetById((props.asset as Reference)._ref)
32
+
33
+ imageAsset.value = assetRef.value
34
+
35
+ unwatchFunc?.()
36
+ unwatchFunc = watch(assetRef, (updatedAsset) => imageAsset.value = updatedAsset)
37
+ return
38
+ }
39
+
40
+ imageAsset.value = (props.asset || null) as ImageAsset | null
41
+ }
42
+
43
+ await resolveImageAsset()
44
+ watch(() => props.asset, resolveImageAsset)
36
45
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "Advanced Sanity integration for Nuxt.js.",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",