@devite/nuxt-sanity 2.0.1 → 2.2.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.1",
3
+ "version": "2.2.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.1";
6
+ const version = "2.2.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
 
@@ -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) {
@@ -5,6 +5,7 @@ export const IMAGE_ASSET_PROJECTION = groq`{
5
5
  url,
6
6
  altText,
7
7
  mimeType,
8
+ originalFilename,
8
9
  metadata { lqip, dimensions }
9
10
  }`;
10
11
  export const IMAGE_WITHOUT_PREVIEW_PROJECTION = groq`{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
4
4
  "description": "Advanced Sanity integration for Nuxt.js.",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",