@sentientui/react 0.44.1 → 0.44.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 +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.cts +123 -0
- package/dist/server.d.ts +123 -0
- package/dist/testing/react.js +1 -1
- package/dist/testing/react.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as _sentientui_core from '@sentientui/core';
|
|
2
|
+
import * as _sentientui_core_server from '@sentientui/core/server';
|
|
3
|
+
import { ServerAssignments } from '@sentientui/core/server';
|
|
4
|
+
export { DecideResult, ServerAssignConfig, ServerAssignments, SlotDeclInput, SlotResult, preloadAssignments, preloadDecisions, readSessionCookie, signUserId, trackServerGoal } from '@sentientui/core/server';
|
|
5
|
+
|
|
6
|
+
/** Return value of `loadAdaptiveAssignments` — includes the session ID used for SSR. */
|
|
7
|
+
type LoadAdaptiveAssignmentsResult = {
|
|
8
|
+
assignments: ServerAssignments;
|
|
9
|
+
/** The session ID used for SSR assignment. Pass as `ssrSessionId` to `<AdaptiveProvider>`. */
|
|
10
|
+
sessionId: string;
|
|
11
|
+
/** Components the operator moved onto the shared track: not in
|
|
12
|
+
* `assignments`. Pass as `initialUnified` to `<AdaptiveProvider>`. */
|
|
13
|
+
unified: string[];
|
|
14
|
+
};
|
|
15
|
+
type LoadAdaptiveAssignmentsOptions = {
|
|
16
|
+
/** Next.js `cookies()` return value, or any object with `get(name)`. */
|
|
17
|
+
cookies: {
|
|
18
|
+
get(name: string): {
|
|
19
|
+
value: string;
|
|
20
|
+
} | undefined;
|
|
21
|
+
};
|
|
22
|
+
apiKey: string;
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
/** Used when `_snt_uid` is absent (e.g. first visit, many crawlers). */
|
|
25
|
+
createSessionId?: () => string;
|
|
26
|
+
/** Must match a value in the project's `allowed_origins` (e.g. `http://localhost:3001`). */
|
|
27
|
+
origin?: string;
|
|
28
|
+
/** From Next.js `headers().get('user-agent')` — aligns SSR segment with the client. */
|
|
29
|
+
userAgent?: string;
|
|
30
|
+
/** From Next.js `headers().get('referer')`. */
|
|
31
|
+
referer?: string;
|
|
32
|
+
/**
|
|
33
|
+
* `utm_*` params from the landing URL. The Referer header never carries the
|
|
34
|
+
* page's OWN query string, so without this the SSR-minted session has no
|
|
35
|
+
* campaign attribution until the client SDK hydrates and re-upserts.
|
|
36
|
+
* Derive with `extractTrackedParams(searchParams)` from `@sentientui/core/server`.
|
|
37
|
+
*/
|
|
38
|
+
utmParams?: Record<string, string>;
|
|
39
|
+
/** Ad-platform click IDs (gclid, fbclid, ttclid, …) from the landing URL — same derivation as `utmParams`. */
|
|
40
|
+
clickIds?: Record<string, string>;
|
|
41
|
+
/** The landing page's path (no query string) — recognises a paid click to a product page or a `/discount/` link on the first decision. */
|
|
42
|
+
landingPath?: string;
|
|
43
|
+
/** Set true when the request carries `DNT: 1` or `Sec-GPC: 1` — skips the SSR session upsert + assignment so no session is minted for an opted-out visitor (audit P4). `AdaptiveRoot` sets this automatically from the request headers. */
|
|
44
|
+
doNotTrack?: boolean;
|
|
45
|
+
/** Milliseconds to wait for the API before returning default variants. Defaults to 1000 (typical decide is well under 150 ms; the full budget is only reached on a cold start or a distant API). */
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Declared persona — the role your app already knows for this visitor (e.g.
|
|
49
|
+
* from your auth context: 'admin', 'evaluator'). Must be a key in the
|
|
50
|
+
* project's persona vocabulary; unrecognized values are ignored server-side.
|
|
51
|
+
* Never a user id or email.
|
|
52
|
+
*/
|
|
53
|
+
persona?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Your team / a test site — the same flag as `<AdaptiveProvider internal>`,
|
|
56
|
+
* sent on the SSR upsert and decide so a server-rendered first page is
|
|
57
|
+
* never counted or learned from. The request's `sentient_internal` cookie
|
|
58
|
+
* (the "mark this browser" link) is read from `cookies` and forwarded too.
|
|
59
|
+
*/
|
|
60
|
+
internal?: boolean;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Fetches bandit assignments on the server for SEO-safe HTML.
|
|
64
|
+
* Pass `assignments` as `initialAssignments` and `sessionId` as `ssrSessionId`
|
|
65
|
+
* on `<AdaptiveProvider>` so the client adopts the same session on first visit.
|
|
66
|
+
*/
|
|
67
|
+
declare function loadAdaptiveAssignments(components: Array<{
|
|
68
|
+
id: string;
|
|
69
|
+
variantIds: string[];
|
|
70
|
+
}>, options: LoadAdaptiveAssignmentsOptions): Promise<LoadAdaptiveAssignmentsResult>;
|
|
71
|
+
|
|
72
|
+
/** Return value of `loadAdaptiveDecision` — includes the session ID used for SSR. */
|
|
73
|
+
type LoadAdaptiveDecisionResult = _sentientui_core_server.DecideResult & {
|
|
74
|
+
sessionId: string;
|
|
75
|
+
};
|
|
76
|
+
type LoadAdaptiveDecisionOptions = LoadAdaptiveAssignmentsOptions & {
|
|
77
|
+
/**
|
|
78
|
+
* Section IDs in default order. Passed to /v1/decide as the candidate
|
|
79
|
+
* layout. Optional since 0.13.0 — slot-only pages may omit it (at least
|
|
80
|
+
* one of `sections`/`components`/`slots` must be non-empty).
|
|
81
|
+
*/
|
|
82
|
+
sections?: string[];
|
|
83
|
+
/** Components to assign in the same decide call. */
|
|
84
|
+
components?: Array<{
|
|
85
|
+
id: string;
|
|
86
|
+
variantIds?: string[];
|
|
87
|
+
}>;
|
|
88
|
+
/** Adaptive-slot declarations (useAdaptiveTokens / AdaptiveGroup) to decide server-side. */
|
|
89
|
+
slots?: _sentientui_core_server.SlotDeclInput[];
|
|
90
|
+
/** 'registry' serves the project's published slot definitions (`<Adaptive id>`)
|
|
91
|
+
* and is the only way `slotConfig`/`palette` come back. Default 'request'.
|
|
92
|
+
* Requires `registrySlotIds`. */
|
|
93
|
+
slotsFrom?: 'request' | 'registry';
|
|
94
|
+
/**
|
|
95
|
+
* Registry mode: the `<Adaptive id>`s THIS page renders — the decide is
|
|
96
|
+
* scoped to exactly these. Required with `slotsFrom: 'registry'`; without it
|
|
97
|
+
* the call downgrades to request mode (with a console.error) instead of
|
|
98
|
+
* recording a close-out trial for every published slot on every page.
|
|
99
|
+
*/
|
|
100
|
+
registrySlotIds?: string[];
|
|
101
|
+
/**
|
|
102
|
+
* Registry mode: what each slot on this page can render, keyed by slot id
|
|
103
|
+
* (see `preloadDecisions`). Ids without an entry get core's default caps.
|
|
104
|
+
* A hybrid `<Adaptive variants>{children}</Adaptive>` needs its entry: the
|
|
105
|
+
* server draws `authored.<key>` only for keys the page declares here.
|
|
106
|
+
*/
|
|
107
|
+
renderCaps?: Record<string, Omit<_sentientui_core.RenderCaps, 'fp'>>;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* SSR helper for pages with a declared section layout and/or adaptive slots.
|
|
111
|
+
* Calls `/v1/decide` instead of multiple `/v1/assign` round trips.
|
|
112
|
+
* Pass `sessionId` as `ssrSessionId` on `<AdaptiveProvider>` so the client
|
|
113
|
+
* adopts the same session on first visit.
|
|
114
|
+
*
|
|
115
|
+
* Keyless: with no valid `pk_` key this never fetches (no timeout burn).
|
|
116
|
+
* Under the `development` export condition the decision is computed by the
|
|
117
|
+
* deterministic local engine with the same sessionId the client will adopt —
|
|
118
|
+
* server and client agree by construction. In production the engine resolves
|
|
119
|
+
* to a stub and defaults are returned with one console.error.
|
|
120
|
+
*/
|
|
121
|
+
declare function loadAdaptiveDecision(options: LoadAdaptiveDecisionOptions): Promise<LoadAdaptiveDecisionResult>;
|
|
122
|
+
|
|
123
|
+
export { type LoadAdaptiveAssignmentsOptions, type LoadAdaptiveAssignmentsResult, type LoadAdaptiveDecisionOptions, type LoadAdaptiveDecisionResult, loadAdaptiveAssignments, loadAdaptiveDecision };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as _sentientui_core from '@sentientui/core';
|
|
2
|
+
import * as _sentientui_core_server from '@sentientui/core/server';
|
|
3
|
+
import { ServerAssignments } from '@sentientui/core/server';
|
|
4
|
+
export { DecideResult, ServerAssignConfig, ServerAssignments, SlotDeclInput, SlotResult, preloadAssignments, preloadDecisions, readSessionCookie, signUserId, trackServerGoal } from '@sentientui/core/server';
|
|
5
|
+
|
|
6
|
+
/** Return value of `loadAdaptiveAssignments` — includes the session ID used for SSR. */
|
|
7
|
+
type LoadAdaptiveAssignmentsResult = {
|
|
8
|
+
assignments: ServerAssignments;
|
|
9
|
+
/** The session ID used for SSR assignment. Pass as `ssrSessionId` to `<AdaptiveProvider>`. */
|
|
10
|
+
sessionId: string;
|
|
11
|
+
/** Components the operator moved onto the shared track: not in
|
|
12
|
+
* `assignments`. Pass as `initialUnified` to `<AdaptiveProvider>`. */
|
|
13
|
+
unified: string[];
|
|
14
|
+
};
|
|
15
|
+
type LoadAdaptiveAssignmentsOptions = {
|
|
16
|
+
/** Next.js `cookies()` return value, or any object with `get(name)`. */
|
|
17
|
+
cookies: {
|
|
18
|
+
get(name: string): {
|
|
19
|
+
value: string;
|
|
20
|
+
} | undefined;
|
|
21
|
+
};
|
|
22
|
+
apiKey: string;
|
|
23
|
+
baseUrl: string;
|
|
24
|
+
/** Used when `_snt_uid` is absent (e.g. first visit, many crawlers). */
|
|
25
|
+
createSessionId?: () => string;
|
|
26
|
+
/** Must match a value in the project's `allowed_origins` (e.g. `http://localhost:3001`). */
|
|
27
|
+
origin?: string;
|
|
28
|
+
/** From Next.js `headers().get('user-agent')` — aligns SSR segment with the client. */
|
|
29
|
+
userAgent?: string;
|
|
30
|
+
/** From Next.js `headers().get('referer')`. */
|
|
31
|
+
referer?: string;
|
|
32
|
+
/**
|
|
33
|
+
* `utm_*` params from the landing URL. The Referer header never carries the
|
|
34
|
+
* page's OWN query string, so without this the SSR-minted session has no
|
|
35
|
+
* campaign attribution until the client SDK hydrates and re-upserts.
|
|
36
|
+
* Derive with `extractTrackedParams(searchParams)` from `@sentientui/core/server`.
|
|
37
|
+
*/
|
|
38
|
+
utmParams?: Record<string, string>;
|
|
39
|
+
/** Ad-platform click IDs (gclid, fbclid, ttclid, …) from the landing URL — same derivation as `utmParams`. */
|
|
40
|
+
clickIds?: Record<string, string>;
|
|
41
|
+
/** The landing page's path (no query string) — recognises a paid click to a product page or a `/discount/` link on the first decision. */
|
|
42
|
+
landingPath?: string;
|
|
43
|
+
/** Set true when the request carries `DNT: 1` or `Sec-GPC: 1` — skips the SSR session upsert + assignment so no session is minted for an opted-out visitor (audit P4). `AdaptiveRoot` sets this automatically from the request headers. */
|
|
44
|
+
doNotTrack?: boolean;
|
|
45
|
+
/** Milliseconds to wait for the API before returning default variants. Defaults to 1000 (typical decide is well under 150 ms; the full budget is only reached on a cold start or a distant API). */
|
|
46
|
+
timeoutMs?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Declared persona — the role your app already knows for this visitor (e.g.
|
|
49
|
+
* from your auth context: 'admin', 'evaluator'). Must be a key in the
|
|
50
|
+
* project's persona vocabulary; unrecognized values are ignored server-side.
|
|
51
|
+
* Never a user id or email.
|
|
52
|
+
*/
|
|
53
|
+
persona?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Your team / a test site — the same flag as `<AdaptiveProvider internal>`,
|
|
56
|
+
* sent on the SSR upsert and decide so a server-rendered first page is
|
|
57
|
+
* never counted or learned from. The request's `sentient_internal` cookie
|
|
58
|
+
* (the "mark this browser" link) is read from `cookies` and forwarded too.
|
|
59
|
+
*/
|
|
60
|
+
internal?: boolean;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Fetches bandit assignments on the server for SEO-safe HTML.
|
|
64
|
+
* Pass `assignments` as `initialAssignments` and `sessionId` as `ssrSessionId`
|
|
65
|
+
* on `<AdaptiveProvider>` so the client adopts the same session on first visit.
|
|
66
|
+
*/
|
|
67
|
+
declare function loadAdaptiveAssignments(components: Array<{
|
|
68
|
+
id: string;
|
|
69
|
+
variantIds: string[];
|
|
70
|
+
}>, options: LoadAdaptiveAssignmentsOptions): Promise<LoadAdaptiveAssignmentsResult>;
|
|
71
|
+
|
|
72
|
+
/** Return value of `loadAdaptiveDecision` — includes the session ID used for SSR. */
|
|
73
|
+
type LoadAdaptiveDecisionResult = _sentientui_core_server.DecideResult & {
|
|
74
|
+
sessionId: string;
|
|
75
|
+
};
|
|
76
|
+
type LoadAdaptiveDecisionOptions = LoadAdaptiveAssignmentsOptions & {
|
|
77
|
+
/**
|
|
78
|
+
* Section IDs in default order. Passed to /v1/decide as the candidate
|
|
79
|
+
* layout. Optional since 0.13.0 — slot-only pages may omit it (at least
|
|
80
|
+
* one of `sections`/`components`/`slots` must be non-empty).
|
|
81
|
+
*/
|
|
82
|
+
sections?: string[];
|
|
83
|
+
/** Components to assign in the same decide call. */
|
|
84
|
+
components?: Array<{
|
|
85
|
+
id: string;
|
|
86
|
+
variantIds?: string[];
|
|
87
|
+
}>;
|
|
88
|
+
/** Adaptive-slot declarations (useAdaptiveTokens / AdaptiveGroup) to decide server-side. */
|
|
89
|
+
slots?: _sentientui_core_server.SlotDeclInput[];
|
|
90
|
+
/** 'registry' serves the project's published slot definitions (`<Adaptive id>`)
|
|
91
|
+
* and is the only way `slotConfig`/`palette` come back. Default 'request'.
|
|
92
|
+
* Requires `registrySlotIds`. */
|
|
93
|
+
slotsFrom?: 'request' | 'registry';
|
|
94
|
+
/**
|
|
95
|
+
* Registry mode: the `<Adaptive id>`s THIS page renders — the decide is
|
|
96
|
+
* scoped to exactly these. Required with `slotsFrom: 'registry'`; without it
|
|
97
|
+
* the call downgrades to request mode (with a console.error) instead of
|
|
98
|
+
* recording a close-out trial for every published slot on every page.
|
|
99
|
+
*/
|
|
100
|
+
registrySlotIds?: string[];
|
|
101
|
+
/**
|
|
102
|
+
* Registry mode: what each slot on this page can render, keyed by slot id
|
|
103
|
+
* (see `preloadDecisions`). Ids without an entry get core's default caps.
|
|
104
|
+
* A hybrid `<Adaptive variants>{children}</Adaptive>` needs its entry: the
|
|
105
|
+
* server draws `authored.<key>` only for keys the page declares here.
|
|
106
|
+
*/
|
|
107
|
+
renderCaps?: Record<string, Omit<_sentientui_core.RenderCaps, 'fp'>>;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* SSR helper for pages with a declared section layout and/or adaptive slots.
|
|
111
|
+
* Calls `/v1/decide` instead of multiple `/v1/assign` round trips.
|
|
112
|
+
* Pass `sessionId` as `ssrSessionId` on `<AdaptiveProvider>` so the client
|
|
113
|
+
* adopts the same session on first visit.
|
|
114
|
+
*
|
|
115
|
+
* Keyless: with no valid `pk_` key this never fetches (no timeout burn).
|
|
116
|
+
* Under the `development` export condition the decision is computed by the
|
|
117
|
+
* deterministic local engine with the same sessionId the client will adopt —
|
|
118
|
+
* server and client agree by construction. In production the engine resolves
|
|
119
|
+
* to a stub and defaults are returned with one console.error.
|
|
120
|
+
*/
|
|
121
|
+
declare function loadAdaptiveDecision(options: LoadAdaptiveDecisionOptions): Promise<LoadAdaptiveDecisionResult>;
|
|
122
|
+
|
|
123
|
+
export { type LoadAdaptiveAssignmentsOptions, type LoadAdaptiveAssignmentsResult, type LoadAdaptiveDecisionOptions, type LoadAdaptiveDecisionResult, loadAdaptiveAssignments, loadAdaptiveDecision };
|
package/dist/testing/react.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";var Le=Object.create;var G=Object.defineProperty,Ge=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?G(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)=>Ge(e,Ue(t));var Ke=(e,t)=>{for(var n in t)G(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&&G(e,a,{get:()=>t[a],enumerable:!(i=Fe(t,a))||i.enumerable});return e};var F=(e,t,n)=>(n=e!=null?Le(Me(e)):{},fe(t||!e||!e.__esModule?G(n,"default",{value:e,enumerable:!0}):n,e)),Be=e=>fe(G({},"__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 U(){var t;if(typeof window=="undefined")return;let e=window;e.__sentient_overrides_version=((t=e.__sentient_overrides_version)!=null?t:0)+1,window.dispatchEvent(new Event(Je))}function ve(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function W(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var 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){W()&&(z().sections=[...e],qe())}var he="0.44.1",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 T(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 V(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",D=null,q=!1;function we(){return q}function Ze(){try{return sessionStorage.getItem(Y)}catch(e){return null}}function K(e){if(D)return D;let t=typeof window=="undefined"?null:Se("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Ze();return q=!!n,D=Promise.resolve(n?{token:n,fresh:!1}:null),D}return q=!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(Y,i)}catch(a){}return{token:i,fresh:!0}}).catch(()=>({error:0})),D}function be(){try{sessionStorage.removeItem(Y)}catch(e){}}var Ce="sentient_preview_cell",xe="sentient_refresh_region",Q="sentient-cell-preview-bar",P="__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},T(n,{kind:"arms"}),V(n,P),U();return}if(!t)return;let d=t.lastIndexOf("~");if(d<=0)return;let g=t.slice(0,d),O=t.slice(d+1);a.then(l=>l?"token"in l?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(g)}&persona=${encodeURIComponent(O)}`,{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)T(g,{kind:"arms",compose:{[P]:c.compose}}),V(g,P);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,P);else if(c.blocks!=null)T(g,{kind:"arms",blocks:{[P]:c.blocks}}),V(g,P);else if(c.content!=null)T(g,{kind:"arms",content:c.content}),V(g,P);else{M("Nothing to preview in that square yet.");return}U(),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,O]=(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,R=!1;return import("@sentientui/core/consent").then(({consentWatcher:x,forgetVisitor:I})=>{if(R)return;let E=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,N=()=>{let _=E.refused()&&E.read()!==!0;_&&!w&&(I(t),i.current()),w=_,O(_);let S=E.read();S!==null&&Z.add(t),d(S!=null?S:Z.has(t)?!1:null)};N(),y=E.subscribe(N)}),()=>{R=!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)(()=>{}),O=rt(e.consentFrom,e.apiKey,()=>g.current()),l=e.consentFrom?(ne=O.granted)!=null?ne:Z.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),R=(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 L,le;if(p.current&&l===!1&&(x.current=[]),l===!1&&R.current&&(p.current&&((L=y.current)==null||L.destroy()),y.current=null,R.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&&(I.current=!1);let f=h=>{!r&&I.current&&h.gated&&h.dispose()},m=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}:{}),u=!1,s=null,b=null,C=h=>{for(let A of x.current.splice(0))setTimeout(()=>{if(y.current!==h){I.current||x.current.push(A);return}try{A(h)}catch(ct){}},0)},k=h=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:A})=>{u||(b=A(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})=>{u||(s=h($(v({},m),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),f(s),y.current=s,R.current=r,C(s),n(s),k(s))}):(s=(0,B.init)(m),f(s),y.current=s,R.current=r,C(s),n(s),k(s)),()=>{var h,A;u=!0,b==null||b(),x.current=x.current.concat((A=(h=s==null?void 0:s.takeHeld)==null?void 0:h.call(s))!=null?A:[]),s==null||s.dispose()}},[l]),(0,o.useEffect)(()=>{if(!t)return;let r=!1,f=async()=>{if(r)return;let u;try{u=await t.fetchWeights()}catch(s){return}if(!r)for(let s of u){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)}};f();let m=setInterval(()=>{f()},6e4);return()=>{r=!0,clearInterval(m)}},[t]);let E=(ie=e.ssrFallback)!=null?ie:"first",w=((re=e.apiBaseUrl)!=null?re:Pe).replace(/\/$/,""),N=(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,internal:e.internal,apiBaseUrl:w},f=N.current;if(N.current=r,f!==null)for(let u of["apiKey","context","country","persona","internal","apiBaseUrl"])Object.is(f[u],r[u])||console.warn(`[sentient] AdaptiveProvider: \`${u}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,e.internal,w]),(0,o.useEffect)(()=>{var r;typeof process!="undefined"&&((r=process.env)==null?void 0:r.NODE_ENV)==="production"||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)(()=>{!W()||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(!W())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]"),u=>u.getAttribute("data-sentient-id"))),m=r.filter(u=>!f.has(u));m.length>0&&console.warn(`[SentientUI] Declared section${m.length>1?"s":""} ${m.map(u=>`"${u}"`).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 te=(0,o.useMemo)(()=>t&&a?ye(t):t,[t,a]),Ne=(0,o.useMemo)(()=>{var r,f,m,u,s,b,C,k,L;return{client:te,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},initialUnified:(f=e.initialUnified)!=null?f:ot,sessionSegment:i,ssrFallback:E,onAssignment:e.onAssignment,initialLayoutOrder:(m=e.initialLayoutOrder)!=null?m:null,initialSlots:(u=e.initialSlots)!=null?u:{},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:(L=e.debug)!=null?L:!1}},[te,e.apiKey,e.initialAssignments,e.initialUnified,i,E,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return(0,Ie.jsx)(it.Provider,{value:Ne,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;U()}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 Le=Object.create;var G=Object.defineProperty,Ge=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?G(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)=>Ge(e,Ue(t));var Ke=(e,t)=>{for(var n in t)G(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&&G(e,a,{get:()=>t[a],enumerable:!(i=Fe(t,a))||i.enumerable});return e};var F=(e,t,n)=>(n=e!=null?Le(Me(e)):{},fe(t||!e||!e.__esModule?G(n,"default",{value:e,enumerable:!0}):n,e)),Be=e=>fe(G({},"__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 U(){var t;if(typeof window=="undefined")return;let e=window;e.__sentient_overrides_version=((t=e.__sentient_overrides_version)!=null?t:0)+1,window.dispatchEvent(new Event(Je))}function ve(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function W(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var 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){W()&&(z().sections=[...e],qe())}var he="0.44.2",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 T(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 V(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",D=null,q=!1;function we(){return q}function Ze(){try{return sessionStorage.getItem(Y)}catch(e){return null}}function K(e){if(D)return D;let t=typeof window=="undefined"?null:Se("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Ze();return q=!!n,D=Promise.resolve(n?{token:n,fresh:!1}:null),D}return q=!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(Y,i)}catch(a){}return{token:i,fresh:!0}}).catch(()=>({error:0})),D}function be(){try{sessionStorage.removeItem(Y)}catch(e){}}var Ce="sentient_preview_cell",xe="sentient_refresh_region",Q="sentient-cell-preview-bar",P="__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},T(n,{kind:"arms"}),V(n,P),U();return}if(!t)return;let d=t.lastIndexOf("~");if(d<=0)return;let g=t.slice(0,d),O=t.slice(d+1);a.then(l=>l?"token"in l?fetch(`${i}/editor/cell-preview?slotId=${encodeURIComponent(g)}&persona=${encodeURIComponent(O)}`,{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)T(g,{kind:"arms",compose:{[P]:c.compose}}),V(g,P);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,P);else if(c.blocks!=null)T(g,{kind:"arms",blocks:{[P]:c.blocks}}),V(g,P);else if(c.content!=null)T(g,{kind:"arms",content:c.content}),V(g,P);else{M("Nothing to preview in that square yet.");return}U(),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,O]=(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,R=!1;return import("@sentientui/core/consent").then(({consentWatcher:x,forgetVisitor:I})=>{if(R)return;let E=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,N=()=>{let _=E.refused()&&E.read()!==!0;_&&!w&&(I(t),i.current()),w=_,O(_);let S=E.read();S!==null&&Z.add(t),d(S!=null?S:Z.has(t)?!1:null)};N(),y=E.subscribe(N)}),()=>{R=!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)(()=>{}),O=rt(e.consentFrom,e.apiKey,()=>g.current()),l=e.consentFrom?(ne=O.granted)!=null?ne:Z.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),R=(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 L,le;if(p.current&&l===!1&&(x.current=[]),l===!1&&R.current&&(p.current&&((L=y.current)==null||L.destroy()),y.current=null,R.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&&(I.current=!1);let f=h=>{!r&&I.current&&h.gated&&h.dispose()},m=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}:{}),u=!1,s=null,b=null,C=h=>{for(let A of x.current.splice(0))setTimeout(()=>{if(y.current!==h){I.current||x.current.push(A);return}try{A(h)}catch(ct){}},0)},k=h=>{e.engagement===!1||!r||import("@sentientui/core/engagement").then(({startEngagementCapture:A})=>{u||(b=A(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})=>{u||(s=h($(v({},m),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),f(s),y.current=s,R.current=r,C(s),n(s),k(s))}):(s=(0,B.init)(m),f(s),y.current=s,R.current=r,C(s),n(s),k(s)),()=>{var h,A;u=!0,b==null||b(),x.current=x.current.concat((A=(h=s==null?void 0:s.takeHeld)==null?void 0:h.call(s))!=null?A:[]),s==null||s.dispose()}},[l]),(0,o.useEffect)(()=>{if(!t)return;let r=!1,f=async()=>{if(r)return;let u;try{u=await t.fetchWeights()}catch(s){return}if(!r)for(let s of u){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)}};f();let m=setInterval(()=>{f()},6e4);return()=>{r=!0,clearInterval(m)}},[t]);let E=(ie=e.ssrFallback)!=null?ie:"first",w=((re=e.apiBaseUrl)!=null?re:Pe).replace(/\/$/,""),N=(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,internal:e.internal,apiBaseUrl:w},f=N.current;if(N.current=r,f!==null)for(let u of["apiKey","context","country","persona","internal","apiBaseUrl"])Object.is(f[u],r[u])||console.warn(`[sentient] AdaptiveProvider: \`${u}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,e.internal,w]),(0,o.useEffect)(()=>{var r;typeof process!="undefined"&&((r=process.env)==null?void 0:r.NODE_ENV)==="production"||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)(()=>{!W()||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(!W())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]"),u=>u.getAttribute("data-sentient-id"))),m=r.filter(u=>!f.has(u));m.length>0&&console.warn(`[SentientUI] Declared section${m.length>1?"s":""} ${m.map(u=>`"${u}"`).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 te=(0,o.useMemo)(()=>t&&a?ye(t):t,[t,a]),Ne=(0,o.useMemo)(()=>{var r,f,m,u,s,b,C,k,L;return{client:te,apiKey:e.apiKey,initialAssignments:(r=e.initialAssignments)!=null?r:{},initialUnified:(f=e.initialUnified)!=null?f:ot,sessionSegment:i,ssrFallback:E,onAssignment:e.onAssignment,initialLayoutOrder:(m=e.initialLayoutOrder)!=null?m:null,initialSlots:(u=e.initialSlots)!=null?u:{},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:(L=e.debug)!=null?L:!1}},[te,e.apiKey,e.initialAssignments,e.initialUnified,i,E,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return(0,Ie.jsx)(it.Provider,{value:Ne,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;U()}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
|
package/dist/testing/react.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
var Ie=Object.defineProperty,Te=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var le=Object.getOwnPropertySymbols;var De=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable;var ce=(e,t,n)=>t in e?Ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,y=(e,t)=>{for(var n in t||(t={}))De.call(t,n)&&ce(e,n,t[n]);if(le)for(var n of le(t))Ne.call(t,n)&&ce(e,n,t[n]);return e},$=(e,t)=>Te(e,Ve(t));import{render as nt}from"@testing-library/react";import{createContext as ze,useContext as It,useEffect as h,useMemo as ke,useRef as x,useState as M,useSyncExternalStore as Tt}from"react";import{deriveSessionSegment as Je,init as Xe}from"@sentientui/core";var Le=new Map,Ge=new Map;function de(e,t){Le.set(e,t);let n=Ge.get(e);if(n)for(let r of n)try{r(t)}catch(l){}}var Fe={on:!1,listeners:new Set};function B(){if(typeof window=="undefined")return Fe;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function ue(e){let t=B();if(t.on!==e){t.on=e;for(let n of t.listeners)n()}}function H(){return B().on}function fe(e){let t=B().listeners;return t.add(e),()=>{t.delete(e)}}function ge(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),isUnified:t=>{var n,r;return(r=(n=e.isUnified)==null?void 0:n.call(e,t))!=null?r:!1},assign:(t,n,r,l,c)=>e.assign(t,n,r,l,c),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getSlotConfig:t=>e.getSlotConfig(t),getSitePalette:()=>e.getSitePalette(),reportSlots:t=>e.reportSlots(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),flush:()=>e.flush(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Ue="sentient:overrides-changed";function 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(Ue))}function pe(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function U(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var We={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function j(){if(typeof window=="undefined")return We;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function Me(){j().version+=1;for(let e of j().listeners)e()}function z(e){U()&&(j().sections=[...e],Me())}var me="0.44.1",J=me!=="0.0.0-dev"?{name:"react",version:me}:void 0;function $e(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function V(e,t){$e()[e]=t}function ye(e){window.__sentient_vocabulary_override=e}function Ke(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function D(e,t){Ke()[e]=t}function ve(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 c=n.slice(0,r.index)+l;history.replaceState(history.state,"",c?"#"+c:location.pathname+location.search)}}catch(n){}return t}var q="__snt_editor_token",N=null,X=!1;function he(){return X}function Be(){try{return sessionStorage.getItem(q)}catch(e){return null}}function K(e){if(N)return N;let t=typeof window=="undefined"?null:ve("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Be();return X=!!n,N=Promise.resolve(n?{token:n,fresh:!1}:null),N}return X=!0,N=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(q,r)}catch(l){}return{token:r,fresh:!0}}).catch(()=>({error:0})),N}function _e(){try{sessionStorage.removeItem(q)}catch(e){}}var Se="sentient_preview_cell",we="sentient_refresh_region",Y="sentient-cell-preview-bar",O="__preview__",He=null;function be(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(Y))return;let t,n;try{let s=new URLSearchParams(window.location.search);t=s.get(Se),n=s.get(we)}catch(s){return}if(!t&&!n)return;let r=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),l=K(r);if(!he())return;if(n){He={slotId:n,session:l,base:r},V(n,{kind:"arms"}),D(n,O),F();return}if(!t)return;let c=t.lastIndexOf("~");if(c<=0)return;let f=t.slice(0,c),I=t.slice(c+1);l.then(s=>s?"token"in s?fetch(`${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)&&ye(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(Y))return;let t=document.createElement("div");t.id=Y,Object.assign(t.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"10px",padding:"10px 14px",borderRadius:"12px",maxWidth:"90vw",background:"#111827",color:"#fff",font:"13px system-ui, sans-serif",border:"1px solid rgba(139,92,246,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});let n=document.createElement("span");n.textContent=e;let 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=()=>{_e();let c=new URL(window.location.href);c.searchParams.delete(Se),c.searchParams.delete(we),window.location.assign(c.toString())},t.append(n,r),((l=document.body)!=null?l:document.documentElement).append(t)}var Ce=!1;function xe(e){if(Ce||typeof window=="undefined")return;Ce=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||je(t,n.token)})}function je(e,t){let n=()=>{window.setTimeout(()=>{import("@sentientui/core/style-sample").then(({sampleStyleVocabulary: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 et}from"react/jsx-runtime";function qe(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return Je({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var Ee="https://api.sentient-ui.com/v1",Ye=ze({client:null,apiKey:"",initialAssignments:{},initialUnified:[],sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:Ee,debug:!1}),Re=!1,Q=new Set;function Qe(e,t,n){let r=x(n);r.current=n;let[l,c]=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 h(()=>{let g=s.current;if(g===void 0||typeof window=="undefined")return;let m,E=!1;return import("@sentientui/core/consent").then(({consentWatcher:k,forgetVisitor:T})=>{if(E)return;let A=k(typeof g=="object"&&g.cmp===void 0&&g.check?y($(y({},g),{check:()=>s.current.check()}),g.refused?{refused:()=>{var _,S;return((S=(_=s.current).refused)==null?void 0:S.call(_))===!0}}:{}):g),w=!1,L=()=>{let _=A.refused()&&A.read()!==!0;_&&!w&&(T(t),r.current()),w=_,I(_);let S=A.read();S!==null&&Q.add(t),c(S!=null?S:Q.has(t)?!1:null)};L(),m=A.subscribe(L)}),()=>{E=!0,m==null||m()}},[a,t]),{granted:l,refused:f}}function Ae(e){var te,ne,ie,re,oe,se;let[t,n]=M(null),[r]=M(()=>{var i;return(i=e.sessionSegment)!=null?i:qe()}),[l,c]=M(H());h(()=>fe(()=>c(H())),[]),h(()=>{be(e.apiBaseUrl),typeof window!="undefined"&&/[?&]sentient_preview=[^&]*(:|%3A)/i.test(window.location.search)&&(ue(!0),import("@sentientui/react/version-preview").then(i=>i.maybeStartVersionPreview(e.apiKey,e.apiBaseUrl)).catch(()=>{})),xe(e.apiBaseUrl)},[]);let f=x(()=>{}),I=Qe(e.consentFrom,e.apiKey,()=>f.current()),s=e.consentFrom?(te=I.granted)!=null?te:Q.has(e.apiKey)?!1:e.consent===!0:e.consent,a=e.consentFrom?I.refused:!0,g=x(a);g.current=a;let m=x(null),E=x(!1),k=x([]),T=x(!1);f.current=()=>{var u;k.current=[],T.current=!0;let i=m.current;i!=null&&i.gated?i.dispose():(u=i==null?void 0:i.takeHeld)==null||u.call(i)},h(()=>{var G,ae;if(g.current&&s===!1&&(k.current=[]),s===!1&&E.current&&(g.current&&((G=m.current)==null||G.destroy()),m.current=null,E.current=!1),s===!1&&!e.preConsentBehavior){g.current&&((ae=m.current)==null||ae.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,initialUnified:e.initialUnified,sessionSegment:r,consent:s,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,cookieDomain:e.cookieDomain,country:e.country,persona:e.persona,internal:e.internal,stageAttributes:e.stageAttributes,localMode:e.localMode,initialSlots:e.initialSlots,initialSlotConfig:e.initialSlotConfig,initialPalette:e.initialPalette,initialVocabulary:e.initialVocabulary,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0,nonce:e.nonce},J?{sdk:J}:{}),d=!1,o=null,b=null,C=v=>{for(let P of k.current.splice(0))setTimeout(()=>{if(m.current!==v){T.current||k.current.push(P);return}try{P(v)}catch(rt){}},0)},R=v=>{e.engagement===!1||!i||import("@sentientui/core/engagement").then(({startEngagementCapture:P})=>{d||(b=P(v,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:v})=>{d||(o=v($(y({},p),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),u(o),m.current=o,E.current=i,C(o),n(o),R(o))}):(o=Xe(p),u(o),m.current=o,E.current=i,C(o),n(o),R(o)),()=>{var v,P;d=!0,b==null||b(),k.current=k.current.concat((P=(v=o==null?void 0:o.takeHeld)==null?void 0:v.call(o))!=null?P:[]),o==null||o.dispose()}},[s]),h(()=>{if(!t)return;let i=!1,u=async()=>{if(i)return;let d;try{d=await t.fetchWeights()}catch(o){return}if(!i)for(let o of d){let b={componentId:o.componentId,updatedAt:o.updatedAt,variants:o.variants.map(C=>{var R;return{variantId:C.variantId,pulls:C.pulls,avgReward:(R=C.avgReward)!=null?R:0}})};de(o.componentId,b)}};u();let p=setInterval(()=>{u()},6e4);return()=>{i=!0,clearInterval(p)}},[t]);let A=(ne=e.ssrFallback)!=null?ne:"first",w=((ie=e.apiBaseUrl)!=null?ie:Ee).replace(/\/$/,""),L=x(null);h(()=>{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,internal:e.internal,apiBaseUrl:w},u=L.current;if(L.current=i,u!==null)for(let d of["apiKey","context","country","persona","internal","apiBaseUrl"])Object.is(u[d],i[d])||console.warn(`[sentient] AdaptiveProvider: \`${d}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,e.internal,w]),h(()=>{var i;typeof process!="undefined"&&((i=process.env)==null?void 0:i.NODE_ENV)==="production"||pe({apiKey:e.apiKey,apiBaseUrl:w,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,w]);let _=(re=e.identity)==null?void 0:re.userId,S=(oe=e.identity)==null?void 0:oe.userHash,Z=(se=e.identity)==null?void 0:se.email;h(()=>{t&&_&&t.identify(_,{userHash:S,email:Z})},[t,_,S,Z]),h(()=>{let i=e.initialLayoutOrder;if(i&&i.length>0){z(i);return}e.declaredSections&&e.declaredSections.length>0&&z(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),h(()=>{!U()||e.consent!==void 0||e.consentFrom!==void 0||Re||(Re=!0,console.warn('[SentientUI] No consent gate: every visitor is tracked from first paint. Pass consentFrom="<your CMP>" (or consent={true} to silence). https://sentient-ui.com/docs#consent'))},[]),h(()=>{if(!U())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]"),d=>d.getAttribute("data-sentient-id"))),p=i.filter(d=>!u.has(d));p.length>0&&console.warn(`[SentientUI] Declared section${p.length>1?"s":""} ${p.map(d=>`"${d}"`).join(", ")} ${p.length>1?"have":"has"} no matching data-sentient-id element, so the layout engine cannot learn what they are and will serve the same order to every persona. Add data-sentient-id="<sectionId>" to each section's element.`)},[e.declaredSections]);let ee=ke(()=>t&&l?ge(t):t,[t,l]),Oe=ke(()=>{var i,u,p,d,o,b,C,R,G;return{client:ee,apiKey:e.apiKey,initialAssignments:(i=e.initialAssignments)!=null?i:{},initialUnified:(u=e.initialUnified)!=null?u:Ze,sessionSegment:r,ssrFallback:A,onAssignment:e.onAssignment,initialLayoutOrder:(p=e.initialLayoutOrder)!=null?p:null,initialSlots:(d=e.initialSlots)!=null?d:{},initialSlotConfig:(o=e.initialSlotConfig)!=null?o:{},initialPalette:(b=e.initialPalette)!=null?b:null,initialVocabulary:(C=e.initialVocabulary)!=null?C:null,initialPersona:(R=e.initialPersona)!=null?R:null,apiBaseUrl:w,debug:(G=e.debug)!=null?G:!1}},[ee,e.apiKey,e.initialAssignments,e.initialUnified,r,A,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return et(Ye.Provider,{value:Oe,children:e.children})}var Ze=[];function tt(e){return e<.3?"low":e<.7?"medium":"high"}function Pe(e={}){var n,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 c=document.documentElement;c.setAttribute("data-sentient-persona",e.persona),c.setAttribute("data-sentient-confidence",tt((l=e.confidence)!=null?l:1))}catch(c){}}else delete t.__sentient_persona_override;F()}import{jsx as it}from"react/jsx-runtime";function Yt(e,t={},n){return Pe(t),nt(it(Ae,{apiKey:"pk_test",consent:!1,children:e}),n)}export{Yt as renderWithSentient};
|
|
2
|
+
var Ie=Object.defineProperty,Te=Object.defineProperties;var Ve=Object.getOwnPropertyDescriptors;var le=Object.getOwnPropertySymbols;var De=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable;var ce=(e,t,n)=>t in e?Ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,y=(e,t)=>{for(var n in t||(t={}))De.call(t,n)&&ce(e,n,t[n]);if(le)for(var n of le(t))Ne.call(t,n)&&ce(e,n,t[n]);return e},$=(e,t)=>Te(e,Ve(t));import{render as nt}from"@testing-library/react";import{createContext as ze,useContext as It,useEffect as h,useMemo as ke,useRef as x,useState as M,useSyncExternalStore as Tt}from"react";import{deriveSessionSegment as Je,init as Xe}from"@sentientui/core";var Le=new Map,Ge=new Map;function de(e,t){Le.set(e,t);let n=Ge.get(e);if(n)for(let r of n)try{r(t)}catch(l){}}var Fe={on:!1,listeners:new Set};function B(){if(typeof window=="undefined")return Fe;let e=window;return e.__sentient_preview||(e.__sentient_preview={on:!1,listeners:new Set}),e.__sentient_preview}function ue(e){let t=B();if(t.on!==e){t.on=e;for(let n of t.listeners)n()}}function H(){return B().on}function fe(e){let t=B().listeners;return t.add(e),()=>{t.delete(e)}}function ge(e){return{isLocal:e.isLocal,track:()=>{},goal:()=>{},componentGoal:()=>{},identify:()=>{},fetchWeights:()=>Promise.resolve([]),getAssignment:(t,n)=>e.getAssignment(t,n),isUnified:t=>{var n,r;return(r=(n=e.isUnified)==null?void 0:n.call(e,t))!=null?r:!1},assign:(t,n,r,l,c)=>e.assign(t,n,r,l,c),decide:()=>Promise.resolve(null),getSlotResult:t=>e.getSlotResult(t),getSlotConfig:t=>e.getSlotConfig(t),getSitePalette:()=>e.getSitePalette(),reportSlots:t=>e.reportSlots(t),getPersona:()=>e.getPersona(),getGraph:()=>e.getGraph(),flush:()=>e.flush(),dispose:()=>e.dispose(),destroy:()=>e.destroy()}}var Ue="sentient:overrides-changed";function 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(Ue))}function pe(e){typeof window!="undefined"&&(window.__sentient_devtools_config=e)}function U(){var e;return typeof process=="undefined"||((e=process.env)==null?void 0:e.NODE_ENV)!=="production"}var We={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0};function j(){if(typeof window=="undefined")return We;let e=window;return e.__sentient_registry||(e.__sentient_registry={components:new Map,slots:new Map,sections:[],listeners:new Set,version:0}),e.__sentient_registry}function Me(){j().version+=1;for(let e of j().listeners)e()}function z(e){U()&&(j().sections=[...e],Me())}var me="0.44.2",J=me!=="0.0.0-dev"?{name:"react",version:me}:void 0;function $e(){let e=window;return e.__sentient_slot_config_overrides||(e.__sentient_slot_config_overrides={}),e.__sentient_slot_config_overrides}function V(e,t){$e()[e]=t}function ye(e){window.__sentient_vocabulary_override=e}function Ke(){let e=window;return e.__sentient_slot_overrides||(e.__sentient_slot_overrides={}),e.__sentient_slot_overrides}function D(e,t){Ke()[e]=t}function ve(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 c=n.slice(0,r.index)+l;history.replaceState(history.state,"",c?"#"+c:location.pathname+location.search)}}catch(n){}return t}var q="__snt_editor_token",N=null,X=!1;function he(){return X}function Be(){try{return sessionStorage.getItem(q)}catch(e){return null}}function K(e){if(N)return N;let t=typeof window=="undefined"?null:ve("sentient_editor_code");if(!t){let n=typeof window=="undefined"?null:Be();return X=!!n,N=Promise.resolve(n?{token:n,fresh:!1}:null),N}return X=!0,N=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(q,r)}catch(l){}return{token:r,fresh:!0}}).catch(()=>({error:0})),N}function _e(){try{sessionStorage.removeItem(q)}catch(e){}}var Se="sentient_preview_cell",we="sentient_refresh_region",Y="sentient-cell-preview-bar",O="__preview__",He=null;function be(e){if(typeof window=="undefined"||typeof document=="undefined"||document.getElementById(Y))return;let t,n;try{let s=new URLSearchParams(window.location.search);t=s.get(Se),n=s.get(we)}catch(s){return}if(!t&&!n)return;let r=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,""),l=K(r);if(!he())return;if(n){He={slotId:n,session:l,base:r},V(n,{kind:"arms"}),D(n,O),F();return}if(!t)return;let c=t.lastIndexOf("~");if(c<=0)return;let f=t.slice(0,c),I=t.slice(c+1);l.then(s=>s?"token"in s?fetch(`${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)&&ye(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(Y))return;let t=document.createElement("div");t.id=Y,Object.assign(t.style,{position:"fixed",bottom:"16px",left:"50%",transform:"translateX(-50%)",zIndex:"2147483647",display:"flex",alignItems:"center",gap:"10px",padding:"10px 14px",borderRadius:"12px",maxWidth:"90vw",background:"#111827",color:"#fff",font:"13px system-ui, sans-serif",border:"1px solid rgba(139,92,246,0.6)",boxShadow:"0 10px 34px rgba(0,0,0,0.45)"});let n=document.createElement("span");n.textContent=e;let 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=()=>{_e();let c=new URL(window.location.href);c.searchParams.delete(Se),c.searchParams.delete(we),window.location.assign(c.toString())},t.append(n,r),((l=document.body)!=null?l:document.documentElement).append(t)}var Ce=!1;function xe(e){if(Ce||typeof window=="undefined")return;Ce=!0;let t=(e!=null?e:"https://api.sentient-ui.com/v1").replace(/\/$/,"");K(t).then(n=>{!n||!("token"in n)||!n.fresh||je(t,n.token)})}function je(e,t){let n=()=>{window.setTimeout(()=>{import("@sentientui/core/style-sample").then(({sampleStyleVocabulary: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 et}from"react/jsx-runtime";function qe(){var e,t;if(typeof window=="undefined")return"desktop:direct";try{return Je({userAgent:(e=navigator.userAgent)!=null?e:"",referer:(t=document.referrer)!=null?t:"",appOrigin:window.location.origin})}catch(n){return"desktop:direct"}}var Ee="https://api.sentient-ui.com/v1",Ye=ze({client:null,apiKey:"",initialAssignments:{},initialUnified:[],sessionSegment:"desktop:direct",ssrFallback:"first",onAssignment:void 0,initialLayoutOrder:null,initialSlots:{},initialSlotConfig:{},initialPalette:null,initialVocabulary:null,initialPersona:null,apiBaseUrl:Ee,debug:!1}),Re=!1,Q=new Set;function Qe(e,t,n){let r=x(n);r.current=n;let[l,c]=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 h(()=>{let g=s.current;if(g===void 0||typeof window=="undefined")return;let m,E=!1;return import("@sentientui/core/consent").then(({consentWatcher:k,forgetVisitor:T})=>{if(E)return;let A=k(typeof g=="object"&&g.cmp===void 0&&g.check?y($(y({},g),{check:()=>s.current.check()}),g.refused?{refused:()=>{var _,S;return((S=(_=s.current).refused)==null?void 0:S.call(_))===!0}}:{}):g),w=!1,L=()=>{let _=A.refused()&&A.read()!==!0;_&&!w&&(T(t),r.current()),w=_,I(_);let S=A.read();S!==null&&Q.add(t),c(S!=null?S:Q.has(t)?!1:null)};L(),m=A.subscribe(L)}),()=>{E=!0,m==null||m()}},[a,t]),{granted:l,refused:f}}function Ae(e){var te,ne,ie,re,oe,se;let[t,n]=M(null),[r]=M(()=>{var i;return(i=e.sessionSegment)!=null?i:qe()}),[l,c]=M(H());h(()=>fe(()=>c(H())),[]),h(()=>{be(e.apiBaseUrl),typeof window!="undefined"&&/[?&]sentient_preview=[^&]*(:|%3A)/i.test(window.location.search)&&(ue(!0),import("@sentientui/react/version-preview").then(i=>i.maybeStartVersionPreview(e.apiKey,e.apiBaseUrl)).catch(()=>{})),xe(e.apiBaseUrl)},[]);let f=x(()=>{}),I=Qe(e.consentFrom,e.apiKey,()=>f.current()),s=e.consentFrom?(te=I.granted)!=null?te:Q.has(e.apiKey)?!1:e.consent===!0:e.consent,a=e.consentFrom?I.refused:!0,g=x(a);g.current=a;let m=x(null),E=x(!1),k=x([]),T=x(!1);f.current=()=>{var u;k.current=[],T.current=!0;let i=m.current;i!=null&&i.gated?i.dispose():(u=i==null?void 0:i.takeHeld)==null||u.call(i)},h(()=>{var G,ae;if(g.current&&s===!1&&(k.current=[]),s===!1&&E.current&&(g.current&&((G=m.current)==null||G.destroy()),m.current=null,E.current=!1),s===!1&&!e.preConsentBehavior){g.current&&((ae=m.current)==null||ae.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,initialUnified:e.initialUnified,sessionSegment:r,consent:s,preConsentBehavior:e.preConsentBehavior,respectDoNotTrack:e.respectDoNotTrack,ssrSessionId:e.ssrSessionId,cookieDomain:e.cookieDomain,country:e.country,persona:e.persona,internal:e.internal,stageAttributes:e.stageAttributes,localMode:e.localMode,initialSlots:e.initialSlots,initialSlotConfig:e.initialSlotConfig,initialPalette:e.initialPalette,initialVocabulary:e.initialVocabulary,initialPersona:e.initialPersona,ingestUrl:e.apiBaseUrl?`${e.apiBaseUrl.replace(/\/$/,"")}/events`:void 0,nonce:e.nonce},J?{sdk:J}:{}),d=!1,o=null,b=null,C=v=>{for(let P of k.current.splice(0))setTimeout(()=>{if(m.current!==v){T.current||k.current.push(P);return}try{P(v)}catch(rt){}},0)},R=v=>{e.engagement===!1||!i||import("@sentientui/core/engagement").then(({startEngagementCapture:P})=>{d||(b=P(v,{apiKey:e.apiKey,sectionTypes:e.sectionTypes,apiBase:e.apiBaseUrl?e.apiBaseUrl.replace(/\/$/,""):void 0}))})};return e.enableGraph!==!1?import("@sentientui/core/graph").then(({init:v})=>{d||(o=v($(y({},p),{graph:!0,captureDomText:e.captureDomText===!0,sectionTypes:e.sectionTypes})),u(o),m.current=o,E.current=i,C(o),n(o),R(o))}):(o=Xe(p),u(o),m.current=o,E.current=i,C(o),n(o),R(o)),()=>{var v,P;d=!0,b==null||b(),k.current=k.current.concat((P=(v=o==null?void 0:o.takeHeld)==null?void 0:v.call(o))!=null?P:[]),o==null||o.dispose()}},[s]),h(()=>{if(!t)return;let i=!1,u=async()=>{if(i)return;let d;try{d=await t.fetchWeights()}catch(o){return}if(!i)for(let o of d){let b={componentId:o.componentId,updatedAt:o.updatedAt,variants:o.variants.map(C=>{var R;return{variantId:C.variantId,pulls:C.pulls,avgReward:(R=C.avgReward)!=null?R:0}})};de(o.componentId,b)}};u();let p=setInterval(()=>{u()},6e4);return()=>{i=!0,clearInterval(p)}},[t]);let A=(ne=e.ssrFallback)!=null?ne:"first",w=((ie=e.apiBaseUrl)!=null?ie:Ee).replace(/\/$/,""),L=x(null);h(()=>{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,internal:e.internal,apiBaseUrl:w},u=L.current;if(L.current=i,u!==null)for(let d of["apiKey","context","country","persona","internal","apiBaseUrl"])Object.is(u[d],i[d])||console.warn(`[sentient] AdaptiveProvider: \`${d}\` changed after initialisation, but the SDK client is stable for the session and only re-inits on \`consent\` \u2014 the new value is ignored. Remount the provider (e.g. via a changing \`key\` prop) to apply it.`)},[e.apiKey,e.context,e.country,e.persona,e.internal,w]),h(()=>{var i;typeof process!="undefined"&&((i=process.env)==null?void 0:i.NODE_ENV)==="production"||pe({apiKey:e.apiKey,apiBaseUrl:w,isLocal:(t==null?void 0:t.isLocal)===!0})},[t,e.apiKey,w]);let _=(re=e.identity)==null?void 0:re.userId,S=(oe=e.identity)==null?void 0:oe.userHash,Z=(se=e.identity)==null?void 0:se.email;h(()=>{t&&_&&t.identify(_,{userHash:S,email:Z})},[t,_,S,Z]),h(()=>{let i=e.initialLayoutOrder;if(i&&i.length>0){z(i);return}e.declaredSections&&e.declaredSections.length>0&&z(e.declaredSections)},[e.initialLayoutOrder,e.declaredSections]),h(()=>{!U()||e.consent!==void 0||e.consentFrom!==void 0||Re||(Re=!0,console.warn('[SentientUI] No consent gate: every visitor is tracked from first paint. Pass consentFrom="<your CMP>" (or consent={true} to silence). https://sentient-ui.com/docs#consent'))},[]),h(()=>{if(!U())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]"),d=>d.getAttribute("data-sentient-id"))),p=i.filter(d=>!u.has(d));p.length>0&&console.warn(`[SentientUI] Declared section${p.length>1?"s":""} ${p.map(d=>`"${d}"`).join(", ")} ${p.length>1?"have":"has"} no matching data-sentient-id element, so the layout engine cannot learn what they are and will serve the same order to every persona. Add data-sentient-id="<sectionId>" to each section's element.`)},[e.declaredSections]);let ee=ke(()=>t&&l?ge(t):t,[t,l]),Oe=ke(()=>{var i,u,p,d,o,b,C,R,G;return{client:ee,apiKey:e.apiKey,initialAssignments:(i=e.initialAssignments)!=null?i:{},initialUnified:(u=e.initialUnified)!=null?u:Ze,sessionSegment:r,ssrFallback:A,onAssignment:e.onAssignment,initialLayoutOrder:(p=e.initialLayoutOrder)!=null?p:null,initialSlots:(d=e.initialSlots)!=null?d:{},initialSlotConfig:(o=e.initialSlotConfig)!=null?o:{},initialPalette:(b=e.initialPalette)!=null?b:null,initialVocabulary:(C=e.initialVocabulary)!=null?C:null,initialPersona:(R=e.initialPersona)!=null?R:null,apiBaseUrl:w,debug:(G=e.debug)!=null?G:!1}},[ee,e.apiKey,e.initialAssignments,e.initialUnified,r,A,e.onAssignment,e.initialLayoutOrder,e.initialSlots,e.initialSlotConfig,e.initialPalette,e.initialVocabulary,e.initialPersona,w,e.debug]);return et(Ye.Provider,{value:Oe,children:e.children})}var Ze=[];function tt(e){return e<.3?"low":e<.7?"medium":"high"}function Pe(e={}){var n,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 c=document.documentElement;c.setAttribute("data-sentient-persona",e.persona),c.setAttribute("data-sentient-confidence",tt((l=e.confidence)!=null?l:1))}catch(c){}}else delete t.__sentient_persona_override;F()}import{jsx as it}from"react/jsx-runtime";function Yt(e,t={},n){return Pe(t),nt(it(Ae,{apiKey:"pk_test",consent:!1,children:e}),n)}export{Yt as renderWithSentient};
|
|
3
3
|
//# sourceMappingURL=react.mjs.map
|