@builder.io/sdk-solid 4.0.8 → 4.0.10

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", "qwik"];
2072
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte", "qwik"];
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") {
@@ -2164,6 +2327,11 @@ var handleABTesting = async ({
2164
2327
  };
2165
2328
  };
2166
2329
 
2330
+ // src/helpers/no-serialize-wrapper.ts
2331
+ function noSerializeWrapper(fn) {
2332
+ return fn;
2333
+ }
2334
+
2167
2335
  // src/helpers/user-attributes.ts
2168
2336
  var USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
2169
2337
  function createUserAttributesService() {
@@ -2194,18 +2362,32 @@ function createUserAttributesService() {
2194
2362
  canTrack
2195
2363
  }) || "{}");
2196
2364
  },
2197
- subscribeOnUserAttributesChange(callback) {
2365
+ subscribeOnUserAttributesChange(callback, {
2366
+ fireImmediately
2367
+ } = {}) {
2198
2368
  subscribers.add(callback);
2199
- return () => {
2369
+ if (fireImmediately) {
2370
+ callback(this.getUserAttributes());
2371
+ }
2372
+ return noSerializeWrapper(function() {
2200
2373
  subscribers.delete(callback);
2201
- };
2374
+ });
2202
2375
  },
2203
2376
  setCanTrack(value) {
2204
2377
  canTrack = value;
2205
2378
  }
2206
2379
  };
2207
2380
  }
2208
- var userAttributesService = createUserAttributesService();
2381
+ var _userAttributesService;
2382
+ if (isBrowser() && TARGET === "qwik") {
2383
+ if (!window.__BUILDER_USER_ATTRIBUTES_SERVICE__) {
2384
+ window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
2385
+ }
2386
+ _userAttributesService = window.__BUILDER_USER_ATTRIBUTES_SERVICE__;
2387
+ } else {
2388
+ _userAttributesService = createUserAttributesService();
2389
+ }
2390
+ var userAttributesService = _userAttributesService;
2209
2391
  var setClientUserAttributes = (attributes) => {
2210
2392
  userAttributesService.setUserAttributes(attributes);
2211
2393
  };
@@ -2921,7 +3103,8 @@ var componentInfo6 = {
2921
3103
  name: "PersonalizationContainer",
2922
3104
  shouldReceiveBuilderProps: {
2923
3105
  builderBlock: true,
2924
- builderContext: true
3106
+ builderContext: true,
3107
+ builderComponents: true
2925
3108
  },
2926
3109
  noWrap: true,
2927
3110
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -2977,199 +3160,6 @@ function isPreviewing(_search) {
2977
3160
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
2978
3161
  }
2979
3162
 
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
3163
  // src/blocks/personalization-container/personalization-container.tsx
3174
3164
  function PersonalizationContainer(props) {
3175
3165
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -3182,6 +3172,13 @@ function PersonalizationContainer(props) {
3182
3172
  props.builderContext?.rootState?.locale
3183
3173
  )
3184
3174
  );
3175
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
3176
+ getUpdateVisibilityStylesScript(
3177
+ props.variants,
3178
+ props.builderBlock?.id || "none",
3179
+ props.builderContext?.rootState?.locale
3180
+ )
3181
+ );
3185
3182
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
3186
3183
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
3187
3184
  checkShouldRenderVariants(
@@ -3189,7 +3186,14 @@ function PersonalizationContainer(props) {
3189
3186
  getDefaultCanTrack(props.builderContext?.canTrack)
3190
3187
  )
3191
3188
  );
3192
- const [isHydrated, setIsHydrated] = createSignal10(false);
3189
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
3190
+ const attrs = createMemo10(() => {
3191
+ return {
3192
+ ...props.attributes,
3193
+ ...{},
3194
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
3195
+ };
3196
+ });
3193
3197
  const filteredVariants = createMemo10(() => {
3194
3198
  return (props.variants || []).filter((variant) => {
3195
3199
  return filterWithCustomTargeting(
@@ -3209,22 +3213,25 @@ function PersonalizationContainer(props) {
3209
3213
  return getBlocksToRender({
3210
3214
  variants: props.variants,
3211
3215
  fallbackBlocks: props.builderBlock?.children,
3212
- isHydrated: isHydrated(),
3216
+ isHydrated: shouldResetVariants(),
3213
3217
  filteredVariants: filteredVariants(),
3214
3218
  previewingIndex: props.previewingIndex
3215
3219
  });
3216
3220
  });
3217
3221
  const hideVariantsStyleString = createMemo10(() => {
3218
3222
  return (props.variants || []).map(
3219
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
3223
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
3220
3224
  ).join("");
3221
3225
  });
3222
3226
  let rootRef;
3223
3227
  onMount5(() => {
3224
- setIsHydrated(true);
3228
+ setShouldResetVariants(true);
3225
3229
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
3226
- (attrs) => {
3227
- setUserAttributes(attrs);
3230
+ (attrs2) => {
3231
+ setUserAttributes(attrs2);
3232
+ },
3233
+ {
3234
+ fireImmediately: TARGET === "qwik"
3228
3235
  }
3229
3236
  );
3230
3237
  if (!(isEditing() || isPreviewing())) {
@@ -3233,7 +3240,7 @@ function PersonalizationContainer(props) {
3233
3240
  rootRef.dispatchEvent(
3234
3241
  new CustomEvent("builder.variantLoaded", {
3235
3242
  detail: {
3236
- variant: variant || "default",
3243
+ variant: variant || DEFAULT_INDEX,
3237
3244
  content: props.builderContext?.content
3238
3245
  },
3239
3246
  bubbles: true
@@ -3245,7 +3252,7 @@ function PersonalizationContainer(props) {
3245
3252
  rootRef.dispatchEvent(
3246
3253
  new CustomEvent("builder.variantDisplayed", {
3247
3254
  detail: {
3248
- variant: variant || "default",
3255
+ variant: variant || DEFAULT_INDEX,
3249
3256
  content: props.builderContext?.content
3250
3257
  },
3251
3258
  bubbles: true
@@ -3259,39 +3266,72 @@ function PersonalizationContainer(props) {
3259
3266
  }
3260
3267
  unsubscribers().push(unsub);
3261
3268
  });
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
3269
+ return <><div ref={rootRef} {...attrs()}>
3270
+ <Show10
3271
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3272
+ ><Blocks_default
3291
3273
  blocks={blocksToRender().blocks}
3292
3274
  parent={props.builderBlock?.id}
3293
3275
  path={blocksToRender().path}
3294
- />
3276
+ context={props.builderContext}
3277
+ registeredComponents={props.builderComponents}
3278
+ BlocksWrapperProps={{
3279
+ ...props.builderContext?.BlocksWrapperProps,
3280
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3281
+ }}
3282
+ /></Show10>
3283
+ <Show10
3284
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3285
+ >
3286
+ <Show10 when={shouldRenderVariants()}>
3287
+ <Inlined_styles_default
3288
+ nonce={props.builderContext?.nonce || ""}
3289
+ styles={hideVariantsStyleString()}
3290
+ id={`variants-styles-${props.builderBlock?.id}`}
3291
+ />
3292
+ <Inlined_script_default
3293
+ nonce={props.builderContext?.nonce || ""}
3294
+ scriptStr={updateVisibilityStylesScript()}
3295
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
3296
+ />
3297
+ <For6 each={props.variants}>{(variant, _index) => {
3298
+ const index = _index();
3299
+ return <Blocks_default
3300
+ key={`${props.builderBlock?.id}-${index}`}
3301
+ BlocksWrapperProps={{
3302
+ ...props.builderContext?.BlocksWrapperProps,
3303
+ "aria-hidden": true,
3304
+ hidden: true,
3305
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
3306
+ }}
3307
+ blocks={variant.blocks}
3308
+ parent={props.builderBlock?.id}
3309
+ path={`component.options.variants.${index}.blocks`}
3310
+ context={props.builderContext}
3311
+ registeredComponents={props.builderComponents}
3312
+ ><Inlined_script_default
3313
+ nonce={props.builderContext?.nonce || ""}
3314
+ scriptStr={scriptStr()}
3315
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
3316
+ /></Blocks_default>;
3317
+ }}</For6>
3318
+ </Show10>
3319
+ <Blocks_default
3320
+ blocks={blocksToRender().blocks}
3321
+ parent={props.builderBlock?.id}
3322
+ path={blocksToRender().path}
3323
+ context={props.builderContext}
3324
+ registeredComponents={props.builderComponents}
3325
+ BlocksWrapperProps={{
3326
+ ...props.builderContext?.BlocksWrapperProps,
3327
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3328
+ }}
3329
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
3330
+ nonce={props.builderContext?.nonce || ""}
3331
+ scriptStr={scriptStr()}
3332
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
3333
+ /></Show10></Blocks_default>
3334
+ </Show10>
3295
3335
  </div></>;
3296
3336
  }
3297
3337
  var personalization_container_default = PersonalizationContainer;
@@ -4172,6 +4212,14 @@ function FormComponent(props) {
4172
4212
  }
4173
4213
  }
4174
4214
  setFormState("sending");
4215
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
4216
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
4217
+ setFormState("error");
4218
+ mergeNewRootState({
4219
+ formErrorMessage: message
4220
+ });
4221
+ return;
4222
+ }
4175
4223
  const formUrl = `${getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(
4176
4224
  props.sendSubmissionsToEmail || ""
4177
4225
  )}&name=${encodeURIComponent(props.name || "")}`;
@@ -4190,17 +4238,30 @@ function FormComponent(props) {
4190
4238
  } else {
4191
4239
  body2 = await res.text();
4192
4240
  }
4193
- if (!res.ok && props.errorMessagePath) {
4194
- let message = get(body2, props.errorMessagePath);
4195
- if (message) {
4196
- if (typeof message !== "string") {
4197
- message = JSON.stringify(message);
4241
+ if (!res.ok) {
4242
+ const submitErrorEvent = new CustomEvent("submit:error", {
4243
+ detail: {
4244
+ error: body2,
4245
+ status: res.status
4198
4246
  }
4199
- setFormErrorMessage(message);
4200
- mergeNewRootState({
4201
- formErrorMessage: message
4202
- });
4247
+ });
4248
+ if (formRef?.nativeElement) {
4249
+ formRef?.nativeElement.dispatchEvent(submitErrorEvent);
4250
+ if (submitErrorEvent.defaultPrevented) {
4251
+ return;
4252
+ }
4253
+ }
4254
+ setResponseData(body2);
4255
+ setFormState("error");
4256
+ let message = props.errorMessagePath ? get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
4257
+ if (typeof message !== "string") {
4258
+ message = JSON.stringify(message);
4203
4259
  }
4260
+ setFormErrorMessage(message);
4261
+ mergeNewRootState({
4262
+ formErrorMessage: message
4263
+ });
4264
+ return;
4204
4265
  }
4205
4266
  setResponseData(body2);
4206
4267
  setFormState(res.ok ? "success" : "error");
@@ -4279,14 +4340,14 @@ function FormComponent(props) {
4279
4340
  blocks={props.sendingMessage}
4280
4341
  context={props.builderContext}
4281
4342
  /></Show12>
4282
- <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-04a43b72">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4343
+ <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-7430044e">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4283
4344
  <Show12 when={submissionState() === "success"}><Blocks_default
4284
4345
  path="successMessage"
4285
4346
  blocks={props.successMessage}
4286
4347
  context={props.builderContext}
4287
4348
  /></Show12>
4288
4349
  </form>
4289
- <style>{`.pre-04a43b72 {
4350
+ <style>{`.pre-7430044e {
4290
4351
  padding: 10px;
4291
4352
  color: red;
4292
4353
  text-align: center;
@@ -4813,7 +4874,7 @@ var getDefaultRegisteredComponents = () => [{
4813
4874
  }, {
4814
4875
  component: text_default,
4815
4876
  ...componentInfo11
4816
- }, ...TARGET === "react" ? [{
4877
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
4817
4878
  component: personalization_container_default,
4818
4879
  ...componentInfo6
4819
4880
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -4850,7 +4911,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
4850
4911
 
4851
4912
  // src/components/content-variants/helpers.ts
4852
4913
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
4853
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
4914
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
4854
4915
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
4855
4916
  ...variant,
4856
4917
  testVariationId: variant.id,
@@ -4875,20 +4936,20 @@ var checkShouldRenderVariants2 = ({
4875
4936
  };
4876
4937
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
4877
4938
  var isAngularSDK = TARGET === "angular";
4878
- var isHydrationTarget = getIsHydrationTarget(TARGET);
4939
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
4879
4940
  var getInitVariantsFnsScriptString = () => `
4880
4941
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
4881
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
4942
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
4882
4943
  `;
4883
4944
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
4884
4945
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
4885
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
4946
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
4886
4947
  )`;
4887
4948
  var getUpdateVariantVisibilityScript = ({
4888
4949
  contentId,
4889
4950
  variationId
4890
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
4891
- "${variationId}", "${contentId}", ${isHydrationTarget}
4951
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
4952
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
4892
4953
  )`;
4893
4954
 
4894
4955
  // src/components/content/components/enable-editor.tsx
@@ -4908,7 +4969,7 @@ function getPreviewContent(_searchParams) {
4908
4969
  }
4909
4970
 
4910
4971
  // src/constants/sdk-version.ts
4911
- var SDK_VERSION = "4.0.8";
4972
+ var SDK_VERSION = "4.0.10";
4912
4973
 
4913
4974
  // src/helpers/sdk-headers.ts
4914
4975
  var getSdkHeaders = () => ({
@@ -6267,11 +6328,18 @@ function ContentVariants(props) {
6267
6328
  setShouldRenderVariants(false);
6268
6329
  });
6269
6330
  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>
6331
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
6332
+ <Inlined_script_default
6333
+ id="builderio-init-variants-fns"
6334
+ scriptStr={getInitVariantsFnsScriptString()}
6335
+ nonce={props.nonce || ""}
6336
+ />
6337
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
6338
+ id="builderio-init-personalization-variants-fns"
6339
+ nonce={props.nonce || ""}
6340
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
6341
+ /></Show16>
6342
+ </Show16>
6275
6343
  <Show16 when={shouldRenderVariants()}>
6276
6344
  <Inlined_styles_default
6277
6345
  id="builderio-variants"