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