@devite/nuxt-sanity 2.3.1 → 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.1",
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.1";
6
+ const version = "2.3.2";
7
7
 
8
8
  const module = defineNuxtModule({
9
9
  meta: {
@@ -16,22 +16,30 @@
16
16
 
17
17
  <script setup lang="ts">
18
18
  import type { ImageAsset, Reference } from '@sanity/types'
19
+ import { ref, watch } from 'vue'
19
20
  import { resolveImageAssetById } from '../utils/resolveImageAssetById'
20
- import { useLazyAsyncData, useAsyncData, useId } from '#imports'
21
21
 
22
22
  const props = defineProps<{
23
23
  asset?: ImageAsset | Reference | null
24
24
  loading?: 'eager' | 'lazy'
25
25
  }>()
26
+ const imageAsset = ref<ImageAsset | null>(null)
27
+ let unwatchFunc = undefined as (() => void) | undefined
26
28
 
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
- )
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)
37
45
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.3.1",
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",