@sanity/preview-kit
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -0,1 +1,3 @@ | ||
'use client'; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
@@ -28,2 +30,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
}; | ||
function useParams(params) { | ||
const stringifiedParams = useMemo(() => JSON.stringify(params || null), [params]); | ||
return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams]); | ||
} | ||
const _definePreview = _ref => { | ||
@@ -51,6 +57,7 @@ let { | ||
let store; | ||
return function usePreview(token, query, params) { | ||
return function usePreview(token, query, _params) { | ||
if (!token && token !== null) { | ||
throw new Error("No `token` given to usePreview hook, if this is intentional then set it to `null`"); | ||
} | ||
const params = useParams(_params); | ||
if (!store) { | ||
@@ -98,6 +105,7 @@ if (onPublicAccessOnly) { | ||
}; | ||
const _preloadQuery = (store, query, params) => store.query(query, params); | ||
const definePreview = config => _definePreview(_objectSpread(_objectSpread({}, config), {}, { | ||
importEventSourcePolyfill: () => suspend(() => _lazyEventSourcePolyfill(), ["@sanity/preview-kit", "event-source-polyfill"]), | ||
importGroqStore: () => suspend(() => _lazyGroqStore(), ["@sanity/preview-kit", "@sanity/groq-store"]), | ||
preload: (store, query, params) => suspend(() => store.query(query, params), ["@sanity/preview-kit", "preload", query, JSON.stringify(params != null ? params : null)]), | ||
preload: (store, query, params) => suspend(() => _preloadQuery(store, query, params), ["@sanity/preview-kit", "preload", query, JSON.stringify(params != null ? params : null)]), | ||
checkAuth: (projectId, token) => suspend(() => _checkAuth(projectId, token), ["@sanity/preview-kit", "checkAuth", projectId, token]) | ||
@@ -104,0 +112,0 @@ })); |
{ | ||
"name": "@sanity/preview-kit", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "General purpose live previews, like next-sanity", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -62,7 +62,22 @@ import type { Config, GroqStore } from '@sanity/groq-store' | ||
checkAuth: (projectId: string, token: string | null) => boolean | ||
/** | ||
* Specify a | ||
*/ | ||
} | ||
/** | ||
* Return params that are stable with deep equal as long as the key order is the same | ||
* @internal | ||
*/ | ||
function useParams<P extends Params = Params>(params?: P): P { | ||
const stringifiedParams = useMemo( | ||
() => JSON.stringify(params || null), | ||
[params] | ||
) | ||
return useMemo(() => JSON.parse(stringifiedParams), [stringifiedParams]) | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
export const _definePreview = ({ | ||
@@ -97,3 +112,3 @@ projectId, | ||
Q extends string = string | ||
>(token: string | null, query: Q, params?: P): R | null { | ||
>(token: string | null, query: Q, _params?: P): R | null { | ||
if (!token && token !== null) { | ||
@@ -104,2 +119,3 @@ throw new Error( | ||
} | ||
const params = useParams<P>(_params) | ||
@@ -229,2 +245,11 @@ // eslint-disable-next-line no-warning-comments | ||
/** | ||
* Return params that are stable with deep equal as long as the key order is the same | ||
* @internal | ||
*/ | ||
const _preloadQuery = (store: GroqStore, query: string, params?: Params) => | ||
// eslint-disable-next-line no-warning-comments | ||
// @todo: fix the casting to any here | ||
store.query<any>(query, params) | ||
/** | ||
* @public | ||
@@ -247,5 +272,3 @@ */ | ||
suspend( | ||
// eslint-disable-next-line no-warning-comments | ||
// @todo: fix the casting to any here | ||
() => store.query<any>(query, params), | ||
() => _preloadQuery(store, query, params), | ||
[ | ||
@@ -252,0 +275,0 @@ '@sanity/preview-kit', |
@@ -0,1 +1,3 @@ | ||
'use client' | ||
export * from './auth' | ||
@@ -2,0 +4,0 @@ export * from './definePreview' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
76511
821