@sentientui/react 0.42.4 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  'use client';
2
- var Ae=Object.defineProperty,Pe=Object.defineProperties;var Oe=Object.getOwnPropertyDescriptors;var oe=Object.getOwnPropertySymbols;var Ie=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var se=(e,t,n)=>t in e?Ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,y=(e,t)=>{for(var n in t||(t={}))Ie.call(t,n)&&se(e,n,t[n]);if(oe)for(var n of oe(t))Te.call(t,n)&&se(e,n,t[n]);return e},M=(e,t)=>Pe(e,Oe(t));import{render as Ze}from"@testing-library/react";import{createContext as Be,useContext as At,useEffect as h,useMemo as be,useRef as x,useState as $,useSyncExternalStore as Pt}from"react";import{deriveSessionSegment as He,init as je}from"@sentientui/core";var Ve=new Map,De=new Map;function ae(e,t){Ve.set(e,t);let n=De.get(e);if(n)for(let i of n)try{i(t)}catch(l){}}var Ne={on:!1,listeners:new Set};function le(){if(typeof window=="undefined")return Ne;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function B(){return le().on}function ce(e){let t=le().listeners;return t.add(e),()=>{t.delete(e)}}function de(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),isUnified:t=>{var n,i;return(i=(n=e.isUnified)==null?void 0:n.call(e,t))!=null?i:!1},assign:(t,n,i,l,c)=>e.assign(t,n,i,l,c),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getSlotConfig:t=>e.getSlotConfig(t),getSitePalette:()=>e.getSitePalette(),reportSlots:t=>e.reportSlots(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),flush:()=>e.flush(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Le="sentient:overrides-changed";function F(){var t;if(typeof window=="undefined")return;let e=window;e.__sentient_overrides_version=((t=e.__sentient_overrides_version)!=null?t:0)+1,window.dispatchEvent(new Event(Le))}function ue(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function W(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var Ge={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function H(){if(typeof window=="undefined")return Ge;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function Fe(){H().version+=1;for(let e of H().listeners)e()}function j(e){W()&&(H().sections=[...e],Fe())}var fe="0.42.4",z=fe!=="0.0.0-dev"?{name:"react",version:fe}:void 0;function We(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function V(e,t){We()[e]=t}function ge(e){window.__sentient_vocabulary_override=e}function Ue(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function D(e,t){Ue()[e]=t}function pe(e){let t=null;try{let n=location.hash.slice(1),i=RegExp("(^|[?&])"+e+"=([^&]*)").exec(n);if(i){t=i[2];let l=n.slice(i.index+i[0].length);i[1]!="&"&&l[0]=="&"&&(l=i[1]+l.slice(1));let c=n.slice(0,i.index)+l;history.replaceState(history.state,"",c?"#"+c:location.pathname+location.search)}}catch(n){}return t}var X="__snt_editor_token",N=null,J=!1;function me(){return J}function $e(){try{return sessionStorage.getItem(X)}catch(e){return null}}function K(e){if(N)return N;let t=typeof window=="undefined"?null:pe("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:$e();return J=!!n,N=Promise.resolve(n?{token:n,fresh:!1}:null),N}return J=!0,N=fetch(`${e}/editor/exchange`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({code:t})}).then(async n=>{let i=n.ok?(await n.json()).token:void 0;if(!i)return{error:n.ok?500:n.status};try{sessionStorage.setItem(X,i)}catch(l){}return{token:i,fresh:!0}}).catch(()=>({error:0})),N}function ye(){try{sessionStorage.removeItem(X)}catch(e){}}var ve="sentient_preview_cell",he="sentient_refresh_region",q="sentient-cell-preview-bar",O="__preview__",Me=null;function _e(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(q))return;let t,n;try{let s=new URLSearchParams(window.location.search);t=s.get(ve),n=s.get(he)}catch(s){return}if(!t&&!n)return;let i=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),l=K(i);if(!me())return;if(n){Me={slotId:n,session:l,base:i},V(n,{kind:"arms"}),D(n,O),F();return}if(!t)return;let c=t.lastIndexOf("~");if(c<=0)return;let f=t.slice(0,c),I=t.slice(c+1);l.then(s=>s?"token"in s?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(f)}&persona=${encodeURIComponent(I)}`,{headers:{authorization:`Bearer ${s.token}`}}):(U(s.error===401?"This preview link has expired \u2014 reopen it from your dashboard.":"Couldn\u2019t load this preview \u2014 reopen it from your dashboard."),null):null).then(async s=>{if(!s)return;if(!s.ok){U(s.status===401?"This preview link has expired \u2014 reopen it from your dashboard.":"Couldn\u2019t load this preview \u2014 reopen it from your dashboard.");return}let a=await s.json();if(a.vocabulary&&Array.isArray(a.vocabulary.entries)&&ge(a.vocabulary),a.compose!=null)V(f,{kind:"arms",compose:{[O]:a.compose}}),D(f,O);else if(a.edits!=null&&typeof a.skeletonFp=="string"&&Array.isArray(a.leafToNode))V(f,{kind:"arms",edits:{edits:a.edits,fp:a.skeletonFp,leafToNode:a.leafToNode}}),D(f,O);else if(a.blocks!=null)V(f,{kind:"arms",blocks:{[O]:a.blocks}}),D(f,O);else if(a.content!=null)V(f,{kind:"arms",content:a.content}),D(f,O);else{U("Nothing to preview in that square yet.");return}F(),U(`Previewing \u201C${a.slotName}\u201D for ${a.personaDisplay}${a.status==="review"?" \u2014 waiting for your approval":""}. Nothing is being tracked.`),setTimeout(()=>{var g;try{(g=document.querySelector(`[data-sentient-slot="${f}"]`))==null||g.scrollIntoView({block:"center"})}catch(m){}},300)}).catch(()=>U("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function U(e){var l;if(document.getElementById(q))return;let t=document.createElement("div");t.id=q,Object.assign(t.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"10px",padding:"10px 14px",borderRadius:"12px",maxWidth:"90vw",background:"#111827",color:"#fff",font:"13px system-ui, sans-serif",border:"1px solid rgba(139,92,246,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});let n=document.createElement("span");n.textContent=e;let i=document.createElement("button");i.textContent="Exit preview",Object.assign(i.style,{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.35)",background:"transparent",color:"#fff",font:"12px system-ui, sans-serif",cursor:"pointer"}),i.onclick=()=>{ye();let c=new URL(window.location.href);c.searchParams.delete(ve),c.searchParams.delete(he),window.location.assign(c.toString())},t.append(n,i),((l=document.body)!=null?l:document.documentElement).append(t)}var Se=!1;function we(e){if(Se||typeof window=="undefined")return;Se=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||Ke(t,n.token)})}function Ke(e,t){let n=()=>{window.setTimeout(()=>{import("@sentientui/core/style-sample").then(({sampleStyleVocabulary:i})=>fetch(`${e}/editor/style-vocabulary`,{method:"POST",headers:{authorization:`Bearer ${t}`,"content-type":"application/json"},body:JSON.stringify(i(document))})).catch(()=>{})},1e3)};document.readyState==="complete"?n():window.addEventListener("load",n,{once:!0})}import{jsx as Ye}from"react/jsx-runtime";function ze(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return He({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var xe="https://api.sentient-ui.com/v1",Je=Be({client:null,apiKey:"",initialAssignments:{},initialUnified:[],sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:xe,debug:!1}),Ce=!1,Y=new Set;function Xe(e,t,n){let i=x(n);i.current=n;let[l,c]=$(null),[f,I]=$(!1),s=x(e);s.current=e;let a=e===void 0?"":typeof e=="string"?e:JSON.stringify(M(y({},e),{check:typeof e.check,refused:typeof e.refused}));return h(()=>{let g=s.current;if(g===void 0||typeof window=="undefined")return;let m,E=!1;return import("@sentientui/core/consent").then(({consentWatcher:k,forgetVisitor:T})=>{if(E)return;let A=k(typeof g=="object"&&g.cmp===void 0&&g.check?y(M(y({},g),{check:()=>s.current.check()}),g.refused?{refused:()=>{var _,S;return((S=(_=s.current).refused)==null?void 0:S.call(_))===!0}}:{}):g),w=!1,L=()=>{let _=A.refused()&&A.read()!==!0;_&&!w&&(T(t),i.current()),w=_,I(_);let S=A.read();S!==null&&Y.add(t),c(S!=null?S:Y.has(t)?!1:null)};L(),m=A.subscribe(L)}),()=>{E=!0,m==null||m()}},[a,t]),{granted:l,refused:f}}function ke(e){var Z,ee,te,ne,ie;let[t,n]=$(null),[i]=$(()=>{var r;return(r=e.sessionSegment)!=null?r:ze()}),[l,c]=$(B());h(()=>ce(()=>c(B())),[]),h(()=>{_e(e.apiBaseUrl),we(e.apiBaseUrl)},[]);let f=x(()=>{}),I=Xe(e.consentFrom,e.apiKey,()=>f.current()),s=e.consentFrom?(Z=I.granted)!=null?Z:Y.has(e.apiKey)?!1:e.consent===!0:e.consent,a=e.consentFrom?I.refused:!0,g=x(a);g.current=a;let m=x(null),E=x(!1),k=x([]),T=x(!1);f.current=()=>{var u;k.current=[],T.current=!0;let r=m.current;r!=null&&r.gated?r.dispose():(u=r==null?void 0:r.takeHeld)==null||u.call(r)},h(()=>{var G,re;if(g.current&&s===!1&&(k.current=[]),s===!1&&E.current&&(g.current&&((G=m.current)==null||G.destroy()),m.current=null,E.current=!1),s===!1&&!e.preConsentBehavior){g.current&&((re=m.current)==null||re.destroy()),m.current=null,n(null);return}let r=s!==!1;r&&(T.current=!1);let u=v=>{!r&&T.current&&v.gated&&v.dispose()},p=y({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,initialUnified:e.initialUnified,sessionSegment:i,consent:s,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,cookieDomain:e.cookieDomain,country:e.country,persona:e.persona,stageAttributes:e.stageAttributes,localMode:e.localMode,initialSlots:e.initialSlots,initialSlotConfig:e.initialSlotConfig,initialPalette:e.initialPalette,initialVocabulary:e.initialVocabulary,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0,nonce:e.nonce},z?{sdk:z}:{}),d=!1,o=null,b=null,C=v=>{for(let P of k.current.splice(0))setTimeout(()=>{if(m.current!==v){T.current||k.current.push(P);return}try{P(v)}catch(tt){}},0)},R=v=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:P})=>{d||(b=P(v,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:v})=>{d||(o=v(M(y({},p),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),u(o),m.current=o,E.current=r,C(o),n(o),R(o))}):(o=je(p),u(o),m.current=o,E.current=r,C(o),n(o),R(o)),()=>{var v,P;d=!0,b==null||b(),k.current=k.current.concat((P=(v=o==null?void 0:o.takeHeld)==null?void 0:v.call(o))!=null?P:[]),o==null||o.dispose()}},[s]),h(()=>{if(!t)return;let r=!1,u=async()=>{if(r)return;let d;try{d=await t.fetchWeights()}catch(o){return}if(!r)for(let o of d){let b={componentId:o.componentId,updatedAt:o.updatedAt,variants:o.variants.map(C=>{var R;return{variantId:C.variantId,pulls:C.pulls,avgReward:(R=C.avgReward)!=null?R:0}})};ae(o.componentId,b)}};u();let p=setInterval(()=>{u()},6e4);return()=>{r=!0,clearInterval(p)}},[t]);let A=(ee=e.ssrFallback)!=null?ee:"first",w=((te=e.apiBaseUrl)!=null?te:xe).replace(/\/$/,""),L=x(null);h(()=>{var p;if(typeof process!="undefined"&&((p=process.env)==null?void 0:p.NODE_ENV)==="production")return;let r={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:w},u=L.current;if(L.current=r,u!==null)for(let d of["apiKey","context","country","persona","apiBaseUrl"])Object.is(u[d],r[d])||console.warn(`[sentient] AdaptiveProvider: \`${d}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,w]),h(()=>{var r;typeof process!="undefined"&&((r=process.env)==null?void 0:r.NODE_ENV)==="production"||ue({apiKey:e.apiKey,apiBaseUrl:w,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,w]);let _=(ne=e.identity)==null?void 0:ne.userId,S=(ie=e.identity)==null?void 0:ie.userHash;h(()=>{t&&_&&t.identify(_,{userHash:S})},[t,_,S]),h(()=>{let r=e.initialLayoutOrder;if(r&&r.length>0){j(r);return}e.declaredSections&&e.declaredSections.length>0&&j(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),h(()=>{!W()||e.consent!==void 0||e.consentFrom!==void 0||Ce||(Ce=!0,console.warn('[SentientUI] No consent gate: every visitor is tracked from first paint. Pass consentFrom="<your CMP>" (or consent={true} to silence). https://sentient-ui.com/docs#consent'))},[]),h(()=>{if(!W())return;let r=e.declaredSections;if(!r||r.length===0||typeof document=="undefined")return;let u=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),d=>d.getAttribute("data-sentient-id"))),p=r.filter(d=>!u.has(d));p.length>0&&console.warn(`[SentientUI] Declared section${p.length>1?"s":""} ${p.map(d=>`"${d}"`).join(", ")} ${p.length>1?"have":"has"} no matching data-sentient-id element, so the layout engine cannot learn what they are and will serve the same order to every persona. Add data-sentient-id="<sectionId>" to each section's element.`)},[e.declaredSections]);let Q=be(()=>t&&l?de(t):t,[t,l]),Ee=be(()=>{var r,u,p,d,o,b,C,R,G;return{client:Q,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},initialUnified:(u=e.initialUnified)!=null?u:qe,sessionSegment:i,ssrFallback:A,onAssignment:e.onAssignment,initialLayoutOrder:(p=e.initialLayoutOrder)!=null?p:null,initialSlots:(d=e.initialSlots)!=null?d:{},initialSlotConfig:(o=e.initialSlotConfig)!=null?o:{},initialPalette:(b=e.initialPalette)!=null?b:null,initialVocabulary:(C=e.initialVocabulary)!=null?C:null,initialPersona:(R=e.initialPersona)!=null?R:null,apiBaseUrl:w,debug:(G=e.debug)!=null?G:!1}},[Q,e.apiKey,e.initialAssignments,e.initialUnified,i,A,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return Ye(Je.Provider,{value:Ee,children:e.children})}var qe=[];function Qe(e){return e<.3?"low":e<.7?"medium":"high"}function Re(e={}){var n,i,l;let t=window;if(t.__sentient_overrides=y({},(n=e.variants)!=null?n:{}),e.layout?t.__sentient_layout_override=e.layout:delete t.__sentient_layout_override,e.slots?t.__sentient_slot_overrides=y({},e.slots):delete t.__sentient_slot_overrides,e.slotConfig?t.__sentient_slot_config_overrides=y({},e.slotConfig):delete t.__sentient_slot_config_overrides,e.persona){t.__sentient_persona_override={persona:e.persona,confidence:(i=e.confidence)!=null?i:1};try{let c=document.documentElement;c.setAttribute("data-sentient-persona",e.persona),c.setAttribute("data-sentient-confidence",Qe((l=e.confidence)!=null?l:1))}catch(c){}}else delete t.__sentient_persona_override;F()}import{jsx as et}from"react/jsx-runtime";function Jt(e,t={},n){return Re(t),Ze(et(ke,{apiKey:"pk_test",consent:!1,children:e}),n)}export{Jt as renderWithSentient};
2
+ var Oe=Object.defineProperty,Ie=Object.defineProperties;var Te=Object.getOwnPropertyDescriptors;var ae=Object.getOwnPropertySymbols;var Ve=Object.prototype.hasOwnProperty,De=Object.prototype.propertyIsEnumerable;var le=(e,t,n)=>t in e?Oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,y=(e,t)=>{for(var n in t||(t={}))Ve.call(t,n)&&le(e,n,t[n]);if(ae)for(var n of ae(t))De.call(t,n)&&le(e,n,t[n]);return e},M=(e,t)=>Ie(e,Te(t));import{render as tt}from"@testing-library/react";import{createContext as je,useContext as Ot,useEffect as h,useMemo as xe,useRef as x,useState as $,useSyncExternalStore as It}from"react";import{deriveSessionSegment as ze,init as Je}from"@sentientui/core";var Ne=new Map,Le=new Map;function ce(e,t){Ne.set(e,t);let n=Le.get(e);if(n)for(let i of n)try{i(t)}catch(l){}}var Ge={on:!1,listeners:new Set};function de(){if(typeof window=="undefined")return Ge;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function B(){return de().on}function ue(e){let t=de().listeners;return t.add(e),()=>{t.delete(e)}}function fe(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),isUnified:t=>{var n,i;return(i=(n=e.isUnified)==null?void 0:n.call(e,t))!=null?i:!1},assign:(t,n,i,l,c)=>e.assign(t,n,i,l,c),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getSlotConfig:t=>e.getSlotConfig(t),getSitePalette:()=>e.getSitePalette(),reportSlots:t=>e.reportSlots(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),flush:()=>e.flush(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Fe="sentient:overrides-changed";function F(){var t;if(typeof window=="undefined")return;let e=window;e.__sentient_overrides_version=((t=e.__sentient_overrides_version)!=null?t:0)+1,window.dispatchEvent(new Event(Fe))}function ge(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function W(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var We={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function H(){if(typeof window=="undefined")return We;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function Ue(){H().version+=1;for(let e of H().listeners)e()}function j(e){W()&&(H().sections=[...e],Ue())}var pe="0.43.0",z=pe!=="0.0.0-dev"?{name:"react",version:pe}:void 0;function $e(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function V(e,t){$e()[e]=t}function me(e){window.__sentient_vocabulary_override=e}function Me(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function D(e,t){Me()[e]=t}function ye(e){let t=null;try{let n=location.hash.slice(1),i=RegExp("(^|[?&])"+e+"=([^&]*)").exec(n);if(i){t=i[2];let l=n.slice(i.index+i[0].length);i[1]!="&"&&l[0]=="&"&&(l=i[1]+l.slice(1));let c=n.slice(0,i.index)+l;history.replaceState(history.state,"",c?"#"+c:location.pathname+location.search)}}catch(n){}return t}var X="__snt_editor_token",N=null,J=!1;function ve(){return J}function Ke(){try{return sessionStorage.getItem(X)}catch(e){return null}}function K(e){if(N)return N;let t=typeof window=="undefined"?null:ye("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Ke();return J=!!n,N=Promise.resolve(n?{token:n,fresh:!1}:null),N}return J=!0,N=fetch(`${e}/editor/exchange`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({code:t})}).then(async n=>{let i=n.ok?(await n.json()).token:void 0;if(!i)return{error:n.ok?500:n.status};try{sessionStorage.setItem(X,i)}catch(l){}return{token:i,fresh:!0}}).catch(()=>({error:0})),N}function he(){try{sessionStorage.removeItem(X)}catch(e){}}var _e="sentient_preview_cell",Se="sentient_refresh_region",q="sentient-cell-preview-bar",O="__preview__",Be=null;function we(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(q))return;let t,n;try{let s=new URLSearchParams(window.location.search);t=s.get(_e),n=s.get(Se)}catch(s){return}if(!t&&!n)return;let i=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),l=K(i);if(!ve())return;if(n){Be={slotId:n,session:l,base:i},V(n,{kind:"arms"}),D(n,O),F();return}if(!t)return;let c=t.lastIndexOf("~");if(c<=0)return;let f=t.slice(0,c),I=t.slice(c+1);l.then(s=>s?"token"in s?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(f)}&persona=${encodeURIComponent(I)}`,{headers:{authorization:`Bearer ${s.token}`}}):(U(s.error===401?"This preview link has expired \u2014 reopen it from your dashboard.":"Couldn\u2019t load this preview \u2014 reopen it from your dashboard."),null):null).then(async s=>{if(!s)return;if(!s.ok){U(s.status===401?"This preview link has expired \u2014 reopen it from your dashboard.":"Couldn\u2019t load this preview \u2014 reopen it from your dashboard.");return}let a=await s.json();if(a.vocabulary&&Array.isArray(a.vocabulary.entries)&&me(a.vocabulary),a.compose!=null)V(f,{kind:"arms",compose:{[O]:a.compose}}),D(f,O);else if(a.edits!=null&&typeof a.skeletonFp=="string"&&Array.isArray(a.leafToNode))V(f,{kind:"arms",edits:{edits:a.edits,fp:a.skeletonFp,leafToNode:a.leafToNode}}),D(f,O);else if(a.blocks!=null)V(f,{kind:"arms",blocks:{[O]:a.blocks}}),D(f,O);else if(a.content!=null)V(f,{kind:"arms",content:a.content}),D(f,O);else{U("Nothing to preview in that square yet.");return}F(),U(`Previewing \u201C${a.slotName}\u201D for ${a.personaDisplay}${a.status==="review"?" \u2014 waiting for your approval":""}. Nothing is being tracked.`),setTimeout(()=>{var g;try{(g=document.querySelector(`[data-sentient-slot="${f}"]`))==null||g.scrollIntoView({block:"center"})}catch(m){}},300)}).catch(()=>U("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function U(e){var l;if(document.getElementById(q))return;let t=document.createElement("div");t.id=q,Object.assign(t.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"10px",padding:"10px 14px",borderRadius:"12px",maxWidth:"90vw",background:"#111827",color:"#fff",font:"13px system-ui, sans-serif",border:"1px solid rgba(139,92,246,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});let n=document.createElement("span");n.textContent=e;let i=document.createElement("button");i.textContent="Exit preview",Object.assign(i.style,{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.35)",background:"transparent",color:"#fff",font:"12px system-ui, sans-serif",cursor:"pointer"}),i.onclick=()=>{he();let c=new URL(window.location.href);c.searchParams.delete(_e),c.searchParams.delete(Se),window.location.assign(c.toString())},t.append(n,i),((l=document.body)!=null?l:document.documentElement).append(t)}var be=!1;function Ce(e){if(be||typeof window=="undefined")return;be=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||He(t,n.token)})}function He(e,t){let n=()=>{window.setTimeout(()=>{import("@sentientui/core/style-sample").then(({sampleStyleVocabulary:i})=>fetch(`${e}/editor/style-vocabulary`,{method:"POST",headers:{authorization:`Bearer ${t}`,"content-type":"application/json"},body:JSON.stringify(i(document))})).catch(()=>{})},1e3)};document.readyState==="complete"?n():window.addEventListener("load",n,{once:!0})}import{jsx as Ze}from"react/jsx-runtime";function Xe(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return ze({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var Re="https://api.sentient-ui.com/v1",qe=je({client:null,apiKey:"",initialAssignments:{},initialUnified:[],sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:Re,debug:!1}),ke=!1,Y=new Set;function Ye(e,t,n){let i=x(n);i.current=n;let[l,c]=$(null),[f,I]=$(!1),s=x(e);s.current=e;let a=e===void 0?"":typeof e=="string"?e:JSON.stringify(M(y({},e),{check:typeof e.check,refused:typeof e.refused}));return h(()=>{let g=s.current;if(g===void 0||typeof window=="undefined")return;let m,E=!1;return import("@sentientui/core/consent").then(({consentWatcher:k,forgetVisitor:T})=>{if(E)return;let A=k(typeof g=="object"&&g.cmp===void 0&&g.check?y(M(y({},g),{check:()=>s.current.check()}),g.refused?{refused:()=>{var _,S;return((S=(_=s.current).refused)==null?void 0:S.call(_))===!0}}:{}):g),w=!1,L=()=>{let _=A.refused()&&A.read()!==!0;_&&!w&&(T(t),i.current()),w=_,I(_);let S=A.read();S!==null&&Y.add(t),c(S!=null?S:Y.has(t)?!1:null)};L(),m=A.subscribe(L)}),()=>{E=!0,m==null||m()}},[a,t]),{granted:l,refused:f}}function Ee(e){var ee,te,ne,ie,re,oe;let[t,n]=$(null),[i]=$(()=>{var r;return(r=e.sessionSegment)!=null?r:Xe()}),[l,c]=$(B());h(()=>ue(()=>c(B())),[]),h(()=>{we(e.apiBaseUrl),Ce(e.apiBaseUrl)},[]);let f=x(()=>{}),I=Ye(e.consentFrom,e.apiKey,()=>f.current()),s=e.consentFrom?(ee=I.granted)!=null?ee:Y.has(e.apiKey)?!1:e.consent===!0:e.consent,a=e.consentFrom?I.refused:!0,g=x(a);g.current=a;let m=x(null),E=x(!1),k=x([]),T=x(!1);f.current=()=>{var u;k.current=[],T.current=!0;let r=m.current;r!=null&&r.gated?r.dispose():(u=r==null?void 0:r.takeHeld)==null||u.call(r)},h(()=>{var G,se;if(g.current&&s===!1&&(k.current=[]),s===!1&&E.current&&(g.current&&((G=m.current)==null||G.destroy()),m.current=null,E.current=!1),s===!1&&!e.preConsentBehavior){g.current&&((se=m.current)==null||se.destroy()),m.current=null,n(null);return}let r=s!==!1;r&&(T.current=!1);let u=v=>{!r&&T.current&&v.gated&&v.dispose()},p=y({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,initialUnified:e.initialUnified,sessionSegment:i,consent:s,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,cookieDomain:e.cookieDomain,country:e.country,persona:e.persona,internal:e.internal,stageAttributes:e.stageAttributes,localMode:e.localMode,initialSlots:e.initialSlots,initialSlotConfig:e.initialSlotConfig,initialPalette:e.initialPalette,initialVocabulary:e.initialVocabulary,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0,nonce:e.nonce},z?{sdk:z}:{}),d=!1,o=null,b=null,C=v=>{for(let P of k.current.splice(0))setTimeout(()=>{if(m.current!==v){T.current||k.current.push(P);return}try{P(v)}catch(it){}},0)},R=v=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:P})=>{d||(b=P(v,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:v})=>{d||(o=v(M(y({},p),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),u(o),m.current=o,E.current=r,C(o),n(o),R(o))}):(o=Je(p),u(o),m.current=o,E.current=r,C(o),n(o),R(o)),()=>{var v,P;d=!0,b==null||b(),k.current=k.current.concat((P=(v=o==null?void 0:o.takeHeld)==null?void 0:v.call(o))!=null?P:[]),o==null||o.dispose()}},[s]),h(()=>{if(!t)return;let r=!1,u=async()=>{if(r)return;let d;try{d=await t.fetchWeights()}catch(o){return}if(!r)for(let o of d){let b={componentId:o.componentId,updatedAt:o.updatedAt,variants:o.variants.map(C=>{var R;return{variantId:C.variantId,pulls:C.pulls,avgReward:(R=C.avgReward)!=null?R:0}})};ce(o.componentId,b)}};u();let p=setInterval(()=>{u()},6e4);return()=>{r=!0,clearInterval(p)}},[t]);let A=(te=e.ssrFallback)!=null?te:"first",w=((ne=e.apiBaseUrl)!=null?ne:Re).replace(/\/$/,""),L=x(null);h(()=>{var p;if(typeof process!="undefined"&&((p=process.env)==null?void 0:p.NODE_ENV)==="production")return;let r={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,internal:e.internal,apiBaseUrl:w},u=L.current;if(L.current=r,u!==null)for(let d of["apiKey","context","country","persona","internal","apiBaseUrl"])Object.is(u[d],r[d])||console.warn(`[sentient] AdaptiveProvider: \`${d}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,e.internal,w]),h(()=>{var r;typeof process!="undefined"&&((r=process.env)==null?void 0:r.NODE_ENV)==="production"||ge({apiKey:e.apiKey,apiBaseUrl:w,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,w]);let _=(ie=e.identity)==null?void 0:ie.userId,S=(re=e.identity)==null?void 0:re.userHash,Q=(oe=e.identity)==null?void 0:oe.email;h(()=>{t&&_&&t.identify(_,{userHash:S,email:Q})},[t,_,S,Q]),h(()=>{let r=e.initialLayoutOrder;if(r&&r.length>0){j(r);return}e.declaredSections&&e.declaredSections.length>0&&j(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),h(()=>{!W()||e.consent!==void 0||e.consentFrom!==void 0||ke||(ke=!0,console.warn('[SentientUI] No consent gate: every visitor is tracked from first paint. Pass consentFrom="<your CMP>" (or consent={true} to silence). https://sentient-ui.com/docs#consent'))},[]),h(()=>{if(!W())return;let r=e.declaredSections;if(!r||r.length===0||typeof document=="undefined")return;let u=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),d=>d.getAttribute("data-sentient-id"))),p=r.filter(d=>!u.has(d));p.length>0&&console.warn(`[SentientUI] Declared section${p.length>1?"s":""} ${p.map(d=>`"${d}"`).join(", ")} ${p.length>1?"have":"has"} no matching data-sentient-id element, so the layout engine cannot learn what they are and will serve the same order to every persona. Add data-sentient-id="<sectionId>" to each section's element.`)},[e.declaredSections]);let Z=xe(()=>t&&l?fe(t):t,[t,l]),Pe=xe(()=>{var r,u,p,d,o,b,C,R,G;return{client:Z,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},initialUnified:(u=e.initialUnified)!=null?u:Qe,sessionSegment:i,ssrFallback:A,onAssignment:e.onAssignment,initialLayoutOrder:(p=e.initialLayoutOrder)!=null?p:null,initialSlots:(d=e.initialSlots)!=null?d:{},initialSlotConfig:(o=e.initialSlotConfig)!=null?o:{},initialPalette:(b=e.initialPalette)!=null?b:null,initialVocabulary:(C=e.initialVocabulary)!=null?C:null,initialPersona:(R=e.initialPersona)!=null?R:null,apiBaseUrl:w,debug:(G=e.debug)!=null?G:!1}},[Z,e.apiKey,e.initialAssignments,e.initialUnified,i,A,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return Ze(qe.Provider,{value:Pe,children:e.children})}var Qe=[];function et(e){return e<.3?"low":e<.7?"medium":"high"}function Ae(e={}){var n,i,l;let t=window;if(t.__sentient_overrides=y({},(n=e.variants)!=null?n:{}),e.layout?t.__sentient_layout_override=e.layout:delete t.__sentient_layout_override,e.slots?t.__sentient_slot_overrides=y({},e.slots):delete t.__sentient_slot_overrides,e.slotConfig?t.__sentient_slot_config_overrides=y({},e.slotConfig):delete t.__sentient_slot_config_overrides,e.persona){t.__sentient_persona_override={persona:e.persona,confidence:(i=e.confidence)!=null?i:1};try{let c=document.documentElement;c.setAttribute("data-sentient-persona",e.persona),c.setAttribute("data-sentient-confidence",et((l=e.confidence)!=null?l:1))}catch(c){}}else delete t.__sentient_persona_override;F()}import{jsx as nt}from"react/jsx-runtime";function qt(e,t={},n){return Ae(t),tt(nt(Ee,{apiKey:"pk_test",consent:!1,children:e}),n)}export{qt as renderWithSentient};
3
3
  //# sourceMappingURL=react.mjs.map