Socket
Socket
Sign inDemoInstall

@sanity/preview-kit

Package Overview
Dependencies
Maintainers
48
Versions
229
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/preview-kit - npm Package Compare versions

Comparing version 5.0.43 to 5.0.44

dist/_virtual/_commonjsHelpers.cjs

2

dist/hooks.js

@@ -1,1 +0,1 @@

import{useQueryParams as t}from"@sanity/preview-kit-compat";import{useContext as n,useMemo as i,useState as r,useCallback as e}from"react";import o from"react-fast-compare";import{useSyncExternalStoreWithSelector as a}from"use-sync-external-store/with-selector.js";import{defineStoreContext as s}from"./context.js";function l(l,u,c,p){const{isEqual:h=o}=p||{},d=n(s),f=t(c),m=i((()=>({subscribe:()=>()=>{},getSnapshot:()=>l})),[l]),b=i((()=>(null==d?void 0:d(l,u,f))||{subscribe:()=>()=>{},getSnapshot:()=>l}),[d,l,f,u]),[S]=r((()=>{if(void 0===l)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(l))}catch(t){return console.warn("Failed to deep clone initialSnapshot, this is likely an error and an indication that the snapshot isn't JSON serializable",{initialSnapshot:l,error:t}),l}})),v=e((()=>S),[S]),w=e((t=>t),[]),y=a((null==b?void 0:b.subscribe)||m.subscribe,(null==b?void 0:b.getSnapshot)||m.getSnapshot,v,w,h),g=null!==d;return[y,g&&S===y,g]}function u(){return null!==n(s)}export{u as useIsEnabled,l as useLiveQuery};//# sourceMappingURL=hooks.js.map
import{useQueryParams as e}from"@sanity/preview-kit-compat";import{useContext as t,useMemo as n,useState as o,useCallback as r}from"react";import i from"./node_modules/.pnpm/react-fast-compare@3.2.2/node_modules/react-fast-compare/index.js";import{w as s}from"./node_modules/.pnpm/use-sync-external-store@1.2.0_react@18.2.0/node_modules/use-sync-external-store/with-selector.js";import{defineStoreContext as a}from"./context.js";function l(l,u,c,p){const{isEqual:d=i}=p||{},m=t(a),h=e(c),f=n((()=>({subscribe:()=>()=>{},getSnapshot:()=>l})),[l]),S=n((()=>(null==m?void 0:m(l,u,h))||{subscribe:()=>()=>{},getSnapshot:()=>l}),[m,l,h,u]),[b]=o((()=>{if(void 0===l)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(l))}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:l,error:e}),l}})),y=r((()=>b),[b]),w=r((e=>e),[]),v=s.useSyncExternalStoreWithSelector((null==S?void 0:S.subscribe)||f.subscribe,(null==S?void 0:S.getSnapshot)||f.getSnapshot,y,w,d),x=null!==m;return[v,x&&b===v,x]}function u(){return null!==t(a)}export{u as useIsEnabled,l as useLiveQuery};//# sourceMappingURL=hooks.js.map

@@ -1,1 +0,1 @@

import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{applySourceDocuments as n}from"@sanity/client/csm";import{useRevalidate as s,useDocumentsInUse as o}from"@sanity/preview-kit-compat";import{vercelStegaSplit as c}from"@vercel/stega";import{LRUCache as i}from"lru-cache";import{applyPatch as a}from"mendoza";import{memo as u,useState as l,useEffect as d,useCallback as f,startTransition as p,useMemo as m}from"react";import{defineStoreContext as h}from"../context.js";const g=new i({max:500}),y=u((function(r){const{children:n,refreshInterval:s=1e4,token:o}=r;if(!r.client)throw new Error("Missing a `client` prop with a configured Sanity client instance");const[c]=l((()=>{const{requestTagPrefix:e,resultSourceMap:t}=r.client.config();return r.client.withConfig({requestTagPrefix:e||"sanity.preview-kit",resultSourceMap:"withKeyArraySelector"!==t||"withKeyArraySelector",...o&&{token:o,useCdn:!1,perspective:"previewDrafts",ignoreBrowserTokenWarning:!0}})})),[i]=l((()=>r.logger));d((()=>{i&&i.log(`[@sanity/preview-kit]: With the current configuration you can expect that: Updates that can be traced using Content Source Maps will be applied in real-time. Other updates will be applied every ${s}ms.`)}),[i,s]);const[a,u]=l([]),[g]=l((()=>new Map)),y=function(e){const[t]=l((()=>new Map)),r=f(((r,n,s,o)=>{t.has(r)||(t.set(r,{query:n,params:s,listeners:new Set}),p((()=>e((e=>e.includes(r)?e:[...e,r])))));const c=t.get(r);if(!c||!c.listeners)throw new TypeError("Inconsistent cache for key: "+r);const{listeners:i}=c;return i.add(o),()=>{i.delete(o),0===i.size&&(t.delete(r),p((()=>e((e=>e.includes(r)?e.filter((e=>e!==r)):e)))))}}),[t,e]);return m((()=>({cache:t,subscribe:r})),[t,r])}(u),[w]=l((()=>function(e,t,r){const n=j(t,r);return g.has(n)||g.set(n,{result:e,resultSourceMap:{}}),{subscribe:e=>{const s=y.subscribe(n,t,r,e);return()=>s()},getSnapshot:()=>{var e;return null==(e=g.get(n))?void 0:e.result}}})),[b,I]=l([]),[M]=l((()=>new Map)),N=f((e=>{var t;const r=new Set;if(M.clear(),null!=(t=e.documents)&&t.length)for(const t of e.documents)r.add(t._id),M.set(t._id,t);p((()=>I((e=>{const t=Array.from(new Set([...e,...r]));return JSON.stringify(t.sort())===JSON.stringify(e.sort())?e:t}))))}),[M]);return e(h.Provider,{value:w,children:[n,t(S,{cache:y.cache,client:c,setTurboIds:I,snapshots:g,turboIds:b,docsInUse:M}),a.map((e=>{if(!y.cache.has(e))return null;const{query:r,params:n,listeners:o}=y.cache.get(e);return t(v,{client:c,listeners:o,params:n,query:r,refreshInterval:s,snapshots:g,turboIdsFromSourceMap:N},e)}))]})}));y.displayName="LiveStoreProvider";const v=u((function(e){const{client:t,refreshInterval:r,query:n,params:o,listeners:c,snapshots:i,turboIdsFromSourceMap:a}=e,{projectId:u,dataset:f}=m((()=>{const{projectId:e,dataset:r}=t.config();return{projectId:e,dataset:r}}),[t]),[p,h]=l(null);if(p)throw p;const[g,y]=s({refreshInterval:r}),v="refresh"===g||"inflight"===g;return d((()=>{if(!v)return;let e=!1;const r=new AbortController;const s=y();return async function(){const{signal:s}=r,{result:l,resultSourceMap:d}=await t.fetch(n,o,{signal:s,filterResponse:!1});if(!s.aborted){i.set(j(n,o),{result:M(u,f,l,d),resultSourceMap:null!=d?d:{}}),d&&a(d);for(const e of c.values())e();e=!0}}().catch((e=>{"AbortError"!==e.name&&h(e)})).finally(s),()=>{e||r.abort()}}),[t,f,c,o,u,n,v,i,y,a]),null}));function w(e,t,r){return`${e}-${t}-${r}`}v.displayName="QuerySubscription";const S=u((function(e){const{client:n,snapshots:s,cache:c,turboIds:i,setTurboIds:u,docsInUse:f}=e,{projectId:h,dataset:y}=m((()=>{const{projectId:e,dataset:t}=n.config();return{projectId:e,dataset:t}}),[n]);d((()=>{var e,t;const r=new Set;f.clear();for(const{query:n,params:o}of c.values()){const c=j(n,o),i=s.get(c);if(i&&null!=(t=null==(e=i.resultSourceMap)?void 0:e.documents)&&t.length)for(const e of i.resultSourceMap.documents)r.add(e._id),f.set(e._id,e)}const n=[...r].sort();JSON.stringify(i)!==JSON.stringify(n)&&p((()=>u(n)))}),[c,u,s,i,f]),o(f,h,y);const[v,S]=l([]);d((()=>{const e=new Set(v.flat()),t=new Set;for(const r of i)!e.has(r)&&!g.has(w(h,y,r))&&t.add(r);const r=[...t].slice(0,100);0!==r.length&&p((()=>S((e=>[...e.slice(-100),r]))))}),[v,y,h,i]);const[I,N]=l();return d((()=>{const e=n.listen("*",{},{events:["mutation"],effectFormat:"mendoza",includePreviousRevision:!1,includeResult:!1,tag:"turbo"}).subscribe((e=>{var t,r;if("mutation"!==e.type||null==(r=null==(t=e.effects)?void 0:t.apply)||!r.length)return;const n=w(h,y,e.documentId),s=g.peek(n);if(s){const t={...s};delete t._rev;const r=a(t,e.effects.apply);g.set(n,r)}p((()=>N(e.documentId)))}));return()=>e.unsubscribe()}),[n,y,h]),d((()=>{var e,t,r;if(!I||!i.includes(I))return;const n=[];for(const[r,o]of s.entries())null!=(t=null==(e=o.resultSourceMap)?void 0:e.documents)&&t.length&&(o.result=M(h,y,o.result,o.resultSourceMap),n.push(r));for(const e of n){const t=null==(r=c.get(e))?void 0:r.listeners;if(t)for(const e of t)e()}p((()=>N(void 0)))}),[c,y,I,h,s,i]),t(r,{children:v.map((e=>t(b,{client:n,projectId:h,dataset:y,ids:e},JSON.stringify(e))))})}));S.displayName="Turbo";const b=u((function(e){const{client:t,projectId:r,dataset:n,ids:s}=e;return d((()=>{const e=s.filter((e=>!g.has(w(r,n,e))));0!==e.length&&t.getDocuments(e).then((e=>{for(const t of e)t&&null!=t&&t._id&&g.set(w(r,n,t._id),t)}),console.error)}),[t,n,s,r]),null}));b.displayName="GetDocuments";let I=!1;function M(e,t,r,s){return s?n(r,s,(r=>{if(!r._projectId)return g.get(w(e,t,r._id));I||(console.warn("Cross dataset references are not supported yet, ignoring source document",r),I=!0)}),((e,{previousValue:t})=>{if("string"==typeof e&&"string"==typeof t){const{encoded:r}=c(t),{cleaned:n}=c(e);return`${r}${n}`}return e}),"previewDrafts"):r}function j(e,t){return`${e}-${JSON.stringify(t)}`}export{y as default};//# sourceMappingURL=LiveQueryProvider.js.map
import{jsxs as e,jsx as t,Fragment as r}from"react/jsx-runtime";import{applySourceDocuments as n}from"@sanity/client/csm";import{useRevalidate as s,useDocumentsInUse as o}from"@sanity/preview-kit-compat";import{vercelStegaSplit as c}from"../node_modules/.pnpm/@vercel_stega@0.1.0/node_modules/@vercel/stega/dist/index.js";import{LRUCache as i}from"../node_modules/.pnpm/lru-cache@10.2.0/node_modules/lru-cache/dist/esm/index.js";import{applyPatch as a}from"mendoza";import{memo as u,useState as l,useEffect as d,useCallback as f,startTransition as p,useMemo as m}from"react";import{defineStoreContext as h}from"../context.js";const g=new i({max:500}),y=u((function(r){const{children:n,refreshInterval:s=1e4,token:o}=r;if(!r.client)throw new Error("Missing a `client` prop with a configured Sanity client instance");const[c]=l((()=>{const{requestTagPrefix:e,resultSourceMap:t}=r.client.config();return r.client.withConfig({requestTagPrefix:e||"sanity.preview-kit",resultSourceMap:"withKeyArraySelector"!==t||"withKeyArraySelector",...o&&{token:o,useCdn:!1,perspective:"previewDrafts",ignoreBrowserTokenWarning:!0}})})),[i]=l((()=>r.logger));d((()=>{i&&i.log(`[@sanity/preview-kit]: With the current configuration you can expect that: Updates that can be traced using Content Source Maps will be applied in real-time. Other updates will be applied every ${s}ms.`)}),[i,s]);const[a,u]=l([]),[g]=l((()=>new Map)),y=function(e){const[t]=l((()=>new Map)),r=f(((r,n,s,o)=>{t.has(r)||(t.set(r,{query:n,params:s,listeners:new Set}),p((()=>e((e=>e.includes(r)?e:[...e,r])))));const c=t.get(r);if(!c||!c.listeners)throw new TypeError("Inconsistent cache for key: "+r);const{listeners:i}=c;return i.add(o),()=>{i.delete(o),0===i.size&&(t.delete(r),p((()=>e((e=>e.includes(r)?e.filter((e=>e!==r)):e)))))}}),[t,e]);return m((()=>({cache:t,subscribe:r})),[t,r])}(u),[S]=l((()=>function(e,t,r){const n=_(t,r);return g.has(n)||g.set(n,{result:e,resultSourceMap:{}}),{subscribe:e=>{const s=y.subscribe(n,t,r,e);return()=>s()},getSnapshot:()=>{var e;return null==(e=g.get(n))?void 0:e.result}}})),[b,I]=l([]),[M]=l((()=>new Map)),j=f((e=>{var t;const r=new Set;if(M.clear(),null!=(t=e.documents)&&t.length)for(const t of e.documents)r.add(t._id),M.set(t._id,t);p((()=>I((e=>{const t=Array.from(new Set([...e,...r]));return JSON.stringify(t.sort())===JSON.stringify(e.sort())?e:t}))))}),[M]);return e(h.Provider,{value:S,children:[n,t(w,{cache:y.cache,client:c,setTurboIds:I,snapshots:g,turboIds:b,docsInUse:M}),a.map((e=>{if(!y.cache.has(e))return null;const{query:r,params:n,listeners:o}=y.cache.get(e);return t(v,{client:c,listeners:o,params:n,query:r,refreshInterval:s,snapshots:g,turboIdsFromSourceMap:j},e)}))]})}));y.displayName="LiveStoreProvider";const v=u((function(e){const{client:t,refreshInterval:r,query:n,params:o,listeners:c,snapshots:i,turboIdsFromSourceMap:a}=e,{projectId:u,dataset:f}=m((()=>{const{projectId:e,dataset:r}=t.config();return{projectId:e,dataset:r}}),[t]),[p,h]=l(null);if(p)throw p;const[g,y]=s({refreshInterval:r}),v="refresh"===g||"inflight"===g;return d((()=>{if(!v)return;let e=!1;const r=new AbortController;const s=y();return async function(){const{signal:s}=r,{result:l,resultSourceMap:d}=await t.fetch(n,o,{signal:s,filterResponse:!1});if(!s.aborted){i.set(_(n,o),{result:M(u,f,l,d),resultSourceMap:null!=d?d:{}}),d&&a(d);for(const e of c.values())e();e=!0}}().catch((e=>{"AbortError"!==e.name&&h(e)})).finally(s),()=>{e||r.abort()}}),[t,f,c,o,u,n,v,i,y,a]),null}));function S(e,t,r){return`${e}-${t}-${r}`}v.displayName="QuerySubscription";const w=u((function(e){const{client:n,snapshots:s,cache:c,turboIds:i,setTurboIds:u,docsInUse:f}=e,{projectId:h,dataset:y}=m((()=>{const{projectId:e,dataset:t}=n.config();return{projectId:e,dataset:t}}),[n]);d((()=>{var e,t;const r=new Set;f.clear();for(const{query:n,params:o}of c.values()){const c=_(n,o),i=s.get(c);if(i&&null!=(t=null==(e=i.resultSourceMap)?void 0:e.documents)&&t.length)for(const e of i.resultSourceMap.documents)r.add(e._id),f.set(e._id,e)}const n=[...r].sort();JSON.stringify(i)!==JSON.stringify(n)&&p((()=>u(n)))}),[c,u,s,i,f]),o(f,h,y);const[v,w]=l([]);d((()=>{const e=new Set(v.flat()),t=new Set;for(const r of i)!e.has(r)&&!g.has(S(h,y,r))&&t.add(r);const r=[...t].slice(0,100);0!==r.length&&p((()=>w((e=>[...e.slice(-100),r]))))}),[v,y,h,i]);const[I,j]=l();return d((()=>{const e=n.listen("*",{},{events:["mutation"],effectFormat:"mendoza",includePreviousRevision:!1,includeResult:!1,tag:"turbo"}).subscribe((e=>{var t,r;if("mutation"!==e.type||null==(r=null==(t=e.effects)?void 0:t.apply)||!r.length)return;const n=S(h,y,e.documentId),s=g.peek(n);if(s){const t={...s};delete t._rev;const r=a(t,e.effects.apply);g.set(n,r)}p((()=>j(e.documentId)))}));return()=>e.unsubscribe()}),[n,y,h]),d((()=>{var e,t,r;if(!I||!i.includes(I))return;const n=[];for(const[r,o]of s.entries())null!=(t=null==(e=o.resultSourceMap)?void 0:e.documents)&&t.length&&(o.result=M(h,y,o.result,o.resultSourceMap),n.push(r));for(const e of n){const t=null==(r=c.get(e))?void 0:r.listeners;if(t)for(const e of t)e()}p((()=>j(void 0)))}),[c,y,I,h,s,i]),t(r,{children:v.map((e=>t(b,{client:n,projectId:h,dataset:y,ids:e},JSON.stringify(e))))})}));w.displayName="Turbo";const b=u((function(e){const{client:t,projectId:r,dataset:n,ids:s}=e;return d((()=>{const e=s.filter((e=>!g.has(S(r,n,e))));0!==e.length&&t.getDocuments(e).then((e=>{for(const t of e)t&&null!=t&&t._id&&g.set(S(r,n,t._id),t)}),console.error)}),[t,n,s,r]),null}));b.displayName="GetDocuments";let I=!1;function M(e,t,r,s){return s?n(r,s,(r=>{if(!r._projectId)return g.get(S(e,t,r._id));I||(console.warn("Cross dataset references are not supported yet, ignoring source document",r),I=!0)}),((e,{previousValue:t})=>{if("string"==typeof e&&"string"==typeof t){const{encoded:r}=c(t),{cleaned:n}=c(e);return`${r}${n}`}return e}),"previewDrafts"):r}function _(e,t){return`${e}-${JSON.stringify(t)}`}export{y as default};//# sourceMappingURL=LiveQueryProvider.js.map
{
"name": "@sanity/preview-kit",
"version": "5.0.43",
"version": "5.0.44",
"description": "General purpose utils for live content and visual editing",

@@ -83,11 +83,7 @@ "keywords": [

"@sanity/preview-kit-compat": "1.4.16",
"@vercel/stega": "0.1.0",
"lru-cache": "10.2.0",
"mendoza": "3.0.7",
"react-fast-compare": "3.2.2",
"use-sync-external-store": "1.2.0"
"mendoza": "3.0.7"
},
"devDependencies": {
"@sanity/client": "^6.15.14",
"@sanity/pkg-utils": "6.6.6",
"@sanity/client": "^6.15.17",
"@sanity/pkg-utils": "6.7.0",
"@sanity/semantic-release-preset": "^4.1.7",

@@ -100,2 +96,3 @@ "@types/node": "^18.18.6",

"@typescript-eslint/parser": "^7.7.0",
"@vercel/stega": "0.1.0",
"@vitest/coverage-v8": "^1.5.0",

@@ -109,7 +106,10 @@ "eslint": "^8.57.0",

"eslint-plugin-simple-import-sort": "^12.1.0",
"lru-cache": "10.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-fast-compare": "3.2.2",
"rimraf": "^5.0.1",
"semantic-release": "^23.0.8",
"typescript": "5.4.5",
"use-sync-external-store": "1.2.0",
"vitest": "^1.5.0",

@@ -119,3 +119,3 @@ "vitest-github-actions-reporter": "^0.11.1"

"peerDependencies": {
"@sanity/client": "^6.15.14",
"@sanity/client": "^6.15.17",
"react": "^18.0.0"

@@ -122,0 +122,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc