@sentientui/react 0.44.3 → 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.
- package/README.md +3 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- 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/next/adaptive-root.d.ts +10 -0
- package/dist/testing/react.js +1 -1
- package/dist/testing/react.js.map +1 -1
- package/dist/testing/react.mjs +1 -1
- package/dist/testing/react.mjs.map +1 -1
- package/llms.txt +4 -0
- package/package.json +3 -3
|
@@ -219,6 +219,16 @@ type AdaptiveProviderProps = {
|
|
|
219
219
|
* `AdaptiveRoot` also writes it in the server HTML.
|
|
220
220
|
*/
|
|
221
221
|
stageAttributes?: StageAttributes;
|
|
222
|
+
/**
|
|
223
|
+
* Send what SentientUI shows to your own Google Analytics 4: a
|
|
224
|
+
* `sentient_exposure` event per component shown and the visitor's
|
|
225
|
+
* `sentient_group` (control or Sentient) as a user property, through the
|
|
226
|
+
* page's own gtag or Tag Manager. Normally switched in the dashboard
|
|
227
|
+
* (Settings → Integrations) with no code; `true` turns it on from code,
|
|
228
|
+
* `false` keeps it off whatever the dashboard says. Google's script is never
|
|
229
|
+
* loaded for you. Your `onAssignment` callback is unaffected.
|
|
230
|
+
*/
|
|
231
|
+
googleAnalytics?: boolean;
|
|
222
232
|
/**
|
|
223
233
|
* Keyless local mode. 'auto' (default) simulates decisions on-device in
|
|
224
234
|
* development builds when no valid API key is configured; `true` forces the
|
package/dist/testing/react.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";var Ge=Object.create;var F=Object.defineProperty,Ne=Object.defineProperties,Fe=Object.getOwnPropertyDescriptor,Ue=Object.getOwnPropertyDescriptors,We=Object.getOwnPropertyNames,ce=Object.getOwnPropertySymbols,Me=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable;var de=(e,t,n)=>t in e?F(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))ue.call(t,n)&&de(e,n,t[n]);if(ce)for(var n of ce(t))$e.call(t,n)&&de(e,n,t[n]);return e},$=(e,t)=>Ne(e,Ue(t));var Ke=(e,t)=>{for(var n in t)F(e,n,{get:t[n],enumerable:!0})},fe=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of We(t))!ue.call(e,a)&&a!==n&&F(e,a,{get:()=>t[a],enumerable:!(i=Fe(t,a))||i.enumerable});return e};var U=(e,t,n)=>(n=e!=null?Ge(Me(e)):{},fe(t||!e||!e.__esModule?F(n,"default",{value:e,enumerable:!0}):n,e)),Be=e=>fe(F({},"__esModule",{value:!0}),e);var lt={};Ke(lt,{renderWithSentient:()=>at});module.exports=Be(lt);var Ve=require("@testing-library/react");var o=require("react"),B=require("@sentientui/core");var He=new Map,je=new Map;function ge(e,t){He.set(e,t);let n=je.get(e);if(n)for(let i of n)try{i(t)}catch(a){}}var ze={on:!1,listeners:new Set};function H(){if(typeof window=="undefined")return ze;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function pe(e){let t=H();if(t.on!==e){t.on=e;for(let n of t.listeners)n()}}function j(){return H().on}function me(e){let t=H().listeners;return t.add(e),()=>{t.delete(e)}}function ye(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,a,d)=>e.assign(t,n,i,a,d),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 Je="sentient:overrides-changed";function W(){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(Je))}function ve(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function R(){try{return process.env.NODE_ENV!=="production"}catch(e){return!0}}var Xe={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function z(){if(typeof window=="undefined")return Xe;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 qe(){z().version+=1;for(let e of z().listeners)e()}function J(e){R()&&(z().sections=[...e],qe())}var he="0.44.3",X=he!=="0.0.0-dev"?{name:"react",version:he}:void 0;function Ye(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function V(e,t){Ye()[e]=t}function _e(e){window.__sentient_vocabulary_override=e}function Qe(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function D(e,t){Qe()[e]=t}function Se(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 d=n.slice(0,i.index)+a;history.replaceState(history.state,"",d?"#"+d:location.pathname+location.search)}}catch(n){}return t}var Y="__snt_editor_token",L=null,q=!1;function we(){return q}function Ze(){try{return sessionStorage.getItem(Y)}catch(e){return null}}function K(e){if(L)return L;let t=typeof window=="undefined"?null:Se("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Ze();return q=!!n,L=Promise.resolve(n?{token:n,fresh:!1}:null),L}return q=!0,L=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(Y,i)}catch(a){}return{token:i,fresh:!0}}).catch(()=>({error:0})),L}function be(){try{sessionStorage.removeItem(Y)}catch(e){}}var Ce="sentient_preview_cell",xe="sentient_refresh_region",Q="sentient-cell-preview-bar",O="__preview__",et=null;function ke(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(Q))return;let t,n;try{let l=new URLSearchParams(window.location.search);t=l.get(Ce),n=l.get(xe)}catch(l){return}if(!t&&!n)return;let i=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),a=K(i);if(!we())return;if(n){et={slotId:n,session:a,base:i},V(n,{kind:"arms"}),D(n,O),W();return}if(!t)return;let d=t.lastIndexOf("~");if(d<=0)return;let g=t.slice(0,d),I=t.slice(d+1);a.then(l=>l?"token"in l?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(g)}&persona=${encodeURIComponent(I)}`,{headers:{authorization:`Bearer ${l.token}`}}):(M(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){M(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)&&_e(c.vocabulary),c.compose!=null)V(g,{kind:"arms",compose:{[O]:c.compose}}),D(g,O);else if(c.edits!=null&&typeof c.skeletonFp=="string"&&Array.isArray(c.leafToNode))V(g,{kind:"arms",edits:{edits:c.edits,fp:c.skeletonFp,leafToNode:c.leafToNode}}),D(g,O);else if(c.blocks!=null)V(g,{kind:"arms",blocks:{[O]:c.blocks}}),D(g,O);else if(c.content!=null)V(g,{kind:"arms",content:c.content}),D(g,O);else{M("Nothing to preview in that square yet.");return}W(),M(`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(()=>M("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function M(e){var a;if(document.getElementById(Q))return;let t=document.createElement("div");t.id=Q,Object.assign(t.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"10px",padding:"10px 14px",borderRadius:"12px",maxWidth:"90vw",background:"#111827",color:"#fff",font:"13px system-ui, sans-serif",border:"1px solid rgba(139,92,246,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});let n=document.createElement("span");n.textContent=e;let i=document.createElement("button");i.textContent="Exit preview",Object.assign(i.style,{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.35)",background:"transparent",color:"#fff",font:"12px system-ui, sans-serif",cursor:"pointer"}),i.onclick=()=>{be();let d=new URL(window.location.href);d.searchParams.delete(Ce),d.searchParams.delete(xe),window.location.assign(d.toString())},t.append(n,i),((a=document.body)!=null?a:document.documentElement).append(t)}var Re=!1;function Ee(e){if(Re||typeof window=="undefined")return;Re=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||tt(t,n.token)})}function tt(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 Ie=require("react/jsx-runtime");function nt(){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 Pe="https://api.sentient-ui.com/v1",it=(0,o.createContext)({client:null,apiKey:"",initialAssignments:{},initialUnified:[],sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:Pe,debug:!1}),Ae=!1,Z=new Set;function rt(e,t,n){let i=(0,o.useRef)(n);i.current=n;let[a,d]=(0,o.useState)(null),[g,I]=(0,o.useState)(!1),l=(0,o.useRef)(e);l.current=e;let c=e===void 0?"":typeof e=="string"?e:JSON.stringify($(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,E=!1;return import("@sentientui/core/consent").then(({consentWatcher:x,forgetVisitor:T})=>{if(E)return;let A=x(typeof p=="object"&&p.cmp===void 0&&p.check?v($(v({},p),{check:()=>l.current.check()}),p.refused?{refused:()=>{var _,S;return((S=(_=l.current).refused)==null?void 0:S.call(_))===!0}}:{}):p),w=!1,G=()=>{let _=A.refused()&&A.read()!==!0;_&&!w&&(T(t),i.current()),w=_,I(_);let S=A.read();S!==null&&Z.add(t),d(S!=null?S:Z.has(t)?!1:null)};G(),y=A.subscribe(G)}),()=>{E=!0,y==null||y()}},[c,t]),{granted:a,refused:g}}function Oe(e){var ne,ie,re,oe,se,ae;let[t,n]=(0,o.useState)(null),[i]=(0,o.useState)(()=>{var r;return(r=e.sessionSegment)!=null?r:nt()}),[a,d]=(0,o.useState)(j());(0,o.useEffect)(()=>me(()=>d(j())),[]),(0,o.useEffect)(()=>{ke(e.apiBaseUrl),typeof window!="undefined"&&/[?&]sentient_preview=[^&]*(:|%3A)/i.test(window.location.search)&&(pe(!0),import("@sentientui/react/version-preview").then(r=>r.maybeStartVersionPreview(e.apiKey,e.apiBaseUrl)).catch(()=>{})),Ee(e.apiBaseUrl)},[]);let g=(0,o.useRef)(()=>{}),I=rt(e.consentFrom,e.apiKey,()=>g.current()),l=e.consentFrom?(ne=I.granted)!=null?ne:Z.has(e.apiKey)?!1:e.consent===!0:e.consent,c=e.consentFrom?I.refused:!0,p=(0,o.useRef)(c);p.current=c;let y=(0,o.useRef)(null),E=(0,o.useRef)(!1),x=(0,o.useRef)([]),T=(0,o.useRef)(!1);g.current=()=>{var u;x.current=[],T.current=!0;let r=y.current;r!=null&&r.gated?r.dispose():(u=r==null?void 0:r.takeHeld)==null||u.call(r)},(0,o.useEffect)(()=>{var N,le;if(p.current&&l===!1&&(x.current=[]),l===!1&&E.current&&(p.current&&((N=y.current)==null||N.destroy()),y.current=null,E.current=!1),l===!1&&!e.preConsentBehavior){p.current&&((le=y.current)==null||le.destroy()),y.current=null,n(null);return}let r=l!==!1;r&&(T.current=!1);let u=h=>{!r&&T.current&&h.gated&&h.dispose()},f=v({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,initialUnified:e.initialUnified,sessionSegment:i,consent:l,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},X?{sdk:X}:{}),m=!1,s=null,b=null,C=h=>{for(let P of x.current.splice(0))setTimeout(()=>{if(y.current!==h){T.current||x.current.push(P);return}try{P(h)}catch(ct){}},0)},k=h=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:P})=>{m||(b=P(h,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:h})=>{m||(s=h($(v({},f),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),u(s),y.current=s,E.current=r,C(s),n(s),k(s))}):(s=(0,B.init)(f),u(s),y.current=s,E.current=r,C(s),n(s),k(s)),()=>{var h,P;m=!0,b==null||b(),x.current=x.current.concat((P=(h=s==null?void 0:s.takeHeld)==null?void 0:h.call(s))!=null?P:[]),s==null||s.dispose()}},[l]),(0,o.useEffect)(()=>{if(!t)return;let r=!1,u=async()=>{if(r)return;let m;try{m=await t.fetchWeights()}catch(s){return}if(!r)for(let s of m){let b={componentId:s.componentId,updatedAt:s.updatedAt,variants:s.variants.map(C=>{var k;return{variantId:C.variantId,pulls:C.pulls,avgReward:(k=C.avgReward)!=null?k:0}})};ge(s.componentId,b)}};u();let f=setInterval(()=>{u()},6e4);return()=>{r=!0,clearInterval(f)}},[t]);let A=(ie=e.ssrFallback)!=null?ie:"first",w=((re=e.apiBaseUrl)!=null?re:Pe).replace(/\/$/,""),G=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!R())return;let r={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,internal:e.internal,apiBaseUrl:w},u=G.current;if(G.current=r,u!==null)for(let f of["apiKey","context","country","persona","internal","apiBaseUrl"])Object.is(u[f],r[f])||console.warn(`[sentient] AdaptiveProvider: \`${f}\` 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]),(0,o.useEffect)(()=>{R()&&ve({apiKey:e.apiKey,apiBaseUrl:w,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,w]);let _=(oe=e.identity)==null?void 0:oe.userId,S=(se=e.identity)==null?void 0:se.userHash,ee=(ae=e.identity)==null?void 0:ae.email;(0,o.useEffect)(()=>{t&&_&&t.identify(_,{userHash:S,email:ee})},[t,_,S,ee]),(0,o.useEffect)(()=>{let r=e.initialLayoutOrder;if(r&&r.length>0){J(r);return}e.declaredSections&&e.declaredSections.length>0&&J(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),(0,o.useEffect)(()=>{!R()||e.consent!==void 0||e.consentFrom!==void 0||Ae||(Ae=!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(!R())return;let r=e.declaredSections;if(!r||r.length===0||typeof document=="undefined")return;let u=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),m=>m.getAttribute("data-sentient-id"))),f=r.filter(m=>!u.has(m));f.length>0&&console.warn(`[SentientUI] Declared section${f.length>1?"s":""} ${f.map(m=>`"${m}"`).join(", ")} ${f.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 te=(0,o.useMemo)(()=>t&&a?ye(t):t,[t,a]),Le=(0,o.useMemo)(()=>{var r,u,f,m,s,b,C,k,N;return{client:te,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},initialUnified:(u=e.initialUnified)!=null?u:ot,sessionSegment:i,ssrFallback:A,onAssignment:e.onAssignment,initialLayoutOrder:(f=e.initialLayoutOrder)!=null?f:null,initialSlots:(m=e.initialSlots)!=null?m:{},initialSlotConfig:(s=e.initialSlotConfig)!=null?s:{},initialPalette:(b=e.initialPalette)!=null?b:null,initialVocabulary:(C=e.initialVocabulary)!=null?C:null,initialPersona:(k=e.initialPersona)!=null?k:null,apiBaseUrl:w,debug:(N=e.debug)!=null?N:!1}},[te,e.apiKey,e.initialAssignments,e.initialUnified,i,A,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return(0,Ie.jsx)(it.Provider,{value:Le,children:e.children})}var ot=[];function st(e){return e<.3?"low":e<.7?"medium":"high"}function Te(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 d=document.documentElement;d.setAttribute("data-sentient-persona",e.persona),d.setAttribute("data-sentient-confidence",st((a=e.confidence)!=null?a:1))}catch(d){}}else delete t.__sentient_persona_override;W()}var De=require("react/jsx-runtime");function at(e,t={},n){return Te(t),(0,Ve.render)((0,De.jsx)(Oe,{apiKey:"pk_test",consent:!1,children:e}),n)}0&&(module.exports={renderWithSentient});
|
|
2
|
+
"use strict";var Ge=Object.create;var F=Object.defineProperty,Ne=Object.defineProperties,Fe=Object.getOwnPropertyDescriptor,Ue=Object.getOwnPropertyDescriptors,We=Object.getOwnPropertyNames,ce=Object.getOwnPropertySymbols,Me=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable;var de=(e,t,n)=>t in e?F(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))ue.call(t,n)&&de(e,n,t[n]);if(ce)for(var n of ce(t))$e.call(t,n)&&de(e,n,t[n]);return e},$=(e,t)=>Ne(e,Ue(t));var Ke=(e,t)=>{for(var n in t)F(e,n,{get:t[n],enumerable:!0})},fe=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of We(t))!ue.call(e,a)&&a!==n&&F(e,a,{get:()=>t[a],enumerable:!(i=Fe(t,a))||i.enumerable});return e};var U=(e,t,n)=>(n=e!=null?Ge(Me(e)):{},fe(t||!e||!e.__esModule?F(n,"default",{value:e,enumerable:!0}):n,e)),Be=e=>fe(F({},"__esModule",{value:!0}),e);var lt={};Ke(lt,{renderWithSentient:()=>at});module.exports=Be(lt);var Ve=require("@testing-library/react");var o=require("react"),B=require("@sentientui/core");var He=new Map,je=new Map;function ge(e,t){He.set(e,t);let n=je.get(e);if(n)for(let i of n)try{i(t)}catch(a){}}var ze={on:!1,listeners:new Set};function H(){if(typeof window=="undefined")return ze;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function pe(e){let t=H();if(t.on!==e){t.on=e;for(let n of t.listeners)n()}}function j(){return H().on}function me(e){let t=H().listeners;return t.add(e),()=>{t.delete(e)}}function ye(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,a,d)=>e.assign(t,n,i,a,d),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 Je="sentient:overrides-changed";function W(){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(Je))}function ve(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function R(){try{return process.env.NODE_ENV!=="production"}catch(e){return!0}}var Xe={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function z(){if(typeof window=="undefined")return Xe;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 qe(){z().version+=1;for(let e of z().listeners)e()}function J(e){R()&&(z().sections=[...e],qe())}var he="0.45.0",X=he!=="0.0.0-dev"?{name:"react",version:he}:void 0;function Ye(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function V(e,t){Ye()[e]=t}function _e(e){window.__sentient_vocabulary_override=e}function Qe(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function D(e,t){Qe()[e]=t}function Se(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 d=n.slice(0,i.index)+a;history.replaceState(history.state,"",d?"#"+d:location.pathname+location.search)}}catch(n){}return t}var Y="__snt_editor_token",L=null,q=!1;function we(){return q}function Ze(){try{return sessionStorage.getItem(Y)}catch(e){return null}}function K(e){if(L)return L;let t=typeof window=="undefined"?null:Se("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Ze();return q=!!n,L=Promise.resolve(n?{token:n,fresh:!1}:null),L}return q=!0,L=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(Y,i)}catch(a){}return{token:i,fresh:!0}}).catch(()=>({error:0})),L}function be(){try{sessionStorage.removeItem(Y)}catch(e){}}var Ce="sentient_preview_cell",xe="sentient_refresh_region",Q="sentient-cell-preview-bar",O="__preview__",et=null;function ke(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(Q))return;let t,n;try{let l=new URLSearchParams(window.location.search);t=l.get(Ce),n=l.get(xe)}catch(l){return}if(!t&&!n)return;let i=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),a=K(i);if(!we())return;if(n){et={slotId:n,session:a,base:i},V(n,{kind:"arms"}),D(n,O),W();return}if(!t)return;let d=t.lastIndexOf("~");if(d<=0)return;let g=t.slice(0,d),I=t.slice(d+1);a.then(l=>l?"token"in l?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(g)}&persona=${encodeURIComponent(I)}`,{headers:{authorization:`Bearer ${l.token}`}}):(M(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){M(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)&&_e(c.vocabulary),c.compose!=null)V(g,{kind:"arms",compose:{[O]:c.compose}}),D(g,O);else if(c.edits!=null&&typeof c.skeletonFp=="string"&&Array.isArray(c.leafToNode))V(g,{kind:"arms",edits:{edits:c.edits,fp:c.skeletonFp,leafToNode:c.leafToNode}}),D(g,O);else if(c.blocks!=null)V(g,{kind:"arms",blocks:{[O]:c.blocks}}),D(g,O);else if(c.content!=null)V(g,{kind:"arms",content:c.content}),D(g,O);else{M("Nothing to preview in that square yet.");return}W(),M(`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(()=>M("Couldn\u2019t load this preview \u2014 check your connection and reopen it from your dashboard."))}function M(e){var a;if(document.getElementById(Q))return;let t=document.createElement("div");t.id=Q,Object.assign(t.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"10px",padding:"10px 14px",borderRadius:"12px",maxWidth:"90vw",background:"#111827",color:"#fff",font:"13px system-ui, sans-serif",border:"1px solid rgba(139,92,246,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});let n=document.createElement("span");n.textContent=e;let i=document.createElement("button");i.textContent="Exit preview",Object.assign(i.style,{padding:"4px 10px",borderRadius:"999px",border:"1px solid rgba(255,255,255,0.35)",background:"transparent",color:"#fff",font:"12px system-ui, sans-serif",cursor:"pointer"}),i.onclick=()=>{be();let d=new URL(window.location.href);d.searchParams.delete(Ce),d.searchParams.delete(xe),window.location.assign(d.toString())},t.append(n,i),((a=document.body)!=null?a:document.documentElement).append(t)}var Re=!1;function Ee(e){if(Re||typeof window=="undefined")return;Re=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||tt(t,n.token)})}function tt(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 Ie=require("react/jsx-runtime");function nt(){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 Pe="https://api.sentient-ui.com/v1",it=(0,o.createContext)({client:null,apiKey:"",initialAssignments:{},initialUnified:[],sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:Pe,debug:!1}),Ae=!1,Z=new Set;function rt(e,t,n){let i=(0,o.useRef)(n);i.current=n;let[a,d]=(0,o.useState)(null),[g,I]=(0,o.useState)(!1),l=(0,o.useRef)(e);l.current=e;let c=e===void 0?"":typeof e=="string"?e:JSON.stringify($(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,E=!1;return import("@sentientui/core/consent").then(({consentWatcher:x,forgetVisitor:T})=>{if(E)return;let A=x(typeof p=="object"&&p.cmp===void 0&&p.check?v($(v({},p),{check:()=>l.current.check()}),p.refused?{refused:()=>{var _,S;return((S=(_=l.current).refused)==null?void 0:S.call(_))===!0}}:{}):p),w=!1,G=()=>{let _=A.refused()&&A.read()!==!0;_&&!w&&(T(t),i.current()),w=_,I(_);let S=A.read();S!==null&&Z.add(t),d(S!=null?S:Z.has(t)?!1:null)};G(),y=A.subscribe(G)}),()=>{E=!0,y==null||y()}},[c,t]),{granted:a,refused:g}}function Oe(e){var ne,ie,re,oe,se,ae;let[t,n]=(0,o.useState)(null),[i]=(0,o.useState)(()=>{var r;return(r=e.sessionSegment)!=null?r:nt()}),[a,d]=(0,o.useState)(j());(0,o.useEffect)(()=>me(()=>d(j())),[]),(0,o.useEffect)(()=>{ke(e.apiBaseUrl),typeof window!="undefined"&&/[?&]sentient_preview=[^&]*(:|%3A)/i.test(window.location.search)&&(pe(!0),import("@sentientui/react/version-preview").then(r=>r.maybeStartVersionPreview(e.apiKey,e.apiBaseUrl)).catch(()=>{})),Ee(e.apiBaseUrl)},[]);let g=(0,o.useRef)(()=>{}),I=rt(e.consentFrom,e.apiKey,()=>g.current()),l=e.consentFrom?(ne=I.granted)!=null?ne:Z.has(e.apiKey)?!1:e.consent===!0:e.consent,c=e.consentFrom?I.refused:!0,p=(0,o.useRef)(c);p.current=c;let y=(0,o.useRef)(null),E=(0,o.useRef)(!1),x=(0,o.useRef)([]),T=(0,o.useRef)(!1);g.current=()=>{var u;x.current=[],T.current=!0;let r=y.current;r!=null&&r.gated?r.dispose():(u=r==null?void 0:r.takeHeld)==null||u.call(r)},(0,o.useEffect)(()=>{var N,le;if(p.current&&l===!1&&(x.current=[]),l===!1&&E.current&&(p.current&&((N=y.current)==null||N.destroy()),y.current=null,E.current=!1),l===!1&&!e.preConsentBehavior){p.current&&((le=y.current)==null||le.destroy()),y.current=null,n(null);return}let r=l!==!1;r&&(T.current=!1);let u=h=>{!r&&T.current&&h.gated&&h.dispose()},f=v({apiKey:e.apiKey,context:e.context,debug:e.debug,initialAssignments:e.initialAssignments,initialUnified:e.initialUnified,sessionSegment:i,consent:l,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},X?{sdk:X}:{}),m=!1,s=null,b=null,C=h=>{for(let P of x.current.splice(0))setTimeout(()=>{if(y.current!==h){T.current||x.current.push(P);return}try{P(h)}catch(ct){}},0)},k=h=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:P})=>{m||(b=P(h,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:h})=>{m||(s=h($(v({},f),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),u(s),y.current=s,E.current=r,C(s),n(s),k(s))}):(s=(0,B.init)(f),u(s),y.current=s,E.current=r,C(s),n(s),k(s)),()=>{var h,P;m=!0,b==null||b(),x.current=x.current.concat((P=(h=s==null?void 0:s.takeHeld)==null?void 0:h.call(s))!=null?P:[]),s==null||s.dispose()}},[l]),(0,o.useEffect)(()=>{if(!t)return;let r=!1,u=async()=>{if(r)return;let m;try{m=await t.fetchWeights()}catch(s){return}if(!r)for(let s of m){let b={componentId:s.componentId,updatedAt:s.updatedAt,variants:s.variants.map(C=>{var k;return{variantId:C.variantId,pulls:C.pulls,avgReward:(k=C.avgReward)!=null?k:0}})};ge(s.componentId,b)}};u();let f=setInterval(()=>{u()},6e4);return()=>{r=!0,clearInterval(f)}},[t]);let A=(ie=e.ssrFallback)!=null?ie:"first",w=((re=e.apiBaseUrl)!=null?re:Pe).replace(/\/$/,""),G=(0,o.useRef)(null);(0,o.useEffect)(()=>{if(!R())return;let r={apiKey:e.apiKey,context:e.context,country:e.country,persona:e.persona,internal:e.internal,apiBaseUrl:w},u=G.current;if(G.current=r,u!==null)for(let f of["apiKey","context","country","persona","internal","apiBaseUrl"])Object.is(u[f],r[f])||console.warn(`[sentient] AdaptiveProvider: \`${f}\` 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]),(0,o.useEffect)(()=>{R()&&ve({apiKey:e.apiKey,apiBaseUrl:w,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,w]);let _=(oe=e.identity)==null?void 0:oe.userId,S=(se=e.identity)==null?void 0:se.userHash,ee=(ae=e.identity)==null?void 0:ae.email;(0,o.useEffect)(()=>{t&&_&&t.identify(_,{userHash:S,email:ee})},[t,_,S,ee]),(0,o.useEffect)(()=>{let r=e.initialLayoutOrder;if(r&&r.length>0){J(r);return}e.declaredSections&&e.declaredSections.length>0&&J(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),(0,o.useEffect)(()=>{!R()||e.consent!==void 0||e.consentFrom!==void 0||Ae||(Ae=!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(!R())return;let r=e.declaredSections;if(!r||r.length===0||typeof document=="undefined")return;let u=new Set(Array.from(document.querySelectorAll("[data-sentient-id]"),m=>m.getAttribute("data-sentient-id"))),f=r.filter(m=>!u.has(m));f.length>0&&console.warn(`[SentientUI] Declared section${f.length>1?"s":""} ${f.map(m=>`"${m}"`).join(", ")} ${f.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 te=(0,o.useMemo)(()=>t&&a?ye(t):t,[t,a]),Le=(0,o.useMemo)(()=>{var r,u,f,m,s,b,C,k,N;return{client:te,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},initialUnified:(u=e.initialUnified)!=null?u:ot,sessionSegment:i,ssrFallback:A,onAssignment:e.onAssignment,initialLayoutOrder:(f=e.initialLayoutOrder)!=null?f:null,initialSlots:(m=e.initialSlots)!=null?m:{},initialSlotConfig:(s=e.initialSlotConfig)!=null?s:{},initialPalette:(b=e.initialPalette)!=null?b:null,initialVocabulary:(C=e.initialVocabulary)!=null?C:null,initialPersona:(k=e.initialPersona)!=null?k:null,apiBaseUrl:w,debug:(N=e.debug)!=null?N:!1}},[te,e.apiKey,e.initialAssignments,e.initialUnified,i,A,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return(0,Ie.jsx)(it.Provider,{value:Le,children:e.children})}var ot=[];function st(e){return e<.3?"low":e<.7?"medium":"high"}function Te(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 d=document.documentElement;d.setAttribute("data-sentient-persona",e.persona),d.setAttribute("data-sentient-confidence",st((a=e.confidence)!=null?a:1))}catch(d){}}else delete t.__sentient_persona_override;W()}var De=require("react/jsx-runtime");function at(e,t={},n){return Te(t),(0,Ve.render)((0,De.jsx)(Oe,{apiKey:"pk_test",consent:!1,children:e}),n)}0&&(module.exports={renderWithSentient});
|
|
3
3
|
//# sourceMappingURL=react.js.map
|