@sentientui/react 0.44.4 → 0.45.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 Ie=Object.defineProperty,Te=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var le=Object.getOwnPropertySymbols;var De=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var ce=(e,t,n)=>t in e?Ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,y=(e,t)=>{for(var n in t||(t={}))De.call(t,n)&&ce(e,n,t[n]);if(le)for(var n of le(t))Le.call(t,n)&&ce(e,n,t[n]);return e},$=(e,t)=>Te(e,Ve(t));import{render as nt}from"@testing-library/react";import{createContext as ze,useContext as Vt,useEffect as h,useMemo as ke,useRef as x,useState as M,useSyncExternalStore as Dt}from"react";import{deriveSessionSegment as Je,init as Xe}from"@sentientui/core";var Ge=new Map,Ne=new Map;function de(e,t){Ge.set(e,t);let n=Ne.get(e);if(n)for(let i of n)try{i(t)}catch(l){}}var Fe={on:!1,listeners:new Set};function B(){if(typeof window=="undefined")return Fe;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function ue(e){let t=B();if(t.on!==e){t.on=e;for(let n of t.listeners)n()}}function H(){return B().on}function fe(e){let t=B().listeners;return t.add(e),()=>{t.delete(e)}}function ge(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 Ue="sentient:overrides-changed";function U(){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(Ue))}function pe(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function E(){try{return process.env.NODE_ENV!=="production"}catch(e){return!0}}var We={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function j(){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 Me(){j().version+=1;for(let e of j().listeners)e()}function z(e){E()&&(j().sections=[...e],Me())}var me="0.44.4",J=me!=="0.0.0-dev"?{name:"react",version:me}:void 0;function $e(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function D(e,t){$e()[e]=t}function ye(e){window.__sentient_vocabulary_override=e}function Ke(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function L(e,t){Ke()[e]=t}function ve(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 q="__snt_editor_token",G=null,X=!1;function he(){return X}function Be(){try{return sessionStorage.getItem(q)}catch(e){return null}}function K(e){if(G)return G;let t=typeof window=="undefined"?null:ve("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Be();return X=!!n,G=Promise.resolve(n?{token:n,fresh:!1}:null),G}return X=!0,G=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(q,i)}catch(l){}return{token:i,fresh:!0}}).catch(()=>({error:0})),G}function _e(){try{sessionStorage.removeItem(q)}catch(e){}}var Se="sentient_preview_cell",we="sentient_refresh_region",Y="sentient-cell-preview-bar",I="__preview__",He=null;function be(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(Y))return;let t,n;try{let s=new URLSearchParams(window.location.search);t=s.get(Se),n=s.get(we)}catch(s){return}if(!t&&!n)return;let i=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),l=K(i);if(!he())return;if(n){He={slotId:n,session:l,base:i},D(n,{kind:"arms"}),L(n,I),U();return}if(!t)return;let c=t.lastIndexOf("~");if(c<=0)return;let f=t.slice(0,c),T=t.slice(c+1);l.then(s=>s?"token"in s?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(f)}&persona=${encodeURIComponent(T)}`,{headers:{authorization:`Bearer ${s.token}`}}):(W(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){W(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)&&ye(a.vocabulary),a.compose!=null)D(f,{kind:"arms",compose:{[I]:a.compose}}),L(f,I);else if(a.edits!=null&&typeof a.skeletonFp=="string"&&Array.isArray(a.leafToNode))D(f,{kind:"arms",edits:{edits:a.edits,fp:a.skeletonFp,leafToNode:a.leafToNode}}),L(f,I);else if(a.blocks!=null)D(f,{kind:"arms",blocks:{[I]:a.blocks}}),L(f,I);else if(a.content!=null)D(f,{kind:"arms",content:a.content}),L(f,I);else{W("Nothing to preview in that square yet.");return}U(),W(`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(()=>W("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function W(e){var l;if(document.getElementById(Y))return;let t=document.createElement("div");t.id=Y,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=()=>{_e();let c=new URL(window.location.href);c.searchParams.delete(Se),c.searchParams.delete(we),window.location.assign(c.toString())},t.append(n,i),((l=document.body)!=null?l:document.documentElement).append(t)}var Ce=!1;function xe(e){if(Ce||typeof window=="undefined")return;Ce=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||je(t,n.token)})}function je(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 et}from"react/jsx-runtime";function qe(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return Je({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var Ee="https://api.sentient-ui.com/v1",Ye=ze({client:null,apiKey:"",initialAssignments:{},initialUnified:[],sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:Ee,debug:!1}),Re=!1,Q=new Set;function Qe(e,t,n){let i=x(n);i.current=n;let[l,c]=M(null),[f,T]=M(!1),s=x(e);s.current=e;let a=e===void 0?"":typeof e=="string"?e:JSON.stringify($(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,A=!1;return import("@sentientui/core/consent").then(({consentWatcher:k,forgetVisitor:V})=>{if(A)return;let P=k(typeof g=="object"&&g.cmp===void 0&&g.check?y($(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,N=()=>{let _=P.refused()&&P.read()!==!0;_&&!w&&(V(t),i.current()),w=_,T(_);let S=P.read();S!==null&&Q.add(t),c(S!=null?S:Q.has(t)?!1:null)};N(),m=P.subscribe(N)}),()=>{A=!0,m==null||m()}},[a,t]),{granted:l,refused:f}}function Ae(e){var te,ne,ie,re,oe,se;let[t,n]=M(null),[i]=M(()=>{var r;return(r=e.sessionSegment)!=null?r:qe()}),[l,c]=M(H());h(()=>fe(()=>c(H())),[]),h(()=>{be(e.apiBaseUrl),typeof window!="undefined"&&/[?&]sentient_preview=[^&]*(:|%3A)/i.test(window.location.search)&&(ue(!0),import("@sentientui/react/version-preview").then(r=>r.maybeStartVersionPreview(e.apiKey,e.apiBaseUrl)).catch(()=>{})),xe(e.apiBaseUrl)},[]);let f=x(()=>{}),T=Qe(e.consentFrom,e.apiKey,()=>f.current()),s=e.consentFrom?(te=T.granted)!=null?te:Q.has(e.apiKey)?!1:e.consent===!0:e.consent,a=e.consentFrom?T.refused:!0,g=x(a);g.current=a;let m=x(null),A=x(!1),k=x([]),V=x(!1);f.current=()=>{var d;k.current=[],V.current=!0;let r=m.current;r!=null&&r.gated?r.dispose():(d=r==null?void 0:r.takeHeld)==null||d.call(r)},h(()=>{var F,ae;if(g.current&&s===!1&&(k.current=[]),s===!1&&A.current&&(g.current&&((F=m.current)==null||F.destroy()),m.current=null,A.current=!1),s===!1&&!e.preConsentBehavior){g.current&&((ae=m.current)==null||ae.destroy()),m.current=null,n(null);return}let r=s!==!1;r&&(V.current=!1);let d=v=>{!r&&V.current&&v.gated&&v.dispose()},u=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},J?{sdk:J}:{}),p=!1,o=null,b=null,C=v=>{for(let O of k.current.splice(0))setTimeout(()=>{if(m.current!==v){V.current||k.current.push(O);return}try{O(v)}catch(rt){}},0)},R=v=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:O})=>{p||(b=O(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})=>{p||(o=v($(y({},u),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),d(o),m.current=o,A.current=r,C(o),n(o),R(o))}):(o=Xe(u),d(o),m.current=o,A.current=r,C(o),n(o),R(o)),()=>{var v,O;p=!0,b==null||b(),k.current=k.current.concat((O=(v=o==null?void 0:o.takeHeld)==null?void 0:v.call(o))!=null?O:[]),o==null||o.dispose()}},[s]),h(()=>{if(!t)return;let r=!1,d=async()=>{if(r)return;let p;try{p=await t.fetchWeights()}catch(o){return}if(!r)for(let o of p){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}})};de(o.componentId,b)}};d();let u=setInterval(()=>{d()},6e4);return()=>{r=!0,clearInterval(u)}},[t]);let P=(ne=e.ssrFallback)!=null?ne:"first",w=((ie=e.apiBaseUrl)!=null?ie:Ee).replace(/\/$/,""),N=x(null);h(()=>{if(!E())return;let r={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,internal:e.internal,apiBaseUrl:w},d=N.current;if(N.current=r,d!==null)for(let u of["apiKey","context","country","persona","internal","apiBaseUrl"])Object.is(d[u],r[u])||console.warn(`[sentient] AdaptiveProvider: \`${u}\` 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(()=>{E()&&pe({apiKey:e.apiKey,apiBaseUrl:w,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,w]);let _=(re=e.identity)==null?void 0:re.userId,S=(oe=e.identity)==null?void 0:oe.userHash,Z=(se=e.identity)==null?void 0:se.email;h(()=>{t&&_&&t.identify(_,{userHash:S,email:Z})},[t,_,S,Z]),h(()=>{let r=e.initialLayoutOrder;if(r&&r.length>0){z(r);return}e.declaredSections&&e.declaredSections.length>0&&z(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),h(()=>{!E()||e.consent!==void 0||e.consentFrom!==void 0||Re||(Re=!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(!E())return;let r=e.declaredSections;if(!r||r.length===0||typeof document=="undefined")return;let d=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),p=>p.getAttribute("data-sentient-id"))),u=r.filter(p=>!d.has(p));u.length>0&&console.warn(`[SentientUI] Declared section${u.length>1?"s":""} ${u.map(p=>`"${p}"`).join(", ")} ${u.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 ee=ke(()=>t&&l?ge(t):t,[t,l]),Oe=ke(()=>{var r,d,u,p,o,b,C,R,F;return{client:ee,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},initialUnified:(d=e.initialUnified)!=null?d:Ze,sessionSegment:i,ssrFallback:P,onAssignment:e.onAssignment,initialLayoutOrder:(u=e.initialLayoutOrder)!=null?u:null,initialSlots:(p=e.initialSlots)!=null?p:{},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:(F=e.debug)!=null?F:!1}},[ee,e.apiKey,e.initialAssignments,e.initialUnified,i,P,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return et(Ye.Provider,{value:Oe,children:e.children})}var Ze=[];function tt(e){return e<.3?"low":e<.7?"medium":"high"}function Pe(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",tt((l=e.confidence)!=null?l:1))}catch(c){}}else delete t.__sentient_persona_override;U()}import{jsx as it}from"react/jsx-runtime";function Zt(e,t={},n){return Pe(t),nt(it(Ae,{apiKey:"pk_test",consent:!1,children:e}),n)}export{Zt as renderWithSentient};
2
+ var Ie=Object.defineProperty,Te=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var le=Object.getOwnPropertySymbols;var De=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var ce=(e,t,n)=>t in e?Ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,y=(e,t)=>{for(var n in t||(t={}))De.call(t,n)&&ce(e,n,t[n]);if(le)for(var n of le(t))Le.call(t,n)&&ce(e,n,t[n]);return e},$=(e,t)=>Te(e,Ve(t));import{render as nt}from"@testing-library/react";import{createContext as ze,useContext as Vt,useEffect as h,useMemo as ke,useRef as x,useState as M,useSyncExternalStore as Dt}from"react";import{deriveSessionSegment as Je,init as Xe}from"@sentientui/core";var Ge=new Map,Ne=new Map;function de(e,t){Ge.set(e,t);let n=Ne.get(e);if(n)for(let i of n)try{i(t)}catch(l){}}var Fe={on:!1,listeners:new Set};function B(){if(typeof window=="undefined")return Fe;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function ue(e){let t=B();if(t.on!==e){t.on=e;for(let n of t.listeners)n()}}function H(){return B().on}function fe(e){let t=B().listeners;return t.add(e),()=>{t.delete(e)}}function ge(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 Ue="sentient:overrides-changed";function U(){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(Ue))}function pe(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function E(){try{return process.env.NODE_ENV!=="production"}catch(e){return!0}}var We={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function j(){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 Me(){j().version+=1;for(let e of j().listeners)e()}function z(e){E()&&(j().sections=[...e],Me())}var me="0.45.0",J=me!=="0.0.0-dev"?{name:"react",version:me}:void 0;function $e(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function D(e,t){$e()[e]=t}function ye(e){window.__sentient_vocabulary_override=e}function Ke(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function L(e,t){Ke()[e]=t}function ve(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 q="__snt_editor_token",G=null,X=!1;function he(){return X}function Be(){try{return sessionStorage.getItem(q)}catch(e){return null}}function K(e){if(G)return G;let t=typeof window=="undefined"?null:ve("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Be();return X=!!n,G=Promise.resolve(n?{token:n,fresh:!1}:null),G}return X=!0,G=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(q,i)}catch(l){}return{token:i,fresh:!0}}).catch(()=>({error:0})),G}function _e(){try{sessionStorage.removeItem(q)}catch(e){}}var Se="sentient_preview_cell",we="sentient_refresh_region",Y="sentient-cell-preview-bar",I="__preview__",He=null;function be(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(Y))return;let t,n;try{let s=new URLSearchParams(window.location.search);t=s.get(Se),n=s.get(we)}catch(s){return}if(!t&&!n)return;let i=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),l=K(i);if(!he())return;if(n){He={slotId:n,session:l,base:i},D(n,{kind:"arms"}),L(n,I),U();return}if(!t)return;let c=t.lastIndexOf("~");if(c<=0)return;let f=t.slice(0,c),T=t.slice(c+1);l.then(s=>s?"token"in s?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(f)}&persona=${encodeURIComponent(T)}`,{headers:{authorization:`Bearer ${s.token}`}}):(W(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){W(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)&&ye(a.vocabulary),a.compose!=null)D(f,{kind:"arms",compose:{[I]:a.compose}}),L(f,I);else if(a.edits!=null&&typeof a.skeletonFp=="string"&&Array.isArray(a.leafToNode))D(f,{kind:"arms",edits:{edits:a.edits,fp:a.skeletonFp,leafToNode:a.leafToNode}}),L(f,I);else if(a.blocks!=null)D(f,{kind:"arms",blocks:{[I]:a.blocks}}),L(f,I);else if(a.content!=null)D(f,{kind:"arms",content:a.content}),L(f,I);else{W("Nothing to preview in that square yet.");return}U(),W(`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(()=>W("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function W(e){var l;if(document.getElementById(Y))return;let t=document.createElement("div");t.id=Y,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=()=>{_e();let c=new URL(window.location.href);c.searchParams.delete(Se),c.searchParams.delete(we),window.location.assign(c.toString())},t.append(n,i),((l=document.body)!=null?l:document.documentElement).append(t)}var Ce=!1;function xe(e){if(Ce||typeof window=="undefined")return;Ce=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||je(t,n.token)})}function je(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 et}from"react/jsx-runtime";function qe(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return Je({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var Ee="https://api.sentient-ui.com/v1",Ye=ze({client:null,apiKey:"",initialAssignments:{},initialUnified:[],sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:Ee,debug:!1}),Re=!1,Q=new Set;function Qe(e,t,n){let i=x(n);i.current=n;let[l,c]=M(null),[f,T]=M(!1),s=x(e);s.current=e;let a=e===void 0?"":typeof e=="string"?e:JSON.stringify($(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,A=!1;return import("@sentientui/core/consent").then(({consentWatcher:k,forgetVisitor:V})=>{if(A)return;let P=k(typeof g=="object"&&g.cmp===void 0&&g.check?y($(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,N=()=>{let _=P.refused()&&P.read()!==!0;_&&!w&&(V(t),i.current()),w=_,T(_);let S=P.read();S!==null&&Q.add(t),c(S!=null?S:Q.has(t)?!1:null)};N(),m=P.subscribe(N)}),()=>{A=!0,m==null||m()}},[a,t]),{granted:l,refused:f}}function Ae(e){var te,ne,ie,re,oe,se;let[t,n]=M(null),[i]=M(()=>{var r;return(r=e.sessionSegment)!=null?r:qe()}),[l,c]=M(H());h(()=>fe(()=>c(H())),[]),h(()=>{be(e.apiBaseUrl),typeof window!="undefined"&&/[?&]sentient_preview=[^&]*(:|%3A)/i.test(window.location.search)&&(ue(!0),import("@sentientui/react/version-preview").then(r=>r.maybeStartVersionPreview(e.apiKey,e.apiBaseUrl)).catch(()=>{})),xe(e.apiBaseUrl)},[]);let f=x(()=>{}),T=Qe(e.consentFrom,e.apiKey,()=>f.current()),s=e.consentFrom?(te=T.granted)!=null?te:Q.has(e.apiKey)?!1:e.consent===!0:e.consent,a=e.consentFrom?T.refused:!0,g=x(a);g.current=a;let m=x(null),A=x(!1),k=x([]),V=x(!1);f.current=()=>{var d;k.current=[],V.current=!0;let r=m.current;r!=null&&r.gated?r.dispose():(d=r==null?void 0:r.takeHeld)==null||d.call(r)},h(()=>{var F,ae;if(g.current&&s===!1&&(k.current=[]),s===!1&&A.current&&(g.current&&((F=m.current)==null||F.destroy()),m.current=null,A.current=!1),s===!1&&!e.preConsentBehavior){g.current&&((ae=m.current)==null||ae.destroy()),m.current=null,n(null);return}let r=s!==!1;r&&(V.current=!1);let d=v=>{!r&&V.current&&v.gated&&v.dispose()},u=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,googleAnalytics:e.googleAnalytics,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},J?{sdk:J}:{}),p=!1,o=null,b=null,C=v=>{for(let O of k.current.splice(0))setTimeout(()=>{if(m.current!==v){V.current||k.current.push(O);return}try{O(v)}catch(rt){}},0)},R=v=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:O})=>{p||(b=O(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})=>{p||(o=v($(y({},u),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),d(o),m.current=o,A.current=r,C(o),n(o),R(o))}):(o=Xe(u),d(o),m.current=o,A.current=r,C(o),n(o),R(o)),()=>{var v,O;p=!0,b==null||b(),k.current=k.current.concat((O=(v=o==null?void 0:o.takeHeld)==null?void 0:v.call(o))!=null?O:[]),o==null||o.dispose()}},[s]),h(()=>{if(!t)return;let r=!1,d=async()=>{if(r)return;let p;try{p=await t.fetchWeights()}catch(o){return}if(!r)for(let o of p){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}})};de(o.componentId,b)}};d();let u=setInterval(()=>{d()},6e4);return()=>{r=!0,clearInterval(u)}},[t]);let P=(ne=e.ssrFallback)!=null?ne:"first",w=((ie=e.apiBaseUrl)!=null?ie:Ee).replace(/\/$/,""),N=x(null);h(()=>{if(!E())return;let r={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,internal:e.internal,apiBaseUrl:w},d=N.current;if(N.current=r,d!==null)for(let u of["apiKey","context","country","persona","internal","apiBaseUrl"])Object.is(d[u],r[u])||console.warn(`[sentient] AdaptiveProvider: \`${u}\` 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(()=>{E()&&pe({apiKey:e.apiKey,apiBaseUrl:w,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,w]);let _=(re=e.identity)==null?void 0:re.userId,S=(oe=e.identity)==null?void 0:oe.userHash,Z=(se=e.identity)==null?void 0:se.email;h(()=>{t&&_&&t.identify(_,{userHash:S,email:Z})},[t,_,S,Z]),h(()=>{let r=e.initialLayoutOrder;if(r&&r.length>0){z(r);return}e.declaredSections&&e.declaredSections.length>0&&z(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),h(()=>{!E()||e.consent!==void 0||e.consentFrom!==void 0||Re||(Re=!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(!E())return;let r=e.declaredSections;if(!r||r.length===0||typeof document=="undefined")return;let d=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),p=>p.getAttribute("data-sentient-id"))),u=r.filter(p=>!d.has(p));u.length>0&&console.warn(`[SentientUI] Declared section${u.length>1?"s":""} ${u.map(p=>`"${p}"`).join(", ")} ${u.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 ee=ke(()=>t&&l?ge(t):t,[t,l]),Oe=ke(()=>{var r,d,u,p,o,b,C,R,F;return{client:ee,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},initialUnified:(d=e.initialUnified)!=null?d:Ze,sessionSegment:i,ssrFallback:P,onAssignment:e.onAssignment,initialLayoutOrder:(u=e.initialLayoutOrder)!=null?u:null,initialSlots:(p=e.initialSlots)!=null?p:{},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:(F=e.debug)!=null?F:!1}},[ee,e.apiKey,e.initialAssignments,e.initialUnified,i,P,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return et(Ye.Provider,{value:Oe,children:e.children})}var Ze=[];function tt(e){return e<.3?"low":e<.7?"medium":"high"}function Pe(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",tt((l=e.confidence)!=null?l:1))}catch(c){}}else delete t.__sentient_persona_override;U()}import{jsx as it}from"react/jsx-runtime";function Zt(e,t={},n){return Pe(t),nt(it(Ae,{apiKey:"pk_test",consent:!1,children:e}),n)}export{Zt as renderWithSentient};
3
3
  //# sourceMappingURL=react.mjs.map