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