Socket
Socket
Sign inDemoInstall

@sanity/preview-kit-compat

Package Overview
Dependencies
Maintainers
42
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/preview-kit-compat - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

8

CHANGELOG.md
# Changelog
## [1.0.1](https://github.com/sanity-io/visual-editing/compare/preview-kit-compat-v1.0.0...preview-kit-compat-v1.0.1) (2023-11-16)
### Bug Fixes
* don't read `location` during render ([f2b0cc7](https://github.com/sanity-io/visual-editing/commit/f2b0cc7ffc7fdcffe7418565b75e857beaff1e37))
* set default `allowStudioOrigin` to same origin ([e1a115f](https://github.com/sanity-io/visual-editing/commit/e1a115f991930438fc968398a90f90f15de8b671))
## 1.0.0 (2023-11-16)

@@ -4,0 +12,0 @@

2

dist/index.d.ts

@@ -9,3 +9,3 @@ import type { ContentSourceMapDocuments } from '@sanity/client/csm'

documentsInUse: Map<string, ContentSourceMapDocuments[number]>,
allowStudioOrigin: string,
allowStudioOrigin: string | null,
projectId: string,

@@ -12,0 +12,0 @@ dataset: string,

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

import{useMemo as n,useState as e,useEffect as t}from"react";let o;const i=new Uint8Array(16);function a(){if(!o&&(o="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!o))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return o(i)}const s=[];for(let n=0;n<256;++n)s.push((n+256).toString(16).slice(1));var c={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function r(n,e,t){if(c.randomUUID&&!e&&!n)return c.randomUUID();const o=(n=n||{}).random||(n.rng||a)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,e){t=t||0;for(let n=0;n<16;++n)e[t+n]=o[n];return e}return function(n,e=0){return s[n[e+0]]+s[n[e+1]]+s[n[e+2]]+s[n[e+3]]+"-"+s[n[e+4]]+s[n[e+5]]+"-"+s[n[e+6]]+s[n[e+7]]+"-"+s[n[e+8]]+s[n[e+9]]+"-"+s[n[e+10]]+s[n[e+11]]+s[n[e+12]]+s[n[e+13]]+s[n[e+14]]+s[n[e+15]]}(o)}const d=1e3,f=3e3,u=["channel/disconnect","channel/response"],p=["handshake/syn","handshake/syn-ack","handshake/ack"],h=n=>Boolean(n)&&"object"==typeof n&&!Array.isArray(n),l=n=>u.some((e=>e===n)),g=n=>p.some((e=>e===n)),m=n=>"channel/heartbeat"===n;function y(n){const e=window.self!==window.top,t=n.connections.map((n=>({buffer:[],config:n,heartbeat:null,id:null,status:"fresh"})));function o(n){n.heartbeat&&window.clearInterval(n.heartbeat)}function i(e,t){const i=e.status;i!==t&&(e.status=t,n.onStatusUpdate?.(t,i,e),"connected"===t&&(function(n){const e=[...n.buffer];n.buffer.splice(0,n.buffer.length),e.forEach((({type:e,data:t})=>{a(n,e,t)}))}(e),function(n){if(o(n),n.config.heartbeat){const e="number"==typeof n.config.heartbeat?n.config.heartbeat:f;n.heartbeat=window.setInterval((()=>{u("channel/heartbeat",void 0,[n])}),e)}}(e)),"disconnected"===t&&o(e))}function a(e,o,i){return new Promise(((a,s)=>{const c={id:r(),type:o,connectionId:e.id,from:n.id,to:e.config.id,data:i},f=l(o),u=g(o),p=m(o),h=t.find((n=>n.id===e.id&&"connected"===n.status));if(f||u||p||h){if(!f||p){const t=setTimeout((()=>{c.connectionId===e.id?s({reason:`Received no response to message '${c.id}' on client '${n.id}'`,msg:c,connection:e}):a(c.id)}),d),o=n=>{const{data:e}=n;"channel/response"===e.type&&e.data?.responseTo&&e.data.responseTo===c.id&&(window.removeEventListener("message",o,!1),clearTimeout(t),a(c.id))};window.addEventListener("message",o,!1)}try{const n=u?"*":e.config.targetOrigin;return e.config.target.postMessage(c,{targetOrigin:n}),void((f||u)&&a(c.id))}catch(t){console.error("Failed to postMessage",t,{msg:c,connection:e}),s({reason:`Failed to postMessage '${c.id}' on client '${n.id}'`,msg:c,connection:e})}}"fresh"!==e.status&&"connecting"!==e.status||(e.buffer.push({type:o,data:i}),a(c.id)),s({reason:`Will not send message '${c.id}' on client '${n.id}'`,msg:c,connection:e})}))}function s(n,e,t){return Promise.allSettled(n.map((n=>a(n,e,t))))}function c(e){const o=function(e){const{source:o,origin:i,data:a}=e;if(h(a))return t.find((e=>n.id===a.to&&e.config.id===a.from&&e.config.target===o&&(e.config.targetOrigin===i||"*"===e.config.targetOrigin)&&(e.id===a.connectionId||g(a.type))))}(e);if(!o)return;const{data:s}=e;if(g(s.type))!function(n,e){if("handshake/syn"===e.data.type){const t=e.data.data?.id||n.id;n.id=t,a(n,"handshake/syn-ack",{id:t})}if("handshake/syn-ack"===e.data.type){const t=e.data.data?.id||n.id;n.id=t,i(n,"connected"),a(n,"handshake/ack",{id:t})}if("handshake/ack"===e.data.type){const t=e.data.data?.id||n.id;n.id=t,i(n,"connected")}}(o,e);else if("channel/disconnect"===s.type)i(o,"disconnected");else if("channel/response"===s.type);else{const e=[s.type,s.data];n.handler(...e),a(o,"channel/response",{responseTo:s.id})}}async function u(n,e,o){const a=await s(o||t,n,e);return a.forEach((n=>{if("rejected"===n.status){const e=t.find((e=>"connected"===e.status&&e.id===n.reason.connection.id));e&&i(e,"unhealthy")}})),a}return function(){window.addEventListener("message",c,!1);const n=t.filter((n=>["disconnected","fresh","unhealthy"].includes(n.status)));Promise.all(n.map((n=>(i(n,"connecting"),a(n,"handshake/syn",{id:r()})))))}(),{disconnect:function(){window.removeEventListener("message",c,!1);const n=t.filter((({status:n})=>"connecting"===n||"connected"===n));n.length&&(s(n,"channel/disconnect"),n.forEach((n=>{i(n,"disconnected")})))},inFrame:e,send:u}}function w(o,i,a,s){const c=n((()=>new URL(i,location.origin).origin),[i]),[r,d]=e(),[f,u]=e(!1);t((()=>{const n=y({id:"preview-kit",onStatusUpdate(n){"connected"===n?u(!0):"disconnected"!==n&&"unhealthy"!==n||u(!1)},connections:[{target:parent,targetOrigin:c,id:"presentation"}],handler:()=>{}}),e=setTimeout((()=>d(n)),0);return()=>{clearTimeout(e),n.disconnect(),d(void 0)}}),[s,a,c]);const p=JSON.stringify(Array.from(o.keys()));t((()=>{"[]"!==p&&r&&f&&r.send("preview-kit/documents",{projectId:a,dataset:s,perspective:"previewDrafts",documents:Array.from(o.values())})}),[p,r,f,s,o,a])}export{w as useDocumentsInUse};//# sourceMappingURL=index.js.map
import{useState as n,useEffect as e}from"react";let t;const o=new Uint8Array(16);function i(){if(!t&&(t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!t))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return t(o)}const a=[];for(let n=0;n<256;++n)a.push((n+256).toString(16).slice(1));var s={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function c(n,e,t){if(s.randomUUID&&!e&&!n)return s.randomUUID();const o=(n=n||{}).random||(n.rng||i)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,e){t=t||0;for(let n=0;n<16;++n)e[t+n]=o[n];return e}return function(n,e=0){return a[n[e+0]]+a[n[e+1]]+a[n[e+2]]+a[n[e+3]]+"-"+a[n[e+4]]+a[n[e+5]]+"-"+a[n[e+6]]+a[n[e+7]]+"-"+a[n[e+8]]+a[n[e+9]]+"-"+a[n[e+10]]+a[n[e+11]]+a[n[e+12]]+a[n[e+13]]+a[n[e+14]]+a[n[e+15]]}(o)}const r=1e3,d=3e3,f=["channel/disconnect","channel/response"],u=["handshake/syn","handshake/syn-ack","handshake/ack"],p=n=>Boolean(n)&&"object"==typeof n&&!Array.isArray(n),h=n=>f.some((e=>e===n)),l=n=>u.some((e=>e===n)),g=n=>"channel/heartbeat"===n;function m(n){const e=window.self!==window.top,t=n.connections.map((n=>({buffer:[],config:n,heartbeat:null,id:null,status:"fresh"})));function o(n){n.heartbeat&&window.clearInterval(n.heartbeat)}function i(e,t){const i=e.status;i!==t&&(e.status=t,n.onStatusUpdate?.(t,i,e),"connected"===t&&(function(n){const e=[...n.buffer];n.buffer.splice(0,n.buffer.length),e.forEach((({type:e,data:t})=>{a(n,e,t)}))}(e),function(n){if(o(n),n.config.heartbeat){const e="number"==typeof n.config.heartbeat?n.config.heartbeat:d;n.heartbeat=window.setInterval((()=>{u("channel/heartbeat",void 0,[n])}),e)}}(e)),"disconnected"===t&&o(e))}function a(e,o,i){return new Promise(((a,s)=>{const d={id:c(),type:o,connectionId:e.id,from:n.id,to:e.config.id,data:i},f=h(o),u=l(o),p=g(o),m=t.find((n=>n.id===e.id&&"connected"===n.status));if(f||u||p||m){if(!f||p){const t=setTimeout((()=>{d.connectionId===e.id?s({reason:`Received no response to message '${d.id}' on client '${n.id}'`,msg:d,connection:e}):a(d.id)}),r),o=n=>{const{data:e}=n;"channel/response"===e.type&&e.data?.responseTo&&e.data.responseTo===d.id&&(window.removeEventListener("message",o,!1),clearTimeout(t),a(d.id))};window.addEventListener("message",o,!1)}try{const n=u?"*":e.config.targetOrigin;return e.config.target.postMessage(d,{targetOrigin:n}),void((f||u)&&a(d.id))}catch(t){console.error("Failed to postMessage",t,{msg:d,connection:e}),s({reason:`Failed to postMessage '${d.id}' on client '${n.id}'`,msg:d,connection:e})}}"fresh"!==e.status&&"connecting"!==e.status||(e.buffer.push({type:o,data:i}),a(d.id)),s({reason:`Will not send message '${d.id}' on client '${n.id}'`,msg:d,connection:e})}))}function s(n,e,t){return Promise.allSettled(n.map((n=>a(n,e,t))))}function f(e){const o=function(e){const{source:o,origin:i,data:a}=e;if(p(a))return t.find((e=>n.id===a.to&&e.config.id===a.from&&e.config.target===o&&(e.config.targetOrigin===i||"*"===e.config.targetOrigin)&&(e.id===a.connectionId||l(a.type))))}(e);if(!o)return;const{data:s}=e;if(l(s.type))!function(n,e){if("handshake/syn"===e.data.type){const t=e.data.data?.id||n.id;n.id=t,a(n,"handshake/syn-ack",{id:t})}if("handshake/syn-ack"===e.data.type){const t=e.data.data?.id||n.id;n.id=t,i(n,"connected"),a(n,"handshake/ack",{id:t})}if("handshake/ack"===e.data.type){const t=e.data.data?.id||n.id;n.id=t,i(n,"connected")}}(o,e);else if("channel/disconnect"===s.type)i(o,"disconnected");else if("channel/response"===s.type);else{const e=[s.type,s.data];n.handler(...e),a(o,"channel/response",{responseTo:s.id})}}async function u(n,e,o){const a=await s(o||t,n,e);return a.forEach((n=>{if("rejected"===n.status){const e=t.find((e=>"connected"===e.status&&e.id===n.reason.connection.id));e&&i(e,"unhealthy")}})),a}return function(){window.addEventListener("message",f,!1);const n=t.filter((n=>["disconnected","fresh","unhealthy"].includes(n.status)));Promise.all(n.map((n=>(i(n,"connecting"),a(n,"handshake/syn",{id:c()})))))}(),{disconnect:function(){window.removeEventListener("message",f,!1);const n=t.filter((({status:n})=>"connecting"===n||"connected"===n));n.length&&(s(n,"channel/disconnect"),n.forEach((n=>{i(n,"disconnected")})))},inFrame:e,send:u}}function y(t,o,i,a){const[s,c]=n(),[r,d]=n(!1);e((()=>{const n=new URL(o||"/",location.origin).origin,e=m({id:"preview-kit",onStatusUpdate(n){"connected"===n?d(!0):"disconnected"!==n&&"unhealthy"!==n||d(!1)},connections:[{target:parent,targetOrigin:n,id:"presentation"}],handler:()=>{}}),t=setTimeout((()=>c(e)),0);return()=>{clearTimeout(t),e.disconnect(),c(void 0)}}),[o,a,i]);const f=JSON.stringify(Array.from(t.keys()));e((()=>{"[]"!==f&&s&&r&&s.send("preview-kit/documents",{projectId:i,dataset:a,perspective:"previewDrafts",documents:Array.from(t.values())})}),[f,s,r,a,t,i])}export{y as useDocumentsInUse};//# sourceMappingURL=index.js.map
{
"name": "@sanity/preview-kit-compat",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-kit-compat#readme",

@@ -59,2 +59,7 @@ "bugs": {

},
"settings": {
"react": {
"version": "detect"
}
},
"plugins": [

@@ -65,7 +70,2 @@ "@typescript-eslint",

],
"settings": {
"react": {
"version": "detect"
}
},
"extends": [

@@ -72,0 +72,0 @@ "plugin:react/recommended",

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