next-sanity 1.1.0 → 2.0.0-preview-kit.2
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 +3 -5
- package/dist/index.cjs +0 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -68
- package/dist/index.js +1 -157
- package/dist/index.js.map +1 -1
- package/dist/preview.cjs +19 -0
- package/dist/preview.cjs.map +1 -0
- package/dist/preview.d.ts +20 -0
- package/dist/preview.js +2 -0
- package/dist/preview.js.map +1 -0
- package/dist/studio.cjs.map +1 -1
- package/dist/studio.d.ts +9 -7
- package/dist/studio.js.map +1 -1
- package/package.json +26 -8
- package/src/index.ts +0 -4
- package/src/preview/definePreview.tsx +37 -0
- package/src/preview/index.ts +2 -0
- package/src/studio/NextStudioHead.tsx +3 -4
- package/src/studio/ServerStyleSheetDocument.tsx +1 -2
- package/src/aborter.ts +0 -22
- package/src/currentUser.ts +0 -44
- package/src/types.ts +0 -30
- package/src/useSubscription.ts +0 -137
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Features:**
|
|
6
6
|
|
|
7
|
-
- Client-side live real-time preview for
|
|
7
|
+
- Client-side live real-time preview for Next 13 and `appDir`. For `pages`, or older versions of Next, you can use [`@sanity/preview-kit`](https://github.com/sanity-io/preview-kit).
|
|
8
8
|
- GROQ syntax highlighting
|
|
9
9
|
- [Embed](#next-sanitystudio-dev-preview) [Studio v3](https://www.sanity.io/studio-v3) in [Next.js](https://nextjs.org/) apps
|
|
10
10
|
|
|
@@ -39,9 +39,7 @@ $ yarn add next-sanity @portabletext/react @sanity/image-url
|
|
|
39
39
|
|
|
40
40
|
## Live real-time preview
|
|
41
41
|
|
|
42
|
-
You can implement real-time client side preview using `
|
|
43
|
-
|
|
44
|
-
You might want to use Vercel’s approach to previews, which is set up with a serverless functions that takes a preview secret, which in turn redirects you to a page with a `preview` prop set to `true`.
|
|
42
|
+
You can implement real-time client side preview using `definePreview`. It works by streaming the whole dataset to the browser, which it keeps updated using [listeners](https://www.sanity.io/docs/realtime-updates) and Mendoza patches. When it receives updates, then the query is run against the client-side datastore using [groq-js](https://github.com/sanity-io/groq-js).
|
|
45
43
|
|
|
46
44
|
### Limits
|
|
47
45
|
|
|
@@ -219,7 +217,7 @@ export async function getStaticPaths() {
|
|
|
219
217
|
|
|
220
218
|
## `next-sanity/studio` (dev-preview)
|
|
221
219
|
|
|
222
|
-
> [See it live](https://next.sanity.build/)
|
|
220
|
+
> [See it live](https://next.sanity.build/studio)
|
|
223
221
|
|
|
224
222
|
The latest version of Sanity Studio allows you to embed a near-infinitely configurable content editing interface into any React application. This opens up many possibilities:
|
|
225
223
|
|
package/dist/index.cjs
CHANGED
|
@@ -4,194 +4,17 @@ Object.defineProperty(exports, '__esModule', {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var sanityClient = require('@sanity/client');
|
|
7
|
-
var react = require('react');
|
|
8
7
|
var groq = require('groq');
|
|
9
8
|
function _interopDefaultLegacy(e) {
|
|
10
9
|
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
11
10
|
'default': e
|
|
12
11
|
};
|
|
13
12
|
}
|
|
14
|
-
function _interopNamespace(e) {
|
|
15
|
-
if (e && e.__esModule) return e;
|
|
16
|
-
var n = Object.create(null);
|
|
17
|
-
if (e) {
|
|
18
|
-
Object.keys(e).forEach(function (k) {
|
|
19
|
-
if (k !== 'default') {
|
|
20
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return e[k];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
n["default"] = e;
|
|
31
|
-
return Object.freeze(n);
|
|
32
|
-
}
|
|
33
13
|
var sanityClient__default = /*#__PURE__*/_interopDefaultLegacy(sanityClient);
|
|
34
14
|
var groq__default = /*#__PURE__*/_interopDefaultLegacy(groq);
|
|
35
15
|
function createClient(config) {
|
|
36
16
|
return sanityClient__default["default"](config);
|
|
37
17
|
}
|
|
38
|
-
class MockAbortController {
|
|
39
|
-
constructor() {
|
|
40
|
-
this._signal = {
|
|
41
|
-
aborted: false
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
get signal() {
|
|
45
|
-
return this._signal;
|
|
46
|
-
}
|
|
47
|
-
abort() {
|
|
48
|
-
this._signal.aborted = true;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function getAborter() {
|
|
52
|
-
return typeof AbortController === "undefined" ? new MockAbortController() : new AbortController();
|
|
53
|
-
}
|
|
54
|
-
function createCurrentUserHook(_ref) {
|
|
55
|
-
let {
|
|
56
|
-
projectId
|
|
57
|
-
} = _ref;
|
|
58
|
-
return () => useCurrentUser(projectId);
|
|
59
|
-
}
|
|
60
|
-
function getCurrentUser(projectId, abort, token) {
|
|
61
|
-
const headers = token ? {
|
|
62
|
-
Authorization: "Bearer ".concat(token)
|
|
63
|
-
} : void 0;
|
|
64
|
-
return fetch("https://".concat(projectId, ".api.sanity.io/v1/users/me"), {
|
|
65
|
-
credentials: "include",
|
|
66
|
-
signal: abort.signal,
|
|
67
|
-
headers
|
|
68
|
-
}).then(res => res.json()).then(res => (res == null ? void 0 : res.id) ? res : null);
|
|
69
|
-
}
|
|
70
|
-
function useCurrentUser(projectId) {
|
|
71
|
-
const [data, setUser] = react.useState();
|
|
72
|
-
const [error, setError] = react.useState();
|
|
73
|
-
react.useEffect(() => {
|
|
74
|
-
const aborter = getAborter();
|
|
75
|
-
getCurrentUser(projectId, aborter).then(setUser).catch(err => err.name !== "AbortError" && setError(err));
|
|
76
|
-
return () => {
|
|
77
|
-
aborter.abort();
|
|
78
|
-
};
|
|
79
|
-
}, [projectId]);
|
|
80
|
-
return {
|
|
81
|
-
data,
|
|
82
|
-
error,
|
|
83
|
-
loading: data !== null || !error
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
const EMPTY_PARAMS = {};
|
|
87
|
-
function createPreviewSubscriptionHook(_ref2) {
|
|
88
|
-
let {
|
|
89
|
-
projectId,
|
|
90
|
-
dataset,
|
|
91
|
-
token,
|
|
92
|
-
EventSource,
|
|
93
|
-
documentLimit = 3e3,
|
|
94
|
-
includeTypes
|
|
95
|
-
} = _ref2;
|
|
96
|
-
let store;
|
|
97
|
-
return function usePreviewSubscription(query) {
|
|
98
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
99
|
-
const {
|
|
100
|
-
params = EMPTY_PARAMS,
|
|
101
|
-
initialData,
|
|
102
|
-
enabled
|
|
103
|
-
} = options;
|
|
104
|
-
return useQuerySubscription({
|
|
105
|
-
getStore,
|
|
106
|
-
projectId,
|
|
107
|
-
query,
|
|
108
|
-
params,
|
|
109
|
-
initialData,
|
|
110
|
-
enabled: enabled ? typeof window !== "undefined" : false,
|
|
111
|
-
token
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
function getStore(abort) {
|
|
115
|
-
if (!store) {
|
|
116
|
-
store = Promise.resolve().then(function () {
|
|
117
|
-
return /*#__PURE__*/_interopNamespace(require('@sanity/groq-store'));
|
|
118
|
-
}).then(_ref3 => {
|
|
119
|
-
let {
|
|
120
|
-
groqStore
|
|
121
|
-
} = _ref3;
|
|
122
|
-
if (abort.signal.aborted) {
|
|
123
|
-
const error = new Error("Cancelling groq store creation");
|
|
124
|
-
error.name = "AbortError";
|
|
125
|
-
return Promise.reject(error);
|
|
126
|
-
}
|
|
127
|
-
return groqStore({
|
|
128
|
-
projectId,
|
|
129
|
-
dataset,
|
|
130
|
-
documentLimit,
|
|
131
|
-
includeTypes,
|
|
132
|
-
token,
|
|
133
|
-
EventSource,
|
|
134
|
-
listen: true,
|
|
135
|
-
overlayDrafts: true,
|
|
136
|
-
subscriptionThrottleMs: 10
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
return store;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function useQuerySubscription(options) {
|
|
144
|
-
const {
|
|
145
|
-
getStore,
|
|
146
|
-
projectId,
|
|
147
|
-
query,
|
|
148
|
-
initialData,
|
|
149
|
-
enabled = false,
|
|
150
|
-
token
|
|
151
|
-
} = options;
|
|
152
|
-
const [error, setError] = react.useState();
|
|
153
|
-
const [loading, setLoading] = react.useState(false);
|
|
154
|
-
const [data, setData] = react.useState();
|
|
155
|
-
const params = useParams(options.params);
|
|
156
|
-
react.useEffect(() => {
|
|
157
|
-
if (!enabled) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
setLoading(true);
|
|
161
|
-
const aborter = getAborter();
|
|
162
|
-
let subscription;
|
|
163
|
-
getCurrentUser(projectId, aborter, token).then(user => {
|
|
164
|
-
if (user) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
console.warn("Not authenticated - preview not available");
|
|
168
|
-
throw new Error("Not authenticated - preview not available");
|
|
169
|
-
}).then(() => getStore(aborter)).then(store => {
|
|
170
|
-
subscription = store.subscribe(query, params, (err, result) => {
|
|
171
|
-
if (err) {
|
|
172
|
-
setError(err);
|
|
173
|
-
} else {
|
|
174
|
-
setData(result);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}).catch(err => err.name === "AbortError" ? null : setError(err)).finally(() => setLoading(false));
|
|
178
|
-
return () => {
|
|
179
|
-
if (subscription) {
|
|
180
|
-
subscription.unsubscribe();
|
|
181
|
-
}
|
|
182
|
-
aborter.abort();
|
|
183
|
-
};
|
|
184
|
-
}, [getStore, query, params, enabled, projectId, token]);
|
|
185
|
-
return {
|
|
186
|
-
data: typeof data === "undefined" ? initialData : data,
|
|
187
|
-
loading,
|
|
188
|
-
error
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
function useParams(params) {
|
|
192
|
-
const stringifiedParams = react.useMemo(() => JSON.stringify(params), [params]);
|
|
193
|
-
return react.useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams]);
|
|
194
|
-
}
|
|
195
18
|
Object.defineProperty(exports, 'groq', {
|
|
196
19
|
enumerable: true,
|
|
197
20
|
get: function () {
|
|
@@ -199,6 +22,4 @@ Object.defineProperty(exports, 'groq', {
|
|
|
199
22
|
}
|
|
200
23
|
});
|
|
201
24
|
exports.createClient = createClient;
|
|
202
|
-
exports.createCurrentUserHook = createCurrentUserHook;
|
|
203
|
-
exports.createPreviewSubscriptionHook = createPreviewSubscriptionHook;
|
|
204
25
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","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 includeTypes,\n}: ProjectConfig & {documentLimit?: number; includeTypes?: string[]}) {\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 includeTypes,\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","includeTypes","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,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;AAGO,SAASG,UAAsB,GAAA;EACpC,OAAO,OAAOC,eAAoB,KAAA,WAAA,GAC9B,IAAIP,mBAAoB,EAAA,GACxB,IAAIO,eAAgB,EAAA;AAC1B;ACfgB,SAAAC,qBAAA,OAA0E;EAAA,IAApD;IAACC;GAAmD;EAEjF,OAAA,MAAMC,eAAeD,SAAS,CAAA;AACvC;AAGgB,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,CAAA,CACEI,IAAK,CAACC,OAAQA,GAAI,CAAAC,IAAA,EAAM,CAAA,CACxBF,KAAMC,GAAA,IAAA,CAASA,GAAK,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAA,GAAA,CAAAE,EAAA,IAAKF,MAAM,IAAK,CAAA;AACzC;AAEA,SAASR,eAAeD,SAAmB,EAAA;EACzC,MAAM,CAACY,IAAA,EAAMC,OAAO,CAAA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CAAAA,OAAA,CAAQ,MAAMC,IAAK,CAAAE,KAAA,CAAMJ,iBAAiB,CAAG,EAAA,CAACA,iBAAiB,CAAC,CAAA;AACzE;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/client.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"],"names":["createClient","config","sanityClient"],"mappings":";;;;;;;;;;;;;;AAIO,SAASA,aAAaC,MAAoC,EAAA;EAC/D,OAAOC,qBAAAA,CAAAA,SAAAA,EAAaD,MAAM,CAAA;AAC5B;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,14 @@
|
|
|
1
1
|
import {ClientConfig} from '@sanity/client'
|
|
2
|
-
import type {Config} from '@sanity/groq-store/dist/typings/types'
|
|
3
2
|
import {default as groq} from 'groq'
|
|
4
3
|
import {SanityClient} from '@sanity/client'
|
|
5
4
|
|
|
6
|
-
/** @public */
|
|
7
|
-
export declare interface Aborter {
|
|
8
|
-
abort(): void
|
|
9
|
-
signal: AbortSignal
|
|
10
|
-
}
|
|
11
|
-
|
|
12
5
|
export {ClientConfig}
|
|
13
6
|
|
|
14
7
|
/** @public */
|
|
15
8
|
export declare function createClient(config: ClientConfig): SanityClient
|
|
16
9
|
|
|
17
|
-
/** @public */
|
|
18
|
-
export declare function createCurrentUserHook({
|
|
19
|
-
projectId,
|
|
20
|
-
}: {
|
|
21
|
-
projectId: string
|
|
22
|
-
dataset?: string
|
|
23
|
-
}): () => {
|
|
24
|
-
data: CurrentUser | null | undefined
|
|
25
|
-
error: Error | undefined
|
|
26
|
-
loading: boolean
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** @public */
|
|
30
|
-
export declare function createPreviewSubscriptionHook({
|
|
31
|
-
projectId,
|
|
32
|
-
dataset,
|
|
33
|
-
token,
|
|
34
|
-
EventSource,
|
|
35
|
-
documentLimit,
|
|
36
|
-
includeTypes,
|
|
37
|
-
}: ProjectConfig & {
|
|
38
|
-
documentLimit?: number
|
|
39
|
-
includeTypes?: string[]
|
|
40
|
-
}): <R = any>(
|
|
41
|
-
query: string,
|
|
42
|
-
options?: SubscriptionOptions<R>
|
|
43
|
-
) => {
|
|
44
|
-
data: R
|
|
45
|
-
loading: boolean
|
|
46
|
-
error: Error | undefined
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** @public */
|
|
50
|
-
export declare interface CurrentUser {
|
|
51
|
-
id: string
|
|
52
|
-
name: string
|
|
53
|
-
profileImage?: string
|
|
54
|
-
}
|
|
55
|
-
|
|
56
10
|
export {groq}
|
|
57
11
|
|
|
58
|
-
/** @public */
|
|
59
|
-
export declare type GroqStoreEventSource = Config['EventSource']
|
|
60
|
-
|
|
61
|
-
/** @public */
|
|
62
|
-
export declare type Params = Record<string, unknown>
|
|
63
|
-
|
|
64
|
-
/** @public */
|
|
65
|
-
export declare interface ProjectConfig {
|
|
66
|
-
projectId: string
|
|
67
|
-
dataset: string
|
|
68
|
-
token?: string
|
|
69
|
-
/** Must be provided when token is used in browser, as native EventSource does not support auth-headers. */
|
|
70
|
-
EventSource?: GroqStoreEventSource
|
|
71
|
-
}
|
|
72
|
-
|
|
73
12
|
export {SanityClient}
|
|
74
13
|
|
|
75
|
-
/** @public */
|
|
76
|
-
export declare interface SubscriptionOptions<R = any> {
|
|
77
|
-
enabled?: boolean
|
|
78
|
-
params?: Params
|
|
79
|
-
initialData?: R
|
|
80
|
-
}
|
|
81
|
-
|
|
82
14
|
export {}
|
package/dist/index.js
CHANGED
|
@@ -1,163 +1,7 @@
|
|
|
1
1
|
import sanityClient from '@sanity/client';
|
|
2
|
-
import { useState, useEffect, useMemo } from 'react';
|
|
3
2
|
export { default as groq } from 'groq';
|
|
4
3
|
function createClient(config) {
|
|
5
4
|
return sanityClient(config);
|
|
6
5
|
}
|
|
7
|
-
|
|
8
|
-
constructor() {
|
|
9
|
-
this._signal = {
|
|
10
|
-
aborted: false
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
get signal() {
|
|
14
|
-
return this._signal;
|
|
15
|
-
}
|
|
16
|
-
abort() {
|
|
17
|
-
this._signal.aborted = true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function getAborter() {
|
|
21
|
-
return typeof AbortController === "undefined" ? new MockAbortController() : new AbortController();
|
|
22
|
-
}
|
|
23
|
-
function createCurrentUserHook(_ref) {
|
|
24
|
-
let {
|
|
25
|
-
projectId
|
|
26
|
-
} = _ref;
|
|
27
|
-
return () => useCurrentUser(projectId);
|
|
28
|
-
}
|
|
29
|
-
function getCurrentUser(projectId, abort, token) {
|
|
30
|
-
const headers = token ? {
|
|
31
|
-
Authorization: "Bearer ".concat(token)
|
|
32
|
-
} : void 0;
|
|
33
|
-
return fetch("https://".concat(projectId, ".api.sanity.io/v1/users/me"), {
|
|
34
|
-
credentials: "include",
|
|
35
|
-
signal: abort.signal,
|
|
36
|
-
headers
|
|
37
|
-
}).then(res => res.json()).then(res => (res == null ? void 0 : res.id) ? res : null);
|
|
38
|
-
}
|
|
39
|
-
function useCurrentUser(projectId) {
|
|
40
|
-
const [data, setUser] = useState();
|
|
41
|
-
const [error, setError] = useState();
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
const aborter = getAborter();
|
|
44
|
-
getCurrentUser(projectId, aborter).then(setUser).catch(err => err.name !== "AbortError" && setError(err));
|
|
45
|
-
return () => {
|
|
46
|
-
aborter.abort();
|
|
47
|
-
};
|
|
48
|
-
}, [projectId]);
|
|
49
|
-
return {
|
|
50
|
-
data,
|
|
51
|
-
error,
|
|
52
|
-
loading: data !== null || !error
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
const EMPTY_PARAMS = {};
|
|
56
|
-
function createPreviewSubscriptionHook(_ref2) {
|
|
57
|
-
let {
|
|
58
|
-
projectId,
|
|
59
|
-
dataset,
|
|
60
|
-
token,
|
|
61
|
-
EventSource,
|
|
62
|
-
documentLimit = 3e3,
|
|
63
|
-
includeTypes
|
|
64
|
-
} = _ref2;
|
|
65
|
-
let store;
|
|
66
|
-
return function usePreviewSubscription(query) {
|
|
67
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
68
|
-
const {
|
|
69
|
-
params = EMPTY_PARAMS,
|
|
70
|
-
initialData,
|
|
71
|
-
enabled
|
|
72
|
-
} = options;
|
|
73
|
-
return useQuerySubscription({
|
|
74
|
-
getStore,
|
|
75
|
-
projectId,
|
|
76
|
-
query,
|
|
77
|
-
params,
|
|
78
|
-
initialData,
|
|
79
|
-
enabled: enabled ? typeof window !== "undefined" : false,
|
|
80
|
-
token
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
function getStore(abort) {
|
|
84
|
-
if (!store) {
|
|
85
|
-
store = import('@sanity/groq-store').then(_ref3 => {
|
|
86
|
-
let {
|
|
87
|
-
groqStore
|
|
88
|
-
} = _ref3;
|
|
89
|
-
if (abort.signal.aborted) {
|
|
90
|
-
const error = new Error("Cancelling groq store creation");
|
|
91
|
-
error.name = "AbortError";
|
|
92
|
-
return Promise.reject(error);
|
|
93
|
-
}
|
|
94
|
-
return groqStore({
|
|
95
|
-
projectId,
|
|
96
|
-
dataset,
|
|
97
|
-
documentLimit,
|
|
98
|
-
includeTypes,
|
|
99
|
-
token,
|
|
100
|
-
EventSource,
|
|
101
|
-
listen: true,
|
|
102
|
-
overlayDrafts: true,
|
|
103
|
-
subscriptionThrottleMs: 10
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return store;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function useQuerySubscription(options) {
|
|
111
|
-
const {
|
|
112
|
-
getStore,
|
|
113
|
-
projectId,
|
|
114
|
-
query,
|
|
115
|
-
initialData,
|
|
116
|
-
enabled = false,
|
|
117
|
-
token
|
|
118
|
-
} = options;
|
|
119
|
-
const [error, setError] = useState();
|
|
120
|
-
const [loading, setLoading] = useState(false);
|
|
121
|
-
const [data, setData] = useState();
|
|
122
|
-
const params = useParams(options.params);
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
if (!enabled) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
setLoading(true);
|
|
128
|
-
const aborter = getAborter();
|
|
129
|
-
let subscription;
|
|
130
|
-
getCurrentUser(projectId, aborter, token).then(user => {
|
|
131
|
-
if (user) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
console.warn("Not authenticated - preview not available");
|
|
135
|
-
throw new Error("Not authenticated - preview not available");
|
|
136
|
-
}).then(() => getStore(aborter)).then(store => {
|
|
137
|
-
subscription = store.subscribe(query, params, (err, result) => {
|
|
138
|
-
if (err) {
|
|
139
|
-
setError(err);
|
|
140
|
-
} else {
|
|
141
|
-
setData(result);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}).catch(err => err.name === "AbortError" ? null : setError(err)).finally(() => setLoading(false));
|
|
145
|
-
return () => {
|
|
146
|
-
if (subscription) {
|
|
147
|
-
subscription.unsubscribe();
|
|
148
|
-
}
|
|
149
|
-
aborter.abort();
|
|
150
|
-
};
|
|
151
|
-
}, [getStore, query, params, enabled, projectId, token]);
|
|
152
|
-
return {
|
|
153
|
-
data: typeof data === "undefined" ? initialData : data,
|
|
154
|
-
loading,
|
|
155
|
-
error
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
function useParams(params) {
|
|
159
|
-
const stringifiedParams = useMemo(() => JSON.stringify(params), [params]);
|
|
160
|
-
return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams]);
|
|
161
|
-
}
|
|
162
|
-
export { createClient, createCurrentUserHook, createPreviewSubscriptionHook };
|
|
6
|
+
export { createClient };
|
|
163
7
|
//# sourceMappingURL=index.js.map
|
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\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 includeTypes,\n}: ProjectConfig & {documentLimit?: number; includeTypes?: string[]}) {\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 includeTypes,\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","includeTypes","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,GAAA;IACX,OAAO,IAAK,CAAAF,OAAA;EACd;EACAG,KAAQ,GAAA;IACN,IAAA,CAAKH,QAAQC,OAAU,GAAA,IAAA;EACzB;AACF;AAGO,SAASG,UAAsB,GAAA;EACpC,OAAO,OAAOC,eAAoB,KAAA,WAAA,GAC9B,IA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G,YAAc,EAAA;QAChBA,YAAA,CAAaO,WAAY,EAAA;MAC3B;MAEAtC,OAAA,CAAQtB,KAAM,EAAA;IAAA,CAChB;EAAA,CACF,EAAG,CAACyC,QAAU,EAAAN,KAAA,EAAOE,QAAQE,OAAS,EAAAnC,SAAA,EAAWG,KAAK,CAAC,CAAA;EAEhD,OAAA;IACLS,IAAM,EAAA,OAAOA,IAAS,KAAA,WAAA,GAAcsB,WAAc,GAAAtB,IAAA;IAClDU,OAAA;IACAP;EAAA,CACF;AACF;AAGO,SAASiC,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;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/client.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"],"names":["createClient","config","sanityClient"],"mappings":";;AAIO,SAASA,aAAaC,MAAoC,EAAA;EAC/D,OAAOC,aAAaD,MAAM,CAAA;AAC5B;"}
|
package/dist/preview.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var previewKit = require('@sanity/preview-kit');
|
|
7
|
+
Object.defineProperty(exports, 'PreviewSuspense', {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return previewKit.PreviewSuspense;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, 'definePreview', {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return previewKit.definePreview;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=preview.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {definePreview} from '@sanity/preview-kit'
|
|
2
|
+
import {Params} from '@sanity/preview-kit'
|
|
3
|
+
import {PreviewConfig} from '@sanity/preview-kit'
|
|
4
|
+
import {PreviewSuspense} from '@sanity/preview-kit'
|
|
5
|
+
import {PreviewSuspenseProps} from '@sanity/preview-kit'
|
|
6
|
+
import {UsePreview} from '@sanity/preview-kit'
|
|
7
|
+
|
|
8
|
+
export {definePreview}
|
|
9
|
+
|
|
10
|
+
export {Params}
|
|
11
|
+
|
|
12
|
+
export {PreviewConfig}
|
|
13
|
+
|
|
14
|
+
export {PreviewSuspense}
|
|
15
|
+
|
|
16
|
+
export {PreviewSuspenseProps}
|
|
17
|
+
|
|
18
|
+
export {UsePreview}
|
|
19
|
+
|
|
20
|
+
export {}
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|