next-sanity 1.0.2 → 1.0.4
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.d.ts +15 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/studio.d.ts +50 -13
- package/dist/studio.esm.js.map +1 -1
- package/dist/studio.js.map +1 -1
- package/package.json +8 -8
- package/src/aborter.ts +2 -0
- package/src/client.ts +1 -0
- package/src/currentUser.ts +2 -0
- package/src/index.ts +2 -12
- package/src/studio/NextStudio.tsx +26 -13
- package/src/studio/NextStudioGlobalStyle.ts +2 -0
- package/src/studio/NextStudioHead.tsx +2 -0
- package/src/studio/NextStudioNoScript.tsx +1 -0
- package/src/studio/ServerStyleSheetDocument.tsx +5 -1
- package/src/studio/utils.ts +15 -0
- package/src/types.ts +5 -0
- package/src/useSubscription.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {ClientConfig} from '@sanity/client'
|
|
2
2
|
import type {Config} from '@sanity/groq-store/dist/typings/types'
|
|
3
3
|
import {default as groq} from 'groq'
|
|
4
|
-
import
|
|
4
|
+
import {SanityClient} from '@sanity/client'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
declare interface Aborter_2 {
|
|
6
|
+
/** @public */
|
|
7
|
+
export declare interface Aborter {
|
|
9
8
|
abort(): void
|
|
10
9
|
signal: AbortSignal
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
export
|
|
12
|
+
export {ClientConfig}
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
/** @public */
|
|
15
|
+
export declare function createClient(config: ClientConfig): SanityClient
|
|
16
16
|
|
|
17
|
+
/** @public */
|
|
17
18
|
export declare function createCurrentUserHook({
|
|
18
19
|
projectId,
|
|
19
20
|
}: {
|
|
@@ -25,6 +26,7 @@ export declare function createCurrentUserHook({
|
|
|
25
26
|
loading: boolean
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
/** @public */
|
|
28
30
|
export declare function createPreviewSubscriptionHook({
|
|
29
31
|
projectId,
|
|
30
32
|
dataset,
|
|
@@ -42,6 +44,7 @@ export declare function createPreviewSubscriptionHook({
|
|
|
42
44
|
error: Error | undefined
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
/** @public */
|
|
45
48
|
export declare interface CurrentUser {
|
|
46
49
|
id: string
|
|
47
50
|
name: string
|
|
@@ -50,10 +53,13 @@ export declare interface CurrentUser {
|
|
|
50
53
|
|
|
51
54
|
export {groq}
|
|
52
55
|
|
|
56
|
+
/** @public */
|
|
53
57
|
export declare type GroqStoreEventSource = Config['EventSource']
|
|
54
58
|
|
|
59
|
+
/** @public */
|
|
55
60
|
export declare type Params = Record<string, unknown>
|
|
56
61
|
|
|
62
|
+
/** @public */
|
|
57
63
|
export declare interface ProjectConfig {
|
|
58
64
|
projectId: string
|
|
59
65
|
dataset: string
|
|
@@ -62,8 +68,9 @@ export declare interface ProjectConfig {
|
|
|
62
68
|
EventSource?: GroqStoreEventSource
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
export
|
|
71
|
+
export {SanityClient}
|
|
66
72
|
|
|
73
|
+
/** @public */
|
|
67
74
|
export declare interface SubscriptionOptions<R = any> {
|
|
68
75
|
enabled?: boolean
|
|
69
76
|
params?: Params
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/client.ts","../src/aborter.ts","../src/currentUser.ts","../src/useSubscription.ts"],"sourcesContent":["import type {ClientConfig, SanityClient} from '@sanity/client'\nimport sanityClient from '@sanity/client'\n\nexport function createClient(config: ClientConfig): SanityClient {\n return sanityClient(config)\n}\n","export interface Aborter {\n abort(): void\n signal: AbortSignal\n}\n\nclass MockAbortController {\n _signal = {aborted: false}\n get signal() {\n return this._signal as AbortSignal\n }\n abort() {\n this._signal.aborted = true\n }\n}\n\nexport function getAborter(): Aborter {\n return typeof AbortController === 'undefined'\n ? new MockAbortController()\n : new AbortController()\n}\n","import {useEffect, useState} from 'react'\n\nimport {Aborter, getAborter} from './aborter'\nimport {CurrentUser} from './types'\n\nexport function createCurrentUserHook({projectId}: {projectId: string; dataset?: string}) {\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n return () => useCurrentUser(projectId)\n}\n\nexport function getCurrentUser(\n projectId: string,\n abort: Aborter,\n token?: string\n): Promise<CurrentUser | null> {\n const headers = token ? {Authorization: `Bearer ${token}`} : undefined\n return fetch(`https://${projectId}.api.sanity.io/v1/users/me`, {\n credentials: 'include',\n signal: abort.signal,\n headers,\n })\n .then((res) => res.json())\n .then((res) => (res?.id ? res : null))\n}\n\nfunction useCurrentUser(projectId: string) {\n const [data, setUser] = useState<CurrentUser | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n const aborter = getAborter()\n getCurrentUser(projectId, aborter)\n .then(setUser)\n .catch((err: Error) => err.name !== 'AbortError' && setError(err))\n\n return () => {\n aborter.abort()\n }\n }, [projectId])\n\n return {data, error, loading: data !== null || !error}\n}\n","import {GroqStore, Subscription} from '@sanity/groq-store'\nimport {useEffect, useMemo, useState} from 'react'\n\nimport {Aborter, getAborter} from './aborter'\nimport {getCurrentUser} from './currentUser'\nimport {Params, ProjectConfig, SubscriptionOptions} from './types'\n\nconst EMPTY_PARAMS = {}\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function createPreviewSubscriptionHook({\n projectId,\n dataset,\n token,\n EventSource,\n documentLimit = 3000,\n}: ProjectConfig & {documentLimit?: number}) {\n // Only construct/setup the store when `getStore()` is called\n let store: Promise<GroqStore>\n\n return function usePreviewSubscription<R = any>(\n query: string,\n options: SubscriptionOptions<R> = {}\n ) {\n const {params = EMPTY_PARAMS, initialData, enabled} = options\n return useQuerySubscription<R>({\n getStore,\n projectId,\n query,\n params,\n initialData: initialData as any,\n enabled: enabled ? typeof window !== 'undefined' : false,\n token,\n })\n }\n\n function getStore(abort: Aborter) {\n if (!store) {\n store = import('@sanity/groq-store').then(({groqStore}) => {\n // Skip creating the groq store if we've been unmounted to save memory and reduce gc pressure\n if (abort.signal.aborted) {\n const error = new Error('Cancelling groq store creation')\n // This ensures we can skip it in the catch block same way\n error.name = 'AbortError'\n return Promise.reject(error)\n }\n\n return groqStore({\n projectId,\n dataset,\n documentLimit,\n token,\n EventSource,\n listen: true,\n overlayDrafts: true,\n subscriptionThrottleMs: 10,\n })\n })\n }\n return store\n }\n}\n\nfunction useQuerySubscription<R = any>(options: {\n getStore: (abort: Aborter) => Promise<GroqStore>\n projectId: string\n query: string\n params: Params\n initialData: R\n enabled: boolean\n token?: string\n}) {\n const {getStore, projectId, query, initialData, enabled = false, token} = options\n const [error, setError] = useState<Error>()\n const [loading, setLoading] = useState(false)\n const [data, setData] = useState<R>()\n const params = useParams(options.params)\n\n // Use \"deep\" dependency comparison because params are often not _referentially_ equal,\n // but contains the same shallow properties, eg `{\"slug\": \"some-slug\"}`\n useEffect(() => {\n if (!enabled) {\n return\n }\n\n setLoading(true)\n\n const aborter = getAborter()\n let subscription: Subscription | undefined\n getCurrentUser(projectId, aborter, token)\n .then((user) => {\n if (user) {\n return\n }\n\n // eslint-disable-next-line no-console\n console.warn('Not authenticated - preview not available')\n throw new Error('Not authenticated - preview not available')\n })\n .then(() => getStore(aborter))\n .then((store) => {\n subscription = store.subscribe(query, params, (err, result) => {\n if (err) {\n setError(err)\n } else {\n setData(result)\n }\n })\n })\n .catch((err: Error) => (err.name === 'AbortError' ? null : setError(err)))\n .finally(() => setLoading(false))\n\n // eslint-disable-next-line consistent-return\n return () => {\n if (subscription) {\n subscription.unsubscribe()\n }\n\n aborter.abort()\n }\n }, [getStore, query, params, enabled, projectId, token])\n\n return {\n data: typeof data === 'undefined' ? initialData : data,\n loading,\n error,\n }\n}\n\n// Return params that are stable with deep equal as long as the key order is the same\nexport function useParams(params: Params): Params {\n const stringifiedParams = useMemo(() => JSON.stringify(params), [params])\n return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams])\n}\n"],"names":["createClient","config","sanityClient","MockAbortController","constructor","_signal","aborted","signal","abort","getAborter","AbortController","createCurrentUserHook","projectId","useCurrentUser","getCurrentUser","token","headers","Authorization","fetch","credentials","then","res","json","id","data","setUser","useState","error","setError","useEffect","aborter","catch","err","name","loading","EMPTY_PARAMS","createPreviewSubscriptionHook","dataset","EventSource","documentLimit","store","usePreviewSubscription","query","options","params","initialData","enabled","useQuerySubscription","getStore","window","groqStore","Error","Promise","reject","listen","overlayDrafts","subscriptionThrottleMs","setLoading","setData","useParams","subscription","user","console","warn","subscribe","result","finally","unsubscribe","stringifiedParams","useMemo","JSON","stringify","parse"],"mappings":";;;AAGO,SAASA,aAAaC,MAAoC,EAAA;EAC/D,OAAOC,aAAaD,MAAM,CAAA;AAC5B;ACAA,MAAME,mBAAoB,CAAA;EAA1BC,WAAA,GAAA;IACY,IAAA,CAAAC,OAAA,GAAA;MAACC,SAAS;IAAK,CAAA;EAAA;EACzB,IAAIC,MAAS,GAAA;IACX,OAAO,IAAK,CAAAF,OAAA;EACd;EACAG,KAAQ,GAAA;IACN,IAAA,CAAKH,QAAQC,OAAU,GAAA,IAAA;EACzB;AACF;AAEO,SAASG,UAAsB,GAAA;EACpC,OAAO,OAAOC,eAAoB,KAAA,WAAA,GAC9B,IAAIP,mBAAoB,EAAA,GACxB,IAAIO,eAAgB,EAAA;AAC1B;ACdgB,SAAAC,qBAAA,OAA0E;EAAA,IAApD;IAACC;GAAmD;EAEjF,OAAA,MAAMC,eAAeD,SAAS,CAAA;AACvC;AAEgB,SAAAE,cAAA,CACdF,SACA,EAAAJ,KAAA,EACAO,KAC6B,EAAA;EAC7B,MAAMC,UAAUD,KAAQ,GAAA;IAACE,aAAe,mBAAUF;GAAW,GAAA,KAAA,CAAA;EACtD,OAAAG,KAAA,mBAAiBN,SAAuC,iCAAA;IAC7DO,WAAa,EAAA,SAAA;IACbZ,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AAA,CAAKC,UAAU3B,MAAM,CAAA,EAAG,CAACA,MAAM,CAAC,CAAA;EACjE,OAAAyB,OAAA,CAAQ,MAAMC,IAAK,CAAAE,KAAA,CAAMJ,iBAAiB,CAAG,EAAA,CAACA,iBAAiB,CAAC,CAAA;AACzE;"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/client.ts","../src/aborter.ts","../src/currentUser.ts","../src/useSubscription.ts"],"sourcesContent":["import type {ClientConfig, SanityClient} from '@sanity/client'\nimport sanityClient from '@sanity/client'\n\n/** @public */\nexport function createClient(config: ClientConfig): SanityClient {\n return sanityClient(config)\n}\n","/** @public */\nexport interface Aborter {\n abort(): void\n signal: AbortSignal\n}\n\nclass MockAbortController {\n _signal = {aborted: false}\n get signal() {\n return this._signal as AbortSignal\n }\n abort() {\n this._signal.aborted = true\n }\n}\n\n/** @internal */\nexport function getAborter(): Aborter {\n return typeof AbortController === 'undefined'\n ? new MockAbortController()\n : new AbortController()\n}\n","import {useEffect, useState} from 'react'\n\nimport {Aborter, getAborter} from './aborter'\nimport {CurrentUser} from './types'\n\n/** @public */\nexport function createCurrentUserHook({projectId}: {projectId: string; dataset?: string}) {\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n return () => useCurrentUser(projectId)\n}\n\n/** @internal */\nexport function getCurrentUser(\n projectId: string,\n abort: Aborter,\n token?: string\n): Promise<CurrentUser | null> {\n const headers = token ? {Authorization: `Bearer ${token}`} : undefined\n return fetch(`https://${projectId}.api.sanity.io/v1/users/me`, {\n credentials: 'include',\n signal: abort.signal,\n headers,\n })\n .then((res) => res.json())\n .then((res) => (res?.id ? res : null))\n}\n\nfunction useCurrentUser(projectId: string) {\n const [data, setUser] = useState<CurrentUser | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n const aborter = getAborter()\n getCurrentUser(projectId, aborter)\n .then(setUser)\n .catch((err: Error) => err.name !== 'AbortError' && setError(err))\n\n return () => {\n aborter.abort()\n }\n }, [projectId])\n\n return {data, error, loading: data !== null || !error}\n}\n","import {GroqStore, Subscription} from '@sanity/groq-store'\nimport {useEffect, useMemo, useState} from 'react'\n\nimport {Aborter, getAborter} from './aborter'\nimport {getCurrentUser} from './currentUser'\nimport {Params, ProjectConfig, SubscriptionOptions} from './types'\n\nconst EMPTY_PARAMS = {}\n\n/** @public */\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function createPreviewSubscriptionHook({\n projectId,\n dataset,\n token,\n EventSource,\n documentLimit = 3000,\n}: ProjectConfig & {documentLimit?: number}) {\n // Only construct/setup the store when `getStore()` is called\n let store: Promise<GroqStore>\n\n return function usePreviewSubscription<R = any>(\n query: string,\n options: SubscriptionOptions<R> = {}\n ) {\n const {params = EMPTY_PARAMS, initialData, enabled} = options\n return useQuerySubscription<R>({\n getStore,\n projectId,\n query,\n params,\n initialData: initialData as any,\n enabled: enabled ? typeof window !== 'undefined' : false,\n token,\n })\n }\n\n function getStore(abort: Aborter) {\n if (!store) {\n store = import('@sanity/groq-store').then(({groqStore}) => {\n // Skip creating the groq store if we've been unmounted to save memory and reduce gc pressure\n if (abort.signal.aborted) {\n const error = new Error('Cancelling groq store creation')\n // This ensures we can skip it in the catch block same way\n error.name = 'AbortError'\n return Promise.reject(error)\n }\n\n return groqStore({\n projectId,\n dataset,\n documentLimit,\n token,\n EventSource,\n listen: true,\n overlayDrafts: true,\n subscriptionThrottleMs: 10,\n })\n })\n }\n return store\n }\n}\n\nfunction useQuerySubscription<R = any>(options: {\n getStore: (abort: Aborter) => Promise<GroqStore>\n projectId: string\n query: string\n params: Params\n initialData: R\n enabled: boolean\n token?: string\n}) {\n const {getStore, projectId, query, initialData, enabled = false, token} = options\n const [error, setError] = useState<Error>()\n const [loading, setLoading] = useState(false)\n const [data, setData] = useState<R>()\n const params = useParams(options.params)\n\n // Use \"deep\" dependency comparison because params are often not _referentially_ equal,\n // but contains the same shallow properties, eg `{\"slug\": \"some-slug\"}`\n useEffect(() => {\n if (!enabled) {\n return\n }\n\n setLoading(true)\n\n const aborter = getAborter()\n let subscription: Subscription | undefined\n getCurrentUser(projectId, aborter, token)\n .then((user) => {\n if (user) {\n return\n }\n\n // eslint-disable-next-line no-console\n console.warn('Not authenticated - preview not available')\n throw new Error('Not authenticated - preview not available')\n })\n .then(() => getStore(aborter))\n .then((store) => {\n subscription = store.subscribe(query, params, (err, result) => {\n if (err) {\n setError(err)\n } else {\n setData(result)\n }\n })\n })\n .catch((err: Error) => (err.name === 'AbortError' ? null : setError(err)))\n .finally(() => setLoading(false))\n\n // eslint-disable-next-line consistent-return\n return () => {\n if (subscription) {\n subscription.unsubscribe()\n }\n\n aborter.abort()\n }\n }, [getStore, query, params, enabled, projectId, token])\n\n return {\n data: typeof data === 'undefined' ? initialData : data,\n loading,\n error,\n }\n}\n\n// Return params that are stable with deep equal as long as the key order is the same\nexport function useParams(params: Params): Params {\n const stringifiedParams = useMemo(() => JSON.stringify(params), [params])\n return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams])\n}\n"],"names":["createClient","config","sanityClient","MockAbortController","constructor","_signal","aborted","signal","abort","getAborter","AbortController","createCurrentUserHook","projectId","useCurrentUser","getCurrentUser","token","headers","Authorization","fetch","credentials","then","res","json","id","data","setUser","useState","error","setError","useEffect","aborter","catch","err","name","loading","EMPTY_PARAMS","createPreviewSubscriptionHook","dataset","EventSource","documentLimit","store","usePreviewSubscription","query","options","params","initialData","enabled","useQuerySubscription","getStore","window","groqStore","Error","Promise","reject","listen","overlayDrafts","subscriptionThrottleMs","setLoading","setData","useParams","subscription","user","console","warn","subscribe","result","finally","unsubscribe","stringifiedParams","useMemo","JSON","stringify","parse"],"mappings":";;;AAIO,SAASA,aAAaC,MAAoC,EAAA;EAC/D,OAAOC,aAAaD,MAAM,CAAA;AAC5B;ACAA,MAAME,mBAAoB,CAAA;EAA1BC,WAAA,GAAA;IACY,IAAA,CAAAC,OAAA,GAAA;MAACC,SAAS;IAAK,CAAA;EAAA;EACzB,IAAIC,MAAS,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BA,IAAIC,IAAS,KAAA,YAAA,GAAe,IAAO,GAAAL,QAAA,CAASI,GAAG,CAAE,CAAA,CACxEkC,QAAQ,MAAMT,UAAA,CAAW,KAAK,CAAC,CAAA;IAGlC,OAAO,MAAM;MACX,IAAIG,YAAc,EAAA;QAChBA,YAAA,CAAaO,WAAY,EAAA;MAC3B;MAEArC,OAAA,CAAQtB,KAAM,EAAA;IAAA,CAChB;EAAA,CACF,EAAG,CAACwC,QAAU,EAAAN,KAAA,EAAOE,QAAQE,OAAS,EAAAlC,SAAA,EAAWG,KAAK,CAAC,CAAA;EAEhD,OAAA;IACLS,IAAM,EAAA,OAAOA,IAAS,KAAA,WAAA,GAAcqB,WAAc,GAAArB,IAAA;IAClDU,OAAA;IACAP;EAAA,CACF;AACF;AAGO,SAASgC,UAAUf,MAAwB,EAAA;EAC1C,MAAAwB,iBAAA,GAAoBC,QAAQ,MAAMC,IAAA,CAAKC,UAAU3B,MAAM,CAAA,EAAG,CAACA,MAAM,CAAC,CAAA;EACjE,OAAAyB,OAAA,CAAQ,MAAMC,IAAK,CAAAE,KAAA,CAAMJ,iBAAiB,CAAG,EAAA,CAACA,iBAAiB,CAAC,CAAA;AACzE;"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/client.ts","../src/aborter.ts","../src/currentUser.ts","../src/useSubscription.ts"],"sourcesContent":["import type {ClientConfig, SanityClient} from '@sanity/client'\nimport sanityClient from '@sanity/client'\n\nexport function createClient(config: ClientConfig): SanityClient {\n return sanityClient(config)\n}\n","export interface Aborter {\n abort(): void\n signal: AbortSignal\n}\n\nclass MockAbortController {\n _signal = {aborted: false}\n get signal() {\n return this._signal as AbortSignal\n }\n abort() {\n this._signal.aborted = true\n }\n}\n\nexport function getAborter(): Aborter {\n return typeof AbortController === 'undefined'\n ? new MockAbortController()\n : new AbortController()\n}\n","import {useEffect, useState} from 'react'\n\nimport {Aborter, getAborter} from './aborter'\nimport {CurrentUser} from './types'\n\nexport function createCurrentUserHook({projectId}: {projectId: string; dataset?: string}) {\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n return () => useCurrentUser(projectId)\n}\n\nexport function getCurrentUser(\n projectId: string,\n abort: Aborter,\n token?: string\n): Promise<CurrentUser | null> {\n const headers = token ? {Authorization: `Bearer ${token}`} : undefined\n return fetch(`https://${projectId}.api.sanity.io/v1/users/me`, {\n credentials: 'include',\n signal: abort.signal,\n headers,\n })\n .then((res) => res.json())\n .then((res) => (res?.id ? res : null))\n}\n\nfunction useCurrentUser(projectId: string) {\n const [data, setUser] = useState<CurrentUser | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n const aborter = getAborter()\n getCurrentUser(projectId, aborter)\n .then(setUser)\n .catch((err: Error) => err.name !== 'AbortError' && setError(err))\n\n return () => {\n aborter.abort()\n }\n }, [projectId])\n\n return {data, error, loading: data !== null || !error}\n}\n","import {GroqStore, Subscription} from '@sanity/groq-store'\nimport {useEffect, useMemo, useState} from 'react'\n\nimport {Aborter, getAborter} from './aborter'\nimport {getCurrentUser} from './currentUser'\nimport {Params, ProjectConfig, SubscriptionOptions} from './types'\n\nconst EMPTY_PARAMS = {}\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function createPreviewSubscriptionHook({\n projectId,\n dataset,\n token,\n EventSource,\n documentLimit = 3000,\n}: ProjectConfig & {documentLimit?: number}) {\n // Only construct/setup the store when `getStore()` is called\n let store: Promise<GroqStore>\n\n return function usePreviewSubscription<R = any>(\n query: string,\n options: SubscriptionOptions<R> = {}\n ) {\n const {params = EMPTY_PARAMS, initialData, enabled} = options\n return useQuerySubscription<R>({\n getStore,\n projectId,\n query,\n params,\n initialData: initialData as any,\n enabled: enabled ? typeof window !== 'undefined' : false,\n token,\n })\n }\n\n function getStore(abort: Aborter) {\n if (!store) {\n store = import('@sanity/groq-store').then(({groqStore}) => {\n // Skip creating the groq store if we've been unmounted to save memory and reduce gc pressure\n if (abort.signal.aborted) {\n const error = new Error('Cancelling groq store creation')\n // This ensures we can skip it in the catch block same way\n error.name = 'AbortError'\n return Promise.reject(error)\n }\n\n return groqStore({\n projectId,\n dataset,\n documentLimit,\n token,\n EventSource,\n listen: true,\n overlayDrafts: true,\n subscriptionThrottleMs: 10,\n })\n })\n }\n return store\n }\n}\n\nfunction useQuerySubscription<R = any>(options: {\n getStore: (abort: Aborter) => Promise<GroqStore>\n projectId: string\n query: string\n params: Params\n initialData: R\n enabled: boolean\n token?: string\n}) {\n const {getStore, projectId, query, initialData, enabled = false, token} = options\n const [error, setError] = useState<Error>()\n const [loading, setLoading] = useState(false)\n const [data, setData] = useState<R>()\n const params = useParams(options.params)\n\n // Use \"deep\" dependency comparison because params are often not _referentially_ equal,\n // but contains the same shallow properties, eg `{\"slug\": \"some-slug\"}`\n useEffect(() => {\n if (!enabled) {\n return\n }\n\n setLoading(true)\n\n const aborter = getAborter()\n let subscription: Subscription | undefined\n getCurrentUser(projectId, aborter, token)\n .then((user) => {\n if (user) {\n return\n }\n\n // eslint-disable-next-line no-console\n console.warn('Not authenticated - preview not available')\n throw new Error('Not authenticated - preview not available')\n })\n .then(() => getStore(aborter))\n .then((store) => {\n subscription = store.subscribe(query, params, (err, result) => {\n if (err) {\n setError(err)\n } else {\n setData(result)\n }\n })\n })\n .catch((err: Error) => (err.name === 'AbortError' ? null : setError(err)))\n .finally(() => setLoading(false))\n\n // eslint-disable-next-line consistent-return\n return () => {\n if (subscription) {\n subscription.unsubscribe()\n }\n\n aborter.abort()\n }\n }, [getStore, query, params, enabled, projectId, token])\n\n return {\n data: typeof data === 'undefined' ? initialData : data,\n loading,\n error,\n }\n}\n\n// Return params that are stable with deep equal as long as the key order is the same\nexport function useParams(params: Params): Params {\n const stringifiedParams = useMemo(() => JSON.stringify(params), [params])\n return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams])\n}\n"],"names":["createClient","config","sanityClient","MockAbortController","constructor","_signal","aborted","signal","abort","getAborter","AbortController","createCurrentUserHook","projectId","useCurrentUser","getCurrentUser","token","headers","Authorization","fetch","credentials","then","res","json","id","data","setUser","useState","error","setError","useEffect","aborter","catch","err","name","loading","EMPTY_PARAMS","createPreviewSubscriptionHook","dataset","EventSource","documentLimit","store","usePreviewSubscription","query","options","params","initialData","enabled","useQuerySubscription","getStore","window","Promise","resolve","_interopNamespace","require","groqStore","Error","reject","listen","overlayDrafts","subscriptionThrottleMs","setLoading","setData","useParams","subscription","user","console","warn","subscribe","result","finally","unsubscribe","stringifiedParams","useMemo","JSON","stringify","parse"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGO,SAASA,aAAaC,MAAoC,EAAA;EAC/D,OAAOC,qBAAAA,CAAAA,SAAAA,EAAaD,MAAM,CAAA;AAC5B;ACAA,MAAME,mBAAoB,CAAA;EAA1BC,WAAA,GAAA;IACY,IAAA,CAAAC,OAAA,GAAA;MAACC,SAAS;IAAK,CAAA;EAAA;EACzB,IAAIC,MAAS,GAAA;IACX,OAAO,IAAK,CAAAF,OAAA;EACd;EACAG,KAAQ,GAAA;IACN,IAAA,CAAKH,QAAQC,OAAU,GAAA,IAAA;EACzB;AACF;AAEO,SAASG,UAAsB,GAAA;EACpC,OAAO,OAAOC,eAAoB,KAAA,WAAA,GAC9B,IAAIP,mBAAoB,EAAA,GACxB,IAAIO,eAAgB,EAAA;AAC1B;ACdgB,SAAAC,qBAAA,OAA0E;EAAA,IAApD;IAACC;GAAmD;EAEjF,OAAA,MAAMC,eAAeD,SAAS,CAAA;AACvC;AAEgB,SAAAE,cAAA,CACdF,SACA,EAAAJ,KAAA,EACAO,KAC6B,EAAA;EAC7B,MAAMC,UAAUD,KAAQ,GAAA;IAACE,aAAe,mBAAUF;GAAW,GAAA,KAAA,CAAA;EACtD,OAAAG,KAAA,mBAAiBN,SAAuC,iCAAA;IAC7DO,WAAa,EAAA,SAAA;IACbZ,QAAQC,KAAM,CAAAD,MAAA;IACdS;EAAA,CACD,CA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AA,GAAcqB,WAAc,GAAArB,IAAA;IAClDU,OAAA;IACAP;EAAA,CACF;AACF;AAGO,SAASmC,UAAUlB,MAAwB,EAAA;EAC1C,MAAA2B,iBAAA,GAAoBC,cAAQ,MAAMC,IAAA,CAAKC,UAAU9B,MAAM,CAAA,EAAG,CAACA,MAAM,CAAC,CAAA;EACjE,OAAA4B,KAAAA,CAAAA,OAAA,CAAQ,MAAMC,IAAK,CAAAE,KAAA,CAAMJ,iBAAiB,CAAG,EAAA,CAACA,iBAAiB,CAAC,CAAA;AACzE;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/client.ts","../src/aborter.ts","../src/currentUser.ts","../src/useSubscription.ts"],"sourcesContent":["import type {ClientConfig, SanityClient} from '@sanity/client'\nimport sanityClient from '@sanity/client'\n\n/** @public */\nexport function createClient(config: ClientConfig): SanityClient {\n return sanityClient(config)\n}\n","/** @public */\nexport interface Aborter {\n abort(): void\n signal: AbortSignal\n}\n\nclass MockAbortController {\n _signal = {aborted: false}\n get signal() {\n return this._signal as AbortSignal\n }\n abort() {\n this._signal.aborted = true\n }\n}\n\n/** @internal */\nexport function getAborter(): Aborter {\n return typeof AbortController === 'undefined'\n ? new MockAbortController()\n : new AbortController()\n}\n","import {useEffect, useState} from 'react'\n\nimport {Aborter, getAborter} from './aborter'\nimport {CurrentUser} from './types'\n\n/** @public */\nexport function createCurrentUserHook({projectId}: {projectId: string; dataset?: string}) {\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n return () => useCurrentUser(projectId)\n}\n\n/** @internal */\nexport function getCurrentUser(\n projectId: string,\n abort: Aborter,\n token?: string\n): Promise<CurrentUser | null> {\n const headers = token ? {Authorization: `Bearer ${token}`} : undefined\n return fetch(`https://${projectId}.api.sanity.io/v1/users/me`, {\n credentials: 'include',\n signal: abort.signal,\n headers,\n })\n .then((res) => res.json())\n .then((res) => (res?.id ? res : null))\n}\n\nfunction useCurrentUser(projectId: string) {\n const [data, setUser] = useState<CurrentUser | null>()\n const [error, setError] = useState<Error>()\n\n useEffect(() => {\n const aborter = getAborter()\n getCurrentUser(projectId, aborter)\n .then(setUser)\n .catch((err: Error) => err.name !== 'AbortError' && setError(err))\n\n return () => {\n aborter.abort()\n }\n }, [projectId])\n\n return {data, error, loading: data !== null || !error}\n}\n","import {GroqStore, Subscription} from '@sanity/groq-store'\nimport {useEffect, useMemo, useState} from 'react'\n\nimport {Aborter, getAborter} from './aborter'\nimport {getCurrentUser} from './currentUser'\nimport {Params, ProjectConfig, SubscriptionOptions} from './types'\n\nconst EMPTY_PARAMS = {}\n\n/** @public */\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function createPreviewSubscriptionHook({\n projectId,\n dataset,\n token,\n EventSource,\n documentLimit = 3000,\n}: ProjectConfig & {documentLimit?: number}) {\n // Only construct/setup the store when `getStore()` is called\n let store: Promise<GroqStore>\n\n return function usePreviewSubscription<R = any>(\n query: string,\n options: SubscriptionOptions<R> = {}\n ) {\n const {params = EMPTY_PARAMS, initialData, enabled} = options\n return useQuerySubscription<R>({\n getStore,\n projectId,\n query,\n params,\n initialData: initialData as any,\n enabled: enabled ? typeof window !== 'undefined' : false,\n token,\n })\n }\n\n function getStore(abort: Aborter) {\n if (!store) {\n store = import('@sanity/groq-store').then(({groqStore}) => {\n // Skip creating the groq store if we've been unmounted to save memory and reduce gc pressure\n if (abort.signal.aborted) {\n const error = new Error('Cancelling groq store creation')\n // This ensures we can skip it in the catch block same way\n error.name = 'AbortError'\n return Promise.reject(error)\n }\n\n return groqStore({\n projectId,\n dataset,\n documentLimit,\n token,\n EventSource,\n listen: true,\n overlayDrafts: true,\n subscriptionThrottleMs: 10,\n })\n })\n }\n return store\n }\n}\n\nfunction useQuerySubscription<R = any>(options: {\n getStore: (abort: Aborter) => Promise<GroqStore>\n projectId: string\n query: string\n params: Params\n initialData: R\n enabled: boolean\n token?: string\n}) {\n const {getStore, projectId, query, initialData, enabled = false, token} = options\n const [error, setError] = useState<Error>()\n const [loading, setLoading] = useState(false)\n const [data, setData] = useState<R>()\n const params = useParams(options.params)\n\n // Use \"deep\" dependency comparison because params are often not _referentially_ equal,\n // but contains the same shallow properties, eg `{\"slug\": \"some-slug\"}`\n useEffect(() => {\n if (!enabled) {\n return\n }\n\n setLoading(true)\n\n const aborter = getAborter()\n let subscription: Subscription | undefined\n getCurrentUser(projectId, aborter, token)\n .then((user) => {\n if (user) {\n return\n }\n\n // eslint-disable-next-line no-console\n console.warn('Not authenticated - preview not available')\n throw new Error('Not authenticated - preview not available')\n })\n .then(() => getStore(aborter))\n .then((store) => {\n subscription = store.subscribe(query, params, (err, result) => {\n if (err) {\n setError(err)\n } else {\n setData(result)\n }\n })\n })\n .catch((err: Error) => (err.name === 'AbortError' ? null : setError(err)))\n .finally(() => setLoading(false))\n\n // eslint-disable-next-line consistent-return\n return () => {\n if (subscription) {\n subscription.unsubscribe()\n }\n\n aborter.abort()\n }\n }, [getStore, query, params, enabled, projectId, token])\n\n return {\n data: typeof data === 'undefined' ? initialData : data,\n loading,\n error,\n }\n}\n\n// Return params that are stable with deep equal as long as the key order is the same\nexport function useParams(params: Params): Params {\n const stringifiedParams = useMemo(() => JSON.stringify(params), [params])\n return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams])\n}\n"],"names":["createClient","config","sanityClient","MockAbortController","constructor","_signal","aborted","signal","abort","getAborter","AbortController","createCurrentUserHook","projectId","useCurrentUser","getCurrentUser","token","headers","Authorization","fetch","credentials","then","res","json","id","data","setUser","useState","error","setError","useEffect","aborter","catch","err","name","loading","EMPTY_PARAMS","createPreviewSubscriptionHook","dataset","EventSource","documentLimit","store","usePreviewSubscription","query","options","params","initialData","enabled","useQuerySubscription","getStore","window","Promise","resolve","_interopNamespace","require","groqStore","Error","reject","listen","overlayDrafts","subscriptionThrottleMs","setLoading","setData","useParams","subscription","user","console","warn","subscribe","result","finally","unsubscribe","stringifiedParams","useMemo","JSON","stringify","parse"],"mappings":";;;;;;;;;;;;;;;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
|
@@ -14,21 +14,41 @@ import {StudioProps} from 'sanity'
|
|
|
14
14
|
import {StudioTheme} from 'sanity'
|
|
15
15
|
import {WorkspaceOptions} from 'sanity'
|
|
16
16
|
|
|
17
|
+
/** @alpha */
|
|
17
18
|
export declare type ConfigWithBasePath = SingleWorkspaceWithBasePath | WorkspaceOptions[]
|
|
18
19
|
|
|
20
|
+
/** @alpha */
|
|
19
21
|
export declare type ConfigWithTheme = SingleWorkspaceWithTheme | WorkspaceOptionsWithTheme[]
|
|
20
22
|
|
|
23
|
+
/** @alpha */
|
|
21
24
|
export declare function isWorkspaces(config: Config): config is WorkspaceOptions[]
|
|
22
25
|
|
|
26
|
+
/** @alpha */
|
|
23
27
|
export declare function isWorkspaceWithTheme(
|
|
24
28
|
workspace: SingleWorkspace | WorkspaceOptions
|
|
25
29
|
): workspace is SingleWorkspaceWithTheme | WorkspaceOptionsWithTheme
|
|
26
30
|
|
|
31
|
+
/** @alpha */
|
|
27
32
|
export declare type MetaThemeColors = {
|
|
28
33
|
themeColorLight: string
|
|
29
34
|
themeColorDark: string
|
|
30
35
|
}
|
|
31
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Override how the Studio renders by passing children.
|
|
39
|
+
* This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:
|
|
40
|
+
* ```
|
|
41
|
+
* import {StudioProvider, StudioLayout} from 'sanity'
|
|
42
|
+
* import {NextStudio} from 'next-sanity/studio'
|
|
43
|
+
* <NextStudio config={config}>
|
|
44
|
+
* <StudioProvider config={config}>
|
|
45
|
+
* <CustomComponentThatUsesContextFromStudioProvider />
|
|
46
|
+
* <StudioLayout />
|
|
47
|
+
* </StudioProvider>
|
|
48
|
+
* </NextStudio>
|
|
49
|
+
* ```
|
|
50
|
+
* @beta
|
|
51
|
+
*/
|
|
32
52
|
export declare const NextStudio: MemoExoticComponent<
|
|
33
53
|
({
|
|
34
54
|
children,
|
|
@@ -45,17 +65,20 @@ export declare const NextStudio: MemoExoticComponent<
|
|
|
45
65
|
}: NextStudioProps) => JSX.Element
|
|
46
66
|
>
|
|
47
67
|
|
|
68
|
+
/** @alpha */
|
|
48
69
|
export declare const NextStudioGlobalStyle: GlobalStyleComponent<
|
|
49
70
|
NextStudioGlobalStyleProps,
|
|
50
71
|
DefaultTheme
|
|
51
72
|
>
|
|
52
73
|
|
|
74
|
+
/** @alpha */
|
|
53
75
|
export declare interface NextStudioGlobalStyleProps {
|
|
54
76
|
fontFamily?: string
|
|
55
77
|
bg?: string
|
|
56
78
|
unstable__tailwindSvgFix?: boolean
|
|
57
79
|
}
|
|
58
80
|
|
|
81
|
+
/** @alpha */
|
|
59
82
|
export declare const NextStudioHead: MemoExoticComponent<
|
|
60
83
|
({
|
|
61
84
|
children,
|
|
@@ -66,69 +89,71 @@ export declare const NextStudioHead: MemoExoticComponent<
|
|
|
66
89
|
}: NextStudioHeadProps) => JSX.Element
|
|
67
90
|
>
|
|
68
91
|
|
|
92
|
+
/** @alpha */
|
|
69
93
|
export declare interface NextStudioHeadProps extends Partial<MetaThemeColors> {
|
|
70
94
|
children?: ComponentProps<typeof Head>['children']
|
|
71
95
|
title?: string
|
|
72
96
|
favicons?: boolean
|
|
73
97
|
}
|
|
74
98
|
|
|
99
|
+
/** @alpha */
|
|
75
100
|
export declare const NextStudioNoScript: () => JSX.Element
|
|
76
101
|
|
|
102
|
+
/** @beta */
|
|
77
103
|
export declare interface NextStudioProps extends StudioProps {
|
|
78
|
-
/**
|
|
79
|
-
* Override how the Studio renders by passing children.
|
|
80
|
-
* This is useful for advanced use cases where you're using StudioProvider and StudioLayout instead of Studio:
|
|
81
|
-
* import {StudioProvider, StudioLayout} from 'sanity'
|
|
82
|
-
* import {NextStudio} from 'next-sanity/studio'
|
|
83
|
-
* <NextStudio config={config}>
|
|
84
|
-
* <StudioProvider config={config}>
|
|
85
|
-
* <CustomComponentThatUsesContextFromStudioProvider />
|
|
86
|
-
* <StudioLayout />
|
|
87
|
-
* </StudioProvider>
|
|
88
|
-
* </NextStudio>
|
|
89
|
-
*/
|
|
90
104
|
children?: React.ReactNode
|
|
91
105
|
/**
|
|
92
106
|
* Turns off the default global styling
|
|
107
|
+
* @alpha
|
|
93
108
|
*/
|
|
94
109
|
unstable__noGlobalStyle?: boolean
|
|
95
110
|
/**
|
|
96
|
-
* Apply fix with SVG icon centering that happens if TailwindCSS is loaded, on by
|
|
111
|
+
* Apply fix with SVG icon centering that happens if TailwindCSS is loaded, on by default
|
|
112
|
+
* @alpha
|
|
97
113
|
*/
|
|
98
114
|
unstable__noTailwindSvgFix?: NextStudioGlobalStyleProps['unstable__tailwindSvgFix']
|
|
99
115
|
/**
|
|
100
116
|
* Add stuff to the head with next/head
|
|
117
|
+
* @alpha
|
|
101
118
|
*/
|
|
102
119
|
unstable__head?: NextStudioHeadProps['children']
|
|
103
120
|
/**
|
|
104
121
|
* Sets the document title
|
|
122
|
+
* @alpha
|
|
105
123
|
*/
|
|
106
124
|
unstable__document_title?: NextStudioHeadProps['title']
|
|
107
125
|
/**
|
|
108
126
|
* Sets the background color of <html>
|
|
127
|
+
* @alpha
|
|
109
128
|
*/
|
|
110
129
|
unstable__bg?: NextStudioGlobalStyleProps['bg']
|
|
111
130
|
/**
|
|
112
131
|
* Sets the font-family of #__next
|
|
132
|
+
* @alpha
|
|
113
133
|
*/
|
|
114
134
|
unstable__fontFamily?: NextStudioGlobalStyleProps['fontFamily']
|
|
115
135
|
/**
|
|
116
136
|
* Don't load the favicon meta tags
|
|
137
|
+
* @alpha
|
|
117
138
|
*/
|
|
118
139
|
unstable__noFavicons?: boolean
|
|
119
140
|
/**
|
|
120
141
|
* Don't render the <noscript> tag
|
|
142
|
+
* @alpha
|
|
121
143
|
*/
|
|
122
144
|
unstable__noNoScript?: boolean
|
|
123
145
|
}
|
|
124
146
|
|
|
125
147
|
/**
|
|
126
148
|
* Usage, from a pages/_document.tsx file:
|
|
149
|
+
* ```
|
|
127
150
|
* import {ServerStyleSheetDocument} from 'next-sanity/studio'
|
|
128
151
|
*
|
|
129
152
|
* export default class MyDocument extends ServerStyleSheetDocument {}
|
|
153
|
+
* ```
|
|
130
154
|
*
|
|
131
155
|
* To do extra stuff in getInitialProps:
|
|
156
|
+
* ```
|
|
132
157
|
* import {ServerStyleSheetDocument} from 'next-sanity/studio'
|
|
133
158
|
* import { type DocumentContext } from 'next/document'
|
|
134
159
|
*
|
|
@@ -148,6 +173,8 @@ export declare interface NextStudioProps extends StudioProps {
|
|
|
148
173
|
* }
|
|
149
174
|
* }
|
|
150
175
|
* }
|
|
176
|
+
* ```
|
|
177
|
+
* @beta
|
|
151
178
|
*/
|
|
152
179
|
export declare class ServerStyleSheetDocument extends Document_2 {
|
|
153
180
|
static getInitialProps(ctx: DocumentContext): Promise<{
|
|
@@ -157,34 +184,44 @@ export declare class ServerStyleSheetDocument extends Document_2 {
|
|
|
157
184
|
}>
|
|
158
185
|
}
|
|
159
186
|
|
|
187
|
+
/** @alpha */
|
|
160
188
|
export declare type SingleWorkspaceWithBasePath = Omit<SingleWorkspace, 'basePath'> & {
|
|
161
189
|
basePath: string
|
|
162
190
|
}
|
|
163
191
|
|
|
192
|
+
/** @alpha */
|
|
164
193
|
export declare type SingleWorkspaceWithTheme = Omit<SingleWorkspace, 'theme'> & WithTheme
|
|
165
194
|
|
|
195
|
+
/** @alpha */
|
|
166
196
|
export declare const useBackgroundColorsFromTheme: (theme: StudioTheme) => MetaThemeColors
|
|
167
197
|
|
|
168
198
|
/**
|
|
169
199
|
* Parses the next route to determine the what the base path for Sanity Studio should be
|
|
200
|
+
* @alpha
|
|
170
201
|
*/
|
|
171
202
|
export declare function useBasePath(): string
|
|
172
203
|
|
|
173
204
|
/**
|
|
174
205
|
* Apply the base path from next to the config, prefixing any defined base path
|
|
206
|
+
* @alpha
|
|
175
207
|
*/
|
|
176
208
|
export declare function useConfigWithBasePath(config: Config): ConfigWithBasePath
|
|
177
209
|
|
|
210
|
+
/** @alpha */
|
|
178
211
|
export declare const useTextFontFamilyFromTheme: (theme: StudioTheme) => string
|
|
179
212
|
|
|
213
|
+
/** @alpha */
|
|
180
214
|
export declare function useTheme(config: Config): StudioTheme
|
|
181
215
|
|
|
216
|
+
/** @alpha */
|
|
182
217
|
export declare type WithTheme = {
|
|
183
218
|
theme: StudioTheme
|
|
184
219
|
}
|
|
185
220
|
|
|
221
|
+
/** @alpha */
|
|
186
222
|
export declare type WorkspaceOptionsWithTheme = Omit<WorkspaceOptions, 'theme'> & WithTheme
|
|
187
223
|
|
|
224
|
+
/** @alpha */
|
|
188
225
|
export declare interface WorkspaceWithBasePath extends Omit<WorkspaceOptions, 'basePath'> {
|
|
189
226
|
basePath: string
|
|
190
227
|
}
|