@devite/nuxt-sanity 1.3.0 → 1.5.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.
Files changed (32) hide show
  1. package/README.md +4 -1
  2. package/dist/module.d.mts +50 -1
  3. package/dist/module.d.ts +50 -1
  4. package/dist/module.json +2 -2
  5. package/dist/runtime/components/SanityLinkExternal.vue +1 -1
  6. package/dist/runtime/components/SanityLinkInternal.vue +6 -3
  7. package/dist/runtime/components/SanityPage.vue +1 -4
  8. package/dist/runtime/components/SanityRichText.vue +2 -2
  9. package/dist/runtime/utils/projections.d.ts +1 -0
  10. package/dist/runtime/utils/projections.js +5 -0
  11. package/dist/runtime/utils/resolveImageAssetById.js +1 -1
  12. package/dist/runtime/utils/resolveInternalLink.d.ts +4 -0
  13. package/dist/runtime/utils/resolveInternalLink.js +4 -0
  14. package/dist/types.d.mts +1 -1
  15. package/dist/types.d.ts +1 -1
  16. package/package.json +12 -12
  17. package/dist/runtime/types/documents/Page.d.ts +0 -10
  18. package/dist/runtime/types/documents/Page.js +0 -0
  19. package/dist/runtime/types/objects/SEO.d.ts +0 -9
  20. package/dist/runtime/types/objects/SEO.js +0 -0
  21. package/dist/runtime/types/objects/global/GlobalSEO.d.ts +0 -5
  22. package/dist/runtime/types/objects/global/GlobalSEO.js +0 -0
  23. package/dist/runtime/types/objects/link/LinkExternal.d.ts +0 -5
  24. package/dist/runtime/types/objects/link/LinkExternal.js +0 -0
  25. package/dist/runtime/types/objects/link/LinkInternal.d.ts +0 -4
  26. package/dist/runtime/types/objects/link/LinkInternal.js +0 -0
  27. package/dist/runtime/types/richText/RichText.d.ts +0 -2
  28. package/dist/runtime/types/richText/RichText.js +0 -0
  29. package/dist/runtime/types/singletons/Home.d.ts +0 -6
  30. package/dist/runtime/types/singletons/Home.js +0 -0
  31. package/dist/runtime/types/singletons/NotFound.d.ts +0 -6
  32. package/dist/runtime/types/singletons/NotFound.js +0 -0
package/README.md CHANGED
@@ -22,11 +22,14 @@ That's it! You can now use data from Sanity in your Nuxt app ✨
22
22
 
23
23
  ```bash
24
24
  # Install dependencies
25
- pnpm install && cd playground/cms && pnpm install
25
+ pnpm install && cd playground/cms && pnpm install && cd -
26
26
 
27
27
  # Generate type stubs
28
28
  pnpm dev:prepare
29
29
 
30
+ # Generate module types and build the module
31
+ pnpm prepack
32
+
30
33
  # Develop with the playground
31
34
  pnpm dev
32
35
 
package/dist/module.d.mts CHANGED
@@ -1,5 +1,54 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { Image, Slug, PortableTextBlock } from '@sanity/types';
3
+
4
+ interface SEO {
5
+ _type: 'seo';
6
+ indexable: boolean;
7
+ title: string;
8
+ shortTitle: string;
9
+ description: string;
10
+ image?: Image;
11
+ }
12
+
13
+ interface Page {
14
+ _id: string;
15
+ _type: 'page';
16
+ title: string;
17
+ slug: Slug;
18
+ modules: Array<object>;
19
+ seo: SEO;
20
+ }
21
+
22
+ interface GlobalSEO {
23
+ siteName: string;
24
+ image: Image;
25
+ }
26
+
27
+ interface LinkExternal {
28
+ _type: 'linkExternal';
29
+ url: string;
30
+ newWindow: boolean;
31
+ }
32
+
33
+ interface LinkInternal {
34
+ _type: 'linkInternal';
35
+ slug: string;
36
+ }
37
+
38
+ type RichText = PortableTextBlock[];
39
+
40
+ interface Home {
41
+ _type: 'home';
42
+ modules: Array<object>;
43
+ seo: SEO;
44
+ }
45
+
46
+ interface NotFound {
47
+ _type: 'notFound';
48
+ modules: Array<object>;
49
+ seo: SEO;
50
+ }
2
51
 
3
52
  declare const _default: _nuxt_schema.NuxtModule<_nuxt_schema.ModuleOptions, _nuxt_schema.ModuleOptions, false>;
4
53
 
5
- export { _default as default };
54
+ export { type GlobalSEO, type Home, type LinkExternal, type LinkInternal, type NotFound, type Page, type RichText, type SEO, _default as default };
package/dist/module.d.ts CHANGED
@@ -1,5 +1,54 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { Image, Slug, PortableTextBlock } from '@sanity/types';
3
+
4
+ interface SEO {
5
+ _type: 'seo';
6
+ indexable: boolean;
7
+ title: string;
8
+ shortTitle: string;
9
+ description: string;
10
+ image?: Image;
11
+ }
12
+
13
+ interface Page {
14
+ _id: string;
15
+ _type: 'page';
16
+ title: string;
17
+ slug: Slug;
18
+ modules: Array<object>;
19
+ seo: SEO;
20
+ }
21
+
22
+ interface GlobalSEO {
23
+ siteName: string;
24
+ image: Image;
25
+ }
26
+
27
+ interface LinkExternal {
28
+ _type: 'linkExternal';
29
+ url: string;
30
+ newWindow: boolean;
31
+ }
32
+
33
+ interface LinkInternal {
34
+ _type: 'linkInternal';
35
+ slug: string;
36
+ }
37
+
38
+ type RichText = PortableTextBlock[];
39
+
40
+ interface Home {
41
+ _type: 'home';
42
+ modules: Array<object>;
43
+ seo: SEO;
44
+ }
45
+
46
+ interface NotFound {
47
+ _type: 'notFound';
48
+ modules: Array<object>;
49
+ seo: SEO;
50
+ }
2
51
 
3
52
  declare const _default: _nuxt_schema.NuxtModule<_nuxt_schema.ModuleOptions, _nuxt_schema.ModuleOptions, false>;
4
53
 
5
- export { _default as default };
54
+ export { type GlobalSEO, type Home, type LinkExternal, type LinkInternal, type NotFound, type Page, type RichText, type SEO, _default as default };
package/dist/module.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
3
  "configKey": "@devite/nuxt-sanity",
4
- "version": "1.3.0",
4
+ "version": "1.5.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
- "unbuild": "2.0.0"
7
+ "unbuild": "unknown"
8
8
  }
9
9
  }
@@ -8,7 +8,7 @@
8
8
  </template>
9
9
 
10
10
  <script setup lang="ts">
11
- import type { LinkExternal } from '../types/objects/link/LinkExternal'
11
+ import type { LinkExternal } from '@devite/nuxt-sanity'
12
12
 
13
13
  defineProps<{ data: LinkExternal }>()
14
14
  </script>
@@ -1,13 +1,16 @@
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>
7
8
  </template>
8
9
 
9
10
  <script setup lang="ts">
10
- import type { LinkInternal } from '../types/objects/link/LinkInternal'
11
+ import type { LinkInternal } from '@devite/nuxt-sanity'
12
+ import type { Ref } from '#imports'
11
13
 
12
- defineProps<{ data: LinkInternal }>()
14
+ const { data } = defineProps<{ data: LinkInternal }>()
15
+ const resolvedLink: Ref<LinkInternal | undefined> | undefined = 'reference' in data ? await resolveInternalLink(data.reference) : data
13
16
  </script>
@@ -13,10 +13,7 @@ import { useSanityQuery } from '@nuxtjs/sanity/runtime/composables/visual-editin
13
13
  import { groq } from '@nuxtjs/sanity/runtime/groq'
14
14
  import type { ComputedRef } from 'vue'
15
15
  import type { ImageAsset } from '@sanity/types'
16
- import type { Home } from '../types/singletons/Home'
17
- import type { Page } from '../types/documents/Page'
18
- import type { NotFound } from '../types/singletons/NotFound'
19
- import type { GlobalSEO } from '../types/objects/global/GlobalSEO'
16
+ import type { Home, Page, NotFound, GlobalSEO } from '@devite/nuxt-sanity'
20
17
  import { IMAGE_WITHOUT_PREVIEW_PROJECTION } from '../utils/projections'
21
18
  import { useHead, useRoute, useRuntimeConfig, useSeoMeta, computed } from '#imports'
22
19
 
@@ -7,11 +7,11 @@
7
7
 
8
8
  <script setup lang="ts">
9
9
  import { PortableText, type PortableTextComponents } from '@portabletext/vue'
10
- import type { RichText } from '../types/richText/RichText'
10
+ import type { RichText } from '@devite/nuxt-sanity'
11
11
  import { computed, h } from '#imports'
12
12
  import { SanityLinkExternal, SanityLinkInternal } from '#components'
13
13
 
14
- const { data, placeholders = {} } = defineProps<{ data: RichText, placeholders?: object }>()
14
+ const { data, placeholders = {} as object } = defineProps<{ data: RichText, placeholders?: object }>()
15
15
  const currentData = computed(() => {
16
16
  return data.map((block) => {
17
17
  return {
@@ -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,4 +1,4 @@
1
- import { useSanityQuery } from "@nuxtjs/sanity/runtime/composables";
1
+ import { useSanityQuery } from "@nuxtjs/sanity/runtime/composables/visual-editing";
2
2
  import { IMAGE_ASSET_PROJECTION } from "./projections.js";
3
3
  export const resolveImageAssetById = async (id) => {
4
4
  return (await useSanityQuery(`*[_type == "sanity.imageAsset" && _id == $assetId][0] ${IMAGE_ASSET_PROJECTION}`, { assetId: id })).data;
@@ -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/dist/types.d.mts CHANGED
@@ -4,4 +4,4 @@ import type { default as Module } from './module.js'
4
4
 
5
5
  export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
6
 
7
- export { default } from './module.js'
7
+ export { type GlobalSEO, type Home, type LinkExternal, type LinkInternal, type NotFound, type Page, type RichText, type SEO, default } from './module.js'
package/dist/types.d.ts CHANGED
@@ -4,4 +4,4 @@ import type { default as Module } from './module'
4
4
 
5
5
  export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
6
 
7
- export { default } from './module'
7
+ export { type GlobalSEO, type Home, type LinkExternal, type LinkInternal, type NotFound, type Page, type RichText, type SEO, default } from './module'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "1.3.0",
3
+ "version": "1.5.1",
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",
@@ -22,26 +22,26 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@nuxt/image": "^1.8.0",
25
+ "@nuxt/image": "^1.8.1",
26
26
  "@nuxt/kit": "^3.13.2",
27
- "@nuxtjs/sanity": "^1.12.1",
27
+ "@nuxtjs/sanity": "^1.12.2",
28
28
  "@portabletext/vue": "^1.0.11",
29
- "@sanity/client": "^6.22.0",
30
- "@sanity/types": "^3.59.0"
29
+ "@sanity/client": "^6.24.1",
30
+ "@sanity/types": "^3.66.1"
31
31
  },
32
32
  "devDependencies": {
33
- "@nuxt/devtools": "^1.5.1",
33
+ "@devite/nuxt-sanity": "link:",
34
34
  "@nuxt/eslint-config": "^0.5.7",
35
35
  "@nuxt/module-builder": "^0.8.4",
36
36
  "@nuxt/schema": "^3.13.2",
37
- "@nuxt/test-utils": "^3.14.2",
38
- "@types/node": "latest",
37
+ "@nuxt/test-utils": "^3.15.1",
38
+ "@types/node": "^22.10.1",
39
39
  "changelogen": "^0.5.7",
40
- "eslint": "^9.11.1",
40
+ "eslint": "^9.12.0",
41
41
  "nuxt": "^3.13.2",
42
- "typescript": "latest",
43
- "vitest": "^2.1.1",
44
- "vue-tsc": "^2.1.6"
42
+ "typescript": "^5.7.2",
43
+ "vitest": "^2.1.8",
44
+ "vue-tsc": "^2.1.10"
45
45
  },
46
46
  "scripts": {
47
47
  "dev": "nuxi dev playground",
@@ -1,10 +0,0 @@
1
- import type { Slug } from '@sanity/types';
2
- import type { SEO } from '../objects/SEO.js';
3
- export interface Page {
4
- _id: string;
5
- _type: 'page';
6
- title: string;
7
- slug: Slug;
8
- modules: Array<object>;
9
- seo: SEO;
10
- }
File without changes
@@ -1,9 +0,0 @@
1
- import type { Image } from '@sanity/types';
2
- export interface SEO {
3
- _type: 'seo';
4
- indexable: boolean;
5
- title: string;
6
- shortTitle: string;
7
- description: string;
8
- image?: Image;
9
- }
File without changes
@@ -1,5 +0,0 @@
1
- import type { Image } from '@sanity/types';
2
- export interface GlobalSEO {
3
- siteName: string;
4
- image: Image;
5
- }
File without changes
@@ -1,5 +0,0 @@
1
- export interface LinkExternal {
2
- _type: 'linkExternal';
3
- url: string;
4
- newWindow: boolean;
5
- }
File without changes
@@ -1,4 +0,0 @@
1
- export interface LinkInternal {
2
- _type: 'linkInternal';
3
- slug: string;
4
- }
File without changes
@@ -1,2 +0,0 @@
1
- import type { PortableTextBlock } from '@sanity/types';
2
- export type RichText = PortableTextBlock[];
File without changes
@@ -1,6 +0,0 @@
1
- import type { SEO } from '../objects/SEO.js';
2
- export interface Home {
3
- _type: 'home';
4
- modules: Array<object>;
5
- seo: SEO;
6
- }
File without changes
@@ -1,6 +0,0 @@
1
- import type { SEO } from '../objects/SEO.js';
2
- export interface NotFound {
3
- _type: 'notFound';
4
- modules: Array<object>;
5
- seo: SEO;
6
- }
File without changes