@builder.io/sdk-solid 4.0.8 → 4.0.9

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.
@@ -1754,7 +1754,7 @@ function BlocksWrapper(props) {
1754
1754
  createEffect5(on5(() => [onUpdateFn_0_props_blocks()], onUpdateFn_0));
1755
1755
  return <>
1756
1756
  <Dynamic4
1757
- class={className() + " dynamic-023c60f2"}
1757
+ class={className() + " dynamic-450facf4"}
1758
1758
  ref={blocksWrapperRef}
1759
1759
  builder-path={dataPath()}
1760
1760
  builder-parent-id={props.parent}
@@ -1766,7 +1766,7 @@ function BlocksWrapper(props) {
1766
1766
  {...props.BlocksWrapperProps}
1767
1767
  component={props.BlocksWrapper}
1768
1768
  >{props.children}</Dynamic4>
1769
- <style>{`.dynamic-023c60f2 {
1769
+ <style>{`.dynamic-450facf4 {
1770
1770
  display: flex;
1771
1771
  flex-direction: column;
1772
1772
  align-items: stretch;
@@ -1784,19 +1784,22 @@ function Blocks(props) {
1784
1784
  parent={props.parent}
1785
1785
  path={props.path}
1786
1786
  styleProp={props.styleProp}
1787
+ BlocksWrapperProps={props.BlocksWrapperProps || props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
1787
1788
  classNameProp={props.className}
1788
1789
  BlocksWrapper={props.context?.BlocksWrapper || builderContext?.BlocksWrapper}
1789
- BlocksWrapperProps={props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
1790
- ><Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
1791
- const index = _index();
1792
- return <Block_default
1793
- key={block.id}
1794
- block={block}
1795
- linkComponent={props.linkComponent}
1796
- context={props.context || builderContext}
1797
- registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
1798
- />;
1799
- }}</For3></Show6></Blocks_wrapper_default></>;
1790
+ >
1791
+ {props.children}
1792
+ <Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
1793
+ const index = _index();
1794
+ return <Block_default
1795
+ key={block.id}
1796
+ block={block}
1797
+ linkComponent={props.linkComponent}
1798
+ context={props.context || builderContext}
1799
+ registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
1800
+ />;
1801
+ }}</For3></Show6>
1802
+ </Blocks_wrapper_default></>;
1800
1803
  }
1801
1804
  var Blocks_default = Blocks;
1802
1805
 
@@ -2147,6 +2150,166 @@ import { onMount as onMount10, on as on9, createEffect as createEffect9, createM
2147
2150
  // src/components/content-variants/content-variants.tsx
2148
2151
  import { Show as Show16, For as For9, onMount as onMount9, createSignal as createSignal19, createMemo as createMemo19 } from "solid-js";
2149
2152
 
2153
+ // src/blocks/personalization-container/helpers/inlined-fns.ts
2154
+ function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
2155
+ function isString(val) {
2156
+ return typeof val === "string";
2157
+ }
2158
+ function isNumber(val) {
2159
+ return typeof val === "number";
2160
+ }
2161
+ function objectMatchesQuery(userattr, query2) {
2162
+ const result = (() => {
2163
+ const property = query2.property;
2164
+ const operator = query2.operator;
2165
+ let testValue = query2.value;
2166
+ if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
2167
+ testValue = query2.value.slice(0, -1);
2168
+ }
2169
+ if (!(property && operator)) {
2170
+ return true;
2171
+ }
2172
+ if (Array.isArray(testValue)) {
2173
+ if (operator === "isNot") {
2174
+ return testValue.every((val) => objectMatchesQuery(userattr, {
2175
+ property,
2176
+ operator,
2177
+ value: val
2178
+ }));
2179
+ }
2180
+ return !!testValue.find((val) => objectMatchesQuery(userattr, {
2181
+ property,
2182
+ operator,
2183
+ value: val
2184
+ }));
2185
+ }
2186
+ const value = userattr[property];
2187
+ if (Array.isArray(value)) {
2188
+ return value.includes(testValue);
2189
+ }
2190
+ switch (operator) {
2191
+ case "is":
2192
+ return value === testValue;
2193
+ case "isNot":
2194
+ return value !== testValue;
2195
+ case "contains":
2196
+ return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
2197
+ case "startsWith":
2198
+ return isString(value) && value.startsWith(String(testValue));
2199
+ case "endsWith":
2200
+ return isString(value) && value.endsWith(String(testValue));
2201
+ case "greaterThan":
2202
+ return isNumber(value) && isNumber(testValue) && value > testValue;
2203
+ case "lessThan":
2204
+ return isNumber(value) && isNumber(testValue) && value < testValue;
2205
+ case "greaterThanOrEqualTo":
2206
+ return isNumber(value) && isNumber(testValue) && value >= testValue;
2207
+ case "lessThanOrEqualTo":
2208
+ return isNumber(value) && isNumber(testValue) && value <= testValue;
2209
+ default:
2210
+ return false;
2211
+ }
2212
+ })();
2213
+ return result;
2214
+ }
2215
+ const item = {
2216
+ query,
2217
+ startDate,
2218
+ endDate
2219
+ };
2220
+ const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
2221
+ if (item.startDate && new Date(item.startDate) > now) {
2222
+ return false;
2223
+ } else if (item.endDate && new Date(item.endDate) < now) {
2224
+ return false;
2225
+ }
2226
+ if (!item.query || !item.query.length) {
2227
+ return true;
2228
+ }
2229
+ return item.query.every((filter) => {
2230
+ return objectMatchesQuery(userAttributes, filter);
2231
+ });
2232
+ }
2233
+ var PERSONALIZATION_SCRIPT = "function getPersonalizedVariant(variants, blockId, isHydrationTarget, locale) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) == ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');\n if (locale) {\n attributes.locale = locale;\n }\n const winningVariantIndex = variants?.findIndex(function (variant) {\n return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);\n });\n const parentDiv = document.currentScript?.parentElement;\n const variantId = parentDiv?.getAttribute('data-variant-id');\n const isDefaultVariant = variantId === `${blockId}-default`;\n const isWinningVariant = winningVariantIndex !== -1 && variantId === `${blockId}-${winningVariantIndex}` || winningVariantIndex === -1 && isDefaultVariant;\n if (isWinningVariant && !isDefaultVariant) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultVariant) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n const itsStyleEl = parentDiv?.previousElementSibling;\n if (itsStyleEl) {\n itsStyleEl.remove();\n }\n parentDiv?.remove();\n }\n const thisScript = document.currentScript;\n if (thisScript) {\n thisScript.remove();\n }\n }\n}";
2234
+ var FILTER_WITH_CUSTOM_TARGETING_SCRIPT = "function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {\n function isString(val) {\n return typeof val === 'string';\n }\n function isNumber(val) {\n return typeof val === 'number';\n }\n function objectMatchesQuery(userattr, query) {\n const result = (() => {\n const property = query.property;\n const operator = query.operator;\n let testValue = query.value;\n if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {\n testValue = query.value.slice(0, -1);\n }\n if (!(property && operator)) {\n return true;\n }\n if (Array.isArray(testValue)) {\n if (operator === 'isNot') {\n return testValue.every(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n return !!testValue.find(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n const value = userattr[property];\n if (Array.isArray(value)) {\n return value.includes(testValue);\n }\n switch (operator) {\n case 'is':\n return value === testValue;\n case 'isNot':\n return value !== testValue;\n case 'contains':\n return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));\n case 'startsWith':\n return isString(value) && value.startsWith(String(testValue));\n case 'endsWith':\n return isString(value) && value.endsWith(String(testValue));\n case 'greaterThan':\n return isNumber(value) && isNumber(testValue) && value > testValue;\n case 'lessThan':\n return isNumber(value) && isNumber(testValue) && value < testValue;\n case 'greaterThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value >= testValue;\n case 'lessThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value <= testValue;\n default:\n return false;\n }\n })();\n return result;\n }\n const item = {\n query,\n startDate,\n endDate\n };\n const now = userAttributes.date && new Date(userAttributes.date) || new Date();\n if (item.startDate && new Date(item.startDate) > now) {\n return false;\n } else if (item.endDate && new Date(item.endDate) < now) {\n return false;\n }\n if (!item.query || !item.query.length) {\n return true;\n }\n return item.query.every(filter => {\n return objectMatchesQuery(userAttributes, filter);\n });\n}";
2235
+ var UPDATE_VISIBILITY_STYLES_SCRIPT = "function updateVisibilityStylesScript(variants, blockId, isHydrationTarget, locale) {\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) == ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const visibilityStylesEl = document.currentScript?.previousElementSibling;\n if (!visibilityStylesEl) {\n return;\n }\n if (isHydrationTarget) {\n visibilityStylesEl.remove();\n const currentScript = document.currentScript;\n if (currentScript) {\n currentScript.remove();\n }\n } else {\n const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');\n if (locale) {\n attributes.locale = locale;\n }\n const winningVariantIndex = variants?.findIndex(function (variant) {\n return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);\n });\n if (winningVariantIndex !== -1) {\n let newStyleStr = variants?.map((_, index) => {\n if (index === winningVariantIndex) return '';\n return `div[data-variant-id=\"${blockId}-${index}\"] { display: none !important; } `;\n }).join('') || '';\n newStyleStr += `div[data-variant-id=\"${blockId}-default\"] { display: none !important; } `;\n visibilityStylesEl.innerHTML = newStyleStr;\n }\n }\n}";
2236
+
2237
+ // src/blocks/personalization-container/helpers.ts
2238
+ var DEFAULT_INDEX = "default";
2239
+ var FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME = "filterWithCustomTargeting";
2240
+ var BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME = "builderIoPersonalization";
2241
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
2242
+ var SDKS_SUPPORTING_PERSONALIZATION = ["react", "vue", "svelte"];
2243
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte"];
2244
+ function checkShouldRenderVariants(variants, canTrack) {
2245
+ const hasVariants = variants && variants.length > 0;
2246
+ if (TARGET === "reactNative")
2247
+ return false;
2248
+ if (!hasVariants)
2249
+ return false;
2250
+ if (!canTrack)
2251
+ return false;
2252
+ if (SDKS_REQUIRING_RESET_APPROACH.includes(TARGET))
2253
+ return true;
2254
+ if (isBrowser())
2255
+ return false;
2256
+ return true;
2257
+ }
2258
+ function getBlocksToRender({
2259
+ variants,
2260
+ previewingIndex,
2261
+ isHydrated,
2262
+ filteredVariants,
2263
+ fallbackBlocks
2264
+ }) {
2265
+ const fallback = {
2266
+ blocks: fallbackBlocks ?? [],
2267
+ path: "this.children",
2268
+ index: DEFAULT_INDEX
2269
+ };
2270
+ if (isHydrated && isEditing()) {
2271
+ if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
2272
+ const variant = variants?.[previewingIndex];
2273
+ if (variant) {
2274
+ return {
2275
+ blocks: variant.blocks,
2276
+ path: `variants.${previewingIndex}.blocks`,
2277
+ index: previewingIndex
2278
+ };
2279
+ }
2280
+ }
2281
+ return fallback;
2282
+ }
2283
+ if (isBrowser()) {
2284
+ const winningVariant = filteredVariants?.[0];
2285
+ if (winningVariant && variants) {
2286
+ const variantIndex = variants.indexOf(winningVariant);
2287
+ if (variantIndex !== -1) {
2288
+ return {
2289
+ blocks: winningVariant.blocks,
2290
+ path: `variants.${variantIndex}.blocks`,
2291
+ index: variantIndex
2292
+ };
2293
+ }
2294
+ }
2295
+ }
2296
+ return fallback;
2297
+ }
2298
+ var getInitPersonalizationVariantsFnsScriptString = () => {
2299
+ return `
2300
+ window.${FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME} = ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
2301
+ window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME} = ${PERSONALIZATION_SCRIPT}
2302
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VISIBILITY_STYLES_SCRIPT}
2303
+ `;
2304
+ };
2305
+ var isHydrationTarget = TARGET === "react";
2306
+ var getPersonalizationScript = (variants, blockId, locale) => {
2307
+ return `window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2308
+ };
2309
+ var getUpdateVisibilityStylesScript = (variants, blockId, locale) => {
2310
+ return `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2311
+ };
2312
+
2150
2313
  // src/helpers/url.ts
2151
2314
  var getTopLevelDomain = (host) => {
2152
2315
  if (host === "localhost" || host === "127.0.0.1") {
@@ -3092,7 +3255,8 @@ var componentInfo6 = {
3092
3255
  name: "PersonalizationContainer",
3093
3256
  shouldReceiveBuilderProps: {
3094
3257
  builderBlock: true,
3095
- builderContext: true
3258
+ builderContext: true,
3259
+ builderComponents: true
3096
3260
  },
3097
3261
  noWrap: true,
3098
3262
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -3148,199 +3312,6 @@ function isPreviewing(_search) {
3148
3312
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
3149
3313
  }
3150
3314
 
3151
- // src/blocks/personalization-container/helpers/inlined-fns.ts
3152
- function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
3153
- function isString(val) {
3154
- return typeof val === "string";
3155
- }
3156
- function isNumber(val) {
3157
- return typeof val === "number";
3158
- }
3159
- function objectMatchesQuery(userattr, query2) {
3160
- const result = (() => {
3161
- const property = query2.property;
3162
- const operator = query2.operator;
3163
- let testValue = query2.value;
3164
- if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
3165
- testValue = query2.value.slice(0, -1);
3166
- }
3167
- if (!(property && operator)) {
3168
- return true;
3169
- }
3170
- if (Array.isArray(testValue)) {
3171
- if (operator === "isNot") {
3172
- return testValue.every((val) => objectMatchesQuery(userattr, {
3173
- property,
3174
- operator,
3175
- value: val
3176
- }));
3177
- }
3178
- return !!testValue.find((val) => objectMatchesQuery(userattr, {
3179
- property,
3180
- operator,
3181
- value: val
3182
- }));
3183
- }
3184
- const value = userattr[property];
3185
- if (Array.isArray(value)) {
3186
- return value.includes(testValue);
3187
- }
3188
- switch (operator) {
3189
- case "is":
3190
- return value === testValue;
3191
- case "isNot":
3192
- return value !== testValue;
3193
- case "contains":
3194
- return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
3195
- case "startsWith":
3196
- return isString(value) && value.startsWith(String(testValue));
3197
- case "endsWith":
3198
- return isString(value) && value.endsWith(String(testValue));
3199
- case "greaterThan":
3200
- return isNumber(value) && isNumber(testValue) && value > testValue;
3201
- case "lessThan":
3202
- return isNumber(value) && isNumber(testValue) && value < testValue;
3203
- case "greaterThanOrEqualTo":
3204
- return isNumber(value) && isNumber(testValue) && value >= testValue;
3205
- case "lessThanOrEqualTo":
3206
- return isNumber(value) && isNumber(testValue) && value <= testValue;
3207
- default:
3208
- return false;
3209
- }
3210
- })();
3211
- return result;
3212
- }
3213
- const item = {
3214
- query,
3215
- startDate,
3216
- endDate
3217
- };
3218
- const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
3219
- if (item.startDate && new Date(item.startDate) > now) {
3220
- return false;
3221
- } else if (item.endDate && new Date(item.endDate) < now) {
3222
- return false;
3223
- }
3224
- if (!item.query || !item.query.length) {
3225
- return true;
3226
- }
3227
- return item.query.every((filter) => {
3228
- return objectMatchesQuery(userAttributes, filter);
3229
- });
3230
- }
3231
- var PERSONALIZATION_SCRIPT = `function getPersonalizedVariant(variants, blockId, locale) {
3232
- if (!navigator.cookieEnabled) {
3233
- return;
3234
- }
3235
- function getCookie(name) {
3236
- const nameEQ = name + '=';
3237
- const ca = document.cookie.split(';');
3238
- for (let i = 0; i < ca.length; i++) {
3239
- let c = ca[i];
3240
- while (c.charAt(0) == ' ') c = c.substring(1, c.length);
3241
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
3242
- }
3243
- return null;
3244
- }
3245
- function removeVariants() {
3246
- variants?.forEach(function (_, index) {
3247
- document.querySelector('template[data-variant-id="' + blockId + '-' + index + '"]')?.remove();
3248
- });
3249
- document.querySelector('script[data-id="variants-script-' + blockId + '"]')?.remove();
3250
- document.querySelector('style[data-id="variants-styles-' + blockId + '"]')?.remove();
3251
- }
3252
- const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
3253
- if (locale) {
3254
- attributes.locale = locale;
3255
- }
3256
- const winningVariantIndex = variants?.findIndex(function (variant) {
3257
- return filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
3258
- });
3259
- const isDebug = location.href.includes('builder.debug=true');
3260
- if (isDebug) {
3261
- console.debug('PersonalizationContainer', {
3262
- attributes,
3263
- variants,
3264
- winningVariantIndex
3265
- });
3266
- }
3267
- if (winningVariantIndex !== -1) {
3268
- const winningVariant = document.querySelector('template[data-variant-id="' + blockId + '-' + winningVariantIndex + '"]');
3269
- if (winningVariant) {
3270
- const parentNode = winningVariant.parentNode;
3271
- if (parentNode) {
3272
- const newParent = parentNode.cloneNode(false);
3273
- newParent.appendChild(winningVariant.content.firstChild);
3274
- newParent.appendChild(winningVariant.content.lastChild);
3275
- parentNode.parentNode?.replaceChild(newParent, parentNode);
3276
- }
3277
- if (isDebug) {
3278
- console.debug('PersonalizationContainer', 'Winning variant Replaced:', winningVariant);
3279
- }
3280
- }
3281
- } else if (variants && variants.length > 0) {
3282
- removeVariants();
3283
- }
3284
- }`;
3285
- var FILTER_WITH_CUSTOM_TARGETING_SCRIPT = "function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {\n function isString(val) {\n return typeof val === 'string';\n }\n function isNumber(val) {\n return typeof val === 'number';\n }\n function objectMatchesQuery(userattr, query) {\n const result = (() => {\n const property = query.property;\n const operator = query.operator;\n let testValue = query.value;\n if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {\n testValue = query.value.slice(0, -1);\n }\n if (!(property && operator)) {\n return true;\n }\n if (Array.isArray(testValue)) {\n if (operator === 'isNot') {\n return testValue.every(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n return !!testValue.find(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n const value = userattr[property];\n if (Array.isArray(value)) {\n return value.includes(testValue);\n }\n switch (operator) {\n case 'is':\n return value === testValue;\n case 'isNot':\n return value !== testValue;\n case 'contains':\n return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));\n case 'startsWith':\n return isString(value) && value.startsWith(String(testValue));\n case 'endsWith':\n return isString(value) && value.endsWith(String(testValue));\n case 'greaterThan':\n return isNumber(value) && isNumber(testValue) && value > testValue;\n case 'lessThan':\n return isNumber(value) && isNumber(testValue) && value < testValue;\n case 'greaterThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value >= testValue;\n case 'lessThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value <= testValue;\n default:\n return false;\n }\n })();\n return result;\n }\n const item = {\n query,\n startDate,\n endDate\n };\n const now = userAttributes.date && new Date(userAttributes.date) || new Date();\n if (item.startDate && new Date(item.startDate) > now) {\n return false;\n } else if (item.endDate && new Date(item.endDate) < now) {\n return false;\n }\n if (!item.query || !item.query.length) {\n return true;\n }\n return item.query.every(filter => {\n return objectMatchesQuery(userAttributes, filter);\n });\n}";
3286
-
3287
- // src/blocks/personalization-container/helpers.ts
3288
- function checkShouldRenderVariants(variants, canTrack) {
3289
- const hasVariants = variants && variants.length > 0;
3290
- if (TARGET === "reactNative")
3291
- return false;
3292
- if (!hasVariants)
3293
- return false;
3294
- if (!canTrack)
3295
- return false;
3296
- if (TARGET === "vue" || TARGET === "svelte")
3297
- return true;
3298
- if (isBrowser())
3299
- return false;
3300
- return true;
3301
- }
3302
- function getBlocksToRender({
3303
- variants,
3304
- previewingIndex,
3305
- isHydrated,
3306
- filteredVariants,
3307
- fallbackBlocks
3308
- }) {
3309
- const fallback = {
3310
- blocks: fallbackBlocks ?? [],
3311
- path: "this.children"
3312
- };
3313
- if (isHydrated && isEditing()) {
3314
- if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
3315
- const variant = variants[previewingIndex];
3316
- return {
3317
- blocks: variant.blocks,
3318
- path: `component.options.variants.${previewingIndex}.blocks`
3319
- };
3320
- }
3321
- return fallback;
3322
- }
3323
- if (isBrowser()) {
3324
- const winningVariant = filteredVariants?.[0];
3325
- if (winningVariant) {
3326
- return {
3327
- blocks: winningVariant.blocks,
3328
- path: `component.options.variants.${variants?.indexOf(winningVariant)}.blocks`
3329
- };
3330
- }
3331
- }
3332
- return fallback;
3333
- }
3334
- var getPersonalizationScript = (variants, blockId, locale) => {
3335
- return `
3336
- (function() {
3337
- ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
3338
- ${PERSONALIZATION_SCRIPT}
3339
- getPersonalizedVariant(${JSON.stringify(variants)}, "${blockId}"${locale ? `, "${locale}"` : ""})
3340
- })();
3341
- `;
3342
- };
3343
-
3344
3315
  // src/blocks/personalization-container/personalization-container.tsx
3345
3316
  function PersonalizationContainer(props) {
3346
3317
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -3353,6 +3324,13 @@ function PersonalizationContainer(props) {
3353
3324
  props.builderContext?.rootState?.locale
3354
3325
  )
3355
3326
  );
3327
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
3328
+ getUpdateVisibilityStylesScript(
3329
+ props.variants,
3330
+ props.builderBlock?.id || "none",
3331
+ props.builderContext?.rootState?.locale
3332
+ )
3333
+ );
3356
3334
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
3357
3335
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
3358
3336
  checkShouldRenderVariants(
@@ -3360,7 +3338,14 @@ function PersonalizationContainer(props) {
3360
3338
  getDefaultCanTrack(props.builderContext?.canTrack)
3361
3339
  )
3362
3340
  );
3363
- const [isHydrated, setIsHydrated] = createSignal10(false);
3341
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
3342
+ const attrs = createMemo10(() => {
3343
+ return {
3344
+ ...props.attributes,
3345
+ ...{},
3346
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
3347
+ };
3348
+ });
3364
3349
  const filteredVariants = createMemo10(() => {
3365
3350
  return (props.variants || []).filter((variant) => {
3366
3351
  return filterWithCustomTargeting(
@@ -3380,22 +3365,22 @@ function PersonalizationContainer(props) {
3380
3365
  return getBlocksToRender({
3381
3366
  variants: props.variants,
3382
3367
  fallbackBlocks: props.builderBlock?.children,
3383
- isHydrated: isHydrated(),
3368
+ isHydrated: shouldResetVariants(),
3384
3369
  filteredVariants: filteredVariants(),
3385
3370
  previewingIndex: props.previewingIndex
3386
3371
  });
3387
3372
  });
3388
3373
  const hideVariantsStyleString = createMemo10(() => {
3389
3374
  return (props.variants || []).map(
3390
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
3375
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
3391
3376
  ).join("");
3392
3377
  });
3393
3378
  let rootRef;
3394
3379
  onMount5(() => {
3395
- setIsHydrated(true);
3380
+ setShouldResetVariants(true);
3396
3381
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
3397
- (attrs) => {
3398
- setUserAttributes(attrs);
3382
+ (attrs2) => {
3383
+ setUserAttributes(attrs2);
3399
3384
  }
3400
3385
  );
3401
3386
  if (!(isEditing() || isPreviewing())) {
@@ -3404,7 +3389,7 @@ function PersonalizationContainer(props) {
3404
3389
  rootRef.dispatchEvent(
3405
3390
  new CustomEvent("builder.variantLoaded", {
3406
3391
  detail: {
3407
- variant: variant || "default",
3392
+ variant: variant || DEFAULT_INDEX,
3408
3393
  content: props.builderContext?.content
3409
3394
  },
3410
3395
  bubbles: true
@@ -3416,7 +3401,7 @@ function PersonalizationContainer(props) {
3416
3401
  rootRef.dispatchEvent(
3417
3402
  new CustomEvent("builder.variantDisplayed", {
3418
3403
  detail: {
3419
- variant: variant || "default",
3404
+ variant: variant || DEFAULT_INDEX,
3420
3405
  content: props.builderContext?.content
3421
3406
  },
3422
3407
  bubbles: true
@@ -3430,39 +3415,72 @@ function PersonalizationContainer(props) {
3430
3415
  }
3431
3416
  unsubscribers().push(unsub);
3432
3417
  });
3433
- return <><div
3434
- class={`builder-personalization-container ${props.attributes?.className || ""}`}
3435
- ref={rootRef}
3436
- {...props.attributes}
3437
- >
3438
- <Show10 when={shouldRenderVariants()}>
3439
- <For6 each={props.variants}>{(variant, _index) => {
3440
- const index = _index();
3441
- return <template
3442
- key={index}
3443
- data-variant-id={`${props.builderBlock?.id}-${index}`}
3444
- ><Blocks_default
3445
- blocks={variant.blocks}
3446
- parent={props.builderBlock?.id}
3447
- path={`component.options.variants.${index}.blocks`}
3448
- /></template>;
3449
- }}</For6>
3450
- <Inlined_styles_default
3451
- nonce={props.builderContext?.nonce || ""}
3452
- styles={hideVariantsStyleString()}
3453
- id={`variants-styles-${props.builderBlock?.id}`}
3454
- />
3455
- <Inlined_script_default
3456
- nonce={props.builderContext?.nonce || ""}
3457
- scriptStr={scriptStr()}
3458
- id={`variants-script-${props.builderBlock?.id}`}
3459
- />
3460
- </Show10>
3461
- <Blocks_default
3418
+ return <><div ref={rootRef} {...attrs()}>
3419
+ <Show10
3420
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3421
+ ><Blocks_default
3462
3422
  blocks={blocksToRender().blocks}
3463
3423
  parent={props.builderBlock?.id}
3464
3424
  path={blocksToRender().path}
3465
- />
3425
+ context={props.builderContext}
3426
+ registeredComponents={props.builderComponents}
3427
+ BlocksWrapperProps={{
3428
+ ...props.builderContext?.BlocksWrapperProps,
3429
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3430
+ }}
3431
+ /></Show10>
3432
+ <Show10
3433
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3434
+ >
3435
+ <Show10 when={shouldRenderVariants()}>
3436
+ <Inlined_styles_default
3437
+ nonce={props.builderContext?.nonce || ""}
3438
+ styles={hideVariantsStyleString()}
3439
+ id={`variants-styles-${props.builderBlock?.id}`}
3440
+ />
3441
+ <Inlined_script_default
3442
+ nonce={props.builderContext?.nonce || ""}
3443
+ scriptStr={updateVisibilityStylesScript()}
3444
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
3445
+ />
3446
+ <For6 each={props.variants}>{(variant, _index) => {
3447
+ const index = _index();
3448
+ return <Blocks_default
3449
+ key={`${props.builderBlock?.id}-${index}`}
3450
+ BlocksWrapperProps={{
3451
+ ...props.builderContext?.BlocksWrapperProps,
3452
+ "aria-hidden": true,
3453
+ hidden: true,
3454
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
3455
+ }}
3456
+ blocks={variant.blocks}
3457
+ parent={props.builderBlock?.id}
3458
+ path={`component.options.variants.${index}.blocks`}
3459
+ context={props.builderContext}
3460
+ registeredComponents={props.builderComponents}
3461
+ ><Inlined_script_default
3462
+ nonce={props.builderContext?.nonce || ""}
3463
+ scriptStr={scriptStr()}
3464
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
3465
+ /></Blocks_default>;
3466
+ }}</For6>
3467
+ </Show10>
3468
+ <Blocks_default
3469
+ blocks={blocksToRender().blocks}
3470
+ parent={props.builderBlock?.id}
3471
+ path={blocksToRender().path}
3472
+ context={props.builderContext}
3473
+ registeredComponents={props.builderComponents}
3474
+ BlocksWrapperProps={{
3475
+ ...props.builderContext?.BlocksWrapperProps,
3476
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3477
+ }}
3478
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
3479
+ nonce={props.builderContext?.nonce || ""}
3480
+ scriptStr={scriptStr()}
3481
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
3482
+ /></Show10></Blocks_default>
3483
+ </Show10>
3466
3484
  </div></>;
3467
3485
  }
3468
3486
  var personalization_container_default = PersonalizationContainer;
@@ -4984,7 +5002,7 @@ var getDefaultRegisteredComponents = () => [{
4984
5002
  }, {
4985
5003
  component: text_default,
4986
5004
  ...componentInfo11
4987
- }, ...TARGET === "react" ? [{
5005
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
4988
5006
  component: personalization_container_default,
4989
5007
  ...componentInfo6
4990
5008
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -5021,7 +5039,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
5021
5039
 
5022
5040
  // src/components/content-variants/helpers.ts
5023
5041
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
5024
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
5042
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
5025
5043
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
5026
5044
  ...variant,
5027
5045
  testVariationId: variant.id,
@@ -5046,20 +5064,20 @@ var checkShouldRenderVariants2 = ({
5046
5064
  };
5047
5065
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
5048
5066
  var isAngularSDK = TARGET === "angular";
5049
- var isHydrationTarget = getIsHydrationTarget(TARGET);
5067
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
5050
5068
  var getInitVariantsFnsScriptString = () => `
5051
5069
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
5052
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5070
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5053
5071
  `;
5054
5072
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
5055
5073
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
5056
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
5074
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
5057
5075
  )`;
5058
5076
  var getUpdateVariantVisibilityScript = ({
5059
5077
  contentId,
5060
5078
  variationId
5061
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
5062
- "${variationId}", "${contentId}", ${isHydrationTarget}
5079
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
5080
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
5063
5081
  )`;
5064
5082
 
5065
5083
  // src/components/content/components/enable-editor.tsx
@@ -5079,7 +5097,7 @@ function getPreviewContent(_searchParams) {
5079
5097
  }
5080
5098
 
5081
5099
  // src/constants/sdk-version.ts
5082
- var SDK_VERSION = "4.0.8";
5100
+ var SDK_VERSION = "4.0.9";
5083
5101
 
5084
5102
  // src/helpers/sdk-headers.ts
5085
5103
  var getSdkHeaders = () => ({
@@ -6438,11 +6456,18 @@ function ContentVariants(props) {
6438
6456
  setShouldRenderVariants(false);
6439
6457
  });
6440
6458
  return <><>
6441
- <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}><Inlined_script_default
6442
- id="builderio-init-variants-fns"
6443
- scriptStr={getInitVariantsFnsScriptString()}
6444
- nonce={props.nonce || ""}
6445
- /></Show16>
6459
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
6460
+ <Inlined_script_default
6461
+ id="builderio-init-variants-fns"
6462
+ scriptStr={getInitVariantsFnsScriptString()}
6463
+ nonce={props.nonce || ""}
6464
+ />
6465
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
6466
+ id="builderio-init-personalization-variants-fns"
6467
+ nonce={props.nonce || ""}
6468
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
6469
+ /></Show16>
6470
+ </Show16>
6446
6471
  <Show16 when={shouldRenderVariants()}>
6447
6472
  <Inlined_styles_default
6448
6473
  id="builderio-variants"