@devite/nuxt-sanity 2.2.1 → 2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
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.2.1";
6
+ const version = "2.3.0";
7
7
 
8
8
  const module = defineNuxtModule({
9
9
  meta: {
@@ -15,14 +15,22 @@
15
15
 
16
16
  <script setup lang="ts">
17
17
  import type { ImageAsset, Reference } from '@sanity/types'
18
- import type { Ref } from 'vue'
19
18
  import { resolveImageAssetById } from '../utils/resolveImageAssetById'
19
+ import { useLazyAsyncData, useAsyncData, useId } from '#imports'
20
20
 
21
- const { asset, loading = 'lazy' } = defineProps<{
22
- asset?: ImageAsset | Reference
21
+ const props = defineProps<{
22
+ asset?: ImageAsset | Reference | null
23
23
  loading?: 'eager' | 'lazy'
24
24
  }>()
25
- const imageAsset: Ref<ImageAsset | null> | ImageAsset | undefined = asset?._ref
26
- ? await resolveImageAssetById((asset as Reference)._ref)
27
- : (asset as ImageAsset | undefined)
25
+
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
+ )
28
36
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "Advanced Sanity integration for Nuxt.js.",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",