@devite/nuxt-sanity 2.5.1 → 2.5.3

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/README.md CHANGED
@@ -14,6 +14,29 @@ npx nuxi module add @devite/nuxt-sanity
14
14
 
15
15
  That's it! You can now use Sanity with your Nuxt app ✨
16
16
 
17
+ ## Configuration
18
+
19
+ Further configuration can be done in the `nuxt.config.ts` file:
20
+
21
+ ```ts
22
+ export default {
23
+ modules: [
24
+ '@devite/nuxt-sanity',
25
+ "@nuxt/image"
26
+ ],
27
+ sanity: {
28
+ projectId: 'YOUR_PROJECT_ID',
29
+ dataset: 'YOUR_DATASET',
30
+ ...
31
+ },
32
+ runtimeConfig: {
33
+ public: {
34
+ // Required for SanityPage component to set a correct "canonical" url
35
+ baseUrl: "https://www.example.com"
36
+ }
37
+ }
38
+ };
39
+ ```
17
40
 
18
41
  ## Contribution
19
42
 
@@ -49,8 +72,10 @@ That's it! You can now use Sanity with your Nuxt app ✨
49
72
  </details>
50
73
 
51
74
  <!-- Links -->
75
+
52
76
  [nuxt-sanity]: https://github.com/nuxt-modules/sanity
53
77
 
54
78
  <!-- Badges -->
79
+
55
80
  [npm-version-src]: https://img.shields.io/npm/v/@devite/nuxt-sanity/latest.svg?style=flat&colorA=020420&colorB=00DC82
56
81
  [npm-version-href]: https://npmjs.com/package/@devite/nuxt-sanity
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
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.5.1";
6
+ const version = "2.5.3";
7
7
 
8
8
  const CONFIG_KEY = "sanity";
9
9
  const module = defineNuxtModule({
@@ -31,11 +31,11 @@ if (sanityData.value?._type === 'notFound' && import.meta.server) {
31
31
  setResponseStatus(event, 404)
32
32
  }
33
33
 
34
- const { baseURL } = useRuntimeConfig().public
34
+ const { baseURL: baseUrl } = useRuntimeConfig().public
35
35
  const seo = computed(() => sanityData.value?.seo)
36
36
  const url = computed(
37
37
  () =>
38
- ((baseURL as string) || '')
38
+ ((baseUrl as string) || '')
39
39
  + ((sanityData.value && ('slug' in sanityData.value ? sanityData.value.slug.current : null)) || '/'),
40
40
  )
41
41
 
@@ -1,11 +1,6 @@
1
1
  import { useSanityVisualEditingState } from "../composables/useSanityVisualEditingState.js";
2
- import { useSanityLiveMode } from "../composables/useSanityLiveMode.js";
3
- import { useSanityVisualEditing } from "../composables/useSanityVisualEditing.js";
4
- import {
5
- defineNuxtPlugin,
6
- useCookie,
7
- useRuntimeConfig
8
- } from "#imports";
2
+ import useSanityClient from "../utils/useSanityClient.js";
3
+ import { defineNuxtPlugin, useCookie, useRuntimeConfig } from "#imports";
9
4
  export default defineNuxtPlugin(async () => {
10
5
  const visualEditingState = useSanityVisualEditingState();
11
6
  const $config = useRuntimeConfig();
@@ -20,11 +15,14 @@ export default defineNuxtPlugin(async () => {
20
15
  switch (visualEditing?.mode) {
21
16
  case "live-visual-editing":
22
17
  case "visual-editing":
23
- useSanityVisualEditing({
18
+ import("../utils/visualEditing/enableVisualEditing.js").then(({ enableVisualEditing }) => enableVisualEditing({
24
19
  refresh: visualEditing?.refresh,
25
20
  zIndex: visualEditing?.zIndex
26
- });
27
- if (visualEditing?.mode === "live-visual-editing") await useSanityLiveMode();
21
+ }));
22
+ if (visualEditing?.mode === "live-visual-editing") {
23
+ const client = await useSanityClient(true, "default", $config.public.sanity);
24
+ client.queryStore?.enableLiveMode({ client: client.client });
25
+ }
28
26
  break;
29
27
  }
30
28
  }
@@ -19,5 +19,5 @@ export const IMAGE_WITH_PREVIEW_PROJECTION = groq`{
19
19
  export const LINK_PROJECTION = groq`{
20
20
  '_type': @._type,
21
21
  _type == 'linkExternal' => { url, newWindow },
22
- _type == 'linkInternal' => { 'slug': coalesce(@.reference->slug.current, '/') }
22
+ _type == 'linkInternal' => { 'slug': '/' + coalesce(@.reference->slug.current, '') }
23
23
  }`;
@@ -1,7 +1,7 @@
1
1
  import { useSanityQuery } from "#imports";
2
2
  export const resolveInternalLink = async (reference) => {
3
3
  return (await useSanityQuery(
4
- `*[_id == $documentId][0] { '_type': 'linkInternal', 'slug': coalesce(slug.current, '/') }`,
4
+ `*[_id == $documentId][0] { '_type': 'linkInternal', 'slug': '/' + coalesce(slug.current, '') }`,
5
5
  { documentId: reference._ref }
6
6
  )).data;
7
7
  };
@@ -5,4 +5,4 @@ export interface VisualEditingProps {
5
5
  zIndex?: VisualEditingOptions['zIndex'];
6
6
  }
7
7
  /** @return A function to disable visual editing */
8
- export declare const useSanityVisualEditing: (options?: VisualEditingProps) => DisableVisualEditing;
8
+ export declare function enableVisualEditing(options?: VisualEditingProps): DisableVisualEditing;
@@ -1,13 +1,12 @@
1
- import { enableVisualEditing } from "@sanity/visual-editing";
2
- import { onScopeDispose } from "vue";
1
+ import { enableVisualEditing as enableSanityVisualEditing } from "@sanity/visual-editing";
3
2
  import { reloadNuxtApp, useRouter } from "#imports";
4
- export const useSanityVisualEditing = (options = {}) => {
3
+ export function enableVisualEditing(options = {}) {
5
4
  const { refresh, zIndex } = options;
6
5
  let disable = () => {
7
6
  };
8
7
  if (import.meta.client) {
9
8
  const router = useRouter();
10
- disable = enableVisualEditing({
9
+ disable = enableSanityVisualEditing({
11
10
  zIndex,
12
11
  refresh: (payload) => {
13
12
  function refreshDefault() {
@@ -39,6 +38,5 @@ export const useSanityVisualEditing = (options = {}) => {
39
38
  }
40
39
  });
41
40
  }
42
- onScopeDispose(disable);
43
41
  return disable;
44
- };
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "Advanced Sanity integration for Nuxt.js.",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",
@@ -1 +0,0 @@
1
- export declare const useSanityLiveMode: () => Promise<() => void>;
@@ -1,12 +0,0 @@
1
- import useSanityClient from "../utils/useSanityClient.js";
2
- import { useRuntimeConfig } from "#imports";
3
- export const useSanityLiveMode = async () => {
4
- if (import.meta.client) {
5
- const client = await useSanityClient(true, "default", useRuntimeConfig().public.sanity);
6
- if (client.queryStore) {
7
- return client.queryStore.enableLiveMode({ client: client.client });
8
- }
9
- }
10
- return () => {
11
- };
12
- };