@sanity/preview-kit
Advanced tools
Comparing version 5.0.46 to 5.0.47-canary.0
@@ -1,6 +0,6 @@ | ||
import type { ClientConfig } from '@sanity/client' | ||
import type { ContentSourceMapParsedPathKeyedSegment } from '@sanity/client/csm' | ||
import type { RawQueryResponse } from '@sanity/client' | ||
import { SanityClient } from '@sanity/client' | ||
import type { StegaConfig } from '@sanity/client' | ||
import type {ClientConfig} from '@sanity/client' | ||
import type {ContentSourceMapParsedPathKeyedSegment} from '@sanity/client/csm' | ||
import type {RawQueryResponse} from '@sanity/client' | ||
import {SanityClient} from '@sanity/client' | ||
import type {StegaConfig} from '@sanity/client' | ||
@@ -16,5 +16,3 @@ /** @public */ | ||
*/ | ||
export declare const createClient: ( | ||
config: PreviewKitClientConfig, | ||
) => SanityClient | ||
export declare const createClient: (config: PreviewKitClientConfig) => SanityClient | ||
@@ -28,6 +26,3 @@ /** @public */ | ||
/** @public */ | ||
export declare type PathSegment = | ||
| string | ||
| number | ||
| ContentSourceMapParsedPathKeyedSegment | ||
export declare type PathSegment = string | number | ContentSourceMapParsedPathKeyedSegment | ||
@@ -113,3 +108,3 @@ /** @public */ | ||
export { StegaConfig } | ||
export {StegaConfig} | ||
@@ -116,0 +111,0 @@ export * from '@sanity/client' |
@@ -1,1 +0,1 @@ | ||
import{createClient as e}from"./createClient.js";export{e as createClient};//# sourceMappingURL=index.js.map | ||
import{createClient as e}from"@sanity/client";const r=r=>{var o,a;const{encodeSourceMap:c=t(),encodeSourceMapAtPath:i,studioUrl:u=n(),logger:l,...s}=r;let p=!0===c;if("auto"===c&&(p=function(){try{return"preview"===import.meta.env.VERCEL_ENV}catch{}try{return"preview"===process.env.VERCEL_ENV}catch{}return!1}()),"string"==typeof c&&"auto"!==c)throw new Error(`Invalid value for encodeSourceMap: ${c}. Did you mean 'auto'?`);try{if(p&&!1!==r.resultSourceMap)return u?(null==(a=null==l?void 0:l.debug)||a.call(l,"[@sanity/preview-kit]: Creating source map enabled client"),e({...s,resultSourceMap:r.resultSourceMap?r.resultSourceMap:"withKeyArraySelector",stega:{enabled:!0,studioUrl:u,logger:l,filter:i?e=>i({path:e.sourcePath,filterDefault:()=>e.filterDefault(e)}):void 0}})):(null==(o=null==l?void 0:l.error)||o.call(l,"[@sanity/preview-kit]: Content source map enabled client is enabled, but no studioUrl is provided. Falling back to @sanity/client"),e(s))}catch(e){console.error("[@sanity/preview-kit]: Error creating client",e,"falling back to non-embedded sourcemap mode")}return e(s)};function t(){try{return"true"===import.meta.env.SANITY_SOURCE_MAP}catch{}try{return"true"===process.env.SANITY_SOURCE_MAP}catch{}return!1}function n(){try{return import.meta.env.SANITY_STUDIO_URL}catch{}try{return process.env.SANITY_STUDIO_URL}catch{}}export{r as createClient};//# sourceMappingURL=index.js.map |
/// <reference types="react" /> | ||
import { LazyExoticComponent } from 'react' | ||
import { NamedExoticComponent } from 'react' | ||
import type { QueryParams } from '@sanity/client' | ||
import type { SanityClient } from '@sanity/client' | ||
import type { SanityStegaClient } from '@sanity/client/stega' | ||
import {LazyExoticComponent} from 'react' | ||
import {NamedExoticComponent} from 'react' | ||
import type {QueryParams} from '@sanity/client' | ||
import type {SanityClient} from '@sanity/client' | ||
import type {SanityStegaClient} from '@sanity/client/stega' | ||
@@ -58,6 +58,3 @@ /** | ||
*/ | ||
export declare type isEqualFn<QueryResult> = ( | ||
a: QueryResult, | ||
b: QueryResult, | ||
) => boolean | ||
export declare type isEqualFn<QueryResult> = (a: QueryResult, b: QueryResult) => boolean | ||
@@ -72,5 +69,3 @@ /** | ||
*/ | ||
export declare type ListenerSubscribe = ( | ||
onStoreChange: () => void, | ||
) => () => void | ||
export declare type ListenerSubscribe = (onStoreChange: () => void) => () => void | ||
@@ -83,6 +78,4 @@ /** @public */ | ||
/** @public */ | ||
declare const LiveQueryProvider: LazyExoticComponent< | ||
NamedExoticComponent<LiveQueryProviderProps> | ||
> | ||
export { LiveQueryProvider } | ||
declare const LiveQueryProvider: LazyExoticComponent<NamedExoticComponent<LiveQueryProviderProps>> | ||
export {LiveQueryProvider} | ||
export default LiveQueryProvider | ||
@@ -123,5 +116,3 @@ | ||
*/ | ||
export declare type Logger = | ||
| typeof console | ||
| Pick<typeof console, 'warn' | 'error' | 'log'> | ||
export declare type Logger = typeof console | Pick<typeof console, 'warn' | 'error' | 'log'> | ||
@@ -145,6 +136,3 @@ /** @public */ | ||
/** @public */ | ||
export declare function useLiveQuery< | ||
QueryResult, | ||
QueryParams extends QueryParams = QueryParams, | ||
>( | ||
export declare function useLiveQuery<QueryResult, QueryParams extends QueryParams = QueryParams>( | ||
initialData: QueryResult, | ||
@@ -151,0 +139,0 @@ query: string, |
@@ -1,1 +0,19 @@ | ||
import{useIsEnabled as r,useLiveQuery as e}from"./hooks.js";import{LiveQueryProvider as o,createLiveQueryProvider as i,LiveQueryProvider as s}from"./LiveQueryProvider/index.js";export{o as LiveQueryProvider,i as createLiveQueryProvider,s as default,r as useIsEnabled,e as useLiveQuery};//# sourceMappingURL=index.js.map | ||
import{useQueryParams as e}from"@sanity/preview-kit-compat";import r,{useContext as t,useMemo as n,useState as u,useCallback as o,lazy as i}from"react";import{d as a}from"./_chunks-es/context.js";function f(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s=typeof Element<"u",c="function"==typeof Map,l="function"==typeof Set,p="function"==typeof ArrayBuffer&&!!ArrayBuffer.isView;function v(e,r){if(e===r)return!0;if(e&&r&&"object"==typeof e&&"object"==typeof r){if(e.constructor!==r.constructor)return!1;var t,n,u,o;if(Array.isArray(e)){if((t=e.length)!=r.length)return!1;for(n=t;0!=n--;)if(!v(e[n],r[n]))return!1;return!0}if(c&&e instanceof Map&&r instanceof Map){if(e.size!==r.size)return!1;for(o=e.entries();!(n=o.next()).done;)if(!r.has(n.value[0]))return!1;for(o=e.entries();!(n=o.next()).done;)if(!v(n.value[1],r.get(n.value[0])))return!1;return!0}if(l&&e instanceof Set&&r instanceof Set){if(e.size!==r.size)return!1;for(o=e.entries();!(n=o.next()).done;)if(!r.has(n.value[0]))return!1;return!0}if(p&&ArrayBuffer.isView(e)&&ArrayBuffer.isView(r)){if((t=e.length)!=r.length)return!1;for(n=t;0!=n--;)if(e[n]!==r[n])return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf&&"function"==typeof e.valueOf&&"function"==typeof r.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString&&"function"==typeof e.toString&&"function"==typeof r.toString)return e.toString()===r.toString();if((t=(u=Object.keys(e)).length)!==Object.keys(r).length)return!1;for(n=t;0!=n--;)if(!Object.prototype.hasOwnProperty.call(r,u[n]))return!1;if(s&&e instanceof Element)return!1;for(n=t;0!=n--;)if(("_owner"!==u[n]&&"__v"!==u[n]&&"__o"!==u[n]||!e.$$typeof)&&!v(e[u[n]],r[u[n]]))return!1;return!0}return e!=e&&r!=r}var O,_=f((function(e,r){try{return v(e,r)}catch(e){if((e.message||"").match(/stack|recursion/i))return console.warn("react-fast-compare cannot handle circular refs"),!1;throw e}})),y={exports:{}},S={}; | ||
/** | ||
* @license React | ||
* use-sync-external-store-with-selector.production.min.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/var h,d={}; | ||
/** | ||
* @license React | ||
* use-sync-external-store-with-selector.development.js | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/"production"===process.env.NODE_ENV?y.exports=function(){if(O)return S;O=1;var e=r,t="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},n=e.useSyncExternalStore,u=e.useRef,o=e.useEffect,i=e.useMemo,a=e.useDebugValue;return S.useSyncExternalStoreWithSelector=function(e,r,f,s,c){var l=u(null);if(null===l.current){var p={hasValue:!1,value:null};l.current=p}else p=l.current;l=i((function(){function e(e){if(!o){if(o=!0,n=e,e=s(e),void 0!==c&&p.hasValue){var r=p.value;if(c(r,e))return u=r}return u=e}if(r=u,t(n,e))return r;var i=s(e);return void 0!==c&&c(r,i)?r:(n=e,u=i)}var n,u,o=!1,i=void 0===f?null:f;return[function(){return e(r())},null===i?void 0:function(){return e(i())}]}),[r,f,s,c]);var v=n(e,l[0],l[1]);return o((function(){p.hasValue=!0,p.value=v}),[v]),a(v),v},S}():y.exports=(h||(h=1,"production"!==process.env.NODE_ENV&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=r,t="function"==typeof Object.is?Object.is:function(e,r){return e===r&&(0!==e||1/e==1/r)||e!=e&&r!=r},n=e.useSyncExternalStore,u=e.useRef,o=e.useEffect,i=e.useMemo,a=e.useDebugValue;d.useSyncExternalStoreWithSelector=function(e,r,f,s,c){var l,p=u(null);null===p.current?(l={hasValue:!1,value:null},p.current=l):l=p.current;var v=i((function(){var e,n,u=!1,o=function(r){if(!u){u=!0,e=r;var o=s(r);if(void 0!==c&&l.hasValue){var i=l.value;if(c(i,o))return n=i,i}return n=o,o}var a=n;if(t(e,r))return a;var f=s(r);return void 0!==c&&c(a,f)?a:(e=r,n=f,f)},i=void 0===f?null:f;return[function(){return o(r())},null===i?void 0:function(){return o(i())}]}),[r,f,s,c]),O=v[0],_=v[1],y=n(e,O,_);return o((function(){l.hasValue=!0,l.value=y}),[y]),a(y),y},typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),d);var E=y.exports;function g(r,i,f,s){const{isEqual:c=_}=s||{},l=t(a),p=e(f),v=n((()=>({subscribe:()=>()=>{},getSnapshot:()=>r})),[r]),O=n((()=>(null==l?void 0:l(r,i,p))||{subscribe:()=>()=>{},getSnapshot:()=>r}),[l,r,p,i]),[y]=u((()=>{if(void 0===r)throw new Error("initialSnapshot can't be undefined, if you don't want an initial value use null instead");try{return JSON.parse(JSON.stringify(r))}catch(e){return console.warn("Failed to deep clone initialSnapshot, this is likely an error and an indication that the snapshot isn't JSON serializable",{initialSnapshot:r,error:e}),r}})),S=o((()=>y),[y]),h=o((e=>e),[]),d=E.useSyncExternalStoreWithSelector((null==O?void 0:O.subscribe)||v.subscribe,(null==O?void 0:O.getSnapshot)||v.getSnapshot,S,h,c),g=null!==l;return[d,g&&y===d,g]}function b(){return null!==t(a)}const L=i((()=>import("./_chunks-es/LiveQueryProvider.js")));function V(e){return L}export{L as LiveQueryProvider,V as createLiveQueryProvider,L as default,b as useIsEnabled,g as useLiveQuery};//# sourceMappingURL=index.js.map |
/// <reference types="react" /> | ||
import type { PropsWithChildren } from 'react' | ||
import type { QueryParams } from '@sanity/client' | ||
import {LiveQueryClientComponentProps} from '@sanity/preview-kit/live-query/client-component' | ||
import type {QueryParams} from '@sanity/client' | ||
/** @public */ | ||
declare function LiveQuery< | ||
QueryResult, | ||
QueryParams extends QueryParams = QueryParams, | ||
>(props: LiveQueryProps<QueryResult, QueryParams>): React.ReactNode | ||
declare function LiveQuery<QueryResult, QueryParams extends QueryParams = QueryParams>( | ||
props: LiveQueryProps<QueryResult, QueryParams>, | ||
): React.ReactNode | ||
@@ -15,24 +14,10 @@ declare namespace LiveQuery { | ||
} | ||
export { LiveQuery } | ||
export {LiveQuery} | ||
export default LiveQuery | ||
/** @public */ | ||
export declare type LiveQueryClientComponentProps<QueryResult, QueryParams> = | ||
PropsWithChildren<{ | ||
/** | ||
* If a parent <LiveQueryProvider> is missing, then an error is thrown. | ||
* If you want to disable this behavior, set this prop to false. | ||
* @defaultValue true | ||
*/ | ||
throwOnMissingProvider?: boolean | ||
initialData: QueryResult | ||
query: string | ||
params?: QueryParams | undefined | ||
}> | ||
export {LiveQueryClientComponentProps} | ||
/** @public */ | ||
export declare interface LiveQueryProps< | ||
QueryResult, | ||
QueryParams extends QueryParams = QueryParams, | ||
> extends LiveQueryClientComponentProps<QueryResult, QueryParams> { | ||
export declare interface LiveQueryProps<QueryResult, QueryParams extends QueryParams = QueryParams> | ||
extends LiveQueryClientComponentProps<QueryResult, QueryParams> { | ||
enabled: boolean | ||
@@ -39,0 +24,0 @@ as?: React.ComponentType<any> |
@@ -1,1 +0,1 @@ | ||
import{LiveQuery as e,LiveQuery as r}from"./LiveQuery.js";export{e as LiveQuery,r as default};//# sourceMappingURL=index.js.map | ||
import{jsx as r}from"react/jsx-runtime";import{lazy as i,Children as e,isValidElement as n}from"react";const a=i((()=>import("@sanity/preview-kit/live-query/client-component"))),t={};function o(i){if(!i.enabled)return i.children;const{query:o,params:l=t,initialData:s,as:c}=i;if(c){if(e.count(i.children)>1)throw new Error("LiveQuery: `as` prop can only be used with a single child");if(!n(i.children))throw new Error("LiveQuery: `as` prop requires a valid `children` prop");return r(a,{initialData:s,query:o,params:l,throwOnMissingProvider:i.throwOnMissingProvider,children:r(c,{...i.children.props})})}return r(a,{initialData:s,query:o,params:l,children:i.children})}o.displayName="LiveQuery";export{o as LiveQuery,o as default};//# sourceMappingURL=index.js.map |
{ | ||
"name": "@sanity/preview-kit", | ||
"version": "5.0.46", | ||
"version": "5.0.47-canary.0", | ||
"description": "General purpose utils for live content and visual editing", | ||
@@ -48,2 +48,8 @@ "keywords": [ | ||
}, | ||
"./live-query/client-component": { | ||
"source": "./src/live-query/client-component/index.ts", | ||
"import": "./dist/live-query/client-component/index.js", | ||
"require": "./dist/live-query/client-component/index.cjs", | ||
"default": "./dist/live-query/client-component/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
@@ -61,2 +67,5 @@ }, | ||
"./dist/live-query/index.d.ts" | ||
], | ||
"live-query/client-component": [ | ||
"./dist/live-query/client-component/index.d.ts" | ||
] | ||
@@ -68,24 +77,12 @@ } | ||
], | ||
"scripts": { | ||
"prebuild": "rimraf coverage dist || true", | ||
"build": "pkg build --strict && pkg --strict", | ||
"watch": "pnpm build watch", | ||
"coverage": "vitest run --coverage", | ||
"lint": "eslint --max-warnings 0 .", | ||
"prepublishOnly": "pnpm run build", | ||
"release": "semantic-release || semantic-release --dry-run --debug", | ||
"test": "vitest" | ||
}, | ||
"browserslist": "extends @sanity/browserslist-config", | ||
"prettier": { | ||
"semi": false, | ||
"singleQuote": true | ||
}, | ||
"prettier": "@sanity/prettier-config", | ||
"dependencies": { | ||
"@sanity/preview-kit-compat": "1.4.18", | ||
"@sanity/preview-kit-compat": "1.4.19", | ||
"mendoza": "3.0.7" | ||
}, | ||
"devDependencies": { | ||
"@sanity/client": "^6.15.19", | ||
"@sanity/pkg-utils": "6.8.1", | ||
"@sanity/client": "^6.15.20", | ||
"@sanity/pkg-utils": "6.8.3", | ||
"@sanity/prettier-config": "^1.0.2", | ||
"@sanity/semantic-release-preset": "^4.1.7", | ||
@@ -119,3 +116,3 @@ "@types/node": "^18.18.6", | ||
"peerDependencies": { | ||
"@sanity/client": "^6.15.19", | ||
"@sanity/client": "^6.15.20", | ||
"react": "^18.0.0" | ||
@@ -132,5 +129,13 @@ }, | ||
"publishConfig": { | ||
"access": "public", | ||
"provenance": true | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"prebuild": "rimraf coverage dist || true", | ||
"build": "pkg build --strict && pkg --strict", | ||
"coverage": "vitest run --coverage", | ||
"lint": "eslint --max-warnings 0 .", | ||
"release": "semantic-release || semantic-release --dry-run --debug", | ||
"test": "vitest", | ||
"watch": "pnpm build watch" | ||
} | ||
} | ||
} |
146
README.md
@@ -84,4 +84,4 @@ # @sanity/preview-kit<!-- omit in toc --> | ||
```ts | ||
import { createClient } from '@sanity/client' | ||
import type { QueryParams } from '@sanity/client' | ||
import {createClient} from '@sanity/client' | ||
import type {QueryParams} from '@sanity/client' | ||
@@ -98,4 +98,3 @@ // Shared on the server and the browser | ||
// Only defined on the server, passed to the browser via a `loader` | ||
export const token = | ||
typeof process === 'undefined' ? '' : process.env.SANITY_API_READ_TOKEN! | ||
export const token = typeof process === 'undefined' ? '' : process.env.SANITY_API_READ_TOKEN! | ||
@@ -115,5 +114,3 @@ const DEFAULT_PARAMS = {} as QueryParams | ||
if (previewDrafts && !token) { | ||
throw new Error( | ||
'The `SANITY_API_READ_TOKEN` environment variable is required.', | ||
) | ||
throw new Error('The `SANITY_API_READ_TOKEN` environment variable is required.') | ||
} | ||
@@ -140,4 +137,4 @@ return client.fetch<QueryResponse>( | ||
```tsx | ||
import { LiveQueryProvider } from '@sanity/preview-kit' | ||
import { client } from '~/lib/sanity' | ||
import {LiveQueryProvider} from '@sanity/preview-kit' | ||
import {client} from '~/lib/sanity' | ||
@@ -170,21 +167,21 @@ export default function PreviewProvider({ | ||
// app/routes/index.tsx | ||
import type { LoaderArgs } from '@vercel/remix' | ||
import { useLoaderData } from '@remix-run/react' | ||
import type {LoaderArgs} from '@vercel/remix' | ||
import {useLoaderData} from '@remix-run/react' | ||
import { client } from '~/lib/sanity' | ||
import type { UsersResponse } from '~/UsersList' | ||
import { UsersList, usersQuery } from '~/UsersList' | ||
import { Layout } from '~/ui' | ||
import {client} from '~/lib/sanity' | ||
import type {UsersResponse} from '~/UsersList' | ||
import {UsersList, usersQuery} from '~/UsersList' | ||
import {Layout} from '~/ui' | ||
export async function loader({ request }: LoaderArgs) { | ||
export async function loader({request}: LoaderArgs) { | ||
const url = new URL(request.url) | ||
const lastId = url.searchParams.get('lastId') || '' | ||
const users = await client.fetch<UsersResponse>(usersQuery, { lastId }) | ||
const users = await client.fetch<UsersResponse>(usersQuery, {lastId}) | ||
return { users, lastId } | ||
return {users, lastId} | ||
} | ||
export default function Index() { | ||
const { users, lastId } = useLoaderData<typeof loader>() | ||
const {users, lastId} = useLoaderData<typeof loader>() | ||
@@ -202,3 +199,3 @@ return ( | ||
```tsx | ||
import { lazy, Suspense } from 'react' | ||
import {lazy, Suspense} from 'react' | ||
@@ -213,3 +210,3 @@ const PreviewProvider = lazy(() => import('~/PreviewProvider')) | ||
```tsx | ||
import { token, sanityFetch } from '~/lib/sanity' | ||
import {token, sanityFetch} from '~/lib/sanity' | ||
@@ -220,3 +217,3 @@ const previewDrafts = process.env.SANITY_API_PREVIEW_DRAFTS === 'true' | ||
query: usersQuery, | ||
params: { lastId }, | ||
params: {lastId}, | ||
}) | ||
@@ -228,3 +225,3 @@ ``` | ||
```tsx | ||
return { previewDrafts, token, users, lastId } | ||
return {previewDrafts, token, users, lastId} | ||
``` | ||
@@ -235,3 +232,3 @@ | ||
```tsx | ||
const { previewDrafts, token, users, lastId } = useLoaderData<typeof loader>() | ||
const {previewDrafts, token, users, lastId} = useLoaderData<typeof loader>() | ||
``` | ||
@@ -261,16 +258,15 @@ | ||
// app/routes/index.tsx | ||
import type { LoaderArgs } from '@vercel/remix' | ||
import { useLoaderData } from '@remix-run/react' | ||
import { lazy, Suspense } from 'react' | ||
import type {LoaderArgs} from '@vercel/remix' | ||
import {useLoaderData} from '@remix-run/react' | ||
import {lazy, Suspense} from 'react' | ||
import { token, sanityFetch } from '~/lib/sanity' | ||
import type { UsersResponse } from '~/UsersList' | ||
import { UsersList, usersQuery } from '~/UsersList' | ||
import { Layout } from '~/ui' | ||
import {token, sanityFetch} from '~/lib/sanity' | ||
import type {UsersResponse} from '~/UsersList' | ||
import {UsersList, usersQuery} from '~/UsersList' | ||
import {Layout} from '~/ui' | ||
const PreviewProvider = lazy(() => import('~/PreviewProvider')) | ||
export async function loader({ request }: LoaderArgs) { | ||
const previewDrafts = | ||
process.env.SANITY_API_PREVIEW_DRAFTS === 'true' ? { token } : undefined | ||
export async function loader({request}: LoaderArgs) { | ||
const previewDrafts = process.env.SANITY_API_PREVIEW_DRAFTS === 'true' ? {token} : undefined | ||
const url = new URL(request.url) | ||
@@ -282,10 +278,10 @@ const lastId = url.searchParams.get('lastId') || '' | ||
query: usersQuery, | ||
params: { lastId }, | ||
params: {lastId}, | ||
}) | ||
return { previewDrafts, token, users, lastId } | ||
return {previewDrafts, token, users, lastId} | ||
} | ||
export default function Index() { | ||
const { previewDrafts, token, users, lastId } = useLoaderData<typeof loader>() | ||
const {previewDrafts, token, users, lastId} = useLoaderData<typeof loader>() | ||
@@ -316,3 +312,3 @@ const children = <UsersList data={users} lastId={lastId} /> | ||
import { ListView, ListPagination } from '~/ui' | ||
import {ListView, ListPagination} from '~/ui' | ||
@@ -335,3 +331,3 @@ export const usersQuery = groq`{ | ||
export function UsersList(props: UsersListProps) { | ||
const { data, lastId } = props | ||
const {data, lastId} = props | ||
@@ -359,3 +355,3 @@ return ( | ||
```tsx | ||
import { useLiveQuery } from '@sanity/preview-kit' | ||
import {useLiveQuery} from '@sanity/preview-kit' | ||
``` | ||
@@ -366,3 +362,3 @@ | ||
```tsx | ||
const { data, lastId } = props | ||
const {data, lastId} = props | ||
``` | ||
@@ -373,4 +369,4 @@ | ||
```tsx | ||
const { data: initialData, lastId } = props | ||
const [data] = useLiveQuery(initialData, usersQuery, { lastId }) | ||
const {data: initialData, lastId} = props | ||
const [data] = useLiveQuery(initialData, usersQuery, {lastId}) | ||
``` | ||
@@ -382,6 +378,6 @@ | ||
// app/UsersList.tsx | ||
import { useLiveQuery } from '@sanity/preview-kit' | ||
import {useLiveQuery} from '@sanity/preview-kit' | ||
import groq from 'groq' | ||
import { ListView, ListPagination } from '~/ui' | ||
import {ListView, ListPagination} from '~/ui' | ||
@@ -404,4 +400,4 @@ export const usersQuery = groq`{ | ||
export function UsersList(props: UsersListProps) { | ||
const { data: initialData, lastId } = props | ||
const [data] = useLiveQuery(initialData, usersQuery, { lastId }) | ||
const {data: initialData, lastId} = props | ||
const [data] = useLiveQuery(initialData, usersQuery, {lastId}) | ||
@@ -425,3 +421,3 @@ return ( | ||
export function UsersList(props: UsersListProps) { | ||
const { data, lastId } = props | ||
const {data, lastId} = props | ||
@@ -437,4 +433,4 @@ return ( | ||
export function PreviewUsersList(props: UsersListProps) { | ||
const { data: initialData, lastId } = props | ||
const [data, loading] = useLiveQuery(initialData, usersQuery, { lastId }) | ||
const {data: initialData, lastId} = props | ||
const [data, loading] = useLiveQuery(initialData, usersQuery, {lastId}) | ||
@@ -494,3 +490,3 @@ return ( | ||
usersQuery, | ||
{ lastId }, | ||
{lastId}, | ||
{ | ||
@@ -510,7 +506,7 @@ // Only re-render in real-time if user ids and names changed, ignore all other differences | ||
```tsx | ||
import { memo, useDeferredValue } from 'react' | ||
import {memo, useDeferredValue} from 'react' | ||
export function PreviewUsersList(props: UsersListProps) { | ||
const { data: initialData, lastId } = props | ||
const [snapshot] = useLiveQuery(initialData, usersQuery, { lastId }) | ||
const {data: initialData, lastId} = props | ||
const [snapshot] = useLiveQuery(initialData, usersQuery, {lastId}) | ||
const data = useDeferredValue(snapshot) | ||
@@ -522,3 +518,3 @@ | ||
export const UsersList = memo(function UsersList(props: UsersListProps) { | ||
const { data, lastId } = props | ||
const {data, lastId} = props | ||
@@ -541,6 +537,6 @@ return ( | ||
```tsx | ||
import { LiveQuery } from '@sanity/preview-kit/live-query' | ||
import {LiveQuery} from '@sanity/preview-kit/live-query' | ||
const UsersList = memo(function UsersList(props: UsersListProps) { | ||
const { data, lastId } = props | ||
const {data, lastId} = props | ||
@@ -560,3 +556,3 @@ return ( | ||
query={usersQuery} | ||
params={{ lastId: props.lastId }} | ||
params={{lastId: props.lastId}} | ||
initialData={props.data} | ||
@@ -583,3 +579,3 @@ > | ||
export default function UsersList(props: UsersListProps) { | ||
const { data, lastId } = props | ||
const {data, lastId} = props | ||
@@ -611,5 +607,5 @@ return ( | ||
```tsx | ||
import { createClient } from '@sanity/client' | ||
import { LiveQuery } from '@sanity/preview-kit/live-query' | ||
import { draftMode } from 'next/headers' | ||
import {createClient} from '@sanity/client' | ||
import {LiveQuery} from '@sanity/preview-kit/live-query' | ||
import {draftMode} from 'next/headers' | ||
import UsersList from './UsersList' | ||
@@ -623,7 +619,7 @@ import UsersListPreview from './UsersListPreview' | ||
export default async function UsersPage(params) { | ||
const { lastId } = params | ||
const {lastId} = params | ||
const data = await client.fetch( | ||
usersQuery, | ||
{ lastId }, | ||
{ perspective: draftMode().isEnabled ? 'previewDrafts' : 'published' }, | ||
{lastId}, | ||
{perspective: draftMode().isEnabled ? 'previewDrafts' : 'published'}, | ||
) | ||
@@ -635,3 +631,3 @@ | ||
query={usersQuery} | ||
params={{ lastId }} | ||
params={{lastId}} | ||
initialData={data} | ||
@@ -668,3 +664,3 @@ as={UsersListPreview} | ||
```tsx | ||
import { useLiveQuery, useIsEnabled } from '@sanity/preview-kit' | ||
import {useLiveQuery, useIsEnabled} from '@sanity/preview-kit' | ||
@@ -694,3 +690,3 @@ export function PreviewUsersList(props) { | ||
```tsx | ||
import { LiveQueryProvider } from '@sanity/preview-kit' | ||
import {LiveQueryProvider} from '@sanity/preview-kit' | ||
@@ -730,3 +726,3 @@ return ( | ||
// Use the enhanced client instead | ||
import { createClient, type ClientConfig } from '@sanity/preview-kit/client' | ||
import {createClient, type ClientConfig} from '@sanity/preview-kit/client' | ||
@@ -753,3 +749,3 @@ const config: ClientConfig = { | ||
```ts | ||
import { createClient } from '@sanity/preview-kit/client' | ||
import {createClient} from '@sanity/preview-kit/client' | ||
@@ -765,3 +761,3 @@ const client = createClient({ | ||
```ts | ||
import { createClient } from '@sanity/preview-kit/client' | ||
import {createClient} from '@sanity/preview-kit/client' | ||
@@ -779,3 +775,3 @@ const client = createClient({ | ||
```tsx | ||
import { createClient } from '@sanity/preview-kit/client' | ||
import {createClient} from '@sanity/preview-kit/client' | ||
@@ -795,3 +791,3 @@ const client = createClient({ | ||
```tsx | ||
import { createClient } from '@sanity/preview-kit/client' | ||
import {createClient} from '@sanity/preview-kit/client' | ||
@@ -815,3 +811,3 @@ const client = createClient({ | ||
```tsx | ||
import { createClient } from '@sanity/preview-kit/client' | ||
import {createClient} from '@sanity/preview-kit/client' | ||
@@ -860,3 +856,3 @@ const client = createClient({ | ||
const { result, resultSourceMap } = await client.fetch(query, params, { | ||
const {result, resultSourceMap} = await client.fetch(query, params, { | ||
filterResponse: false, | ||
@@ -863,0 +859,0 @@ }) |
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
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
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 5 instances in 1 package
6
436825
29
35
589
853
1
+ Added@sanity/preview-kit-compat@1.4.19(transitive)
- Removed@sanity/preview-kit-compat@1.4.18(transitive)