next-sanity 7.0.16 → 7.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/index.cjs +1 -1
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +1 -1
- package/dist/visual-editing/VisualEditing.cjs +2 -0
- package/dist/visual-editing/VisualEditing.cjs.map +1 -0
- package/dist/visual-editing/VisualEditing.js +2 -0
- package/dist/visual-editing/VisualEditing.js.map +1 -0
- package/dist/visual-editing/index.cjs +2 -0
- package/dist/visual-editing/index.cjs.map +1 -0
- package/dist/visual-editing/index.js +2 -0
- package/dist/visual-editing/index.js.map +1 -0
- package/package.json +11 -11
- package/src/index.ts +2 -0
- package/src/visual-editing/VisualEditing.tsx +68 -0
- package/src/visual-editing/index.tsx +16 -0
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./client.cjs"),t=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./client.cjs"),t=require("./visual-editing/index.cjs"),r=require("groq"),n=require("@sanity/client");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=i(r);exports.createClient=e.createClient,exports.VisualEditing=t.VisualEditing,Object.defineProperty(exports,"groq",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(exports,"unstable__adapter",{enumerable:!0,get:function(){return n.unstable__adapter}}),Object.defineProperty(exports,"unstable__environment",{enumerable:!0,get:function(){return n.unstable__environment}});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import cjs from './index.cjs';
|
|
2
2
|
|
|
3
3
|
export const createClient = cjs.createClient;
|
|
4
|
+
export const VisualEditing = cjs.VisualEditing;
|
|
4
5
|
export const groq = cjs.groq;
|
|
5
6
|
export const unstable__adapter = cjs.unstable__adapter;
|
|
6
7
|
export const unstable__environment = cjs.unstable__environment;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
|
|
1
3
|
import {createClient as createClient_2} from '@sanity/preview-kit/client'
|
|
2
4
|
import {default as groq} from 'groq'
|
|
3
5
|
import {PreviewKitClientConfig} from '@sanity/preview-kit/client'
|
|
4
6
|
import {unstable__adapter} from '@sanity/client'
|
|
5
7
|
import {unstable__environment} from '@sanity/client'
|
|
8
|
+
import {VisualEditingOptions} from '@sanity/visual-editing'
|
|
6
9
|
|
|
7
10
|
/** @public */
|
|
8
11
|
export declare interface ClientConfig
|
|
@@ -37,6 +40,21 @@ export {unstable__adapter}
|
|
|
37
40
|
|
|
38
41
|
export {unstable__environment}
|
|
39
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export declare function VisualEditing(props: VisualEditingProps): React.ReactElement
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export declare interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated The histoy adapter is already implemented
|
|
54
|
+
*/
|
|
55
|
+
history?: never
|
|
56
|
+
}
|
|
57
|
+
|
|
40
58
|
export * from '@sanity/preview-kit/client'
|
|
41
59
|
|
|
42
60
|
export {}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{createClient}from"./client.js";export{default as groq}from"groq";export{unstable__adapter,unstable__environment}from"@sanity/client";
|
|
1
|
+
export{createClient}from"./client.js";export{VisualEditing}from"./visual-editing/index.js";export{default as groq}from"groq";export{unstable__adapter,unstable__environment}from"@sanity/client";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";"use strict";var e=require("@sanity/visual-editing"),t=require("next/navigation.js"),r=require("react");module.exports=function(u){const{zIndex:n}=u,c=t.useRouter(),s=r.useRef(c),[a,i]=r.useState();r.useEffect((()=>{s.current=c}),[c]),r.useEffect((()=>{const t=e.enableVisualEditing({zIndex:n,history:{subscribe:e=>(i((()=>e)),()=>i(void 0)),update:e=>{switch(e.type){case"push":return s.current.push(e.url);case"pop":return s.current.back();case"replace":return s.current.replace(e.url);default:throw new Error("Unknown update type: ".concat(e.type))}}}});return()=>t()}),[n]);const o=t.usePathname(),l=t.useSearchParams();return r.useEffect((()=>{a&&a({type:"push",url:"".concat(o).concat((null==l?void 0:l.size)?"?".concat(l):"")})}),[a,o,l]),null};
|
|
2
|
+
//# sourceMappingURL=VisualEditing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VisualEditing.cjs","sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["'use client'\n\nimport {\n enableVisualEditing,\n type HistoryAdapterNavigate,\n type VisualEditingOptions,\n} from '@sanity/visual-editing'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {useEffect, useRef, useState} from 'react'\n\n/**\n * @public\n */\nexport interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {\n /**\n * @deprecated The histoy adapter is already implemented\n */\n history?: never\n}\n\nexport default function VisualEditing(props: VisualEditingProps): null {\n const {zIndex} = props\n\n const router = useRouter()\n const routerRef = useRef(router)\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\n\n useEffect(() => {\n routerRef.current = router\n }, [router])\n useEffect(() => {\n const disable = enableVisualEditing({\n zIndex,\n history: {\n subscribe: (_navigate) => {\n setNavigate(() => _navigate)\n return () => setNavigate(undefined)\n },\n update: (update) => {\n switch (update.type) {\n case 'push':\n return routerRef.current.push(update.url)\n case 'pop':\n return routerRef.current.back()\n case 'replace':\n return routerRef.current.replace(update.url)\n default:\n throw new Error(`Unknown update type: ${update.type}`)\n }\n },\n },\n })\n return () => disable()\n }, [zIndex])\n\n const pathname = usePathname()\n const searchParams = useSearchParams()\n useEffect(() => {\n if (navigate) {\n navigate({\n type: 'push',\n url: `${pathname}${searchParams?.size ? `?${searchParams}` : ''}`,\n })\n }\n }, [navigate, pathname, searchParams])\n\n return null\n}\n"],"names":["props","zIndex","router","useRouter","routerRef","useRef","navigate","setNavigate","useState","useEffect","current","disable","enableVisualEditing","history","subscribe","_navigate","update","type","push","url","back","replace","Error","concat","pathname","usePathname","searchParams","useSearchParams","size"],"mappings":"oIAoBA,SAAsCA,GAC9B,MAAAC,OAACA,GAAUD,EAEXE,EAASC,EAAAA,YACTC,EAAYC,SAAOH,IAClBI,EAAUC,GAAeC,EAA6CA,WAE7EC,EAAAA,WAAU,KACRL,EAAUM,QAAUR,CAAA,GACnB,CAACA,IACJO,EAAAA,WAAU,KACR,MAAME,EAAUC,EAAAA,oBAAoB,CAClCX,SACAY,QAAS,CACPC,UAAYC,IACVR,GAAY,IAAMQ,IACX,IAAMR,OAAY,IAE3BS,OAASA,IACP,OAAQA,EAAOC,MACb,IAAK,OACH,OAAOb,EAAUM,QAAQQ,KAAKF,EAAOG,KACvC,IAAK,MACI,OAAAf,EAAUM,QAAQU,OAC3B,IAAK,UACH,OAAOhB,EAAUM,QAAQW,QAAQL,EAAOG,KAC1C,QACE,MAAM,IAAIG,MAAM,wBAAwBC,OAAAP,EAAOC,OACnD,KAIN,MAAO,IAAMN,GAAQ,GACpB,CAACV,IAEJ,MAAMuB,EAAWC,EAAAA,cACXC,EAAeC,EAAAA,kBAUd,OATPlB,EAAAA,WAAU,KACJH,GACOA,EAAA,CACPW,KAAM,OACNE,IAAK,GAAGI,OAAAC,GAAWD,QAAc,MAAAG,OAAA,EAAAA,EAAAE,MAAO,IAAIL,OAAiBG,GAAA,KAEjE,GACC,CAACpB,EAAUkB,EAAUE,IAEjB,IACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";import{enableVisualEditing as t}from"@sanity/visual-editing";import{useRouter as r,usePathname as e,useSearchParams as n}from"next/navigation.js";import{useRef as c,useState as u,useEffect as o}from"react";function a(a){const{zIndex:s}=a,i=r(),p=c(i),[l,d]=u();o((()=>{p.current=i}),[i]),o((()=>{const r=t({zIndex:s,history:{subscribe:t=>(d((()=>t)),()=>d(void 0)),update:t=>{switch(t.type){case"push":return p.current.push(t.url);case"pop":return p.current.back();case"replace":return p.current.replace(t.url);default:throw new Error("Unknown update type: ".concat(t.type))}}}});return()=>r()}),[s]);const f=e(),h=n();return o((()=>{l&&l({type:"push",url:"".concat(f).concat((null==h?void 0:h.size)?"?".concat(h):"")})}),[l,f,h]),null}export{a as default};
|
|
2
|
+
//# sourceMappingURL=VisualEditing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VisualEditing.js","sources":["../../src/visual-editing/VisualEditing.tsx"],"sourcesContent":["'use client'\n\nimport {\n enableVisualEditing,\n type HistoryAdapterNavigate,\n type VisualEditingOptions,\n} from '@sanity/visual-editing'\nimport {usePathname, useRouter, useSearchParams} from 'next/navigation.js'\nimport {useEffect, useRef, useState} from 'react'\n\n/**\n * @public\n */\nexport interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {\n /**\n * @deprecated The histoy adapter is already implemented\n */\n history?: never\n}\n\nexport default function VisualEditing(props: VisualEditingProps): null {\n const {zIndex} = props\n\n const router = useRouter()\n const routerRef = useRef(router)\n const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()\n\n useEffect(() => {\n routerRef.current = router\n }, [router])\n useEffect(() => {\n const disable = enableVisualEditing({\n zIndex,\n history: {\n subscribe: (_navigate) => {\n setNavigate(() => _navigate)\n return () => setNavigate(undefined)\n },\n update: (update) => {\n switch (update.type) {\n case 'push':\n return routerRef.current.push(update.url)\n case 'pop':\n return routerRef.current.back()\n case 'replace':\n return routerRef.current.replace(update.url)\n default:\n throw new Error(`Unknown update type: ${update.type}`)\n }\n },\n },\n })\n return () => disable()\n }, [zIndex])\n\n const pathname = usePathname()\n const searchParams = useSearchParams()\n useEffect(() => {\n if (navigate) {\n navigate({\n type: 'push',\n url: `${pathname}${searchParams?.size ? `?${searchParams}` : ''}`,\n })\n }\n }, [navigate, pathname, searchParams])\n\n return null\n}\n"],"names":["VisualEditing","props","zIndex","router","useRouter","routerRef","useRef","navigate","setNavigate","useState","useEffect","current","disable","enableVisualEditing","history","subscribe","_navigate","update","type","push","url","back","replace","Error","concat","pathname","usePathname","searchParams","useSearchParams","size"],"mappings":"2NAoBA,SAAwBA,EAAcC,GAC9B,MAAAC,OAACA,GAAUD,EAEXE,EAASC,IACTC,EAAYC,EAAOH,IAClBI,EAAUC,GAAeC,IAEhCC,GAAU,KACRL,EAAUM,QAAUR,CAAA,GACnB,CAACA,IACJO,GAAU,KACR,MAAME,EAAUC,EAAoB,CAClCX,SACAY,QAAS,CACPC,UAAYC,IACVR,GAAY,IAAMQ,IACX,IAAMR,OAAY,IAE3BS,OAASA,IACP,OAAQA,EAAOC,MACb,IAAK,OACH,OAAOb,EAAUM,QAAQQ,KAAKF,EAAOG,KACvC,IAAK,MACI,OAAAf,EAAUM,QAAQU,OAC3B,IAAK,UACH,OAAOhB,EAAUM,QAAQW,QAAQL,EAAOG,KAC1C,QACE,MAAM,IAAIG,MAAM,wBAAwBC,OAAAP,EAAOC,OACnD,KAIN,MAAO,IAAMN,GAAQ,GACpB,CAACV,IAEJ,MAAMuB,EAAWC,IACXC,EAAeC,IAUd,OATPlB,GAAU,KACJH,GACOA,EAAA,CACPW,KAAM,OACNE,IAAK,GAAGI,OAAAC,GAAWD,QAAc,MAAAG,OAAA,EAAAA,EAAAE,MAAO,IAAIL,OAAiBG,GAAA,KAEjE,GACC,CAACpB,EAAUkB,EAAUE,IAEjB,IACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react");function t(e){return Object.freeze({__proto__:null,default:e})}const n=r.lazy((()=>Promise.resolve().then((function(){return t(require("./VisualEditing.cjs"))}))));exports.VisualEditing=function(t){return e.jsx(r.Suspense,{fallback:null,children:e.jsx(n,{...t})})};
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/visual-editing/index.tsx"],"sourcesContent":["import {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingComponent = lazy(() => import('./VisualEditing'))\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n return (\n <Suspense fallback={null}>\n <VisualEditingComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["VisualEditingComponent","lazy","Promise","resolve","then","_interopNamespaceDefaultOnly","require","props","jsx","Suspense","fallback","children"],"mappings":"yLAIA,MAAMA,EAAyBC,EAAAA,MAAK,IAAMC,QAAOC,UAAAC,MAAA,WAAA,OAAAC,EAAAC,QAAA,uBAAkB,4BAK5D,SAAuBC,GAE1B,OAAAC,MAACC,EAAAA,UAASC,SAAU,KAClBC,eAACX,EAAwB,IAAGO,KAGlC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/visual-editing/index.tsx"],"sourcesContent":["import {lazy, Suspense} from 'react'\n\nimport type {VisualEditingProps} from './VisualEditing'\n\nconst VisualEditingComponent = lazy(() => import('./VisualEditing'))\n\n/**\n * @public\n */\nexport function VisualEditing(props: VisualEditingProps): React.ReactElement {\n return (\n <Suspense fallback={null}>\n <VisualEditingComponent {...props} />\n </Suspense>\n )\n}\n"],"names":["VisualEditingComponent","lazy","import","VisualEditing","props","jsx","Suspense","fallback","children"],"mappings":"mFAIA,MAAMA,EAAyBC,GAAK,IAAMC,OAAO,wBAK1C,SAASC,EAAcC,GAE1B,OAAAC,EAACC,GAASC,SAAU,KAClBC,WAACR,EAAwB,IAAGI,KAGlC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-sanity",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Sanity.io toolkit for Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -175,7 +175,8 @@
|
|
|
175
175
|
},
|
|
176
176
|
"dependencies": {
|
|
177
177
|
"@sanity/client": "^6.12.3",
|
|
178
|
-
"@sanity/preview-kit": "5.0.
|
|
178
|
+
"@sanity/preview-kit": "5.0.19",
|
|
179
|
+
"@sanity/visual-editing": "1.0.1",
|
|
179
180
|
"@sanity/webhook": "4.0.0",
|
|
180
181
|
"groq": "^3.19"
|
|
181
182
|
},
|
|
@@ -186,13 +187,12 @@
|
|
|
186
187
|
"@sanity/browserslist-config": "^1.0.0",
|
|
187
188
|
"@sanity/eslint-config-studio": "^3.0.1",
|
|
188
189
|
"@sanity/image-url": "^1.0.2",
|
|
189
|
-
"@sanity/
|
|
190
|
-
"@sanity/pkg-utils": "^4.1.1",
|
|
190
|
+
"@sanity/pkg-utils": "^4.1.3",
|
|
191
191
|
"@sanity/ui": "^2.0.1",
|
|
192
|
-
"@sanity/vision": "3.
|
|
193
|
-
"@types/react": "^18.2.
|
|
192
|
+
"@sanity/vision": "3.27.1",
|
|
193
|
+
"@types/react": "^18.2.55",
|
|
194
194
|
"@types/react-dom": "^18.2.18",
|
|
195
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
195
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
196
196
|
"@vitest/coverage-v8": "^1.2.2",
|
|
197
197
|
"autoprefixer": "^10.4.17",
|
|
198
198
|
"eslint": "^8.56.0",
|
|
@@ -204,15 +204,15 @@
|
|
|
204
204
|
"groqd": "^0.15.10",
|
|
205
205
|
"ls-engines": "^0.9.1",
|
|
206
206
|
"next": "14.1.0",
|
|
207
|
-
"postcss": "^8.4.
|
|
208
|
-
"prettier": "^3.2.
|
|
209
|
-
"prettier-plugin-packagejson": "^2.4.
|
|
207
|
+
"postcss": "^8.4.34",
|
|
208
|
+
"prettier": "^3.2.5",
|
|
209
|
+
"prettier-plugin-packagejson": "^2.4.10",
|
|
210
210
|
"prettier-plugin-tailwindcss": "^0.5.11",
|
|
211
211
|
"react": "^18.2.0",
|
|
212
212
|
"react-dom": "^18.2.0",
|
|
213
213
|
"react-is": "^18.2.0",
|
|
214
214
|
"rollup": "^4.9.6",
|
|
215
|
-
"sanity": "3.
|
|
215
|
+
"sanity": "3.27.1",
|
|
216
216
|
"server-only": "^0.0.1",
|
|
217
217
|
"styled-components": "^6.1.8",
|
|
218
218
|
"suspend-react": "^0.1.3",
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
enableVisualEditing,
|
|
5
|
+
type HistoryAdapterNavigate,
|
|
6
|
+
type VisualEditingOptions,
|
|
7
|
+
} from '@sanity/visual-editing'
|
|
8
|
+
import {usePathname, useRouter, useSearchParams} from 'next/navigation.js'
|
|
9
|
+
import {useEffect, useRef, useState} from 'react'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface VisualEditingProps extends Omit<VisualEditingOptions, 'history'> {
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated The histoy adapter is already implemented
|
|
17
|
+
*/
|
|
18
|
+
history?: never
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function VisualEditing(props: VisualEditingProps): null {
|
|
22
|
+
const {zIndex} = props
|
|
23
|
+
|
|
24
|
+
const router = useRouter()
|
|
25
|
+
const routerRef = useRef(router)
|
|
26
|
+
const [navigate, setNavigate] = useState<HistoryAdapterNavigate | undefined>()
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
routerRef.current = router
|
|
30
|
+
}, [router])
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const disable = enableVisualEditing({
|
|
33
|
+
zIndex,
|
|
34
|
+
history: {
|
|
35
|
+
subscribe: (_navigate) => {
|
|
36
|
+
setNavigate(() => _navigate)
|
|
37
|
+
return () => setNavigate(undefined)
|
|
38
|
+
},
|
|
39
|
+
update: (update) => {
|
|
40
|
+
switch (update.type) {
|
|
41
|
+
case 'push':
|
|
42
|
+
return routerRef.current.push(update.url)
|
|
43
|
+
case 'pop':
|
|
44
|
+
return routerRef.current.back()
|
|
45
|
+
case 'replace':
|
|
46
|
+
return routerRef.current.replace(update.url)
|
|
47
|
+
default:
|
|
48
|
+
throw new Error(`Unknown update type: ${update.type}`)
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
return () => disable()
|
|
54
|
+
}, [zIndex])
|
|
55
|
+
|
|
56
|
+
const pathname = usePathname()
|
|
57
|
+
const searchParams = useSearchParams()
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (navigate) {
|
|
60
|
+
navigate({
|
|
61
|
+
type: 'push',
|
|
62
|
+
url: `${pathname}${searchParams?.size ? `?${searchParams}` : ''}`,
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
}, [navigate, pathname, searchParams])
|
|
66
|
+
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {lazy, Suspense} from 'react'
|
|
2
|
+
|
|
3
|
+
import type {VisualEditingProps} from './VisualEditing'
|
|
4
|
+
|
|
5
|
+
const VisualEditingComponent = lazy(() => import('./VisualEditing'))
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export function VisualEditing(props: VisualEditingProps): React.ReactElement {
|
|
11
|
+
return (
|
|
12
|
+
<Suspense fallback={null}>
|
|
13
|
+
<VisualEditingComponent {...props} />
|
|
14
|
+
</Suspense>
|
|
15
|
+
)
|
|
16
|
+
}
|