@sanity/preview-kit-compat
Advanced tools
Comparing version 1.3.3 to 1.4.0
@@ -33,2 +33,22 @@ # Changelog | ||
## [1.4.0](https://github.com/sanity-io/visual-editing/compare/preview-kit-compat-v1.3.3...preview-kit-compat-v1.4.0) (2024-01-10) | ||
### Features | ||
* add share URL button and improve popup window mode ([#639](https://github.com/sanity-io/visual-editing/issues/639)) ([76daf22](https://github.com/sanity-io/visual-editing/commit/76daf22374afa7ffd92e6e107f0e3bf8f215d46f)) | ||
### Bug Fixes | ||
* **deps:** update dependency @sanity/client to ^6.11.0 ([#649](https://github.com/sanity-io/visual-editing/issues/649)) ([b94f848](https://github.com/sanity-io/visual-editing/commit/b94f8482e2928f77748b75a4b26536b33cf21330)) | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* devDependencies | ||
* @sanity/channels bumped from 0.3.0 to 0.4.0 | ||
* @sanity/visual-editing-helpers bumped from 0.2.1 to 0.2.2 | ||
## [1.3.0](https://github.com/sanity-io/visual-editing/compare/preview-kit-compat-v1.2.3...preview-kit-compat-v1.3.0) (2023-12-12) | ||
@@ -35,0 +55,0 @@ |
@@ -1,1 +0,1 @@ | ||
import{useState as n,useEffect as e,useMemo as t,useSyncExternalStore as i,useCallback as o}from"react";let r;const s=new Uint8Array(16);function a(){if(!r&&(r="undefined"!=typeof crypto&&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 d=[];for(let n=0;n<256;++n)d.push((n+256).toString(16).slice(1));var c={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function u(n,e,t){if(c.randomUUID&&!e&&!n)return c.randomUUID();const i=(n=n||{}).random||(n.rng||a)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,e){t=t||0;for(let n=0;n<16;++n)e[t+n]=i[n];return e}return function(n,e=0){return d[n[e+0]]+d[n[e+1]]+d[n[e+2]]+d[n[e+3]]+"-"+d[n[e+4]]+d[n[e+5]]+"-"+d[n[e+6]]+d[n[e+7]]+"-"+d[n[e+8]]+d[n[e+9]]+"-"+d[n[e+10]]+d[n[e+11]]+d[n[e+12]]+d[n[e+13]]+d[n[e+14]]+d[n[e+15]]}(i)}const f=["channel/disconnect","channel/response","channel/heartbeat"],p=["handshake/syn","handshake/syn-ack","handshake/ack"],l=n=>f.some((e=>e===n)),h=n=>p.some((e=>e===n)),y=({data:n={}})=>"object"==typeof n&&null!==n&&!Array.isArray(n)&&!("domain"in n)&&["id","type","from","to"].every((e=>e in n))&&n.type.startsWith("handshake/");function m(n){const e=window.self!==window.top,t={buffer:[],id:null,origin:null,status:"connecting"};function i(e,i){if(h(e)||l(e)||"connecting"!==t.status&&"reconnecting"!==t.status){if(t.id&&t.origin){const o={connectionId:t.id,data:i,domain:"sanity/channels",from:n.id,id:u(),to:n.connectTo,type:e};try{parent.postMessage(o,{targetOrigin:t.origin})}catch(e){throw new Error(`Failed to postMessage '${o.id}' on '${n.id}'`)}}}else t.buffer.push({type:e,data:i})}function o(e){if(y(e))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(e){const{data:t}=e;return"sanity/channels"===t.domain&&t.to===n.id&&t.from===n.connectTo&&"channel/response"!==t.type}(e)){const{data:o}=e;if(h(o.type)&&o.data){if("handshake/syn"===o.type)return t.origin=e.origin,t.id=o.data.id,r("connecting"),void i("handshake/syn-ack",{id:t.id});if("handshake/ack"===o.type&&o.data.id===t.id)return void r("connected")}else if(o.connectionId===t.id&&e.origin===t.origin){if("channel/disconnect"===o.type)return void r("disconnected");{const e=[o.type,o.data];n.onEvent?.(...e),i("channel/response",{responseTo:o.id})}return}}}function r(e){t.status=e,n?.onStatusUpdate?.(e),"connected"===e&&function(){const n=[...t.buffer];t.buffer.splice(0,t.buffer.length),n.forEach((({type:n,data:e})=>{i(n,e)}))}()}return window.addEventListener("message",o,!1),r("connecting"),{destroy:function(){["disconnected"].includes(t.status)||r("disconnected"),window.removeEventListener("message",o,!1)},inFrame:e,send:function(n,e){i(n,e)}}}function g(t,i,o){const[r,s]=n(),[a,d]=n(!1);e((()=>{if(window.self===window.top)return;const n=m({id:"preview-kit",connectTo:"presentation",onStatusUpdate(n){"connected"===n?d(!0):"disconnected"===n&&d(!1)}}),e=setTimeout((()=>s(n)),0);return()=>{clearTimeout(e),n.destroy(),s(void 0)}}),[o,i]);const c=JSON.stringify(Array.from(t.keys()));e((()=>{"[]"!==c&&r&&a&&r.send("preview-kit/documents",{projectId:i,dataset:o,perspective:"previewDrafts",documents:Array.from(t.values())})}),[c,r,a,o,t,i])}function v(n){const e=t((()=>JSON.stringify(n||{})),[n]);return t((()=>JSON.parse(e)),[e])}function w(t){const{refreshInterval:r}=t,s=function(){const[t,o]=n(!1);e((()=>{o(navigator.onLine);const n=()=>o(!0),e=()=>o(!1);return window.addEventListener("online",n),window.addEventListener("offline",e),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",e)}}),[]);const r=i(k,(()=>document.visibilityState),(()=>"hidden"));return!t||"hidden"===r}(),[a,d]=n("hit"),c=o((()=>(d("inflight"),()=>d("hit"))),[]);return e((()=>{if(!r||"hit"!==a)return;const n=setTimeout((()=>d("stale")),r);return()=>clearTimeout(n)}),[r,a]),e((()=>{if("hit"!==a)return;const n=()=>d("stale");return window.addEventListener("focus",n),()=>window.removeEventListener("focus",n)}),[r,a]),e((()=>{s&&"hit"===a&&d("stale"),s||"stale"!==a||d("refresh")}),[s,a]),[a,c]}function k(n){return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)}export{g as useDocumentsInUse,v as useQueryParams,w as useRevalidate};//# sourceMappingURL=index.js.map | ||
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="undefined"!=typeof crypto&&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:"undefined"!=typeof crypto&&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)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){t=t||0;for(let e=0;e<16;++e)n[t+e]=o[e];return n}return 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(n){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:i}=n;if(t.origin&&n.origin!==t.origin)return;if(n.source&&t.source!==n.source&&(t.source=n.source),h(i.type)&&i.data){if("handshake/syn"===i.type)return t.origin=n.origin,t.id=i.data.id,r("connecting"),void o("handshake/syn-ack",{id:t.id});if("handshake/ack"===i.type&&i.data.id===t.id)return void r("connected")}else if(i.connectionId===t.id&&n.origin===t.origin){if("channel/disconnect"===i.type)return void r("disconnected");{const n=[i.type,i.data];e.onEvent?.(...n),o("channel/response",{responseTo:i.id})}return}}}function r(n){t.status=n,e?.onStatusUpdate?.(n),"connected"===n&&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),r("connecting"),{destroy:function(){["disconnected"].includes(t.status)||r("disconnected"),window.removeEventListener("message",i,!1)},inFrame:n,send:function(e,n){o(e,n)}}}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",onStatusUpdate(e){"connected"===e?c(!0):"disconnected"===e&&c(!1)}}),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 w(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{g as useDocumentsInUse,v as useQueryParams,w as useRevalidate};//# sourceMappingURL=index.js.map |
{ | ||
"name": "@sanity/preview-kit-compat", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-kit-compat#readme", | ||
@@ -106,9 +106,9 @@ "bugs": { | ||
"devDependencies": { | ||
"@sanity/channels": "0.3.0", | ||
"@sanity/client": "^6.10.0", | ||
"@sanity/pkg-utils": "^3.3.6", | ||
"@sanity/visual-editing-helpers": "0.2.1", | ||
"@types/react": "^18.2.46", | ||
"@typescript-eslint/eslint-plugin": "^6.17.0", | ||
"@typescript-eslint/parser": "^6.17.0", | ||
"@sanity/channels": "0.4.0", | ||
"@sanity/client": "^6.11.0", | ||
"@sanity/pkg-utils": "^3.3.7", | ||
"@sanity/visual-editing-helpers": "0.2.2", | ||
"@types/react": "^18.2.47", | ||
"@typescript-eslint/eslint-plugin": "^6.18.1", | ||
"@typescript-eslint/parser": "^6.18.1", | ||
"eslint": "^8.56.0", | ||
@@ -120,6 +120,6 @@ "eslint-config-prettier": "^9.1.0", | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.1.1" | ||
"vitest": "^1.1.3" | ||
}, | ||
"peerDependencies": { | ||
"@sanity/client": "^6.10.0", | ||
"@sanity/client": "^6.11.0", | ||
"react": "^18.2.0" | ||
@@ -126,0 +126,0 @@ }, |
@@ -23,3 +23,3 @@ import { type ChannelsNode, createChannelsNode } from '@sanity/channels' | ||
useEffect(() => { | ||
if (window.self === window.top) { | ||
if (window.self === window.top && !window.opener) { | ||
return | ||
@@ -26,0 +26,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
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
63042
137
7
148
148