@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.
@@ -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", "qwik"];
2080
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte", "qwik"];
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") {
@@ -2172,6 +2335,11 @@ var handleABTesting = async ({
2172
2335
  };
2173
2336
  };
2174
2337
 
2338
+ // src/helpers/no-serialize-wrapper.ts
2339
+ function noSerializeWrapper(fn) {
2340
+ return fn;
2341
+ }
2342
+
2175
2343
  // src/helpers/user-attributes.ts
2176
2344
  var USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
2177
2345
  function createUserAttributesService() {
@@ -2202,18 +2370,32 @@ function createUserAttributesService() {
2202
2370
  canTrack
2203
2371
  }) || "{}");
2204
2372
  },
2205
- subscribeOnUserAttributesChange(callback) {
2373
+ subscribeOnUserAttributesChange(callback, {
2374
+ fireImmediately
2375
+ } = {}) {
2206
2376
  subscribers.add(callback);
2207
- return () => {
2377
+ if (fireImmediately) {
2378
+ callback(this.getUserAttributes());
2379
+ }
2380
+ return noSerializeWrapper(function() {
2208
2381
  subscribers.delete(callback);
2209
- };
2382
+ });
2210
2383
  },
2211
2384
  setCanTrack(value) {
2212
2385
  canTrack = value;
2213
2386
  }
2214
2387
  };
2215
2388
  }
2216
- var userAttributesService = createUserAttributesService();
2389
+ var _userAttributesService;
2390
+ if (isBrowser() && TARGET === "qwik") {
2391
+ if (!window.__BUILDER_USER_ATTRIBUTES_SERVICE__) {
2392
+ window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
2393
+ }
2394
+ _userAttributesService = window.__BUILDER_USER_ATTRIBUTES_SERVICE__;
2395
+ } else {
2396
+ _userAttributesService = createUserAttributesService();
2397
+ }
2398
+ var userAttributesService = _userAttributesService;
2217
2399
  var setClientUserAttributes = (attributes) => {
2218
2400
  userAttributesService.setUserAttributes(attributes);
2219
2401
  };
@@ -2930,7 +3112,8 @@ var componentInfo6 = {
2930
3112
  name: "PersonalizationContainer",
2931
3113
  shouldReceiveBuilderProps: {
2932
3114
  builderBlock: true,
2933
- builderContext: true
3115
+ builderContext: true,
3116
+ builderComponents: true
2934
3117
  },
2935
3118
  noWrap: true,
2936
3119
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -2986,199 +3169,6 @@ function isPreviewing(_search) {
2986
3169
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
2987
3170
  }
2988
3171
 
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
3172
  // src/blocks/personalization-container/personalization-container.tsx
3183
3173
  function PersonalizationContainer(props) {
3184
3174
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -3191,6 +3181,13 @@ function PersonalizationContainer(props) {
3191
3181
  props.builderContext?.rootState?.locale
3192
3182
  )
3193
3183
  );
3184
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
3185
+ getUpdateVisibilityStylesScript(
3186
+ props.variants,
3187
+ props.builderBlock?.id || "none",
3188
+ props.builderContext?.rootState?.locale
3189
+ )
3190
+ );
3194
3191
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
3195
3192
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
3196
3193
  checkShouldRenderVariants(
@@ -3198,7 +3195,14 @@ function PersonalizationContainer(props) {
3198
3195
  getDefaultCanTrack(props.builderContext?.canTrack)
3199
3196
  )
3200
3197
  );
3201
- const [isHydrated, setIsHydrated] = createSignal10(false);
3198
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
3199
+ const attrs = createMemo10(() => {
3200
+ return {
3201
+ ...props.attributes,
3202
+ ...{},
3203
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
3204
+ };
3205
+ });
3202
3206
  const filteredVariants = createMemo10(() => {
3203
3207
  return (props.variants || []).filter((variant) => {
3204
3208
  return filterWithCustomTargeting(
@@ -3218,22 +3222,25 @@ function PersonalizationContainer(props) {
3218
3222
  return getBlocksToRender({
3219
3223
  variants: props.variants,
3220
3224
  fallbackBlocks: props.builderBlock?.children,
3221
- isHydrated: isHydrated(),
3225
+ isHydrated: shouldResetVariants(),
3222
3226
  filteredVariants: filteredVariants(),
3223
3227
  previewingIndex: props.previewingIndex
3224
3228
  });
3225
3229
  });
3226
3230
  const hideVariantsStyleString = createMemo10(() => {
3227
3231
  return (props.variants || []).map(
3228
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
3232
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
3229
3233
  ).join("");
3230
3234
  });
3231
3235
  let rootRef;
3232
3236
  onMount5(() => {
3233
- setIsHydrated(true);
3237
+ setShouldResetVariants(true);
3234
3238
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
3235
- (attrs) => {
3236
- setUserAttributes(attrs);
3239
+ (attrs2) => {
3240
+ setUserAttributes(attrs2);
3241
+ },
3242
+ {
3243
+ fireImmediately: TARGET === "qwik"
3237
3244
  }
3238
3245
  );
3239
3246
  if (!(isEditing() || isPreviewing())) {
@@ -3242,7 +3249,7 @@ function PersonalizationContainer(props) {
3242
3249
  rootRef.dispatchEvent(
3243
3250
  new CustomEvent("builder.variantLoaded", {
3244
3251
  detail: {
3245
- variant: variant || "default",
3252
+ variant: variant || DEFAULT_INDEX,
3246
3253
  content: props.builderContext?.content
3247
3254
  },
3248
3255
  bubbles: true
@@ -3254,7 +3261,7 @@ function PersonalizationContainer(props) {
3254
3261
  rootRef.dispatchEvent(
3255
3262
  new CustomEvent("builder.variantDisplayed", {
3256
3263
  detail: {
3257
- variant: variant || "default",
3264
+ variant: variant || DEFAULT_INDEX,
3258
3265
  content: props.builderContext?.content
3259
3266
  },
3260
3267
  bubbles: true
@@ -3268,39 +3275,72 @@ function PersonalizationContainer(props) {
3268
3275
  }
3269
3276
  unsubscribers().push(unsub);
3270
3277
  });
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
3278
+ return <><div ref={rootRef} {...attrs()}>
3279
+ <Show10
3280
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3281
+ ><Blocks_default
3300
3282
  blocks={blocksToRender().blocks}
3301
3283
  parent={props.builderBlock?.id}
3302
3284
  path={blocksToRender().path}
3303
- />
3285
+ context={props.builderContext}
3286
+ registeredComponents={props.builderComponents}
3287
+ BlocksWrapperProps={{
3288
+ ...props.builderContext?.BlocksWrapperProps,
3289
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3290
+ }}
3291
+ /></Show10>
3292
+ <Show10
3293
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3294
+ >
3295
+ <Show10 when={shouldRenderVariants()}>
3296
+ <Inlined_styles_default
3297
+ nonce={props.builderContext?.nonce || ""}
3298
+ styles={hideVariantsStyleString()}
3299
+ id={`variants-styles-${props.builderBlock?.id}`}
3300
+ />
3301
+ <Inlined_script_default
3302
+ nonce={props.builderContext?.nonce || ""}
3303
+ scriptStr={updateVisibilityStylesScript()}
3304
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
3305
+ />
3306
+ <For6 each={props.variants}>{(variant, _index) => {
3307
+ const index = _index();
3308
+ return <Blocks_default
3309
+ key={`${props.builderBlock?.id}-${index}`}
3310
+ BlocksWrapperProps={{
3311
+ ...props.builderContext?.BlocksWrapperProps,
3312
+ "aria-hidden": true,
3313
+ hidden: true,
3314
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
3315
+ }}
3316
+ blocks={variant.blocks}
3317
+ parent={props.builderBlock?.id}
3318
+ path={`component.options.variants.${index}.blocks`}
3319
+ context={props.builderContext}
3320
+ registeredComponents={props.builderComponents}
3321
+ ><Inlined_script_default
3322
+ nonce={props.builderContext?.nonce || ""}
3323
+ scriptStr={scriptStr()}
3324
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
3325
+ /></Blocks_default>;
3326
+ }}</For6>
3327
+ </Show10>
3328
+ <Blocks_default
3329
+ blocks={blocksToRender().blocks}
3330
+ parent={props.builderBlock?.id}
3331
+ path={blocksToRender().path}
3332
+ context={props.builderContext}
3333
+ registeredComponents={props.builderComponents}
3334
+ BlocksWrapperProps={{
3335
+ ...props.builderContext?.BlocksWrapperProps,
3336
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3337
+ }}
3338
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
3339
+ nonce={props.builderContext?.nonce || ""}
3340
+ scriptStr={scriptStr()}
3341
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
3342
+ /></Show10></Blocks_default>
3343
+ </Show10>
3304
3344
  </div></>;
3305
3345
  }
3306
3346
  var personalization_container_default = PersonalizationContainer;
@@ -4181,6 +4221,15 @@ function FormComponent(props) {
4181
4221
  }
4182
4222
  }
4183
4223
  setFormState("sending");
4224
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
4225
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
4226
+ console.error(message);
4227
+ setFormState("error");
4228
+ mergeNewRootState({
4229
+ formErrorMessage: message
4230
+ });
4231
+ return;
4232
+ }
4184
4233
  const formUrl = `${getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(
4185
4234
  props.sendSubmissionsToEmail || ""
4186
4235
  )}&name=${encodeURIComponent(props.name || "")}`;
@@ -4199,17 +4248,30 @@ function FormComponent(props) {
4199
4248
  } else {
4200
4249
  body2 = await res.text();
4201
4250
  }
4202
- if (!res.ok && props.errorMessagePath) {
4203
- let message = get(body2, props.errorMessagePath);
4204
- if (message) {
4205
- if (typeof message !== "string") {
4206
- message = JSON.stringify(message);
4251
+ if (!res.ok) {
4252
+ const submitErrorEvent = new CustomEvent("submit:error", {
4253
+ detail: {
4254
+ error: body2,
4255
+ status: res.status
4207
4256
  }
4208
- setFormErrorMessage(message);
4209
- mergeNewRootState({
4210
- formErrorMessage: message
4211
- });
4257
+ });
4258
+ if (formRef?.nativeElement) {
4259
+ formRef?.nativeElement.dispatchEvent(submitErrorEvent);
4260
+ if (submitErrorEvent.defaultPrevented) {
4261
+ return;
4262
+ }
4263
+ }
4264
+ setResponseData(body2);
4265
+ setFormState("error");
4266
+ let message = props.errorMessagePath ? get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
4267
+ if (typeof message !== "string") {
4268
+ message = JSON.stringify(message);
4212
4269
  }
4270
+ setFormErrorMessage(message);
4271
+ mergeNewRootState({
4272
+ formErrorMessage: message
4273
+ });
4274
+ return;
4213
4275
  }
4214
4276
  setResponseData(body2);
4215
4277
  setFormState(res.ok ? "success" : "error");
@@ -4288,14 +4350,14 @@ function FormComponent(props) {
4288
4350
  blocks={props.sendingMessage}
4289
4351
  context={props.builderContext}
4290
4352
  /></Show12>
4291
- <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-04a43b72">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4353
+ <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-7430044e">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4292
4354
  <Show12 when={submissionState() === "success"}><Blocks_default
4293
4355
  path="successMessage"
4294
4356
  blocks={props.successMessage}
4295
4357
  context={props.builderContext}
4296
4358
  /></Show12>
4297
4359
  </form>
4298
- <style>{`.pre-04a43b72 {
4360
+ <style>{`.pre-7430044e {
4299
4361
  padding: 10px;
4300
4362
  color: red;
4301
4363
  text-align: center;
@@ -4823,7 +4885,7 @@ var getDefaultRegisteredComponents = () => [{
4823
4885
  }, {
4824
4886
  component: text_default,
4825
4887
  ...componentInfo11
4826
- }, ...TARGET === "react" ? [{
4888
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
4827
4889
  component: personalization_container_default,
4828
4890
  ...componentInfo6
4829
4891
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -4860,7 +4922,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
4860
4922
 
4861
4923
  // src/components/content-variants/helpers.ts
4862
4924
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
4863
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
4925
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
4864
4926
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
4865
4927
  ...variant,
4866
4928
  testVariationId: variant.id,
@@ -4885,20 +4947,20 @@ var checkShouldRenderVariants2 = ({
4885
4947
  };
4886
4948
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
4887
4949
  var isAngularSDK = TARGET === "angular";
4888
- var isHydrationTarget = getIsHydrationTarget(TARGET);
4950
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
4889
4951
  var getInitVariantsFnsScriptString = () => `
4890
4952
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
4891
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
4953
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
4892
4954
  `;
4893
4955
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
4894
4956
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
4895
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
4957
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
4896
4958
  )`;
4897
4959
  var getUpdateVariantVisibilityScript = ({
4898
4960
  contentId,
4899
4961
  variationId
4900
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
4901
- "${variationId}", "${contentId}", ${isHydrationTarget}
4962
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
4963
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
4902
4964
  )`;
4903
4965
 
4904
4966
  // src/components/content/components/enable-editor.tsx
@@ -4918,7 +4980,7 @@ function getPreviewContent(_searchParams) {
4918
4980
  }
4919
4981
 
4920
4982
  // src/constants/sdk-version.ts
4921
- var SDK_VERSION = "4.0.8";
4983
+ var SDK_VERSION = "4.0.10";
4922
4984
 
4923
4985
  // src/helpers/sdk-headers.ts
4924
4986
  var getSdkHeaders = () => ({
@@ -6284,11 +6346,18 @@ function ContentVariants(props) {
6284
6346
  setShouldRenderVariants(false);
6285
6347
  });
6286
6348
  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>
6349
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
6350
+ <Inlined_script_default
6351
+ id="builderio-init-variants-fns"
6352
+ scriptStr={getInitVariantsFnsScriptString()}
6353
+ nonce={props.nonce || ""}
6354
+ />
6355
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
6356
+ id="builderio-init-personalization-variants-fns"
6357
+ nonce={props.nonce || ""}
6358
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
6359
+ /></Show16>
6360
+ </Show16>
6292
6361
  <Show16 when={shouldRenderVariants()}>
6293
6362
  <Inlined_styles_default
6294
6363
  id="builderio-variants"