@sentientui/react 0.37.0 → 0.37.2
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.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/testing/react.js +1 -1
- package/dist/testing/react.mjs +1 -1
- package/package.json +3 -3
package/dist/testing/react.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";var Ae=Object.create;var G=Object.defineProperty,Oe=Object.defineProperties,Ie=Object.getOwnPropertyDescriptor,Te=Object.getOwnPropertyDescriptors,Ve=Object.getOwnPropertyNames,ie=Object.getOwnPropertySymbols,De=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var re=(e,t,n)=>t in e?G(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))oe.call(t,n)&&re(e,n,t[n]);if(ie)for(var n of ie(t))Le.call(t,n)&&re(e,n,t[n]);return e},M=(e,t)=>Oe(e,Te(t));var Ge=(e,t)=>{for(var n in t)G(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Ve(t))!oe.call(e,a)&&a!==n&&G(e,a,{get:()=>t[a],enumerable:!(i=Ie(t,a))||i.enumerable});return e};var $=(e,t,n)=>(n=e!=null?Ae(De(e)):{},se(t||!e||!e.__esModule?G(n,"default",{value:e,enumerable:!0}):n,e)),Fe=e=>se(G({},"__esModule",{value:!0}),e);var et={};Ge(et,{renderWithSentient:()=>Ze});module.exports=Fe(et);var Ee=require("@testing-library/react");var o=require("react"),B=require("@sentientui/core");var Ne=new Map,We=new Map;function ae(e,t){Ne.set(e,t);let n=We.get(e);if(n)for(let i of n)try{i(t)}catch(a){}}var Me={on:!1,listeners:new Set};function le(){if(typeof window=="undefined")return Me;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function U(){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),assign:(t,n,i,a)=>e.assign(t,n,i,a),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 $e="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($e))}function ue(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function N(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var Ke={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function j(){if(typeof window=="undefined")return Ke;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 Be(){j().version+=1;for(let e of j().listeners)e()}function H(e){N()&&(j().sections=[...e],Be())}var fe="0.37.0",z=fe!=="0.0.0-dev"?{name:"react",version:fe}:void 0;function Ue(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function T(e,t){Ue()[e]=t}function ge(e){window.__sentient_vocabulary_override=e}function je(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function V(e,t){je()[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 a=n.slice(i.index+i[0].length);i[1]!="&"&&a[0]=="&"&&(a=i[1]+a.slice(1));let u=n.slice(0,i.index)+a;history.replaceState(history.state,"",u?"#"+u:location.pathname+location.search)}}catch(n){}return t}var q="__snt_editor_token",D=null,J=!1;function me(){return J}function He(){try{return sessionStorage.getItem(q)}catch(e){return null}}function K(e){if(D)return D;let t=typeof window=="undefined"?null:pe("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:He();return J=!!n,D=Promise.resolve(n?{token:n,fresh:!1}:null),D}return J=!0,D=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(a){}return{token:i,fresh:!0}}).catch(()=>({error:0})),D}function ye(){try{sessionStorage.removeItem(q)}catch(e){}}var ve="sentient_preview_cell",_e="sentient_refresh_region",X="sentient-cell-preview-bar",A="__preview__",ze=null;function Se(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(X))return;let t,n;try{let l=new URLSearchParams(window.location.search);t=l.get(ve),n=l.get(_e)}catch(l){return}if(!t&&!n)return;let i=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),a=K(i);if(!me())return;if(n){ze={slotId:n,session:a,base:i},T(n,{kind:"arms"}),V(n,A),F();return}if(!t)return;let u=t.lastIndexOf("~");if(u<=0)return;let g=t.slice(0,u),O=t.slice(u+1);a.then(l=>l?"token"in l?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(g)}&persona=${encodeURIComponent(O)}`,{headers:{authorization:`Bearer ${l.token}`}}):(W(l.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 l=>{if(!l)return;if(!l.ok){W(l.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 c=await l.json();if(c.vocabulary&&Array.isArray(c.vocabulary.entries)&&ge(c.vocabulary),c.compose!=null)T(g,{kind:"arms",compose:{[A]:c.compose}}),V(g,A);else if(c.edits!=null&&typeof c.skeletonFp=="string"&&Array.isArray(c.leafToNode))T(g,{kind:"arms",edits:{edits:c.edits,fp:c.skeletonFp,leafToNode:c.leafToNode}}),V(g,A);else if(c.blocks!=null)T(g,{kind:"arms",blocks:{[A]:c.blocks}}),V(g,A);else if(c.content!=null)T(g,{kind:"arms",content:c.content}),V(g,A);else{W("Nothing to preview in that square yet.");return}F(),W(`Previewing \u201C${c.slotName}\u201D for ${c.personaDisplay}${c.status==="review"?" \u2014 waiting for your approval":""}. Nothing is being tracked.`),setTimeout(()=>{var p;try{(p=document.querySelector(`[data-sentient-slot="${g}"]`))==null||p.scrollIntoView({block:"center"})}catch(y){}},300)}).catch(()=>W("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function W(e){var a;if(document.getElementById(X))return;let t=document.createElement("div");t.id=X,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 u=new URL(window.location.href);u.searchParams.delete(ve),u.searchParams.delete(_e),window.location.assign(u.toString())},t.append(n,i),((a=document.body)!=null?a:document.documentElement).append(t)}var he=!1;function we(e){if(he||typeof window=="undefined")return;he=!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})}var Re=require("react/jsx-runtime");function qe(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return(0,B.deriveSessionSegment)({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var Ce="https://api.sentient-ui.com/v1",Xe=(0,o.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:Ce,debug:!1}),be=!1,Y=new Set;function Ye(e,t,n){let i=(0,o.useRef)(n);i.current=n;let[a,u]=(0,o.useState)(null),[g,O]=(0,o.useState)(!1),l=(0,o.useRef)(e);l.current=e;let c=e===void 0?"":typeof e=="string"?e:JSON.stringify(M(v({},e),{check:typeof e.check,refused:typeof e.refused}));return(0,o.useEffect)(()=>{let p=l.current;if(p===void 0||typeof window=="undefined")return;let y,k=!1;return import("@sentientui/core/consent").then(({consentWatcher:x,forgetVisitor:I})=>{if(k)return;let E=x(typeof p=="object"&&p.cmp===void 0&&p.check?v(M(v({},p),{check:()=>l.current.check()}),p.refused?{refused:()=>{var h,w;return((w=(h=l.current).refused)==null?void 0:w.call(h))===!0}}:{}):p),S=!1,L=()=>{let h=E.refused()&&E.read()!==!0;h&&!S&&(I(t),i.current()),S=h,O(h);let w=E.read();w!==null&&Y.add(t),u(w!=null?w:Y.has(t)?!1:null)};L(),y=E.subscribe(L)}),()=>{k=!0,y==null||y()}},[c,t]),{granted:a,refused:g}}function xe(e){var Q,Z,ee;let[t,n]=(0,o.useState)(null),[i]=(0,o.useState)(()=>{var r;return(r=e.sessionSegment)!=null?r:qe()}),[a,u]=(0,o.useState)(U());(0,o.useEffect)(()=>ce(()=>u(U())),[]),(0,o.useEffect)(()=>{Se(e.apiBaseUrl),we(e.apiBaseUrl)},[]);let g=(0,o.useRef)(()=>{}),O=Ye(e.consentFrom,e.apiKey,()=>g.current()),l=e.consentFrom?(Q=O.granted)!=null?Q:Y.has(e.apiKey)?!1:e.consent===!0:e.consent,c=e.consentFrom?O.refused:!0,p=(0,o.useRef)(c);p.current=c;let y=(0,o.useRef)(null),k=(0,o.useRef)(!1),x=(0,o.useRef)([]),I=(0,o.useRef)(!1);g.current=()=>{var f;x.current=[],I.current=!0;let r=y.current;r!=null&&r.gated?r.dispose():(f=r==null?void 0:r.takeHeld)==null||f.call(r)},(0,o.useEffect)(()=>{var te,ne;if(p.current&&l===!1&&(x.current=[]),l===!1&&k.current&&(p.current&&((te=y.current)==null||te.destroy()),y.current=null,k.current=!1),l===!1&&!e.preConsentBehavior){p.current&&((ne=y.current)==null||ne.destroy()),y.current=null,n(null);return}let r=l!==!1;r&&(I.current=!1);let f=_=>{!r&&I.current&&_.gated&&_.dispose()},m=v({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:i,consent:l,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,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,s=null,b=null,C=_=>{for(let P of x.current.splice(0))setTimeout(()=>{if(y.current!==_){I.current||x.current.push(P);return}try{P(_)}catch(tt){}},0)},R=_=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:P})=>{d||(b=P(_,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:_})=>{d||(s=_(M(v({},m),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),f(s),y.current=s,k.current=r,C(s),n(s),R(s))}):(s=(0,B.init)(m),f(s),y.current=s,k.current=r,C(s),n(s),R(s)),()=>{var _,P;d=!0,b==null||b(),x.current=x.current.concat((P=(_=s==null?void 0:s.takeHeld)==null?void 0:_.call(s))!=null?P:[]),s==null||s.dispose()}},[l]),(0,o.useEffect)(()=>{if(!t)return;let r=!1,f=async()=>{if(r)return;let d;try{d=await t.fetchWeights()}catch(s){return}if(!r)for(let s of d){let b={componentId:s.componentId,updatedAt:s.updatedAt,variants:s.variants.map(C=>{var R;return{variantId:C.variantId,pulls:C.pulls,avgReward:(R=C.avgReward)!=null?R:0}})};ae(s.componentId,b)}};f();let m=setInterval(()=>{f()},6e4);return()=>{r=!0,clearInterval(m)}},[t]);let E=(Z=e.ssrFallback)!=null?Z:"first",S=((ee=e.apiBaseUrl)!=null?ee:Ce).replace(/\/$/,""),L=(0,o.useRef)(null);(0,o.useEffect)(()=>{var m;if(typeof process!="undefined"&&((m=process.env)==null?void 0:m.NODE_ENV)==="production")return;let r={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:S},f=L.current;if(L.current=r,f!==null)for(let d of["apiKey","context","country","persona","apiBaseUrl"])Object.is(f[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,S]),(0,o.useEffect)(()=>{var r;typeof process!="undefined"&&((r=process.env)==null?void 0:r.NODE_ENV)==="production"||ue({apiKey:e.apiKey,apiBaseUrl:S,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,S]),(0,o.useEffect)(()=>{let r=e.initialLayoutOrder;if(r&&r.length>0){H(r);return}e.declaredSections&&e.declaredSections.length>0&&H(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),(0,o.useEffect)(()=>{!N()||e.consent!==void 0||e.consentFrom!==void 0||be||(be=!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'))},[]),(0,o.useEffect)(()=>{if(!N())return;let r=e.declaredSections;if(!r||r.length===0||typeof document=="undefined")return;let f=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),d=>d.getAttribute("data-sentient-id"))),m=r.filter(d=>!f.has(d));m.length>0&&console.warn(`[SentientUI] Declared section${m.length>1?"s":""} ${m.map(d=>`"${d}"`).join(", ")} ${m.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 h=(0,o.useMemo)(()=>t&&a?de(t):t,[t,a]),w=(0,o.useMemo)(()=>{var r,f,m,d,s,b,C,R;return{client:h,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},sessionSegment:i,ssrFallback:E,onAssignment:e.onAssignment,initialLayoutOrder:(f=e.initialLayoutOrder)!=null?f:null,initialSlots:(m=e.initialSlots)!=null?m:{},initialSlotConfig:(d=e.initialSlotConfig)!=null?d:{},initialPalette:(s=e.initialPalette)!=null?s:null,initialVocabulary:(b=e.initialVocabulary)!=null?b:null,initialPersona:(C=e.initialPersona)!=null?C:null,apiBaseUrl:S,debug:(R=e.debug)!=null?R:!1}},[h,e.apiKey,e.initialAssignments,i,E,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,S,e.debug]);return(0,Re.jsx)(Xe.Provider,{value:w,children:e.children})}function Qe(e){return e<.3?"low":e<.7?"medium":"high"}function ke(e={}){var n,i,a;let t=window;if(t.__sentient_overrides=v({},(n=e.variants)!=null?n:{}),e.layout?t.__sentient_layout_override=e.layout:delete t.__sentient_layout_override,e.slots?t.__sentient_slot_overrides=v({},e.slots):delete t.__sentient_slot_overrides,e.slotConfig?t.__sentient_slot_config_overrides=v({},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 u=document.documentElement;u.setAttribute("data-sentient-persona",e.persona),u.setAttribute("data-sentient-confidence",Qe((a=e.confidence)!=null?a:1))}catch(u){}}else delete t.__sentient_persona_override;F()}var Pe=require("react/jsx-runtime");function Ze(e,t={},n){return ke(t),(0,Ee.render)((0,Pe.jsx)(xe,{apiKey:"pk_test",consent:!1,children:e}),n)}0&&(module.exports={renderWithSentient});
|
|
2
|
+
"use strict";var Ae=Object.create;var G=Object.defineProperty,Oe=Object.defineProperties,Ie=Object.getOwnPropertyDescriptor,Te=Object.getOwnPropertyDescriptors,Ve=Object.getOwnPropertyNames,ie=Object.getOwnPropertySymbols,De=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var re=(e,t,n)=>t in e?G(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))oe.call(t,n)&&re(e,n,t[n]);if(ie)for(var n of ie(t))Le.call(t,n)&&re(e,n,t[n]);return e},M=(e,t)=>Oe(e,Te(t));var Ge=(e,t)=>{for(var n in t)G(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Ve(t))!oe.call(e,a)&&a!==n&&G(e,a,{get:()=>t[a],enumerable:!(i=Ie(t,a))||i.enumerable});return e};var $=(e,t,n)=>(n=e!=null?Ae(De(e)):{},se(t||!e||!e.__esModule?G(n,"default",{value:e,enumerable:!0}):n,e)),Fe=e=>se(G({},"__esModule",{value:!0}),e);var et={};Ge(et,{renderWithSentient:()=>Ze});module.exports=Fe(et);var Ee=require("@testing-library/react");var o=require("react"),B=require("@sentientui/core");var Ne=new Map,We=new Map;function ae(e,t){Ne.set(e,t);let n=We.get(e);if(n)for(let i of n)try{i(t)}catch(a){}}var Me={on:!1,listeners:new Set};function le(){if(typeof window=="undefined")return Me;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function U(){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),assign:(t,n,i,a)=>e.assign(t,n,i,a),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 $e="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($e))}function ue(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function N(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var Ke={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function j(){if(typeof window=="undefined")return Ke;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 Be(){j().version+=1;for(let e of j().listeners)e()}function H(e){N()&&(j().sections=[...e],Be())}var fe="0.37.2",z=fe!=="0.0.0-dev"?{name:"react",version:fe}:void 0;function Ue(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function T(e,t){Ue()[e]=t}function ge(e){window.__sentient_vocabulary_override=e}function je(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function V(e,t){je()[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 a=n.slice(i.index+i[0].length);i[1]!="&"&&a[0]=="&"&&(a=i[1]+a.slice(1));let u=n.slice(0,i.index)+a;history.replaceState(history.state,"",u?"#"+u:location.pathname+location.search)}}catch(n){}return t}var q="__snt_editor_token",D=null,J=!1;function me(){return J}function He(){try{return sessionStorage.getItem(q)}catch(e){return null}}function K(e){if(D)return D;let t=typeof window=="undefined"?null:pe("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:He();return J=!!n,D=Promise.resolve(n?{token:n,fresh:!1}:null),D}return J=!0,D=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(a){}return{token:i,fresh:!0}}).catch(()=>({error:0})),D}function ye(){try{sessionStorage.removeItem(q)}catch(e){}}var ve="sentient_preview_cell",_e="sentient_refresh_region",X="sentient-cell-preview-bar",A="__preview__",ze=null;function Se(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(X))return;let t,n;try{let l=new URLSearchParams(window.location.search);t=l.get(ve),n=l.get(_e)}catch(l){return}if(!t&&!n)return;let i=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),a=K(i);if(!me())return;if(n){ze={slotId:n,session:a,base:i},T(n,{kind:"arms"}),V(n,A),F();return}if(!t)return;let u=t.lastIndexOf("~");if(u<=0)return;let g=t.slice(0,u),O=t.slice(u+1);a.then(l=>l?"token"in l?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(g)}&persona=${encodeURIComponent(O)}`,{headers:{authorization:`Bearer ${l.token}`}}):(W(l.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 l=>{if(!l)return;if(!l.ok){W(l.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 c=await l.json();if(c.vocabulary&&Array.isArray(c.vocabulary.entries)&&ge(c.vocabulary),c.compose!=null)T(g,{kind:"arms",compose:{[A]:c.compose}}),V(g,A);else if(c.edits!=null&&typeof c.skeletonFp=="string"&&Array.isArray(c.leafToNode))T(g,{kind:"arms",edits:{edits:c.edits,fp:c.skeletonFp,leafToNode:c.leafToNode}}),V(g,A);else if(c.blocks!=null)T(g,{kind:"arms",blocks:{[A]:c.blocks}}),V(g,A);else if(c.content!=null)T(g,{kind:"arms",content:c.content}),V(g,A);else{W("Nothing to preview in that square yet.");return}F(),W(`Previewing \u201C${c.slotName}\u201D for ${c.personaDisplay}${c.status==="review"?" \u2014 waiting for your approval":""}. Nothing is being tracked.`),setTimeout(()=>{var p;try{(p=document.querySelector(`[data-sentient-slot="${g}"]`))==null||p.scrollIntoView({block:"center"})}catch(y){}},300)}).catch(()=>W("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function W(e){var a;if(document.getElementById(X))return;let t=document.createElement("div");t.id=X,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 u=new URL(window.location.href);u.searchParams.delete(ve),u.searchParams.delete(_e),window.location.assign(u.toString())},t.append(n,i),((a=document.body)!=null?a:document.documentElement).append(t)}var he=!1;function we(e){if(he||typeof window=="undefined")return;he=!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})}var Re=require("react/jsx-runtime");function qe(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return(0,B.deriveSessionSegment)({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var Ce="https://api.sentient-ui.com/v1",Xe=(0,o.createContext)({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:Ce,debug:!1}),be=!1,Y=new Set;function Ye(e,t,n){let i=(0,o.useRef)(n);i.current=n;let[a,u]=(0,o.useState)(null),[g,O]=(0,o.useState)(!1),l=(0,o.useRef)(e);l.current=e;let c=e===void 0?"":typeof e=="string"?e:JSON.stringify(M(v({},e),{check:typeof e.check,refused:typeof e.refused}));return(0,o.useEffect)(()=>{let p=l.current;if(p===void 0||typeof window=="undefined")return;let y,k=!1;return import("@sentientui/core/consent").then(({consentWatcher:x,forgetVisitor:I})=>{if(k)return;let E=x(typeof p=="object"&&p.cmp===void 0&&p.check?v(M(v({},p),{check:()=>l.current.check()}),p.refused?{refused:()=>{var h,w;return((w=(h=l.current).refused)==null?void 0:w.call(h))===!0}}:{}):p),S=!1,L=()=>{let h=E.refused()&&E.read()!==!0;h&&!S&&(I(t),i.current()),S=h,O(h);let w=E.read();w!==null&&Y.add(t),u(w!=null?w:Y.has(t)?!1:null)};L(),y=E.subscribe(L)}),()=>{k=!0,y==null||y()}},[c,t]),{granted:a,refused:g}}function xe(e){var Q,Z,ee;let[t,n]=(0,o.useState)(null),[i]=(0,o.useState)(()=>{var r;return(r=e.sessionSegment)!=null?r:qe()}),[a,u]=(0,o.useState)(U());(0,o.useEffect)(()=>ce(()=>u(U())),[]),(0,o.useEffect)(()=>{Se(e.apiBaseUrl),we(e.apiBaseUrl)},[]);let g=(0,o.useRef)(()=>{}),O=Ye(e.consentFrom,e.apiKey,()=>g.current()),l=e.consentFrom?(Q=O.granted)!=null?Q:Y.has(e.apiKey)?!1:e.consent===!0:e.consent,c=e.consentFrom?O.refused:!0,p=(0,o.useRef)(c);p.current=c;let y=(0,o.useRef)(null),k=(0,o.useRef)(!1),x=(0,o.useRef)([]),I=(0,o.useRef)(!1);g.current=()=>{var f;x.current=[],I.current=!0;let r=y.current;r!=null&&r.gated?r.dispose():(f=r==null?void 0:r.takeHeld)==null||f.call(r)},(0,o.useEffect)(()=>{var te,ne;if(p.current&&l===!1&&(x.current=[]),l===!1&&k.current&&(p.current&&((te=y.current)==null||te.destroy()),y.current=null,k.current=!1),l===!1&&!e.preConsentBehavior){p.current&&((ne=y.current)==null||ne.destroy()),y.current=null,n(null);return}let r=l!==!1;r&&(I.current=!1);let f=_=>{!r&&I.current&&_.gated&&_.dispose()},m=v({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:i,consent:l,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,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,s=null,b=null,C=_=>{for(let P of x.current.splice(0))setTimeout(()=>{if(y.current!==_){I.current||x.current.push(P);return}try{P(_)}catch(tt){}},0)},R=_=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:P})=>{d||(b=P(_,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:_})=>{d||(s=_(M(v({},m),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),f(s),y.current=s,k.current=r,C(s),n(s),R(s))}):(s=(0,B.init)(m),f(s),y.current=s,k.current=r,C(s),n(s),R(s)),()=>{var _,P;d=!0,b==null||b(),x.current=x.current.concat((P=(_=s==null?void 0:s.takeHeld)==null?void 0:_.call(s))!=null?P:[]),s==null||s.dispose()}},[l]),(0,o.useEffect)(()=>{if(!t)return;let r=!1,f=async()=>{if(r)return;let d;try{d=await t.fetchWeights()}catch(s){return}if(!r)for(let s of d){let b={componentId:s.componentId,updatedAt:s.updatedAt,variants:s.variants.map(C=>{var R;return{variantId:C.variantId,pulls:C.pulls,avgReward:(R=C.avgReward)!=null?R:0}})};ae(s.componentId,b)}};f();let m=setInterval(()=>{f()},6e4);return()=>{r=!0,clearInterval(m)}},[t]);let E=(Z=e.ssrFallback)!=null?Z:"first",S=((ee=e.apiBaseUrl)!=null?ee:Ce).replace(/\/$/,""),L=(0,o.useRef)(null);(0,o.useEffect)(()=>{var m;if(typeof process!="undefined"&&((m=process.env)==null?void 0:m.NODE_ENV)==="production")return;let r={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:S},f=L.current;if(L.current=r,f!==null)for(let d of["apiKey","context","country","persona","apiBaseUrl"])Object.is(f[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,S]),(0,o.useEffect)(()=>{var r;typeof process!="undefined"&&((r=process.env)==null?void 0:r.NODE_ENV)==="production"||ue({apiKey:e.apiKey,apiBaseUrl:S,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,S]),(0,o.useEffect)(()=>{let r=e.initialLayoutOrder;if(r&&r.length>0){H(r);return}e.declaredSections&&e.declaredSections.length>0&&H(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),(0,o.useEffect)(()=>{!N()||e.consent!==void 0||e.consentFrom!==void 0||be||(be=!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'))},[]),(0,o.useEffect)(()=>{if(!N())return;let r=e.declaredSections;if(!r||r.length===0||typeof document=="undefined")return;let f=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),d=>d.getAttribute("data-sentient-id"))),m=r.filter(d=>!f.has(d));m.length>0&&console.warn(`[SentientUI] Declared section${m.length>1?"s":""} ${m.map(d=>`"${d}"`).join(", ")} ${m.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 h=(0,o.useMemo)(()=>t&&a?de(t):t,[t,a]),w=(0,o.useMemo)(()=>{var r,f,m,d,s,b,C,R;return{client:h,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},sessionSegment:i,ssrFallback:E,onAssignment:e.onAssignment,initialLayoutOrder:(f=e.initialLayoutOrder)!=null?f:null,initialSlots:(m=e.initialSlots)!=null?m:{},initialSlotConfig:(d=e.initialSlotConfig)!=null?d:{},initialPalette:(s=e.initialPalette)!=null?s:null,initialVocabulary:(b=e.initialVocabulary)!=null?b:null,initialPersona:(C=e.initialPersona)!=null?C:null,apiBaseUrl:S,debug:(R=e.debug)!=null?R:!1}},[h,e.apiKey,e.initialAssignments,i,E,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,S,e.debug]);return(0,Re.jsx)(Xe.Provider,{value:w,children:e.children})}function Qe(e){return e<.3?"low":e<.7?"medium":"high"}function ke(e={}){var n,i,a;let t=window;if(t.__sentient_overrides=v({},(n=e.variants)!=null?n:{}),e.layout?t.__sentient_layout_override=e.layout:delete t.__sentient_layout_override,e.slots?t.__sentient_slot_overrides=v({},e.slots):delete t.__sentient_slot_overrides,e.slotConfig?t.__sentient_slot_config_overrides=v({},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 u=document.documentElement;u.setAttribute("data-sentient-persona",e.persona),u.setAttribute("data-sentient-confidence",Qe((a=e.confidence)!=null?a:1))}catch(u){}}else delete t.__sentient_persona_override;F()}var Pe=require("react/jsx-runtime");function Ze(e,t={},n){return ke(t),(0,Ee.render)((0,Pe.jsx)(xe,{apiKey:"pk_test",consent:!1,children:e}),n)}0&&(module.exports={renderWithSentient});
|
|
3
3
|
//# sourceMappingURL=react.js.map
|
package/dist/testing/react.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
var xe=Object.defineProperty,Re=Object.defineProperties;var ke=Object.getOwnPropertyDescriptors;var ne=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var ie=(e,t,n)=>t in e?xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,y=(e,t)=>{for(var n in t||(t={}))Ee.call(t,n)&&ie(e,n,t[n]);if(ne)for(var n of ne(t))Pe.call(t,n)&&ie(e,n,t[n]);return e},$=(e,t)=>Re(e,ke(t));import{render as Je}from"@testing-library/react";import{createContext as Me,useContext as Ct,useEffect as _,useMemo as Se,useRef as x,useState as M,useSyncExternalStore as xt}from"react";import{deriveSessionSegment as $e,init as Ke}from"@sentientui/core";var Ae=new Map,Oe=new Map;function re(e,t){Ae.set(e,t);let n=Oe.get(e);if(n)for(let r of n)try{r(t)}catch(l){}}var Ie={on:!1,listeners:new Set};function oe(){if(typeof window=="undefined")return Ie;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function B(){return oe().on}function se(e){let t=oe().listeners;return t.add(e),()=>{t.delete(e)}}function ae(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,r,l)=>e.assign(t,n,r,l),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 Te="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(Te))}function le(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function N(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var Ve={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function U(){if(typeof window=="undefined")return Ve;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 De(){U().version+=1;for(let e of U().listeners)e()}function j(e){N()&&(U().sections=[...e],De())}var ce="0.37.0",H=ce!=="0.0.0-dev"?{name:"react",version:ce}:void 0;function Le(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function V(e,t){Le()[e]=t}function de(e){window.__sentient_vocabulary_override=e}function Ge(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function D(e,t){Ge()[e]=t}function ue(e){let t=null;try{let n=location.hash.slice(1),r=RegExp("(^|[?&])"+e+"=([^&]*)").exec(n);if(r){t=r[2];let l=n.slice(r.index+r[0].length);r[1]!="&"&&l[0]=="&"&&(l=r[1]+l.slice(1));let d=n.slice(0,r.index)+l;history.replaceState(history.state,"",d?"#"+d:location.pathname+location.search)}}catch(n){}return t}var J="__snt_editor_token",L=null,z=!1;function fe(){return z}function Fe(){try{return sessionStorage.getItem(J)}catch(e){return null}}function K(e){if(L)return L;let t=typeof window=="undefined"?null:ue("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Fe();return z=!!n,L=Promise.resolve(n?{token:n,fresh:!1}:null),L}return z=!0,L=fetch(`${e}/editor/exchange`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({code:t})}).then(async n=>{let r=n.ok?(await n.json()).token:void 0;if(!r)return{error:n.ok?500:n.status};try{sessionStorage.setItem(J,r)}catch(l){}return{token:r,fresh:!0}}).catch(()=>({error:0})),L}function ge(){try{sessionStorage.removeItem(J)}catch(e){}}var pe="sentient_preview_cell",me="sentient_refresh_region",q="sentient-cell-preview-bar",O="__preview__",Ne=null;function ye(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(pe),n=s.get(me)}catch(s){return}if(!t&&!n)return;let r=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),l=K(r);if(!fe())return;if(n){Ne={slotId:n,session:l,base:r},V(n,{kind:"arms"}),D(n,O),F();return}if(!t)return;let d=t.lastIndexOf("~");if(d<=0)return;let f=t.slice(0,d),I=t.slice(d+1);l.then(s=>s?"token"in s?fetch(`${r}/editor/cell-preview?slotId=${encodeURIComponent(f)}&persona=${encodeURIComponent(I)}`,{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)&&de(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{W("Nothing to preview in that square yet.");return}F(),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(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 r=document.createElement("button");r.textContent="Exit preview",Object.assign(r.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"}),r.onclick=()=>{ge();let d=new URL(window.location.href);d.searchParams.delete(pe),d.searchParams.delete(me),window.location.assign(d.toString())},t.append(n,r),((l=document.body)!=null?l:document.documentElement).append(t)}var ve=!1;function _e(e){if(ve||typeof window=="undefined")return;ve=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||We(t,n.token)})}function We(e,t){let n=()=>{window.setTimeout(()=>{import("@sentientui/core/style-sample").then(({sampleStyleVocabulary:r})=>fetch(`${e}/editor/style-vocabulary`,{method:"POST",headers:{authorization:`Bearer ${t}`,"content-type":"application/json"},body:JSON.stringify(r(document))})).catch(()=>{})},1e3)};document.readyState==="complete"?n():window.addEventListener("load",n,{once:!0})}import{jsx as He}from"react/jsx-runtime";function Be(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return $e({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var we="https://api.sentient-ui.com/v1",Ue=Me({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:we,debug:!1}),he=!1,X=new Set;function je(e,t,n){let r=x(n);r.current=n;let[l,d]=M(null),[f,I]=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 _(()=>{let g=s.current;if(g===void 0||typeof window=="undefined")return;let m,E=!1;return import("@sentientui/core/consent").then(({consentWatcher:R,forgetVisitor:T})=>{if(E)return;let P=R(typeof g=="object"&&g.cmp===void 0&&g.check?y($(y({},g),{check:()=>s.current.check()}),g.refused?{refused:()=>{var h,w;return((w=(h=s.current).refused)==null?void 0:w.call(h))===!0}}:{}):g),S=!1,G=()=>{let h=P.refused()&&P.read()!==!0;h&&!S&&(T(t),r.current()),S=h,I(h);let w=P.read();w!==null&&X.add(t),d(w!=null?w:X.has(t)?!1:null)};G(),m=P.subscribe(G)}),()=>{E=!0,m==null||m()}},[a,t]),{granted:l,refused:f}}function be(e){var Y,Q,Z;let[t,n]=M(null),[r]=M(()=>{var i;return(i=e.sessionSegment)!=null?i:Be()}),[l,d]=M(B());_(()=>se(()=>d(B())),[]),_(()=>{ye(e.apiBaseUrl),_e(e.apiBaseUrl)},[]);let f=x(()=>{}),I=je(e.consentFrom,e.apiKey,()=>f.current()),s=e.consentFrom?(Y=I.granted)!=null?Y:X.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),R=x([]),T=x(!1);f.current=()=>{var u;R.current=[],T.current=!0;let i=m.current;i!=null&&i.gated?i.dispose():(u=i==null?void 0:i.takeHeld)==null||u.call(i)},_(()=>{var ee,te;if(g.current&&s===!1&&(R.current=[]),s===!1&&E.current&&(g.current&&((ee=m.current)==null||ee.destroy()),m.current=null,E.current=!1),s===!1&&!e.preConsentBehavior){g.current&&((te=m.current)==null||te.destroy()),m.current=null,n(null);return}let i=s!==!1;i&&(T.current=!1);let u=v=>{!i&&T.current&&v.gated&&v.dispose()},p=y({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:s,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,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},H?{sdk:H}:{}),c=!1,o=null,b=null,C=v=>{for(let A of R.current.splice(0))setTimeout(()=>{if(m.current!==v){T.current||R.current.push(A);return}try{A(v)}catch(Xe){}},0)},k=v=>{e.engagement===!1||!i||import("@sentientui/core/engagement").then(({startEngagementCapture:A})=>{c||(b=A(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})=>{c||(o=v($(y({},p),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),u(o),m.current=o,E.current=i,C(o),n(o),k(o))}):(o=Ke(p),u(o),m.current=o,E.current=i,C(o),n(o),k(o)),()=>{var v,A;c=!0,b==null||b(),R.current=R.current.concat((A=(v=o==null?void 0:o.takeHeld)==null?void 0:v.call(o))!=null?A:[]),o==null||o.dispose()}},[s]),_(()=>{if(!t)return;let i=!1,u=async()=>{if(i)return;let c;try{c=await t.fetchWeights()}catch(o){return}if(!i)for(let o of c){let b={componentId:o.componentId,updatedAt:o.updatedAt,variants:o.variants.map(C=>{var k;return{variantId:C.variantId,pulls:C.pulls,avgReward:(k=C.avgReward)!=null?k:0}})};re(o.componentId,b)}};u();let p=setInterval(()=>{u()},6e4);return()=>{i=!0,clearInterval(p)}},[t]);let P=(Q=e.ssrFallback)!=null?Q:"first",S=((Z=e.apiBaseUrl)!=null?Z:we).replace(/\/$/,""),G=x(null);_(()=>{var p;if(typeof process!="undefined"&&((p=process.env)==null?void 0:p.NODE_ENV)==="production")return;let i={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:S},u=G.current;if(G.current=i,u!==null)for(let c of["apiKey","context","country","persona","apiBaseUrl"])Object.is(u[c],i[c])||console.warn(`[sentient] AdaptiveProvider: \`${c}\` 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,S]),_(()=>{var i;typeof process!="undefined"&&((i=process.env)==null?void 0:i.NODE_ENV)==="production"||le({apiKey:e.apiKey,apiBaseUrl:S,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,S]),_(()=>{let i=e.initialLayoutOrder;if(i&&i.length>0){j(i);return}e.declaredSections&&e.declaredSections.length>0&&j(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),_(()=>{!N()||e.consent!==void 0||e.consentFrom!==void 0||he||(he=!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'))},[]),_(()=>{if(!N())return;let i=e.declaredSections;if(!i||i.length===0||typeof document=="undefined")return;let u=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),c=>c.getAttribute("data-sentient-id"))),p=i.filter(c=>!u.has(c));p.length>0&&console.warn(`[SentientUI] Declared section${p.length>1?"s":""} ${p.map(c=>`"${c}"`).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 h=Se(()=>t&&l?ae(t):t,[t,l]),w=Se(()=>{var i,u,p,c,o,b,C,k;return{client:h,apiKey:e.apiKey,initialAssignments:(i=e.initialAssignments)!=null?i:{},sessionSegment:r,ssrFallback:P,onAssignment:e.onAssignment,initialLayoutOrder:(u=e.initialLayoutOrder)!=null?u:null,initialSlots:(p=e.initialSlots)!=null?p:{},initialSlotConfig:(c=e.initialSlotConfig)!=null?c:{},initialPalette:(o=e.initialPalette)!=null?o:null,initialVocabulary:(b=e.initialVocabulary)!=null?b:null,initialPersona:(C=e.initialPersona)!=null?C:null,apiBaseUrl:S,debug:(k=e.debug)!=null?k:!1}},[h,e.apiKey,e.initialAssignments,r,P,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,S,e.debug]);return He(Ue.Provider,{value:w,children:e.children})}function ze(e){return e<.3?"low":e<.7?"medium":"high"}function Ce(e={}){var n,r,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:(r=e.confidence)!=null?r:1};try{let d=document.documentElement;d.setAttribute("data-sentient-persona",e.persona),d.setAttribute("data-sentient-confidence",ze((l=e.confidence)!=null?l:1))}catch(d){}}else delete t.__sentient_persona_override;F()}import{jsx as qe}from"react/jsx-runtime";function Bt(e,t={},n){return Ce(t),Je(qe(be,{apiKey:"pk_test",consent:!1,children:e}),n)}export{Bt as renderWithSentient};
|
|
2
|
+
var xe=Object.defineProperty,Re=Object.defineProperties;var ke=Object.getOwnPropertyDescriptors;var ne=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var ie=(e,t,n)=>t in e?xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,y=(e,t)=>{for(var n in t||(t={}))Ee.call(t,n)&&ie(e,n,t[n]);if(ne)for(var n of ne(t))Pe.call(t,n)&&ie(e,n,t[n]);return e},$=(e,t)=>Re(e,ke(t));import{render as Je}from"@testing-library/react";import{createContext as Me,useContext as Ct,useEffect as _,useMemo as Se,useRef as x,useState as M,useSyncExternalStore as xt}from"react";import{deriveSessionSegment as $e,init as Ke}from"@sentientui/core";var Ae=new Map,Oe=new Map;function re(e,t){Ae.set(e,t);let n=Oe.get(e);if(n)for(let r of n)try{r(t)}catch(l){}}var Ie={on:!1,listeners:new Set};function oe(){if(typeof window=="undefined")return Ie;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function B(){return oe().on}function se(e){let t=oe().listeners;return t.add(e),()=>{t.delete(e)}}function ae(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),assign:(t,n,r,l)=>e.assign(t,n,r,l),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 Te="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(Te))}function le(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function N(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var Ve={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function U(){if(typeof window=="undefined")return Ve;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 De(){U().version+=1;for(let e of U().listeners)e()}function j(e){N()&&(U().sections=[...e],De())}var ce="0.37.2",H=ce!=="0.0.0-dev"?{name:"react",version:ce}:void 0;function Le(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function V(e,t){Le()[e]=t}function de(e){window.__sentient_vocabulary_override=e}function Ge(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function D(e,t){Ge()[e]=t}function ue(e){let t=null;try{let n=location.hash.slice(1),r=RegExp("(^|[?&])"+e+"=([^&]*)").exec(n);if(r){t=r[2];let l=n.slice(r.index+r[0].length);r[1]!="&"&&l[0]=="&"&&(l=r[1]+l.slice(1));let d=n.slice(0,r.index)+l;history.replaceState(history.state,"",d?"#"+d:location.pathname+location.search)}}catch(n){}return t}var J="__snt_editor_token",L=null,z=!1;function fe(){return z}function Fe(){try{return sessionStorage.getItem(J)}catch(e){return null}}function K(e){if(L)return L;let t=typeof window=="undefined"?null:ue("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Fe();return z=!!n,L=Promise.resolve(n?{token:n,fresh:!1}:null),L}return z=!0,L=fetch(`${e}/editor/exchange`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({code:t})}).then(async n=>{let r=n.ok?(await n.json()).token:void 0;if(!r)return{error:n.ok?500:n.status};try{sessionStorage.setItem(J,r)}catch(l){}return{token:r,fresh:!0}}).catch(()=>({error:0})),L}function ge(){try{sessionStorage.removeItem(J)}catch(e){}}var pe="sentient_preview_cell",me="sentient_refresh_region",q="sentient-cell-preview-bar",O="__preview__",Ne=null;function ye(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(pe),n=s.get(me)}catch(s){return}if(!t&&!n)return;let r=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),l=K(r);if(!fe())return;if(n){Ne={slotId:n,session:l,base:r},V(n,{kind:"arms"}),D(n,O),F();return}if(!t)return;let d=t.lastIndexOf("~");if(d<=0)return;let f=t.slice(0,d),I=t.slice(d+1);l.then(s=>s?"token"in s?fetch(`${r}/editor/cell-preview?slotId=${encodeURIComponent(f)}&persona=${encodeURIComponent(I)}`,{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)&&de(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{W("Nothing to preview in that square yet.");return}F(),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(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 r=document.createElement("button");r.textContent="Exit preview",Object.assign(r.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"}),r.onclick=()=>{ge();let d=new URL(window.location.href);d.searchParams.delete(pe),d.searchParams.delete(me),window.location.assign(d.toString())},t.append(n,r),((l=document.body)!=null?l:document.documentElement).append(t)}var ve=!1;function _e(e){if(ve||typeof window=="undefined")return;ve=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||We(t,n.token)})}function We(e,t){let n=()=>{window.setTimeout(()=>{import("@sentientui/core/style-sample").then(({sampleStyleVocabulary:r})=>fetch(`${e}/editor/style-vocabulary`,{method:"POST",headers:{authorization:`Bearer ${t}`,"content-type":"application/json"},body:JSON.stringify(r(document))})).catch(()=>{})},1e3)};document.readyState==="complete"?n():window.addEventListener("load",n,{once:!0})}import{jsx as He}from"react/jsx-runtime";function Be(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return $e({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var we="https://api.sentient-ui.com/v1",Ue=Me({client:null,apiKey:"",initialAssignments:{},sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:we,debug:!1}),he=!1,X=new Set;function je(e,t,n){let r=x(n);r.current=n;let[l,d]=M(null),[f,I]=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 _(()=>{let g=s.current;if(g===void 0||typeof window=="undefined")return;let m,E=!1;return import("@sentientui/core/consent").then(({consentWatcher:R,forgetVisitor:T})=>{if(E)return;let P=R(typeof g=="object"&&g.cmp===void 0&&g.check?y($(y({},g),{check:()=>s.current.check()}),g.refused?{refused:()=>{var h,w;return((w=(h=s.current).refused)==null?void 0:w.call(h))===!0}}:{}):g),S=!1,G=()=>{let h=P.refused()&&P.read()!==!0;h&&!S&&(T(t),r.current()),S=h,I(h);let w=P.read();w!==null&&X.add(t),d(w!=null?w:X.has(t)?!1:null)};G(),m=P.subscribe(G)}),()=>{E=!0,m==null||m()}},[a,t]),{granted:l,refused:f}}function be(e){var Y,Q,Z;let[t,n]=M(null),[r]=M(()=>{var i;return(i=e.sessionSegment)!=null?i:Be()}),[l,d]=M(B());_(()=>se(()=>d(B())),[]),_(()=>{ye(e.apiBaseUrl),_e(e.apiBaseUrl)},[]);let f=x(()=>{}),I=je(e.consentFrom,e.apiKey,()=>f.current()),s=e.consentFrom?(Y=I.granted)!=null?Y:X.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),R=x([]),T=x(!1);f.current=()=>{var u;R.current=[],T.current=!0;let i=m.current;i!=null&&i.gated?i.dispose():(u=i==null?void 0:i.takeHeld)==null||u.call(i)},_(()=>{var ee,te;if(g.current&&s===!1&&(R.current=[]),s===!1&&E.current&&(g.current&&((ee=m.current)==null||ee.destroy()),m.current=null,E.current=!1),s===!1&&!e.preConsentBehavior){g.current&&((te=m.current)==null||te.destroy()),m.current=null,n(null);return}let i=s!==!1;i&&(T.current=!1);let u=v=>{!i&&T.current&&v.gated&&v.dispose()},p=y({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,sessionSegment:r,consent:s,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,country:e.country,persona:e.persona,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},H?{sdk:H}:{}),c=!1,o=null,b=null,C=v=>{for(let A of R.current.splice(0))setTimeout(()=>{if(m.current!==v){T.current||R.current.push(A);return}try{A(v)}catch(Xe){}},0)},k=v=>{e.engagement===!1||!i||import("@sentientui/core/engagement").then(({startEngagementCapture:A})=>{c||(b=A(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})=>{c||(o=v($(y({},p),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),u(o),m.current=o,E.current=i,C(o),n(o),k(o))}):(o=Ke(p),u(o),m.current=o,E.current=i,C(o),n(o),k(o)),()=>{var v,A;c=!0,b==null||b(),R.current=R.current.concat((A=(v=o==null?void 0:o.takeHeld)==null?void 0:v.call(o))!=null?A:[]),o==null||o.dispose()}},[s]),_(()=>{if(!t)return;let i=!1,u=async()=>{if(i)return;let c;try{c=await t.fetchWeights()}catch(o){return}if(!i)for(let o of c){let b={componentId:o.componentId,updatedAt:o.updatedAt,variants:o.variants.map(C=>{var k;return{variantId:C.variantId,pulls:C.pulls,avgReward:(k=C.avgReward)!=null?k:0}})};re(o.componentId,b)}};u();let p=setInterval(()=>{u()},6e4);return()=>{i=!0,clearInterval(p)}},[t]);let P=(Q=e.ssrFallback)!=null?Q:"first",S=((Z=e.apiBaseUrl)!=null?Z:we).replace(/\/$/,""),G=x(null);_(()=>{var p;if(typeof process!="undefined"&&((p=process.env)==null?void 0:p.NODE_ENV)==="production")return;let i={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,apiBaseUrl:S},u=G.current;if(G.current=i,u!==null)for(let c of["apiKey","context","country","persona","apiBaseUrl"])Object.is(u[c],i[c])||console.warn(`[sentient] AdaptiveProvider: \`${c}\` 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,S]),_(()=>{var i;typeof process!="undefined"&&((i=process.env)==null?void 0:i.NODE_ENV)==="production"||le({apiKey:e.apiKey,apiBaseUrl:S,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,S]),_(()=>{let i=e.initialLayoutOrder;if(i&&i.length>0){j(i);return}e.declaredSections&&e.declaredSections.length>0&&j(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),_(()=>{!N()||e.consent!==void 0||e.consentFrom!==void 0||he||(he=!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'))},[]),_(()=>{if(!N())return;let i=e.declaredSections;if(!i||i.length===0||typeof document=="undefined")return;let u=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),c=>c.getAttribute("data-sentient-id"))),p=i.filter(c=>!u.has(c));p.length>0&&console.warn(`[SentientUI] Declared section${p.length>1?"s":""} ${p.map(c=>`"${c}"`).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 h=Se(()=>t&&l?ae(t):t,[t,l]),w=Se(()=>{var i,u,p,c,o,b,C,k;return{client:h,apiKey:e.apiKey,initialAssignments:(i=e.initialAssignments)!=null?i:{},sessionSegment:r,ssrFallback:P,onAssignment:e.onAssignment,initialLayoutOrder:(u=e.initialLayoutOrder)!=null?u:null,initialSlots:(p=e.initialSlots)!=null?p:{},initialSlotConfig:(c=e.initialSlotConfig)!=null?c:{},initialPalette:(o=e.initialPalette)!=null?o:null,initialVocabulary:(b=e.initialVocabulary)!=null?b:null,initialPersona:(C=e.initialPersona)!=null?C:null,apiBaseUrl:S,debug:(k=e.debug)!=null?k:!1}},[h,e.apiKey,e.initialAssignments,r,P,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,S,e.debug]);return He(Ue.Provider,{value:w,children:e.children})}function ze(e){return e<.3?"low":e<.7?"medium":"high"}function Ce(e={}){var n,r,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:(r=e.confidence)!=null?r:1};try{let d=document.documentElement;d.setAttribute("data-sentient-persona",e.persona),d.setAttribute("data-sentient-confidence",ze((l=e.confidence)!=null?l:1))}catch(d){}}else delete t.__sentient_persona_override;F()}import{jsx as qe}from"react/jsx-runtime";function Bt(e,t={},n){return Ce(t),Je(qe(be,{apiKey:"pk_test",consent:!1,children:e}),n)}export{Bt as renderWithSentient};
|
|
3
3
|
//# sourceMappingURL=react.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentientui/react",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"llms.txt"
|
|
79
79
|
],
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@sentientui/core": "0.36.
|
|
82
|
-
"@sentientui/policy": "0.
|
|
81
|
+
"@sentientui/core": "0.36.2",
|
|
82
|
+
"@sentientui/policy": "0.13.1"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"@testing-library/react": ">=14.0.0 <17.0.0",
|