@devite/nuxt-sanity 2.10.2 → 2.11.1

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.10.2",
3
+ "version": "2.11.1",
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.10.2";
6
+ const version = "2.11.1";
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);
@@ -8,7 +8,7 @@
8
8
  :alt="imageAsset.altText as (string | undefined)"
9
9
  :placeholder="loading === 'eager' || !lqip ? undefined : imageAsset.metadata.lqip"
10
10
  :loading="loading || 'lazy'"
11
- :format="imageAsset.mimeType === 'image/svg+xml' ? undefined : 'webp'"
11
+ :format="imageAsset.mimeType === 'image/svg+xml' ? 'svg+xml' : 'webp'"
12
12
  draggable="false"
13
13
  provider="cachedSanity"
14
14
  />
@@ -0,0 +1,49 @@
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' ? 'svg+xml' : 'webp'"
12
+ legacy-format="png"
13
+ :img-attrs="{ ...imgAttrs, draggable: false }"
14
+ provider="cachedSanity"
15
+ >
16
+ <slot />
17
+ </NuxtPicture>
18
+ </template>
19
+
20
+ <script setup lang="ts">
21
+ import type { ImageAsset, Reference } from '@sanity/types'
22
+ import { ref, watch } from 'vue'
23
+ import { resolveImageAssetById } from '#imports'
24
+
25
+ const props = defineProps<{
26
+ asset?: ImageAsset | Reference | null
27
+ loading?: 'eager' | 'lazy'
28
+ lqip?: boolean
29
+ imgAttrs?: Record<string, unknown>
30
+ }>()
31
+ const imageAsset = ref<ImageAsset | null>(null)
32
+ let unwatchFunc = undefined as (() => void) | undefined
33
+
34
+ async function resolveImageAsset() {
35
+ if (props.asset?._ref) {
36
+ const assetRef = await resolveImageAssetById((props.asset as Reference)._ref, false)
37
+
38
+ imageAsset.value = assetRef.value
39
+
40
+ unwatchFunc?.()
41
+ unwatchFunc = watch(assetRef, (updatedAsset) => imageAsset.value = updatedAsset)
42
+ return
43
+ }
44
+
45
+ imageAsset.value = (props.asset || null) as ImageAsset | null
46
+ }
47
+
48
+ await resolveImageAsset()
49
+ </script>
@@ -1,2 +1,2 @@
1
- import type { ProviderGetImage } from '@nuxt/image';
2
- export declare const getImage: ProviderGetImage;
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,14 @@
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 const getImage = (src, { modifiers = {} } = {}, ctx) => {
6
- const sanityConfig = useRuntimeConfig().public.sanity;
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: joinURL(minimalClientConfig.cacheClientBaseUrl, minimalClientConfig.assetEndpoint + `?${params.toString()}`) };
8
+ return { url: cacheEndpoint + `?${params.toString()}` };
14
9
  }
15
- return getSanityImage(src, { modifiers, projectId: sanityConfig.projectId, dataset: sanityConfig.dataset }, ctx);
16
- };
10
+ return getSanityImage(src, { modifiers: {
11
+ ...modifiers,
12
+ format: modifiers.format === "svg+xml" ? "auto" : modifiers.format
13
+ }, projectId, dataset }, context);
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.10.2",
3
+ "version": "2.11.1",
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.28.4",
33
- "@sanity/core-loader": "^1.8.1",
34
- "@sanity/preview-url-secret": "^2.1.7",
35
- "@sanity/types": "^3.83.0",
36
- "@sanity/visual-editing": "^2.13.15",
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.24.0",
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.8"
59
+ "vue-tsc": "^2.2.10"
60
60
  },
61
61
  "resolutions": {
62
62
  "@devite/nuxt-sanity": "link:."