@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
package/dist/module.mjs
CHANGED
|
@@ -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
|
-
|
|
28
|
-
props.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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>
|