@devite/nuxt-sanity 1.4.0 → 1.5.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
3
  "configKey": "@devite/nuxt-sanity",
4
- "version": "1.4.0",
4
+ "version": "1.5.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "unknown"
@@ -14,8 +14,11 @@
14
14
  </template>
15
15
 
16
16
  <script setup lang="ts">
17
- import type { ImageAsset } from '@sanity/types'
17
+ import type { ImageAsset, Reference } from '@sanity/types'
18
+ import { type Ref, resolveImageAssetById } from '#imports'
18
19
 
19
- const { asset, loading = 'lazy' } = defineProps<{ asset?: ImageAsset, loading?: 'lazy' | 'eager' }>()
20
- const imageAsset = asset?._ref ? await resolveImageAssetById(asset._ref) : asset
20
+ const { asset, loading = 'lazy' } = defineProps<{ asset?: ImageAsset | Reference, loading?: 'lazy' | 'eager' }>()
21
+ const imageAsset: Ref<ImageAsset | undefined> | ImageAsset | undefined = asset?._ref
22
+ ? await resolveImageAssetById((asset as Reference)._ref)
23
+ : asset as (ImageAsset | undefined)
21
24
  </script>
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <NuxtLink
3
- :to="data.slug"
3
+ v-if="resolvedLink"
4
+ :to="resolvedLink.slug"
4
5
  >
5
6
  <slot />
6
7
  </NuxtLink>
@@ -8,6 +9,11 @@
8
9
 
9
10
  <script setup lang="ts">
10
11
  import type { LinkInternal } from '@devite/nuxt-sanity'
12
+ import type { Reference } from '@sanity/types'
13
+ import { type Ref, resolveInternalLink } from '#imports'
11
14
 
12
- defineProps<{ data: LinkInternal }>()
15
+ const { data } = defineProps<{ data: LinkInternal | { reference: Reference } }>()
16
+ const resolvedLink: Ref<LinkInternal | undefined> | LinkInternal = 'reference' in data
17
+ ? await resolveInternalLink(data.reference)
18
+ : data as LinkInternal
13
19
  </script>
@@ -1,3 +1,4 @@
1
1
  export declare const IMAGE_ASSET_PROJECTION: any;
2
2
  export declare const IMAGE_WITHOUT_PREVIEW_PROJECTION: any;
3
3
  export declare const IMAGE_WITH_PREVIEW_PROJECTION: any;
4
+ export declare const LINK_PROJECTION: any;
@@ -15,3 +15,8 @@ export const IMAGE_WITH_PREVIEW_PROJECTION = groq`{
15
15
  _type,
16
16
  asset-> ${IMAGE_ASSET_PROJECTION}
17
17
  }`;
18
+ export const LINK_PROJECTION = groq`{
19
+ '_type': @._type,
20
+ _type == 'linkExternal' => { url, newWindow },
21
+ _type == 'linkInternal' => { 'slug': coalesce(@.reference->slug.current, '/') }
22
+ }`;
@@ -1,3 +1,3 @@
1
1
  import type { ImageAsset } from '@sanity/types';
2
2
  import type { Ref } from '#imports';
3
- export declare const resolveImageAssetById: (id: string) => Promise<Ref<ImageAsset | null>>;
3
+ export declare const resolveImageAssetById: (id: string) => Promise<Ref<ImageAsset | undefined>>;
@@ -0,0 +1,4 @@
1
+ import type { Reference } from '@sanity/types';
2
+ import type { LinkInternal } from '@devite/nuxt-sanity';
3
+ import type { Ref } from '#imports';
4
+ export declare const resolveInternalLink: (reference: Reference) => Promise<Ref<LinkInternal | undefined>>;
@@ -0,0 +1,4 @@
1
+ import { useSanityQuery } from "@nuxtjs/sanity/runtime/composables/visual-editing";
2
+ export const resolveInternalLink = async (reference) => {
3
+ return (await useSanityQuery(`*[_id == $documentId][0] { '_type': 'linkInternal', 'slug': coalesce(slug.current, '/') }`, { documentId: reference._ref })).data;
4
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "1.4.0",
3
+ "version": "1.5.2",
4
4
  "description": "Provides additional helper components and utilities for the Nuxt.js Sanity module",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",
@@ -26,23 +26,22 @@
26
26
  "@nuxt/kit": "^3.13.2",
27
27
  "@nuxtjs/sanity": "^1.12.2",
28
28
  "@portabletext/vue": "^1.0.11",
29
- "@sanity/client": "^6.22.1",
30
- "@sanity/types": "^3.60.0"
29
+ "@sanity/client": "^6.24.1",
30
+ "@sanity/types": "^3.66.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@devite/nuxt-sanity": "link:",
34
- "@nuxt/devtools": "^1.6.0",
35
34
  "@nuxt/eslint-config": "^0.5.7",
36
35
  "@nuxt/module-builder": "^0.8.4",
37
36
  "@nuxt/schema": "^3.13.2",
38
- "@nuxt/test-utils": "^3.14.3",
39
- "@types/node": "latest",
37
+ "@nuxt/test-utils": "^3.15.1",
38
+ "@types/node": "^22.10.1",
40
39
  "changelogen": "^0.5.7",
41
40
  "eslint": "^9.12.0",
42
41
  "nuxt": "^3.13.2",
43
- "typescript": "latest",
44
- "vitest": "^2.1.2",
45
- "vue-tsc": "^2.1.6"
42
+ "typescript": "^5.7.2",
43
+ "vitest": "^2.1.8",
44
+ "vue-tsc": "^2.1.10"
46
45
  },
47
46
  "scripts": {
48
47
  "dev": "nuxi dev playground",