@devite/nuxt-sanity 2.0.0 → 2.1.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "configKey": "sanity",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
package/dist/module.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import crypto from 'node:crypto';
2
- import { defineNuxtModule, createResolver, addPlugin, addServerHandler, addImportsDir, addComponentsDir } from '@nuxt/kit';
2
+ import { defineNuxtModule, createResolver, addPlugin, addServerHandler, addImportsDir, addImports, addComponentsDir } from '@nuxt/kit';
3
3
  import defu from 'defu';
4
4
 
5
5
  const name = "@devite/nuxt-sanity";
6
- const version = "2.0.0";
6
+ const version = "2.1.0";
7
7
 
8
8
  const module = defineNuxtModule({
9
9
  meta: {
@@ -22,6 +22,7 @@ const module = defineNuxtModule({
22
22
  apiVersion: options.apiVersion || "2024-08-08",
23
23
  visualEditing: options.visualEditing || null
24
24
  });
25
+ nuxt.options.build.transpile.push("@sanity/core-loader");
25
26
  if (options.visualEditing) {
26
27
  const previewMode = moduleConfig.visualEditing.previewMode !== false;
27
28
  const visualEditingConfig = defu(moduleConfig.visualEditing, {
@@ -42,14 +43,8 @@ const module = defineNuxtModule({
42
43
  console.warn("Visual editing requires a studio URL");
43
44
  if (visualEditingConfig.mode === "live-visual-editing" && !visualEditingConfig.stega)
44
45
  console.warn('Visual Editing requires "stega" to be enabled in "live-visual-editing" mode');
45
- nuxt.options.build.transpile.push(
46
- "async-cache-dedupe",
47
- "@sanity/core-loader",
48
- "@sanity/preview-url-secret"
49
- );
50
- nuxt.options.vite.resolve = defu(nuxt.options.vite.resolve, {
51
- dedupe: ["@sanity/client"]
52
- });
46
+ nuxt.options.build.transpile.push("@sanity/preview-url-secret", "async-cache-dedupe");
47
+ nuxt.options.vite.resolve = defu(nuxt.options.vite.resolve, { dedupe: ["@sanity/client"] });
53
48
  nuxt.options.vite.optimizeDeps = defu(nuxt.options.vite.optimizeDeps, {
54
49
  include: [
55
50
  `${name} > @sanity/visual-editing > @sanity/mutate > lodash/groupBy.js`,
@@ -92,17 +87,41 @@ const module = defineNuxtModule({
92
87
  /* Visual Editing */
93
88
  token: options.token || "",
94
89
  withCredentials: options.withCredentials || false,
95
- stega: moduleConfig.visualEditing && moduleConfig.visualEditing.stega !== false && moduleConfig.visualEditing.previewMode !== false && { enabled: true, studioUrl: moduleConfig.visualEditing.studioUrl } || {},
90
+ stega: moduleConfig.visualEditing && moduleConfig.visualEditing.stega !== false && moduleConfig.visualEditing.previewMode !== false && {
91
+ enabled: true,
92
+ studioUrl: moduleConfig.visualEditing.studioUrl
93
+ } || {},
96
94
  visualEditing: moduleConfig.visualEditing
97
95
  });
98
96
  addImportsDir(resolve("runtime/client"));
99
- addImportsDir(resolve("runtime/composables"));
100
- addImportsDir(resolve("runtime/utils/groq"));
101
- addImportsDir(resolve("runtime/utils/projections"));
102
- addImportsDir(resolve("runtime/utils/resolveImageAssetById"));
103
- addImportsDir(resolve("runtime/utils/resolveInternalLink"));
97
+ addImports(
98
+ [
99
+ // composables
100
+ { name: "useSanityQuery", from: resolve("runtime/composables/useSanityQuery") },
101
+ { name: "useLazySanityQuery", from: resolve("runtime/composables/useLazySanityQuery") },
102
+ // helper methods
103
+ { name: "groq", from: resolve("runtime/utils/groq") },
104
+ { name: "resolveImageAssetById", from: resolve("runtime/utils/resolveImageAssetById") },
105
+ { name: "resolveInternalLink", from: resolve("runtime/utils/resolveInternalLink") },
106
+ // projections
107
+ ...[
108
+ "IMAGE_ASSET_PROJECTION",
109
+ "IMAGE_WITHOUT_PREVIEW_PROJECTION",
110
+ "IMAGE_WITH_PREVIEW_PROJECTION",
111
+ "LINK_PROJECTION"
112
+ ].map((field) => ({
113
+ name: field,
114
+ from: resolve("runtime/utils/projections")
115
+ }))
116
+ ]
117
+ );
104
118
  await addComponentsDir({ path: resolve("runtime/components") });
105
- await addComponentsDir({ path: "~/sanity", global: true, prefix: "Sanity" });
119
+ await addComponentsDir({
120
+ path: "~/sanity",
121
+ global: true,
122
+ prefix: "Sanity",
123
+ pathPrefix: false
124
+ });
106
125
  }
107
126
  });
108
127
 
@@ -1,4 +1,4 @@
1
- import { type ClientPerspective, type FilteredResponseQueryOptions, type QueryParams, type SanityClient as SanityClientType } from '@sanity/client';
1
+ import { type ClientPerspective, type QueryParams, type SanityClient as SanityClientType } from '@sanity/client';
2
2
  import type { ModuleOptions } from '@devite/nuxt-sanity';
3
3
  import { type QueryStore } from '@sanity/core-loader';
4
4
  import SanityClient from './SanityClient.js';
@@ -8,7 +8,7 @@ declare class DefaultSanityClient extends SanityClient {
8
8
  constructor(config: ModuleOptions);
9
9
  fetch<T = unknown>(query: string, params: QueryParams, options?: {
10
10
  perspective?: ClientPerspective;
11
- } & FilteredResponseQueryOptions): Promise<T>;
11
+ }): Promise<T>;
12
12
  createQueryStore(tag?: string): void;
13
13
  clone(): DefaultSanityClient;
14
14
  }
@@ -1,4 +1,4 @@
1
- import type { ClientPerspective, FilteredResponseQueryOptions, QueryParams } from '@sanity/client';
1
+ import type { ClientPerspective, QueryParams } from '@sanity/client';
2
2
  import type { ModuleOptions } from '@devite/nuxt-sanity';
3
3
  import SanityClient from './SanityClient.js';
4
4
  declare class MinimalSanityClient extends SanityClient {
@@ -9,7 +9,7 @@ declare class MinimalSanityClient extends SanityClient {
9
9
  private toQueryString;
10
10
  fetch<T>(query: string, params: QueryParams, _options?: {
11
11
  perspective?: ClientPerspective;
12
- } & FilteredResponseQueryOptions): Promise<T>;
12
+ }): Promise<T>;
13
13
  clone(): MinimalSanityClient;
14
14
  }
15
15
  export default MinimalSanityClient;
@@ -1,4 +1,4 @@
1
- import type { ClientPerspective, ContentSourceMap, FilteredResponseQueryOptions, QueryParams } from '@sanity/client';
1
+ import type { ClientPerspective, ContentSourceMap, QueryParams } from '@sanity/client';
2
2
  import type { ModuleOptions } from '@devite/nuxt-sanity';
3
3
  export default abstract class SanityClient {
4
4
  config: ModuleOptions;
@@ -6,5 +6,5 @@ export default abstract class SanityClient {
6
6
  protected constructor(config: ModuleOptions);
7
7
  abstract fetch<T = unknown>(query: string, params: QueryParams, options?: {
8
8
  perspective?: ClientPerspective;
9
- } & FilteredResponseQueryOptions): Promise<T>;
9
+ }): Promise<T>;
10
10
  }
@@ -8,12 +8,12 @@ export const useSanityQuery = (query, _params = {}, _options = {}, lazy = false)
8
8
  const client = clientType ? useSanityClient(clientType) : useSanityClient();
9
9
  const hasQueryStore = "queryStore" in client && client.queryStore !== null;
10
10
  const perspective = _perspective || (hasQueryStore ? "previewDrafts" : "published");
11
- const key = "sanity-" + hash(query + (_params ? JSON.stringify(_params) : ""));
12
11
  const reactiveParams = _params ? reactive(_params) : void 0;
13
12
  if (reactiveParams) {
14
13
  options.watch ||= [];
15
14
  options.watch.push(reactiveParams);
16
15
  }
16
+ const key = "sanity-" + hash(query + (reactiveParams ? JSON.stringify(reactiveParams) : ""));
17
17
  const data = ref(null);
18
18
  const sourceMap = ref(null);
19
19
  const encodeDataAttribute = ref(() => {
@@ -31,7 +31,7 @@ export const useSanityQuery = (query, _params = {}, _options = {}, lazy = false)
31
31
  if (hasQueryStore) {
32
32
  let setupFetcher = function(cb) {
33
33
  unsubscribe();
34
- const deepClonedParams = JSON.parse(JSON.stringify(_params));
34
+ const deepClonedParams = _params ? JSON.parse(JSON.stringify(_params)) : void 0;
35
35
  const fetcher = defaultClient.queryStore.createFetcherStore(query, deepClonedParams, void 0);
36
36
  unsubscribe = fetcher.subscribe((newSnapshot) => {
37
37
  if (newSnapshot.data) {
@@ -1,4 +1,4 @@
1
1
  import type { ModuleOptions } from '@devite/nuxt-sanity';
2
- import type SanityClient from '~/src/runtime/client/SanityClient';
2
+ import type SanityClient from '../client/SanityClient.js';
3
3
  export type SanityClientType = 'minimal' | 'default';
4
4
  export default function getOrCreateSanityClient(visualEditing: boolean, config: ModuleOptions, type?: SanityClientType): SanityClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Advanced Sanity integration for Nuxt.js.",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",
@@ -26,27 +26,28 @@
26
26
  "@nuxt/kit": "^3.14.1592",
27
27
  "@portabletext/vue": "^1.0.11",
28
28
  "@sanity/client": "^6.24.1",
29
- "@sanity/core-loader": "^1.7.19",
29
+ "@sanity/core-loader": "^1.7.21",
30
30
  "@sanity/preview-url-secret": "^2.0.5",
31
- "@sanity/types": "^3.66.1",
32
- "@sanity/visual-editing": "^2.10.5",
31
+ "@sanity/types": "^3.68.3",
32
+ "@sanity/visual-editing": "^2.11.0",
33
33
  "defu": "^6.1.4",
34
34
  "ofetch": "^1.4.1",
35
35
  "ohash": "^1.1.4"
36
36
  },
37
37
  "devDependencies": {
38
- "@nuxt/eslint-config": "^0.7.2",
38
+ "@nuxt/eslint-config": "^0.7.4",
39
39
  "@nuxt/module-builder": "^0.8.4",
40
40
  "@nuxt/schema": "^3.14.1592",
41
41
  "@nuxt/test-utils": "^3.15.1",
42
42
  "@types/node": "latest",
43
43
  "changelogen": "^0.5.7",
44
- "eslint": "^9.16.0",
44
+ "eslint": "^9.17.0",
45
45
  "h3": "^1.13.0",
46
46
  "nuxt": "^3.14.1592",
47
- "prettier": "^3.4.2",
48
47
  "typescript": "~5.6.3",
49
48
  "vitest": "^2.1.8",
49
+ "vitest-environment-nuxt": "1.0.1",
50
+ "vue": "3.5.13",
50
51
  "vue-router": "^4.5.0",
51
52
  "vue-tsc": "^2.1.10"
52
53
  },