@sanity/preview-kit-compat
Advanced tools
Comparing version 1.5.5 to 1.5.6
@@ -39,2 +39,16 @@ <!-- markdownlint-disable --><!-- textlint-disable --> | ||
## [1.5.6](https://github.com/sanity-io/visual-editing/compare/preview-kit-compat-v1.5.5...preview-kit-compat-v1.5.6) (2024-08-12) | ||
### Bug Fixes | ||
* **deps:** update dependency @sanity/client to v6.21.2 ([#1749](https://github.com/sanity-io/visual-editing/issues/1749)) ([b9efdd2](https://github.com/sanity-io/visual-editing/commit/b9efdd2a672fdef518bc22a29a25992c938ba1ef)) | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* devDependencies | ||
* @repo/visual-editing-helpers bumped to 0.6.20 | ||
## [1.5.5](https://github.com/sanity-io/visual-editing/compare/preview-kit-compat-v1.5.4...preview-kit-compat-v1.5.5) (2024-08-02) | ||
@@ -41,0 +55,0 @@ |
@@ -1,1 +0,1 @@ | ||
import{useState as e,useEffect as n,useMemo as t,useSyncExternalStore as o,useCallback as i}from"react";let r;const s=new Uint8Array(16);function a(){if(!r&&(r=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!r))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return r(s)}const c=[];for(let e=0;e<256;++e)c.push((e+256).toString(16).slice(1));var d={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function u(e,n,t){if(d.randomUUID&&!n&&!e)return d.randomUUID();const o=(e=e||{}).random||(e.rng||a)();return o[6]=15&o[6]|64,o[8]=63&o[8]|128,function(e,n=0){return c[e[n+0]]+c[e[n+1]]+c[e[n+2]]+c[e[n+3]]+"-"+c[e[n+4]]+c[e[n+5]]+"-"+c[e[n+6]]+c[e[n+7]]+"-"+c[e[n+8]]+c[e[n+9]]+"-"+c[e[n+10]]+c[e[n+11]]+c[e[n+12]]+c[e[n+13]]+c[e[n+14]]+c[e[n+15]]}(o)}const f=["channel/disconnect","channel/response","channel/heartbeat"],l=["handshake/syn","handshake/syn-ack","handshake/ack"],p=e=>f.some((n=>n===e)),h=e=>l.some((n=>n===e)),y=({data:e={}})=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&!("domain"in e)&&["id","type","from","to"].every((n=>n in e))&&e.type.startsWith("handshake/");function m(e){const n=window.self!==window.top||window.opener,t={buffer:[],id:null,origin:null,source:null,status:"connecting"};function o(n,o){if(h(n)||p(n)||"connecting"!==t.status&&"reconnecting"!==t.status){if(t.id&&t.origin&&t.source){const i={connectionId:t.id,data:o,domain:"sanity/channels",from:e.id,id:u(),to:e.connectTo,type:n};try{t.source.postMessage(i,{targetOrigin:t.origin})}catch{throw new Error(`Failed to postMessage '${i.id}' on '${e.id}'`)}}}else t.buffer.push({type:n,data:o})}function i(n){if(y(n))console.error("Visual editing package mismatch detected! Please ensure you are using the latest version of Sanity Studio and any packages listed here:\nhttps://github.com/sanity-io/visual-editing");else if(function(n){const{data:t}=n;return"sanity/channels"===t.domain&&t.to===e.id&&t.from===e.connectTo&&"channel/response"!==t.type}(n)){const{data:e}=n;if(t.origin&&n.origin!==t.origin)return;if(n.source&&t.source!==n.source&&(t.source=n.source),h(e.type)&&e.data){if("handshake/syn"===e.type)return t.origin=n.origin,t.id=e.data.id,a("connecting"),void o("handshake/syn-ack",{id:t.id});if("handshake/ack"===e.type&&e.data.id===t.id)return void a("connected")}else if(e.connectionId===t.id&&n.origin===t.origin){if("channel/disconnect"===e.type)return void a("disconnected");{const n=[e.type,e.data];r.forEach((e=>{e(...n)})),o("channel/response",{responseTo:e.id})}return}}}const r=new Set;const s=new Set;function a(e){t.status=e,s.forEach((n=>{n(e)})),"connected"===e&&function(){const e=[...t.buffer];t.buffer.splice(0,t.buffer.length),e.forEach((({type:e,data:n})=>{o(e,n)}))}()}return window.addEventListener("message",i,!1),a("connecting"),{destroy:function(){["disconnected"].includes(t.status)||a("disconnected"),r.clear(),s.clear(),window.removeEventListener("message",i,!1)},inFrame:n,send:function(e,n){o(e,n)},subscribe:function(e){return r.add(e),()=>r.delete(e)},onStatusUpdate:function(e){return s.add(e),()=>s.delete(e)}}}function g(t,o,i){const[r,s]=e(),[a,c]=e(!1);n((()=>{if(window.self===window.top&&!window.opener)return;const e=m({id:"preview-kit",connectTo:"presentation"});e.onStatusUpdate((e=>{"connected"===e?c(!0):"disconnected"===e&&c(!1)}));const n=setTimeout((()=>s(e)),0);return()=>{clearTimeout(n),e.destroy(),s(void 0)}}),[i,o]);const d=JSON.stringify(Array.from(t.keys()));n((()=>{"[]"!==d&&r&&a&&r.send("preview-kit/documents",{projectId:o,dataset:i,perspective:"previewDrafts",documents:Array.from(t.values())})}),[d,r,a,i,t,o])}function w(e){const n=t((()=>JSON.stringify(e||{})),[e]);return t((()=>JSON.parse(n)),[n])}function v(t){const{refreshInterval:r}=t,s=function(){const[t,i]=e(!1);n((()=>{i(navigator.onLine);const e=()=>i(!0),n=()=>i(!1);return window.addEventListener("online",e),window.addEventListener("offline",n),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",n)}}),[]);const r=o(b,(()=>document.visibilityState),(()=>"hidden"));return!t||"hidden"===r}(),[a,c]=e("hit"),d=i((()=>(c("inflight"),()=>c("hit"))),[]);return n((()=>{if(!r||"hit"!==a)return;const e=setTimeout((()=>c("stale")),r);return()=>clearTimeout(e)}),[r,a]),n((()=>{if("hit"!==a)return;const e=()=>c("stale");return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)}),[r,a]),n((()=>{s&&"hit"===a&&c("stale"),!s&&"stale"===a&&c("refresh")}),[s,a]),[a,d]}function b(e){return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)}export{g as useDocumentsInUse,w as useQueryParams,v as useRevalidate};//# sourceMappingURL=index.js.map | ||
import{useState as e,useEffect as n,useMemo as t,useSyncExternalStore as o,useCallback as i}from"react";for(var r=[],s=0;s<256;++s)r.push((s+256).toString(16).slice(1));var a,c=new Uint8Array(16);function d(){if(!a&&!(a=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return a(c)}var u={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function f(e,n,t){if(u.randomUUID&&!n&&!e)return u.randomUUID();var o=(e=e||{}).random||(e.rng||d)();return o[6]=15&o[6]|64,o[8]=63&o[8]|128,function(e,n=0){return(r[e[n+0]]+r[e[n+1]]+r[e[n+2]]+r[e[n+3]]+"-"+r[e[n+4]]+r[e[n+5]]+"-"+r[e[n+6]]+r[e[n+7]]+"-"+r[e[n+8]]+r[e[n+9]]+"-"+r[e[n+10]]+r[e[n+11]]+r[e[n+12]]+r[e[n+13]]+r[e[n+14]]+r[e[n+15]]).toLowerCase()}(o)}const l=["channel/disconnect","channel/response","channel/heartbeat"],p=["handshake/syn","handshake/syn-ack","handshake/ack"],h=e=>l.some((n=>n===e)),y=e=>p.some((n=>n===e)),m=({data:e={}})=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&!("domain"in e)&&["id","type","from","to"].every((n=>n in e))&&e.type.startsWith("handshake/");function g(e){const n=window.self!==window.top||window.opener,t={buffer:[],id:null,origin:null,source:null,status:"connecting"};function o(n,o){if(y(n)||h(n)||"connecting"!==t.status&&"reconnecting"!==t.status){if(t.id&&t.origin&&t.source){const i={connectionId:t.id,data:o,domain:"sanity/channels",from:e.id,id:f(),to:e.connectTo,type:n};try{t.source.postMessage(i,{targetOrigin:t.origin})}catch{throw new Error(`Failed to postMessage '${i.id}' on '${e.id}'`)}}}else t.buffer.push({type:n,data:o})}function i(n){if(m(n))console.error("Visual editing package mismatch detected! Please ensure you are using the latest version of Sanity Studio and any packages listed here:\nhttps://github.com/sanity-io/visual-editing");else if(function(n){const{data:t}=n;return"sanity/channels"===t.domain&&t.to===e.id&&t.from===e.connectTo&&"channel/response"!==t.type}(n)){const{data:e}=n;if(t.origin&&n.origin!==t.origin)return;if(n.source&&t.source!==n.source&&(t.source=n.source),y(e.type)&&e.data){if("handshake/syn"===e.type)return t.origin=n.origin,t.id=e.data.id,a("connecting"),void o("handshake/syn-ack",{id:t.id});if("handshake/ack"===e.type&&e.data.id===t.id)return void a("connected")}else if(e.connectionId===t.id&&n.origin===t.origin){if("channel/disconnect"===e.type)return void a("disconnected");{const n=[e.type,e.data];r.forEach((e=>{e(...n)})),o("channel/response",{responseTo:e.id})}return}}}const r=new Set;const s=new Set;function a(e){t.status=e,s.forEach((n=>{n(e)})),"connected"===e&&function(){const e=[...t.buffer];t.buffer.splice(0,t.buffer.length),e.forEach((({type:e,data:n})=>{o(e,n)}))}()}return window.addEventListener("message",i,!1),a("connecting"),{destroy:function(){["disconnected"].includes(t.status)||a("disconnected"),r.clear(),s.clear(),window.removeEventListener("message",i,!1)},inFrame:n,send:function(e,n){o(e,n)},subscribe:function(e){return r.add(e),()=>r.delete(e)},onStatusUpdate:function(e){return s.add(e),()=>s.delete(e)}}}function w(t,o,i){const[r,s]=e(),[a,c]=e(!1);n((()=>{if(window.self===window.top&&!window.opener)return;const e=g({id:"preview-kit",connectTo:"presentation"});e.onStatusUpdate((e=>{"connected"===e?c(!0):"disconnected"===e&&c(!1)}));const n=setTimeout((()=>s(e)),0);return()=>{clearTimeout(n),e.destroy(),s(void 0)}}),[i,o]);const d=JSON.stringify(Array.from(t.keys()));n((()=>{"[]"!==d&&r&&a&&r.send("preview-kit/documents",{projectId:o,dataset:i,perspective:"previewDrafts",documents:Array.from(t.values())})}),[d,r,a,i,t,o])}function v(e){const n=t((()=>JSON.stringify(e||{})),[e]);return t((()=>JSON.parse(n)),[n])}function b(t){const{refreshInterval:r}=t,s=function(){const[t,i]=e(!1);n((()=>{i(navigator.onLine);const e=()=>i(!0),n=()=>i(!1);return window.addEventListener("online",e),window.addEventListener("offline",n),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",n)}}),[]);const r=o(k,(()=>document.visibilityState),(()=>"hidden"));return!t||"hidden"===r}(),[a,c]=e("hit"),d=i((()=>(c("inflight"),()=>c("hit"))),[]);return n((()=>{if(!r||"hit"!==a)return;const e=setTimeout((()=>c("stale")),r);return()=>clearTimeout(e)}),[r,a]),n((()=>{if("hit"!==a)return;const e=()=>c("stale");return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)}),[r,a]),n((()=>{s&&"hit"===a&&c("stale"),!s&&"stale"===a&&c("refresh")}),[s,a]),[a,d]}function k(e){return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)}export{w as useDocumentsInUse,v as useQueryParams,b as useRevalidate};//# sourceMappingURL=index.js.map |
{ | ||
"name": "@sanity/preview-kit-compat", | ||
"version": "1.5.5", | ||
"version": "1.5.6", | ||
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-kit-compat#readme", | ||
@@ -91,20 +91,20 @@ "bugs": { | ||
"devDependencies": { | ||
"@repo/channels": "0.4.0", | ||
"@repo/visual-editing-helpers": "0.6.19", | ||
"@sanity/client": "^6.21.1", | ||
"@sanity/client": "^6.21.2", | ||
"@sanity/pkg-utils": "6.9.3", | ||
"@types/react": "^18.3.3", | ||
"@typescript-eslint/eslint-plugin": "^7.13.1", | ||
"@typescript-eslint/parser": "^7.13.1", | ||
"@typescript-eslint/eslint-plugin": "^7.18.0", | ||
"@typescript-eslint/parser": "^7.18.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-simple-import-sort": "^12.1.0", | ||
"eslint-plugin-prettier": "^5.2.1", | ||
"eslint-plugin-simple-import-sort": "^12.1.1", | ||
"react": "^18.3.1", | ||
"typescript": "5.4.5", | ||
"vitest": "^1.6.0", | ||
"@repo/package.config": "0.0.0" | ||
"vitest": "^2.0.5", | ||
"@repo/channels": "0.4.0", | ||
"@repo/package.config": "0.0.0", | ||
"@repo/visual-editing-helpers": "0.6.20" | ||
}, | ||
"peerDependencies": { | ||
"@sanity/client": "^6.21.1", | ||
"@sanity/client": "^6.21.2", | ||
"react": "^18.3 || >=19.0.0-rc" | ||
@@ -120,6 +120,6 @@ }, | ||
"build": "pkg build --strict --check --clean", | ||
"dev": "pkg build --strict", | ||
"lint": "eslint .", | ||
"test": "vitest --pass-with-no-tests --typecheck", | ||
"watch": "pkg watch --strict" | ||
"test": "vitest --pass-with-no-tests --typecheck" | ||
} | ||
} |
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
80263