@devite/nuxt-sanity 2.10.2 → 2.11.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
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.
|
|
6
|
+
const version = "2.11.0";
|
|
7
7
|
|
|
8
8
|
const CONFIG_KEY = "sanity";
|
|
9
9
|
const module = defineNuxtModule({
|
|
@@ -193,7 +193,12 @@ const module = defineNuxtModule({
|
|
|
193
193
|
await installModule("@nuxt/image", {
|
|
194
194
|
providers: {
|
|
195
195
|
cachedSanity: {
|
|
196
|
-
provider: resolve("runtime/imageProviders/sanity")
|
|
196
|
+
provider: resolve("runtime/imageProviders/sanity"),
|
|
197
|
+
options: {
|
|
198
|
+
projectId: moduleConfig.projectId,
|
|
199
|
+
dataset: moduleConfig.dataset,
|
|
200
|
+
cacheEndpoint: typeof moduleConfig.minimalClient === "object" && moduleConfig.minimalClient.cachingEnabled && moduleConfig.minimalClient.cacheClientBaseUrl + moduleConfig.minimalClient.assetEndpoint || void 0
|
|
201
|
+
}
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
204
|
}, nuxt);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<NuxtPicture
|
|
3
|
+
v-if="imageAsset?._id"
|
|
4
|
+
densities="x1 x2"
|
|
5
|
+
:src="imageAsset._id"
|
|
6
|
+
:width="imageAsset.metadata.dimensions.width"
|
|
7
|
+
:height="imageAsset.metadata.dimensions.height"
|
|
8
|
+
:alt="imageAsset.altText as (string | undefined)"
|
|
9
|
+
:placeholder="loading === 'eager' || !lqip ? undefined : imageAsset.metadata.lqip"
|
|
10
|
+
:loading="loading || 'lazy'"
|
|
11
|
+
:format="imageAsset.mimeType === 'image/svg+xml' ? undefined : 'webp'"
|
|
12
|
+
:img-attrs="{ ...imgAttrs, draggable: false }"
|
|
13
|
+
provider="cachedSanity"
|
|
14
|
+
>
|
|
15
|
+
<slot />
|
|
16
|
+
</NuxtPicture>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup lang="ts">
|
|
20
|
+
import type { ImageAsset, Reference } from '@sanity/types'
|
|
21
|
+
import { ref, watch } from 'vue'
|
|
22
|
+
import { resolveImageAssetById } from '#imports'
|
|
23
|
+
|
|
24
|
+
const props = defineProps<{
|
|
25
|
+
asset?: ImageAsset | Reference | null
|
|
26
|
+
loading?: 'eager' | 'lazy'
|
|
27
|
+
lqip?: boolean
|
|
28
|
+
imgAttrs?: Record<string, unknown>
|
|
29
|
+
}>()
|
|
30
|
+
const imageAsset = ref<ImageAsset | null>(null)
|
|
31
|
+
let unwatchFunc = undefined as (() => void) | undefined
|
|
32
|
+
|
|
33
|
+
async function resolveImageAsset() {
|
|
34
|
+
if (props.asset?._ref) {
|
|
35
|
+
const assetRef = await resolveImageAssetById((props.asset as Reference)._ref, false)
|
|
36
|
+
|
|
37
|
+
imageAsset.value = assetRef.value
|
|
38
|
+
|
|
39
|
+
unwatchFunc?.()
|
|
40
|
+
unwatchFunc = watch(assetRef, (updatedAsset) => imageAsset.value = updatedAsset)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
imageAsset.value = (props.asset || null) as ImageAsset | null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await resolveImageAsset()
|
|
48
|
+
</script>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare
|
|
1
|
+
import type { ImageCTX, ImageOptions, ResolvedImage } from '@nuxt/image';
|
|
2
|
+
export declare function getImage(src: string, { modifiers, projectId, dataset, cacheEndpoint }: ImageOptions, context: ImageCTX): ResolvedImage;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { joinURL } from "ufo";
|
|
2
1
|
import { useSanityVisualEditingState } from "../composables/useSanityVisualEditingState.js";
|
|
3
|
-
import { useRuntimeConfig } from "#imports";
|
|
4
2
|
import { getImage as getSanityImage } from "#image/providers/sanity";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
const minimalClientConfig = sanityConfig.minimalClient;
|
|
8
|
-
const useCaching = typeof minimalClientConfig === "object" && minimalClientConfig.cachingEnabled;
|
|
9
|
-
if (useCaching && minimalClientConfig.cacheClientBaseUrl && !useSanityVisualEditingState().enabled) {
|
|
3
|
+
export function getImage(src, { modifiers = {}, projectId, dataset, cacheEndpoint }, context) {
|
|
4
|
+
if (cacheEndpoint && !(import.meta.client && useSanityVisualEditingState().enabled)) {
|
|
10
5
|
const params = new URLSearchParams();
|
|
11
6
|
params.set("src", src);
|
|
12
7
|
params.set("modifiers", JSON.stringify(modifiers));
|
|
13
|
-
return { url:
|
|
8
|
+
return { url: cacheEndpoint + `?${params.toString()}` };
|
|
14
9
|
}
|
|
15
|
-
return getSanityImage(src, { modifiers, projectId
|
|
16
|
-
}
|
|
10
|
+
return getSanityImage(src, { modifiers, projectId, dataset }, context);
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devite/nuxt-sanity",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "Advanced Sanity integration for Nuxt.js.",
|
|
5
5
|
"repository": "devite-io/nuxt-sanity",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@nuxt/image": "^1.10.0",
|
|
31
31
|
"@portabletext/vue": "^1.0.12",
|
|
32
|
-
"@sanity/client": "^6.
|
|
33
|
-
"@sanity/core-loader": "^1.8.
|
|
34
|
-
"@sanity/preview-url-secret": "^2.1.
|
|
35
|
-
"@sanity/types": "^3.
|
|
36
|
-
"@sanity/visual-editing": "^2.13.
|
|
32
|
+
"@sanity/client": "^6.29.0",
|
|
33
|
+
"@sanity/core-loader": "^1.8.5",
|
|
34
|
+
"@sanity/preview-url-secret": "^2.1.8",
|
|
35
|
+
"@sanity/types": "^3.86.0",
|
|
36
|
+
"@sanity/visual-editing": "^2.13.18",
|
|
37
37
|
"defu": "^6.1.4",
|
|
38
38
|
"ofetch": "^1.4.1",
|
|
39
39
|
"ohash": "^1.1.6",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@nuxt/test-utils": "^3.17.2",
|
|
48
48
|
"@types/node": "latest",
|
|
49
49
|
"changelogen": "^0.5.7",
|
|
50
|
-
"eslint": "^9.
|
|
50
|
+
"eslint": "^9.25.1",
|
|
51
51
|
"h3": "^1.15.1",
|
|
52
52
|
"nuxt": "^3.16.2",
|
|
53
53
|
"typescript": "5.6.3",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"vitest-environment-nuxt": "1.0.1",
|
|
57
57
|
"vue": "3.5.13",
|
|
58
58
|
"vue-router": "^4.5.0",
|
|
59
|
-
"vue-tsc": "^2.2.
|
|
59
|
+
"vue-tsc": "^2.2.10"
|
|
60
60
|
},
|
|
61
61
|
"resolutions": {
|
|
62
62
|
"@devite/nuxt-sanity": "link:."
|