@sanity/preview-kit-compat
Advanced tools
Comparing version 1.4.4 to 1.4.5
@@ -1,26 +0,16 @@ | ||
# Changelog | ||
<!-- markdownlint-disable --><!-- textlint-disable --> | ||
### Dependencies | ||
# 📓 Changelog | ||
* The following workspace dependencies were updated | ||
* devDependencies | ||
* @sanity/visual-editing-helpers bumped from 0.1.0 to 0.1.1 | ||
All notable changes to this project will be documented in this file. See | ||
[Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* devDependencies | ||
* @sanity/visual-editing-helpers bumped from 0.1.2 to 0.1.3 | ||
## [1.4.5](https://github.com/sanity-io/visual-editing/compare/preview-kit-compat-v1.4.4...preview-kit-compat-v1.4.5) (2024-02-15) | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* devDependencies | ||
* @sanity/channels bumped from 0.2.0 to 0.3.0 | ||
### Bug Fixes | ||
### Dependencies | ||
* **deps:** update dependency @sanity/client to v6.13.3 ([#921](https://github.com/sanity-io/visual-editing/issues/921)) ([e150d8d](https://github.com/sanity-io/visual-editing/commit/e150d8d375a0fc12d8b9d4d11f04454a93a6a2c0)) | ||
* The following workspace dependencies were updated | ||
* devDependencies | ||
* @sanity/visual-editing-helpers bumped from 0.1.4 to 0.2.0 | ||
@@ -31,10 +21,4 @@ ### Dependencies | ||
* devDependencies | ||
* @sanity/visual-editing-helpers bumped from 0.2.0 to 0.2.1 | ||
* @sanity/visual-editing-helpers bumped from 0.2.6 to 0.3.0 | ||
### Dependencies | ||
* The following workspace dependencies were updated | ||
* devDependencies | ||
* @sanity/visual-editing-helpers bumped from 0.2.3 to 0.2.4 | ||
## [1.4.4](https://github.com/sanity-io/visual-editing/compare/preview-kit-compat-v1.4.3...preview-kit-compat-v1.4.4) (2024-01-29) | ||
@@ -41,0 +25,0 @@ |
@@ -1,1 +0,1 @@ | ||
import{useState as n,useEffect as e,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 n=0;n<256;++n)c.push((n+256).toString(16).slice(1));var d={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function u(n,e,t){if(d.randomUUID&&!e&&!n)return d.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 c[n[e+0]]+c[n[e+1]]+c[n[e+2]]+c[n[e+3]]+"-"+c[n[e+4]]+c[n[e+5]]+"-"+c[n[e+6]]+c[n[e+7]]+"-"+c[n[e+8]]+c[n[e+9]]+"-"+c[n[e+10]]+c[n[e+11]]+c[n[e+12]]+c[n[e+13]]+c[n[e+14]]+c[n[e+15]]}(o)}const f=["channel/disconnect","channel/response","channel/heartbeat"],l=["handshake/syn","handshake/syn-ack","handshake/ack"],p=n=>f.some((e=>e===n)),h=n=>l.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||window.opener,t={buffer:[],id:null,origin:null,source:null,status:"connecting"};function o(e,o){if(h(e)||p(e)||"connecting"!==t.status&&"reconnecting"!==t.status){if(t.id&&t.origin&&t.source){const i={connectionId:t.id,data:o,domain:"sanity/channels",from:n.id,id:u(),to:n.connectTo,type:e};try{t.source.postMessage(i,{targetOrigin:t.origin})}catch(e){throw new Error("Failed to postMessage '".concat(i.id,"' on '").concat(n.id,"'"))}}}else t.buffer.push({type:e,data:o})}function i(e){var i;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:s}=e;if(t.origin&&e.origin!==t.origin)return;if(e.source&&t.source!==e.source&&(t.source=e.source),h(s.type)&&s.data){if("handshake/syn"===s.type)return t.origin=e.origin,t.id=s.data.id,r("connecting"),void o("handshake/syn-ack",{id:t.id});if("handshake/ack"===s.type&&s.data.id===t.id)return void r("connected")}else if(s.connectionId===t.id&&e.origin===t.origin){if("channel/disconnect"===s.type)return void r("disconnected");{const e=[s.type,s.data];null==(i=n.onEvent)||i.call(n,...e),o("channel/response",{responseTo:s.id})}return}}}function r(e){var i;t.status=e,null==(i=null==n?void 0:n.onStatusUpdate)||i.call(n,e),"connected"===e&&function(){const n=[...t.buffer];t.buffer.splice(0,t.buffer.length),n.forEach((({type:n,data:e})=>{o(n,e)}))}()}return window.addEventListener("message",i,!1),r("connecting"),{destroy:function(){["disconnected"].includes(t.status)||r("disconnected"),window.removeEventListener("message",i,!1)},inFrame:e,send:function(n,e){o(n,e)}}}function g(t,o,i){const[r,s]=n(),[a,c]=n(!1);e((()=>{if(window.self===window.top&&!window.opener)return;const n=m({id:"preview-kit",connectTo:"presentation",onStatusUpdate(n){"connected"===n?c(!0):"disconnected"===n&&c(!1)}}),e=setTimeout((()=>s(n)),0);return()=>{clearTimeout(e),n.destroy(),s(void 0)}}),[i,o]);const d=JSON.stringify(Array.from(t.keys()));e((()=>{"[]"!==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(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,i]=n(!1);e((()=>{i(navigator.onLine);const n=()=>i(!0),e=()=>i(!1);return window.addEventListener("online",n),window.addEventListener("offline",e),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",e)}}),[]);const r=o(k,(()=>document.visibilityState),(()=>"hidden"));return!t||"hidden"===r}(),[a,c]=n("hit"),d=i((()=>(c("inflight"),()=>c("hit"))),[]);return e((()=>{if(!r||"hit"!==a)return;const n=setTimeout((()=>c("stale")),r);return()=>clearTimeout(n)}),[r,a]),e((()=>{if("hit"!==a)return;const n=()=>c("stale");return window.addEventListener("focus",n),()=>window.removeEventListener("focus",n)}),[r,a]),e((()=>{s&&"hit"===a&&c("stale"),s||"stale"!==a||c("refresh")}),[s,a]),[a,d]}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 c(){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 a=[];for(let e=0;e<256;++e)a.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||c)();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 a[e[n+0]]+a[e[n+1]]+a[e[n+2]]+a[e[n+3]]+"-"+a[e[n+4]]+a[e[n+5]]+"-"+a[e[n+6]]+a[e[n+7]]+"-"+a[e[n+8]]+a[e[n+9]]+"-"+a[e[n+10]]+a[e[n+11]]+a[e[n+12]]+a[e[n+13]]+a[e[n+14]]+a[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 '".concat(i.id,"' on '").concat(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,c("connecting"),void o("handshake/syn-ack",{id:t.id});if("handshake/ack"===e.type&&e.data.id===t.id)return void c("connected")}else if(e.connectionId===t.id&&n.origin===t.origin){if("channel/disconnect"===e.type)return void c("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 c(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),c("connecting"),{destroy:function(){["disconnected"].includes(t.status)||c("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(),[c,a]=e(!1);n((()=>{if(window.self===window.top&&!window.opener)return;const e=m({id:"preview-kit",connectTo:"presentation"});e.onStatusUpdate((e=>{"connected"===e?a(!0):"disconnected"===e&&a(!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&&c&&r.send("preview-kit/documents",{projectId:o,dataset:i,perspective:"previewDrafts",documents:Array.from(t.values())})}),[d,r,c,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}(),[c,a]=e("hit"),d=i((()=>(a("inflight"),()=>a("hit"))),[]);return n((()=>{if(!r||"hit"!==c)return;const e=setTimeout((()=>a("stale")),r);return()=>clearTimeout(e)}),[r,c]),n((()=>{if("hit"!==c)return;const e=()=>a("stale");return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)}),[r,c]),n((()=>{s&&"hit"===c&&a("stale"),s||"stale"!==c||a("refresh")}),[s,c]),[c,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 |
{ | ||
"name": "@sanity/preview-kit-compat", | ||
"version": "1.4.4", | ||
"version": "1.4.5", | ||
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/preview-kit-compat#readme", | ||
@@ -104,12 +104,12 @@ "bugs": { | ||
"@sanity/channels": "0.4.0", | ||
"@sanity/client": "^6.12.3", | ||
"@sanity/pkg-utils": "^4.1.1", | ||
"@sanity/visual-editing-helpers": "0.2.6", | ||
"@types/react": "^18.2.48", | ||
"@typescript-eslint/eslint-plugin": "^6.20.0", | ||
"@typescript-eslint/parser": "^6.20.0", | ||
"@sanity/client": "^6.12.4", | ||
"@sanity/pkg-utils": "^4.2.0", | ||
"@sanity/visual-editing-helpers": "0.3.0", | ||
"@types/react": "^18.2.55", | ||
"@typescript-eslint/eslint-plugin": "^7.0.1", | ||
"@typescript-eslint/parser": "^7.0.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
"eslint-plugin-simple-import-sort": "^12.0.0", | ||
"react": "^18.2.0", | ||
@@ -120,3 +120,3 @@ "typescript": "^5.3.3", | ||
"peerDependencies": { | ||
"@sanity/client": "^6.12.3", | ||
"@sanity/client": "^6.12.4", | ||
"react": "^18.2.0" | ||
@@ -123,0 +123,0 @@ }, |
import { type ChannelsNode, createChannelsNode } from '@sanity/channels' | ||
import type { ContentSourceMapDocuments } from '@sanity/client/csm' | ||
import { | ||
type PresentationMsg, | ||
type PreviewKitMsg, | ||
type VisualEditingConnectionIds, | ||
type VisualEditingMsg, | ||
} from '@sanity/visual-editing-helpers' | ||
@@ -19,3 +20,3 @@ import { useEffect, useState } from 'react' | ||
const [channel, setChannel] = useState< | ||
ChannelsNode<VisualEditingMsg> | undefined | ||
ChannelsNode<PreviewKitMsg, PresentationMsg> | undefined | ||
>() | ||
@@ -27,13 +28,15 @@ const [connected, setConnected] = useState(false) | ||
} | ||
const channel = createChannelsNode<VisualEditingMsg>({ | ||
const channel = createChannelsNode<PreviewKitMsg, PresentationMsg>({ | ||
id: 'preview-kit' satisfies VisualEditingConnectionIds, | ||
connectTo: 'presentation' satisfies VisualEditingConnectionIds, | ||
onStatusUpdate(status) { | ||
if (status === 'connected') { | ||
setConnected(true) | ||
} else if (status === 'disconnected') { | ||
setConnected(false) | ||
} | ||
}, | ||
}) | ||
channel.onStatusUpdate((status) => { | ||
if (status === 'connected') { | ||
setConnected(true) | ||
} else if (status === 'disconnected') { | ||
setConnected(false) | ||
} | ||
}) | ||
const timeout = setTimeout(() => setChannel(channel), 0) | ||
@@ -40,0 +43,0 @@ return () => { |
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
67998
140