@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.
@@ -1590,7 +1590,7 @@ function BlocksWrapper(props) {
1590
1590
  createEffect5(on5(() => [onUpdateFn_0_props_blocks()], onUpdateFn_0));
1591
1591
  return <>
1592
1592
  <Dynamic4
1593
- class={className() + " dynamic-023c60f2"}
1593
+ class={className() + " dynamic-450facf4"}
1594
1594
  ref={blocksWrapperRef}
1595
1595
  builder-path={dataPath()}
1596
1596
  builder-parent-id={props.parent}
@@ -1602,7 +1602,7 @@ function BlocksWrapper(props) {
1602
1602
  {...props.BlocksWrapperProps}
1603
1603
  component={props.BlocksWrapper}
1604
1604
  >{props.children}</Dynamic4>
1605
- <style>{`.dynamic-023c60f2 {
1605
+ <style>{`.dynamic-450facf4 {
1606
1606
  display: flex;
1607
1607
  flex-direction: column;
1608
1608
  align-items: stretch;
@@ -1620,19 +1620,22 @@ function Blocks(props) {
1620
1620
  parent={props.parent}
1621
1621
  path={props.path}
1622
1622
  styleProp={props.styleProp}
1623
+ BlocksWrapperProps={props.BlocksWrapperProps || props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
1623
1624
  classNameProp={props.className}
1624
1625
  BlocksWrapper={props.context?.BlocksWrapper || builderContext?.BlocksWrapper}
1625
- BlocksWrapperProps={props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
1626
- ><Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
1627
- const index = _index();
1628
- return <Block_default
1629
- key={block.id}
1630
- block={block}
1631
- linkComponent={props.linkComponent}
1632
- context={props.context || builderContext}
1633
- registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
1634
- />;
1635
- }}</For3></Show6></Blocks_wrapper_default></>;
1626
+ >
1627
+ {props.children}
1628
+ <Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
1629
+ const index = _index();
1630
+ return <Block_default
1631
+ key={block.id}
1632
+ block={block}
1633
+ linkComponent={props.linkComponent}
1634
+ context={props.context || builderContext}
1635
+ registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
1636
+ />;
1637
+ }}</For3></Show6>
1638
+ </Blocks_wrapper_default></>;
1636
1639
  }
1637
1640
  var Blocks_default = Blocks;
1638
1641
 
@@ -1984,6 +1987,166 @@ import { onMount as onMount10, on as on9, createEffect as createEffect9, createM
1984
1987
  // src/components/content-variants/content-variants.tsx
1985
1988
  import { Show as Show16, For as For9, onMount as onMount9, createSignal as createSignal19, createMemo as createMemo19 } from "solid-js";
1986
1989
 
1990
+ // src/blocks/personalization-container/helpers/inlined-fns.ts
1991
+ function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
1992
+ function isString(val) {
1993
+ return typeof val === "string";
1994
+ }
1995
+ function isNumber(val) {
1996
+ return typeof val === "number";
1997
+ }
1998
+ function objectMatchesQuery(userattr, query2) {
1999
+ const result = (() => {
2000
+ const property = query2.property;
2001
+ const operator = query2.operator;
2002
+ let testValue = query2.value;
2003
+ if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
2004
+ testValue = query2.value.slice(0, -1);
2005
+ }
2006
+ if (!(property && operator)) {
2007
+ return true;
2008
+ }
2009
+ if (Array.isArray(testValue)) {
2010
+ if (operator === "isNot") {
2011
+ return testValue.every((val) => objectMatchesQuery(userattr, {
2012
+ property,
2013
+ operator,
2014
+ value: val
2015
+ }));
2016
+ }
2017
+ return !!testValue.find((val) => objectMatchesQuery(userattr, {
2018
+ property,
2019
+ operator,
2020
+ value: val
2021
+ }));
2022
+ }
2023
+ const value = userattr[property];
2024
+ if (Array.isArray(value)) {
2025
+ return value.includes(testValue);
2026
+ }
2027
+ switch (operator) {
2028
+ case "is":
2029
+ return value === testValue;
2030
+ case "isNot":
2031
+ return value !== testValue;
2032
+ case "contains":
2033
+ return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
2034
+ case "startsWith":
2035
+ return isString(value) && value.startsWith(String(testValue));
2036
+ case "endsWith":
2037
+ return isString(value) && value.endsWith(String(testValue));
2038
+ case "greaterThan":
2039
+ return isNumber(value) && isNumber(testValue) && value > testValue;
2040
+ case "lessThan":
2041
+ return isNumber(value) && isNumber(testValue) && value < testValue;
2042
+ case "greaterThanOrEqualTo":
2043
+ return isNumber(value) && isNumber(testValue) && value >= testValue;
2044
+ case "lessThanOrEqualTo":
2045
+ return isNumber(value) && isNumber(testValue) && value <= testValue;
2046
+ default:
2047
+ return false;
2048
+ }
2049
+ })();
2050
+ return result;
2051
+ }
2052
+ const item = {
2053
+ query,
2054
+ startDate,
2055
+ endDate
2056
+ };
2057
+ const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
2058
+ if (item.startDate && new Date(item.startDate) > now) {
2059
+ return false;
2060
+ } else if (item.endDate && new Date(item.endDate) < now) {
2061
+ return false;
2062
+ }
2063
+ if (!item.query || !item.query.length) {
2064
+ return true;
2065
+ }
2066
+ return item.query.every((filter) => {
2067
+ return objectMatchesQuery(userAttributes, filter);
2068
+ });
2069
+ }
2070
+ 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}";
2071
+ 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}";
2072
+ 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}";
2073
+
2074
+ // src/blocks/personalization-container/helpers.ts
2075
+ var DEFAULT_INDEX = "default";
2076
+ var FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME = "filterWithCustomTargeting";
2077
+ var BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME = "builderIoPersonalization";
2078
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
2079
+ var SDKS_SUPPORTING_PERSONALIZATION = ["react", "vue", "svelte"];
2080
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte"];
2081
+ function checkShouldRenderVariants(variants, canTrack) {
2082
+ const hasVariants = variants && variants.length > 0;
2083
+ if (TARGET === "reactNative")
2084
+ return false;
2085
+ if (!hasVariants)
2086
+ return false;
2087
+ if (!canTrack)
2088
+ return false;
2089
+ if (SDKS_REQUIRING_RESET_APPROACH.includes(TARGET))
2090
+ return true;
2091
+ if (isBrowser())
2092
+ return false;
2093
+ return true;
2094
+ }
2095
+ function getBlocksToRender({
2096
+ variants,
2097
+ previewingIndex,
2098
+ isHydrated,
2099
+ filteredVariants,
2100
+ fallbackBlocks
2101
+ }) {
2102
+ const fallback = {
2103
+ blocks: fallbackBlocks ?? [],
2104
+ path: "this.children",
2105
+ index: DEFAULT_INDEX
2106
+ };
2107
+ if (isHydrated && isEditing()) {
2108
+ if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
2109
+ const variant = variants?.[previewingIndex];
2110
+ if (variant) {
2111
+ return {
2112
+ blocks: variant.blocks,
2113
+ path: `variants.${previewingIndex}.blocks`,
2114
+ index: previewingIndex
2115
+ };
2116
+ }
2117
+ }
2118
+ return fallback;
2119
+ }
2120
+ if (isBrowser()) {
2121
+ const winningVariant = filteredVariants?.[0];
2122
+ if (winningVariant && variants) {
2123
+ const variantIndex = variants.indexOf(winningVariant);
2124
+ if (variantIndex !== -1) {
2125
+ return {
2126
+ blocks: winningVariant.blocks,
2127
+ path: `variants.${variantIndex}.blocks`,
2128
+ index: variantIndex
2129
+ };
2130
+ }
2131
+ }
2132
+ }
2133
+ return fallback;
2134
+ }
2135
+ var getInitPersonalizationVariantsFnsScriptString = () => {
2136
+ return `
2137
+ window.${FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME} = ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
2138
+ window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME} = ${PERSONALIZATION_SCRIPT}
2139
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VISIBILITY_STYLES_SCRIPT}
2140
+ `;
2141
+ };
2142
+ var isHydrationTarget = TARGET === "react";
2143
+ var getPersonalizationScript = (variants, blockId, locale) => {
2144
+ return `window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2145
+ };
2146
+ var getUpdateVisibilityStylesScript = (variants, blockId, locale) => {
2147
+ return `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2148
+ };
2149
+
1987
2150
  // src/helpers/url.ts
1988
2151
  var getTopLevelDomain = (host) => {
1989
2152
  if (host === "localhost" || host === "127.0.0.1") {
@@ -2930,7 +3093,8 @@ var componentInfo6 = {
2930
3093
  name: "PersonalizationContainer",
2931
3094
  shouldReceiveBuilderProps: {
2932
3095
  builderBlock: true,
2933
- builderContext: true
3096
+ builderContext: true,
3097
+ builderComponents: true
2934
3098
  },
2935
3099
  noWrap: true,
2936
3100
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -2986,199 +3150,6 @@ function isPreviewing(_search) {
2986
3150
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
2987
3151
  }
2988
3152
 
2989
- // src/blocks/personalization-container/helpers/inlined-fns.ts
2990
- function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
2991
- function isString(val) {
2992
- return typeof val === "string";
2993
- }
2994
- function isNumber(val) {
2995
- return typeof val === "number";
2996
- }
2997
- function objectMatchesQuery(userattr, query2) {
2998
- const result = (() => {
2999
- const property = query2.property;
3000
- const operator = query2.operator;
3001
- let testValue = query2.value;
3002
- if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
3003
- testValue = query2.value.slice(0, -1);
3004
- }
3005
- if (!(property && operator)) {
3006
- return true;
3007
- }
3008
- if (Array.isArray(testValue)) {
3009
- if (operator === "isNot") {
3010
- return testValue.every((val) => objectMatchesQuery(userattr, {
3011
- property,
3012
- operator,
3013
- value: val
3014
- }));
3015
- }
3016
- return !!testValue.find((val) => objectMatchesQuery(userattr, {
3017
- property,
3018
- operator,
3019
- value: val
3020
- }));
3021
- }
3022
- const value = userattr[property];
3023
- if (Array.isArray(value)) {
3024
- return value.includes(testValue);
3025
- }
3026
- switch (operator) {
3027
- case "is":
3028
- return value === testValue;
3029
- case "isNot":
3030
- return value !== testValue;
3031
- case "contains":
3032
- return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
3033
- case "startsWith":
3034
- return isString(value) && value.startsWith(String(testValue));
3035
- case "endsWith":
3036
- return isString(value) && value.endsWith(String(testValue));
3037
- case "greaterThan":
3038
- return isNumber(value) && isNumber(testValue) && value > testValue;
3039
- case "lessThan":
3040
- return isNumber(value) && isNumber(testValue) && value < testValue;
3041
- case "greaterThanOrEqualTo":
3042
- return isNumber(value) && isNumber(testValue) && value >= testValue;
3043
- case "lessThanOrEqualTo":
3044
- return isNumber(value) && isNumber(testValue) && value <= testValue;
3045
- default:
3046
- return false;
3047
- }
3048
- })();
3049
- return result;
3050
- }
3051
- const item = {
3052
- query,
3053
- startDate,
3054
- endDate
3055
- };
3056
- const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
3057
- if (item.startDate && new Date(item.startDate) > now) {
3058
- return false;
3059
- } else if (item.endDate && new Date(item.endDate) < now) {
3060
- return false;
3061
- }
3062
- if (!item.query || !item.query.length) {
3063
- return true;
3064
- }
3065
- return item.query.every((filter) => {
3066
- return objectMatchesQuery(userAttributes, filter);
3067
- });
3068
- }
3069
- var PERSONALIZATION_SCRIPT = `function getPersonalizedVariant(variants, blockId, locale) {
3070
- if (!navigator.cookieEnabled) {
3071
- return;
3072
- }
3073
- function getCookie(name) {
3074
- const nameEQ = name + '=';
3075
- const ca = document.cookie.split(';');
3076
- for (let i = 0; i < ca.length; i++) {
3077
- let c = ca[i];
3078
- while (c.charAt(0) == ' ') c = c.substring(1, c.length);
3079
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
3080
- }
3081
- return null;
3082
- }
3083
- function removeVariants() {
3084
- variants?.forEach(function (_, index) {
3085
- document.querySelector('template[data-variant-id="' + blockId + '-' + index + '"]')?.remove();
3086
- });
3087
- document.querySelector('script[data-id="variants-script-' + blockId + '"]')?.remove();
3088
- document.querySelector('style[data-id="variants-styles-' + blockId + '"]')?.remove();
3089
- }
3090
- const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
3091
- if (locale) {
3092
- attributes.locale = locale;
3093
- }
3094
- const winningVariantIndex = variants?.findIndex(function (variant) {
3095
- return filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
3096
- });
3097
- const isDebug = location.href.includes('builder.debug=true');
3098
- if (isDebug) {
3099
- console.debug('PersonalizationContainer', {
3100
- attributes,
3101
- variants,
3102
- winningVariantIndex
3103
- });
3104
- }
3105
- if (winningVariantIndex !== -1) {
3106
- const winningVariant = document.querySelector('template[data-variant-id="' + blockId + '-' + winningVariantIndex + '"]');
3107
- if (winningVariant) {
3108
- const parentNode = winningVariant.parentNode;
3109
- if (parentNode) {
3110
- const newParent = parentNode.cloneNode(false);
3111
- newParent.appendChild(winningVariant.content.firstChild);
3112
- newParent.appendChild(winningVariant.content.lastChild);
3113
- parentNode.parentNode?.replaceChild(newParent, parentNode);
3114
- }
3115
- if (isDebug) {
3116
- console.debug('PersonalizationContainer', 'Winning variant Replaced:', winningVariant);
3117
- }
3118
- }
3119
- } else if (variants && variants.length > 0) {
3120
- removeVariants();
3121
- }
3122
- }`;
3123
- 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}";
3124
-
3125
- // src/blocks/personalization-container/helpers.ts
3126
- function checkShouldRenderVariants(variants, canTrack) {
3127
- const hasVariants = variants && variants.length > 0;
3128
- if (TARGET === "reactNative")
3129
- return false;
3130
- if (!hasVariants)
3131
- return false;
3132
- if (!canTrack)
3133
- return false;
3134
- if (TARGET === "vue" || TARGET === "svelte")
3135
- return true;
3136
- if (isBrowser())
3137
- return false;
3138
- return true;
3139
- }
3140
- function getBlocksToRender({
3141
- variants,
3142
- previewingIndex,
3143
- isHydrated,
3144
- filteredVariants,
3145
- fallbackBlocks
3146
- }) {
3147
- const fallback = {
3148
- blocks: fallbackBlocks ?? [],
3149
- path: "this.children"
3150
- };
3151
- if (isHydrated && isEditing()) {
3152
- if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
3153
- const variant = variants[previewingIndex];
3154
- return {
3155
- blocks: variant.blocks,
3156
- path: `component.options.variants.${previewingIndex}.blocks`
3157
- };
3158
- }
3159
- return fallback;
3160
- }
3161
- if (isBrowser()) {
3162
- const winningVariant = filteredVariants?.[0];
3163
- if (winningVariant) {
3164
- return {
3165
- blocks: winningVariant.blocks,
3166
- path: `component.options.variants.${variants?.indexOf(winningVariant)}.blocks`
3167
- };
3168
- }
3169
- }
3170
- return fallback;
3171
- }
3172
- var getPersonalizationScript = (variants, blockId, locale) => {
3173
- return `
3174
- (function() {
3175
- ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
3176
- ${PERSONALIZATION_SCRIPT}
3177
- getPersonalizedVariant(${JSON.stringify(variants)}, "${blockId}"${locale ? `, "${locale}"` : ""})
3178
- })();
3179
- `;
3180
- };
3181
-
3182
3153
  // src/blocks/personalization-container/personalization-container.tsx
3183
3154
  function PersonalizationContainer(props) {
3184
3155
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -3191,6 +3162,13 @@ function PersonalizationContainer(props) {
3191
3162
  props.builderContext?.rootState?.locale
3192
3163
  )
3193
3164
  );
3165
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
3166
+ getUpdateVisibilityStylesScript(
3167
+ props.variants,
3168
+ props.builderBlock?.id || "none",
3169
+ props.builderContext?.rootState?.locale
3170
+ )
3171
+ );
3194
3172
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
3195
3173
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
3196
3174
  checkShouldRenderVariants(
@@ -3198,7 +3176,14 @@ function PersonalizationContainer(props) {
3198
3176
  getDefaultCanTrack(props.builderContext?.canTrack)
3199
3177
  )
3200
3178
  );
3201
- const [isHydrated, setIsHydrated] = createSignal10(false);
3179
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
3180
+ const attrs = createMemo10(() => {
3181
+ return {
3182
+ ...props.attributes,
3183
+ ...{},
3184
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
3185
+ };
3186
+ });
3202
3187
  const filteredVariants = createMemo10(() => {
3203
3188
  return (props.variants || []).filter((variant) => {
3204
3189
  return filterWithCustomTargeting(
@@ -3218,22 +3203,22 @@ function PersonalizationContainer(props) {
3218
3203
  return getBlocksToRender({
3219
3204
  variants: props.variants,
3220
3205
  fallbackBlocks: props.builderBlock?.children,
3221
- isHydrated: isHydrated(),
3206
+ isHydrated: shouldResetVariants(),
3222
3207
  filteredVariants: filteredVariants(),
3223
3208
  previewingIndex: props.previewingIndex
3224
3209
  });
3225
3210
  });
3226
3211
  const hideVariantsStyleString = createMemo10(() => {
3227
3212
  return (props.variants || []).map(
3228
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
3213
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
3229
3214
  ).join("");
3230
3215
  });
3231
3216
  let rootRef;
3232
3217
  onMount5(() => {
3233
- setIsHydrated(true);
3218
+ setShouldResetVariants(true);
3234
3219
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
3235
- (attrs) => {
3236
- setUserAttributes(attrs);
3220
+ (attrs2) => {
3221
+ setUserAttributes(attrs2);
3237
3222
  }
3238
3223
  );
3239
3224
  if (!(isEditing() || isPreviewing())) {
@@ -3242,7 +3227,7 @@ function PersonalizationContainer(props) {
3242
3227
  rootRef.dispatchEvent(
3243
3228
  new CustomEvent("builder.variantLoaded", {
3244
3229
  detail: {
3245
- variant: variant || "default",
3230
+ variant: variant || DEFAULT_INDEX,
3246
3231
  content: props.builderContext?.content
3247
3232
  },
3248
3233
  bubbles: true
@@ -3254,7 +3239,7 @@ function PersonalizationContainer(props) {
3254
3239
  rootRef.dispatchEvent(
3255
3240
  new CustomEvent("builder.variantDisplayed", {
3256
3241
  detail: {
3257
- variant: variant || "default",
3242
+ variant: variant || DEFAULT_INDEX,
3258
3243
  content: props.builderContext?.content
3259
3244
  },
3260
3245
  bubbles: true
@@ -3268,39 +3253,72 @@ function PersonalizationContainer(props) {
3268
3253
  }
3269
3254
  unsubscribers().push(unsub);
3270
3255
  });
3271
- return <><div
3272
- class={`builder-personalization-container ${props.attributes?.className || ""}`}
3273
- ref={rootRef}
3274
- {...props.attributes}
3275
- >
3276
- <Show10 when={shouldRenderVariants()}>
3277
- <For6 each={props.variants}>{(variant, _index) => {
3278
- const index = _index();
3279
- return <template
3280
- key={index}
3281
- data-variant-id={`${props.builderBlock?.id}-${index}`}
3282
- ><Blocks_default
3283
- blocks={variant.blocks}
3284
- parent={props.builderBlock?.id}
3285
- path={`component.options.variants.${index}.blocks`}
3286
- /></template>;
3287
- }}</For6>
3288
- <Inlined_styles_default
3289
- nonce={props.builderContext?.nonce || ""}
3290
- styles={hideVariantsStyleString()}
3291
- id={`variants-styles-${props.builderBlock?.id}`}
3292
- />
3293
- <Inlined_script_default
3294
- nonce={props.builderContext?.nonce || ""}
3295
- scriptStr={scriptStr()}
3296
- id={`variants-script-${props.builderBlock?.id}`}
3297
- />
3298
- </Show10>
3299
- <Blocks_default
3256
+ return <><div ref={rootRef} {...attrs()}>
3257
+ <Show10
3258
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3259
+ ><Blocks_default
3300
3260
  blocks={blocksToRender().blocks}
3301
3261
  parent={props.builderBlock?.id}
3302
3262
  path={blocksToRender().path}
3303
- />
3263
+ context={props.builderContext}
3264
+ registeredComponents={props.builderComponents}
3265
+ BlocksWrapperProps={{
3266
+ ...props.builderContext?.BlocksWrapperProps,
3267
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3268
+ }}
3269
+ /></Show10>
3270
+ <Show10
3271
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3272
+ >
3273
+ <Show10 when={shouldRenderVariants()}>
3274
+ <Inlined_styles_default
3275
+ nonce={props.builderContext?.nonce || ""}
3276
+ styles={hideVariantsStyleString()}
3277
+ id={`variants-styles-${props.builderBlock?.id}`}
3278
+ />
3279
+ <Inlined_script_default
3280
+ nonce={props.builderContext?.nonce || ""}
3281
+ scriptStr={updateVisibilityStylesScript()}
3282
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
3283
+ />
3284
+ <For6 each={props.variants}>{(variant, _index) => {
3285
+ const index = _index();
3286
+ return <Blocks_default
3287
+ key={`${props.builderBlock?.id}-${index}`}
3288
+ BlocksWrapperProps={{
3289
+ ...props.builderContext?.BlocksWrapperProps,
3290
+ "aria-hidden": true,
3291
+ hidden: true,
3292
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
3293
+ }}
3294
+ blocks={variant.blocks}
3295
+ parent={props.builderBlock?.id}
3296
+ path={`component.options.variants.${index}.blocks`}
3297
+ context={props.builderContext}
3298
+ registeredComponents={props.builderComponents}
3299
+ ><Inlined_script_default
3300
+ nonce={props.builderContext?.nonce || ""}
3301
+ scriptStr={scriptStr()}
3302
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
3303
+ /></Blocks_default>;
3304
+ }}</For6>
3305
+ </Show10>
3306
+ <Blocks_default
3307
+ blocks={blocksToRender().blocks}
3308
+ parent={props.builderBlock?.id}
3309
+ path={blocksToRender().path}
3310
+ context={props.builderContext}
3311
+ registeredComponents={props.builderComponents}
3312
+ BlocksWrapperProps={{
3313
+ ...props.builderContext?.BlocksWrapperProps,
3314
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3315
+ }}
3316
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
3317
+ nonce={props.builderContext?.nonce || ""}
3318
+ scriptStr={scriptStr()}
3319
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
3320
+ /></Show10></Blocks_default>
3321
+ </Show10>
3304
3322
  </div></>;
3305
3323
  }
3306
3324
  var personalization_container_default = PersonalizationContainer;
@@ -4823,7 +4841,7 @@ var getDefaultRegisteredComponents = () => [{
4823
4841
  }, {
4824
4842
  component: text_default,
4825
4843
  ...componentInfo11
4826
- }, ...TARGET === "react" ? [{
4844
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
4827
4845
  component: personalization_container_default,
4828
4846
  ...componentInfo6
4829
4847
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -4860,7 +4878,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
4860
4878
 
4861
4879
  // src/components/content-variants/helpers.ts
4862
4880
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
4863
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
4881
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
4864
4882
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
4865
4883
  ...variant,
4866
4884
  testVariationId: variant.id,
@@ -4885,20 +4903,20 @@ var checkShouldRenderVariants2 = ({
4885
4903
  };
4886
4904
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
4887
4905
  var isAngularSDK = TARGET === "angular";
4888
- var isHydrationTarget = getIsHydrationTarget(TARGET);
4906
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
4889
4907
  var getInitVariantsFnsScriptString = () => `
4890
4908
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
4891
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
4909
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
4892
4910
  `;
4893
4911
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
4894
4912
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
4895
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
4913
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
4896
4914
  )`;
4897
4915
  var getUpdateVariantVisibilityScript = ({
4898
4916
  contentId,
4899
4917
  variationId
4900
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
4901
- "${variationId}", "${contentId}", ${isHydrationTarget}
4918
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
4919
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
4902
4920
  )`;
4903
4921
 
4904
4922
  // src/components/content/components/enable-editor.tsx
@@ -4918,7 +4936,7 @@ function getPreviewContent(_searchParams) {
4918
4936
  }
4919
4937
 
4920
4938
  // src/constants/sdk-version.ts
4921
- var SDK_VERSION = "4.0.8";
4939
+ var SDK_VERSION = "4.0.9";
4922
4940
 
4923
4941
  // src/helpers/sdk-headers.ts
4924
4942
  var getSdkHeaders = () => ({
@@ -6284,11 +6302,18 @@ function ContentVariants(props) {
6284
6302
  setShouldRenderVariants(false);
6285
6303
  });
6286
6304
  return <><>
6287
- <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}><Inlined_script_default
6288
- id="builderio-init-variants-fns"
6289
- scriptStr={getInitVariantsFnsScriptString()}
6290
- nonce={props.nonce || ""}
6291
- /></Show16>
6305
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
6306
+ <Inlined_script_default
6307
+ id="builderio-init-variants-fns"
6308
+ scriptStr={getInitVariantsFnsScriptString()}
6309
+ nonce={props.nonce || ""}
6310
+ />
6311
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
6312
+ id="builderio-init-personalization-variants-fns"
6313
+ nonce={props.nonce || ""}
6314
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
6315
+ /></Show16>
6316
+ </Show16>
6292
6317
  <Show16 when={shouldRenderVariants()}>
6293
6318
  <Inlined_styles_default
6294
6319
  id="builderio-variants"