Socket
Socket
Sign inDemoInstall

@sanity/presentation

Package Overview
Dependencies
89
Maintainers
48
Versions
127
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.12.3 to 1.12.4

2

dist/_chunks-es/LoaderQueries.js

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

import{jsxs as e,Fragment as t,jsx as n}from"react/jsx-runtime";import{applySourceDocuments as r,getPublishedId as s}from"@sanity/client/csm";import{useMemo as o,useState as c,useEffect as a,useSyncExternalStore as i,useCallback as u,memo as l}from"react";import{applyPatch as d}from"mendoza";import p from"mnemonist/lru-cache-with-delete";import{useClient as f}from"sanity";import{L as m,d as h}from"./index.js";function v(e){return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)}function w(r){const{liveDocument:s,channel:i,perspective:u,liveQueries:l,documentsOnPage:d}=r,[h]=c((()=>new p(m))),v=f({apiVersion:"2023-10-16"}),w=o((()=>v.config()),[v]),g=o((()=>v.withConfig({resultSourceMap:"withKeyArraySelector"})),[v]);a((()=>{if(i){const{projectId:e,dataset:t}=w;i.send("loaders","loader/perspective",{projectId:e,dataset:t,perspective:u})}}),[i,w,u]);const L=o((()=>{const e=d.map((({_id:e})=>e)),t=[...new Set(e)],n=h.capacity;return t.length>=n&&(t.length=n),t}),[h.capacity,d]),[S,b]=c(0);return e(t,{children:[n(y,{cache:h,client:g,turboIds:L,setDocumentsCacheLastUpdated:b}),Object.entries(l).map((([e,{query:t,params:r,perspective:o}])=>n(I,{cache:h,projectId:w.projectId,dataset:w.dataset,perspective:o,query:t,params:r,channel:i,client:g,refreshInterval:u?2e3:0,liveDocument:s,documentsCacheLastUpdated:S},`${e}${o}`)))]})}const y=l((function(e){const{cache:r,client:s,turboIds:o,setDocumentsCacheLastUpdated:i}=e,[u,l]=c([]);return a((()=>{const e=new Set(u.flat()),t=new Set;for(const n of o)!e.has(n)&&!r.has(n)&&t.add(n);const n=[...t].slice(0,h);0!==n.length&&l((e=>[...e.slice(-h),n]))}),[u,r,o]),a((()=>{const e=s.listen("*",{},{events:["mutation"],effectFormat:"mendoza",includePreviousRevision:!1,includeResult:!1,tag:"presentation-loader"}).subscribe((e=>{var t,n;if("mutation"===e.type&&"disappear"===e.transition&&r.delete(e.documentId)&&i(Date.now()),"mutation"!==e.type||null==(n=null==(t=e.effects)?void 0:t.apply)||!n.length)return;const s=r.peek(e.documentId);if(s){const t={...s};delete t._rev;const n=d(t,e.effects.apply);r.set(e.documentId,n),i(Date.now())}}));return()=>e.unsubscribe()}),[r,s,i]),n(t,{children:u.map((e=>n(g,{cache:r,client:s,ids:e,setDocumentsCacheLastUpdated:i},JSON.stringify(e))))})})),g=l((function(e){const{client:t,cache:n,ids:r,setDocumentsCacheLastUpdated:s}=e;return a((()=>{const e=r.filter((e=>!n.has(e)));0!==e.length&&t.getDocuments(e).then((e=>{for(const t of e)t&&null!=t&&t._id&&(n.set(t._id,t),s(Date.now()))}),console.error)}),[n,t,r,s]),null}));function I(e){const{cache:t,projectId:n,dataset:r,perspective:s,query:l,client:d,refreshInterval:p,liveDocument:f,channel:m,documentsCacheLastUpdated:h}=e,w=function(e){const t=o((()=>JSON.stringify(e||{})),[e]);return o((()=>JSON.parse(t)),[t])}(e.params),y=function(e){const{cache:t,liveDocument:n,client:r,refreshInterval:s,query:l,params:d,perspective:p,documentsCacheLastUpdated:f}=e,[m,h]=c(null),{projectId:w,dataset:y}=o((()=>{const{projectId:e,dataset:t}=r.config();return{projectId:e,dataset:t}}),[r]),[g,I]=c(null);if(g)throw g;const[L,b]=function(e){const{refreshInterval:t}=e,n=function(){const[e,t]=c(!1);a((()=>{t(navigator.onLine);const e=()=>t(!0),n=()=>t(!1);return window.addEventListener("online",e),window.addEventListener("offline",n),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",n)}}),[]);const n=i(v,(()=>document.visibilityState),(()=>"hidden"));return!e||"hidden"===n}(),[r,s]=c("hit"),o=u((()=>(s("inflight"),()=>s("hit"))),[]);return a((()=>{if(!t||"hit"!==r)return;const e=setTimeout((()=>s("stale")),t);return()=>clearTimeout(e)}),[t,r]),a((()=>{if("hit"!==r)return;const e=()=>s("stale");return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)}),[t,r]),a((()=>{n&&"hit"===r&&s("stale"),!n&&"stale"===r&&s("refresh")}),[n,r]),[r,o]}({refreshInterval:s}),D="refresh"===L||"inflight"===L;return a((()=>{if(!D)return;let e=!1,t=!1;const n=new AbortController;async function s(){const{signal:s}=n;t=!0;const{result:o,resultSourceMap:c}=await r.fetch(l,d,{tag:"presentation-loader",signal:s,perspective:p,filterResponse:!1});t=!1,s.aborted||(h({result:o,resultSourceMap:c}),e=!0)}const o=b();return s().catch((e=>{t=!1,"AbortError"!==e.name&&I(e)})).finally(o),()=>{!e&&!t&&n.abort()}}),[r,y,n,d,p,w,l,D,b]),o((()=>f&&null!=m&&m.resultSourceMap?{result:S(t,n,m.result,p,m.resultSourceMap),resultSourceMap:m.resultSourceMap}:m),[t,f,n,p,m])}({cache:t,client:d,liveDocument:f,params:w,perspective:s,query:l,refreshInterval:p,documentsCacheLastUpdated:h}),g=null==y?void 0:y.result,I=null==y?void 0:y.resultSourceMap;return a((()=>{I&&m.send("loaders","loader/query-change",{projectId:n,dataset:r,perspective:s,query:l,params:w,result:g,resultSourceMap:I})}),[m,r,w,s,n,l,g,I]),null}g.displayName="GetDocuments";let L=!1;function S(e,t,n,o,c){if("raw"===o)throw new Error("turboChargeResultIfSourceMap does not support raw perspective");return r(n,c,(n=>{if(!n._projectId)return null!=t&&t._id&&s(t._id)===s(n._id)?t:e.get(n._id);L||(console.warn("Cross dataset references are not supported yet, ignoring source document",n),L=!0)}),((e,{previousValue:t})=>"number"==typeof e&&"string"==typeof t?`${e}`:e),o)}export{w as default,S as turboChargeResultIfSourceMap};//# sourceMappingURL=LoaderQueries.js.map
import{jsxs as e,Fragment as t,jsx as n}from"react/jsx-runtime";import{useMemo as r,useState as s,useEffect as o,useSyncExternalStore as c,useCallback as a,memo as i}from"react";import{applySourceDocuments as u,getPublishedId as l}from"@sanity/client/csm";import{applyPatch as d}from"mendoza";import p from"mnemonist/lru-cache-with-delete";import{useClient as f}from"sanity";import{L as m,d as h}from"./index.js";function v(e){return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)}function w(c){const{liveDocument:a,channel:i,perspective:u,liveQueries:l,documentsOnPage:d}=c,[h]=s((()=>new p(m))),v=f({apiVersion:"2023-10-16"}),w=r((()=>v.config()),[v]),g=r((()=>v.withConfig({resultSourceMap:"withKeyArraySelector"})),[v]);o((()=>{if(i){const{projectId:e,dataset:t}=w;i.send("loaders","loader/perspective",{projectId:e,dataset:t,perspective:u})}}),[i,w,u]);const L=r((()=>{const e=d.map((({_id:e})=>e)),t=[...new Set(e)],n=h.capacity;return t.length>=n&&(t.length=n),t}),[h.capacity,d]),[S,b]=s(0);return e(t,{children:[n(y,{cache:h,client:g,turboIds:L,setDocumentsCacheLastUpdated:b}),Object.entries(l).map((([e,{query:t,params:r,perspective:s}])=>n(I,{cache:h,projectId:w.projectId,dataset:w.dataset,perspective:s,query:t,params:r,channel:i,client:g,refreshInterval:u?2e3:0,liveDocument:a,documentsCacheLastUpdated:S},`${e}${s}`)))]})}const y=i((function(e){const{cache:r,client:c,turboIds:a,setDocumentsCacheLastUpdated:i}=e,[u,l]=s([]);return o((()=>{const e=new Set(u.flat()),t=new Set;for(const n of a)!e.has(n)&&!r.has(n)&&t.add(n);const n=[...t].slice(0,h);0!==n.length&&l((e=>[...e.slice(-h),n]))}),[u,r,a]),o((()=>{const e=c.listen("*",{},{events:["mutation"],effectFormat:"mendoza",includePreviousRevision:!1,includeResult:!1,tag:"presentation-loader"}).subscribe((e=>{var t,n;if("mutation"===e.type&&"disappear"===e.transition&&r.delete(e.documentId)&&i(Date.now()),"mutation"!==e.type||null==(n=null==(t=e.effects)?void 0:t.apply)||!n.length)return;const s=r.peek(e.documentId);if(s){const t={...s};delete t._rev;const n=d(t,e.effects.apply);r.set(e.documentId,n),i(Date.now())}}));return()=>e.unsubscribe()}),[r,c,i]),n(t,{children:u.map((e=>n(g,{cache:r,client:c,ids:e,setDocumentsCacheLastUpdated:i},JSON.stringify(e))))})})),g=i((function(e){const{client:t,cache:n,ids:r,setDocumentsCacheLastUpdated:s}=e;return o((()=>{const e=r.filter((e=>!n.has(e)));0!==e.length&&t.getDocuments(e).then((e=>{for(const t of e)t&&null!=t&&t._id&&(n.set(t._id,t),s(Date.now()))}),console.error)}),[n,t,r,s]),null}));function I(e){const{cache:t,projectId:n,dataset:i,perspective:u,query:l,client:d,refreshInterval:p,liveDocument:f,channel:m,documentsCacheLastUpdated:h}=e,w=function(e){const t=r((()=>JSON.stringify(e||{})),[e]);return r((()=>JSON.parse(t)),[t])}(e.params),y=function(e){const{cache:t,liveDocument:n,client:i,refreshInterval:u,query:l,params:d,perspective:p,documentsCacheLastUpdated:f}=e,[m,h]=s(null),{projectId:w,dataset:y}=r((()=>{const{projectId:e,dataset:t}=i.config();return{projectId:e,dataset:t}}),[i]),[g,I]=s(null);if(g)throw g;const[L,b]=function(e){const{refreshInterval:t}=e,n=function(){const[e,t]=s(!1);o((()=>{t(navigator.onLine);const e=()=>t(!0),n=()=>t(!1);return window.addEventListener("online",e),window.addEventListener("offline",n),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",n)}}),[]);const n=c(v,(()=>document.visibilityState),(()=>"hidden"));return!e||"hidden"===n}(),[r,i]=s("hit"),u=a((()=>(i("inflight"),()=>i("hit"))),[]);return o((()=>{if(!t||"hit"!==r)return;const e=setTimeout((()=>i("stale")),t);return()=>clearTimeout(e)}),[t,r]),o((()=>{if("hit"!==r)return;const e=()=>i("stale");return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)}),[t,r]),o((()=>{n&&"hit"===r&&i("stale"),!n&&"stale"===r&&i("refresh")}),[n,r]),[r,u]}({refreshInterval:u}),D="refresh"===L||"inflight"===L;return o((()=>{if(!D)return;let e=!1,t=!1;const n=new AbortController;async function r(){const{signal:r}=n;t=!0;const{result:s,resultSourceMap:o}=await i.fetch(l,d,{tag:"presentation-loader",signal:r,perspective:p,filterResponse:!1});t=!1,r.aborted||(h({result:s,resultSourceMap:o}),e=!0)}const s=b();return r().catch((e=>{t=!1,"AbortError"!==e.name&&I(e)})).finally(s),()=>{!e&&!t&&n.abort()}}),[i,y,n,d,p,w,l,D,b]),r((()=>f&&null!=m&&m.resultSourceMap?{result:S(t,n,m.result,p,m.resultSourceMap),resultSourceMap:m.resultSourceMap}:m),[t,f,n,p,m])}({cache:t,client:d,liveDocument:f,params:w,perspective:u,query:l,refreshInterval:p,documentsCacheLastUpdated:h}),g=null==y?void 0:y.result,I=null==y?void 0:y.resultSourceMap;return o((()=>{I&&m.send("loaders","loader/query-change",{projectId:n,dataset:i,perspective:u,query:l,params:w,result:g,resultSourceMap:I})}),[m,i,w,u,n,l,g,I]),null}g.displayName="GetDocuments";let L=!1;function S(e,t,n,r,s){if("raw"===r)throw new Error("turboChargeResultIfSourceMap does not support raw perspective");return u(n,s,(n=>{if(!n._projectId)return null!=t&&t._id&&l(t._id)===l(n._id)?t:e.get(n._id);L||(console.warn("Cross dataset references are not supported yet, ignoring source document",n),L=!0)}),((e,{previousValue:t})=>"number"==typeof e&&"string"==typeof t?`${e}`:e),r)}export{w as default,S as turboChargeResultIfSourceMap};//# sourceMappingURL=LoaderQueries.js.map
{
"name": "@sanity/presentation",
"version": "1.12.3",
"version": "1.12.4",
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/presentation#readme",

@@ -28,3 +28,2 @@ "bugs": {

"module": "./dist/index.js",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",

@@ -101,5 +100,5 @@ "files": [

"dependencies": {
"@sanity/icons": "^2.11.7",
"@sanity/preview-url-secret": "^1.6.7",
"@sanity/ui": "^2.0.15",
"@sanity/icons": "^2.11.8",
"@sanity/preview-url-secret": "^1.6.8",
"@sanity/ui": "^2.1.3",
"@sanity/uuid": "3.0.2",

@@ -110,3 +109,3 @@ "@types/lodash.isequal": "^4.5.8",

"lodash.isequal": "^4.5.0",
"mendoza": "3.0.6",
"mendoza": "3.0.7",
"mnemonist": "0.39.8",

@@ -117,16 +116,17 @@ "rxjs": "^7.8.1",

"devDependencies": {
"@sanity/channels": "0.4.0",
"@sanity/client": "^6.15.11",
"@sanity/pkg-utils": "^5.1.11",
"@sanity/visual-editing-helpers": "0.6.4",
"happy-dom": "^14.5.1",
"@repo/channels": "0.4.0",
"@repo/visual-editing-helpers": "0.6.5",
"@sanity/client": "^6.15.14",
"@sanity/pkg-utils": "6.6.5",
"happy-dom": "^14.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sanity": "^3.36.4",
"sanity": "^3.37.2",
"styled-components": "6.1.8",
"typescript": "5.4.2",
"vitest": "^1.4.0"
"typescript": "5.4.5",
"vitest": "^1.5.0",
"@repo/package.config": "0.0.0"
},
"peerDependencies": {
"@sanity/client": "^6.15.11"
"@sanity/client": "^6.15.14"
},

@@ -140,4 +140,3 @@ "engines": {

"scripts": {
"prebuild": "rimraf dist",
"build": "pkg build --strict && pkg --strict",
"build": "pkg build --strict --check --clean",
"lint": "eslint .",

@@ -144,0 +143,0 @@ "test": "vitest --typecheck",

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

import { urlStringToPath } from '@repo/visual-editing-helpers'
import { studioPath } from '@sanity/client/csm'
import { urlStringToPath } from '@sanity/visual-editing-helpers'

@@ -4,0 +4,0 @@ import type { PresentationStateParams } from '../types'

Sorry, the diff of this file is too big to display

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

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc