@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.
@@ -1754,7 +1754,7 @@ function BlocksWrapper(props) {
1754
1754
  createEffect5(on5(() => [onUpdateFn_0_props_blocks()], onUpdateFn_0));
1755
1755
  return <>
1756
1756
  <Dynamic4
1757
- class={className() + " dynamic-023c60f2"}
1757
+ class={className() + " dynamic-450facf4"}
1758
1758
  ref={blocksWrapperRef}
1759
1759
  builder-path={dataPath()}
1760
1760
  builder-parent-id={props.parent}
@@ -1766,7 +1766,7 @@ function BlocksWrapper(props) {
1766
1766
  {...props.BlocksWrapperProps}
1767
1767
  component={props.BlocksWrapper}
1768
1768
  >{props.children}</Dynamic4>
1769
- <style>{`.dynamic-023c60f2 {
1769
+ <style>{`.dynamic-450facf4 {
1770
1770
  display: flex;
1771
1771
  flex-direction: column;
1772
1772
  align-items: stretch;
@@ -1784,19 +1784,22 @@ function Blocks(props) {
1784
1784
  parent={props.parent}
1785
1785
  path={props.path}
1786
1786
  styleProp={props.styleProp}
1787
+ BlocksWrapperProps={props.BlocksWrapperProps || props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
1787
1788
  classNameProp={props.className}
1788
1789
  BlocksWrapper={props.context?.BlocksWrapper || builderContext?.BlocksWrapper}
1789
- BlocksWrapperProps={props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
1790
- ><Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
1791
- const index = _index();
1792
- return <Block_default
1793
- key={block.id}
1794
- block={block}
1795
- linkComponent={props.linkComponent}
1796
- context={props.context || builderContext}
1797
- registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
1798
- />;
1799
- }}</For3></Show6></Blocks_wrapper_default></>;
1790
+ >
1791
+ {props.children}
1792
+ <Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
1793
+ const index = _index();
1794
+ return <Block_default
1795
+ key={block.id}
1796
+ block={block}
1797
+ linkComponent={props.linkComponent}
1798
+ context={props.context || builderContext}
1799
+ registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
1800
+ />;
1801
+ }}</For3></Show6>
1802
+ </Blocks_wrapper_default></>;
1800
1803
  }
1801
1804
  var Blocks_default = Blocks;
1802
1805
 
@@ -2147,6 +2150,166 @@ import { onMount as onMount10, on as on9, createEffect as createEffect9, createM
2147
2150
  // src/components/content-variants/content-variants.tsx
2148
2151
  import { Show as Show16, For as For9, onMount as onMount9, createSignal as createSignal19, createMemo as createMemo19 } from "solid-js";
2149
2152
 
2153
+ // src/blocks/personalization-container/helpers/inlined-fns.ts
2154
+ function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
2155
+ function isString(val) {
2156
+ return typeof val === "string";
2157
+ }
2158
+ function isNumber(val) {
2159
+ return typeof val === "number";
2160
+ }
2161
+ function objectMatchesQuery(userattr, query2) {
2162
+ const result = (() => {
2163
+ const property = query2.property;
2164
+ const operator = query2.operator;
2165
+ let testValue = query2.value;
2166
+ if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
2167
+ testValue = query2.value.slice(0, -1);
2168
+ }
2169
+ if (!(property && operator)) {
2170
+ return true;
2171
+ }
2172
+ if (Array.isArray(testValue)) {
2173
+ if (operator === "isNot") {
2174
+ return testValue.every((val) => objectMatchesQuery(userattr, {
2175
+ property,
2176
+ operator,
2177
+ value: val
2178
+ }));
2179
+ }
2180
+ return !!testValue.find((val) => objectMatchesQuery(userattr, {
2181
+ property,
2182
+ operator,
2183
+ value: val
2184
+ }));
2185
+ }
2186
+ const value = userattr[property];
2187
+ if (Array.isArray(value)) {
2188
+ return value.includes(testValue);
2189
+ }
2190
+ switch (operator) {
2191
+ case "is":
2192
+ return value === testValue;
2193
+ case "isNot":
2194
+ return value !== testValue;
2195
+ case "contains":
2196
+ return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
2197
+ case "startsWith":
2198
+ return isString(value) && value.startsWith(String(testValue));
2199
+ case "endsWith":
2200
+ return isString(value) && value.endsWith(String(testValue));
2201
+ case "greaterThan":
2202
+ return isNumber(value) && isNumber(testValue) && value > testValue;
2203
+ case "lessThan":
2204
+ return isNumber(value) && isNumber(testValue) && value < testValue;
2205
+ case "greaterThanOrEqualTo":
2206
+ return isNumber(value) && isNumber(testValue) && value >= testValue;
2207
+ case "lessThanOrEqualTo":
2208
+ return isNumber(value) && isNumber(testValue) && value <= testValue;
2209
+ default:
2210
+ return false;
2211
+ }
2212
+ })();
2213
+ return result;
2214
+ }
2215
+ const item = {
2216
+ query,
2217
+ startDate,
2218
+ endDate
2219
+ };
2220
+ const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
2221
+ if (item.startDate && new Date(item.startDate) > now) {
2222
+ return false;
2223
+ } else if (item.endDate && new Date(item.endDate) < now) {
2224
+ return false;
2225
+ }
2226
+ if (!item.query || !item.query.length) {
2227
+ return true;
2228
+ }
2229
+ return item.query.every((filter) => {
2230
+ return objectMatchesQuery(userAttributes, filter);
2231
+ });
2232
+ }
2233
+ var PERSONALIZATION_SCRIPT = "function getPersonalizedVariant(variants, blockId, isHydrationTarget, locale) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) == ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');\n if (locale) {\n attributes.locale = locale;\n }\n const winningVariantIndex = variants?.findIndex(function (variant) {\n return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);\n });\n const parentDiv = document.currentScript?.parentElement;\n const variantId = parentDiv?.getAttribute('data-variant-id');\n const isDefaultVariant = variantId === `${blockId}-default`;\n const isWinningVariant = winningVariantIndex !== -1 && variantId === `${blockId}-${winningVariantIndex}` || winningVariantIndex === -1 && isDefaultVariant;\n if (isWinningVariant && !isDefaultVariant) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultVariant) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n const itsStyleEl = parentDiv?.previousElementSibling;\n if (itsStyleEl) {\n itsStyleEl.remove();\n }\n parentDiv?.remove();\n }\n const thisScript = document.currentScript;\n if (thisScript) {\n thisScript.remove();\n }\n }\n}";
2234
+ var FILTER_WITH_CUSTOM_TARGETING_SCRIPT = "function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {\n function isString(val) {\n return typeof val === 'string';\n }\n function isNumber(val) {\n return typeof val === 'number';\n }\n function objectMatchesQuery(userattr, query) {\n const result = (() => {\n const property = query.property;\n const operator = query.operator;\n let testValue = query.value;\n if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {\n testValue = query.value.slice(0, -1);\n }\n if (!(property && operator)) {\n return true;\n }\n if (Array.isArray(testValue)) {\n if (operator === 'isNot') {\n return testValue.every(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n return !!testValue.find(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n const value = userattr[property];\n if (Array.isArray(value)) {\n return value.includes(testValue);\n }\n switch (operator) {\n case 'is':\n return value === testValue;\n case 'isNot':\n return value !== testValue;\n case 'contains':\n return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));\n case 'startsWith':\n return isString(value) && value.startsWith(String(testValue));\n case 'endsWith':\n return isString(value) && value.endsWith(String(testValue));\n case 'greaterThan':\n return isNumber(value) && isNumber(testValue) && value > testValue;\n case 'lessThan':\n return isNumber(value) && isNumber(testValue) && value < testValue;\n case 'greaterThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value >= testValue;\n case 'lessThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value <= testValue;\n default:\n return false;\n }\n })();\n return result;\n }\n const item = {\n query,\n startDate,\n endDate\n };\n const now = userAttributes.date && new Date(userAttributes.date) || new Date();\n if (item.startDate && new Date(item.startDate) > now) {\n return false;\n } else if (item.endDate && new Date(item.endDate) < now) {\n return false;\n }\n if (!item.query || !item.query.length) {\n return true;\n }\n return item.query.every(filter => {\n return objectMatchesQuery(userAttributes, filter);\n });\n}";
2235
+ var UPDATE_VISIBILITY_STYLES_SCRIPT = "function updateVisibilityStylesScript(variants, blockId, isHydrationTarget, locale) {\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) == ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const visibilityStylesEl = document.currentScript?.previousElementSibling;\n if (!visibilityStylesEl) {\n return;\n }\n if (isHydrationTarget) {\n visibilityStylesEl.remove();\n const currentScript = document.currentScript;\n if (currentScript) {\n currentScript.remove();\n }\n } else {\n const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');\n if (locale) {\n attributes.locale = locale;\n }\n const winningVariantIndex = variants?.findIndex(function (variant) {\n return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);\n });\n if (winningVariantIndex !== -1) {\n let newStyleStr = variants?.map((_, index) => {\n if (index === winningVariantIndex) return '';\n return `div[data-variant-id=\"${blockId}-${index}\"] { display: none !important; } `;\n }).join('') || '';\n newStyleStr += `div[data-variant-id=\"${blockId}-default\"] { display: none !important; } `;\n visibilityStylesEl.innerHTML = newStyleStr;\n }\n }\n}";
2236
+
2237
+ // src/blocks/personalization-container/helpers.ts
2238
+ var DEFAULT_INDEX = "default";
2239
+ var FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME = "filterWithCustomTargeting";
2240
+ var BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME = "builderIoPersonalization";
2241
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
2242
+ var SDKS_SUPPORTING_PERSONALIZATION = ["react", "vue", "svelte", "qwik"];
2243
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte", "qwik"];
2244
+ function checkShouldRenderVariants(variants, canTrack) {
2245
+ const hasVariants = variants && variants.length > 0;
2246
+ if (TARGET === "reactNative")
2247
+ return false;
2248
+ if (!hasVariants)
2249
+ return false;
2250
+ if (!canTrack)
2251
+ return false;
2252
+ if (SDKS_REQUIRING_RESET_APPROACH.includes(TARGET))
2253
+ return true;
2254
+ if (isBrowser())
2255
+ return false;
2256
+ return true;
2257
+ }
2258
+ function getBlocksToRender({
2259
+ variants,
2260
+ previewingIndex,
2261
+ isHydrated,
2262
+ filteredVariants,
2263
+ fallbackBlocks
2264
+ }) {
2265
+ const fallback = {
2266
+ blocks: fallbackBlocks ?? [],
2267
+ path: "this.children",
2268
+ index: DEFAULT_INDEX
2269
+ };
2270
+ if (isHydrated && isEditing()) {
2271
+ if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
2272
+ const variant = variants?.[previewingIndex];
2273
+ if (variant) {
2274
+ return {
2275
+ blocks: variant.blocks,
2276
+ path: `variants.${previewingIndex}.blocks`,
2277
+ index: previewingIndex
2278
+ };
2279
+ }
2280
+ }
2281
+ return fallback;
2282
+ }
2283
+ if (isBrowser()) {
2284
+ const winningVariant = filteredVariants?.[0];
2285
+ if (winningVariant && variants) {
2286
+ const variantIndex = variants.indexOf(winningVariant);
2287
+ if (variantIndex !== -1) {
2288
+ return {
2289
+ blocks: winningVariant.blocks,
2290
+ path: `variants.${variantIndex}.blocks`,
2291
+ index: variantIndex
2292
+ };
2293
+ }
2294
+ }
2295
+ }
2296
+ return fallback;
2297
+ }
2298
+ var getInitPersonalizationVariantsFnsScriptString = () => {
2299
+ return `
2300
+ window.${FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME} = ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
2301
+ window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME} = ${PERSONALIZATION_SCRIPT}
2302
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VISIBILITY_STYLES_SCRIPT}
2303
+ `;
2304
+ };
2305
+ var isHydrationTarget = TARGET === "react";
2306
+ var getPersonalizationScript = (variants, blockId, locale) => {
2307
+ return `window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2308
+ };
2309
+ var getUpdateVisibilityStylesScript = (variants, blockId, locale) => {
2310
+ return `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2311
+ };
2312
+
2150
2313
  // src/helpers/url.ts
2151
2314
  var getTopLevelDomain = (host) => {
2152
2315
  if (host === "localhost" || host === "127.0.0.1") {
@@ -2335,6 +2498,11 @@ var handleABTesting = async ({
2335
2498
  };
2336
2499
  };
2337
2500
 
2501
+ // src/helpers/no-serialize-wrapper.ts
2502
+ function noSerializeWrapper(fn) {
2503
+ return fn;
2504
+ }
2505
+
2338
2506
  // src/helpers/user-attributes.ts
2339
2507
  var USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
2340
2508
  function createUserAttributesService() {
@@ -2365,18 +2533,32 @@ function createUserAttributesService() {
2365
2533
  canTrack
2366
2534
  }) || "{}");
2367
2535
  },
2368
- subscribeOnUserAttributesChange(callback) {
2536
+ subscribeOnUserAttributesChange(callback, {
2537
+ fireImmediately
2538
+ } = {}) {
2369
2539
  subscribers.add(callback);
2370
- return () => {
2540
+ if (fireImmediately) {
2541
+ callback(this.getUserAttributes());
2542
+ }
2543
+ return noSerializeWrapper(function() {
2371
2544
  subscribers.delete(callback);
2372
- };
2545
+ });
2373
2546
  },
2374
2547
  setCanTrack(value) {
2375
2548
  canTrack = value;
2376
2549
  }
2377
2550
  };
2378
2551
  }
2379
- var userAttributesService = createUserAttributesService();
2552
+ var _userAttributesService;
2553
+ if (isBrowser() && TARGET === "qwik") {
2554
+ if (!window.__BUILDER_USER_ATTRIBUTES_SERVICE__) {
2555
+ window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
2556
+ }
2557
+ _userAttributesService = window.__BUILDER_USER_ATTRIBUTES_SERVICE__;
2558
+ } else {
2559
+ _userAttributesService = createUserAttributesService();
2560
+ }
2561
+ var userAttributesService = _userAttributesService;
2380
2562
  var setClientUserAttributes = (attributes) => {
2381
2563
  userAttributesService.setUserAttributes(attributes);
2382
2564
  };
@@ -3092,7 +3274,8 @@ var componentInfo6 = {
3092
3274
  name: "PersonalizationContainer",
3093
3275
  shouldReceiveBuilderProps: {
3094
3276
  builderBlock: true,
3095
- builderContext: true
3277
+ builderContext: true,
3278
+ builderComponents: true
3096
3279
  },
3097
3280
  noWrap: true,
3098
3281
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -3148,199 +3331,6 @@ function isPreviewing(_search) {
3148
3331
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
3149
3332
  }
3150
3333
 
3151
- // src/blocks/personalization-container/helpers/inlined-fns.ts
3152
- function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
3153
- function isString(val) {
3154
- return typeof val === "string";
3155
- }
3156
- function isNumber(val) {
3157
- return typeof val === "number";
3158
- }
3159
- function objectMatchesQuery(userattr, query2) {
3160
- const result = (() => {
3161
- const property = query2.property;
3162
- const operator = query2.operator;
3163
- let testValue = query2.value;
3164
- if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
3165
- testValue = query2.value.slice(0, -1);
3166
- }
3167
- if (!(property && operator)) {
3168
- return true;
3169
- }
3170
- if (Array.isArray(testValue)) {
3171
- if (operator === "isNot") {
3172
- return testValue.every((val) => objectMatchesQuery(userattr, {
3173
- property,
3174
- operator,
3175
- value: val
3176
- }));
3177
- }
3178
- return !!testValue.find((val) => objectMatchesQuery(userattr, {
3179
- property,
3180
- operator,
3181
- value: val
3182
- }));
3183
- }
3184
- const value = userattr[property];
3185
- if (Array.isArray(value)) {
3186
- return value.includes(testValue);
3187
- }
3188
- switch (operator) {
3189
- case "is":
3190
- return value === testValue;
3191
- case "isNot":
3192
- return value !== testValue;
3193
- case "contains":
3194
- return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
3195
- case "startsWith":
3196
- return isString(value) && value.startsWith(String(testValue));
3197
- case "endsWith":
3198
- return isString(value) && value.endsWith(String(testValue));
3199
- case "greaterThan":
3200
- return isNumber(value) && isNumber(testValue) && value > testValue;
3201
- case "lessThan":
3202
- return isNumber(value) && isNumber(testValue) && value < testValue;
3203
- case "greaterThanOrEqualTo":
3204
- return isNumber(value) && isNumber(testValue) && value >= testValue;
3205
- case "lessThanOrEqualTo":
3206
- return isNumber(value) && isNumber(testValue) && value <= testValue;
3207
- default:
3208
- return false;
3209
- }
3210
- })();
3211
- return result;
3212
- }
3213
- const item = {
3214
- query,
3215
- startDate,
3216
- endDate
3217
- };
3218
- const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
3219
- if (item.startDate && new Date(item.startDate) > now) {
3220
- return false;
3221
- } else if (item.endDate && new Date(item.endDate) < now) {
3222
- return false;
3223
- }
3224
- if (!item.query || !item.query.length) {
3225
- return true;
3226
- }
3227
- return item.query.every((filter) => {
3228
- return objectMatchesQuery(userAttributes, filter);
3229
- });
3230
- }
3231
- var PERSONALIZATION_SCRIPT = `function getPersonalizedVariant(variants, blockId, locale) {
3232
- if (!navigator.cookieEnabled) {
3233
- return;
3234
- }
3235
- function getCookie(name) {
3236
- const nameEQ = name + '=';
3237
- const ca = document.cookie.split(';');
3238
- for (let i = 0; i < ca.length; i++) {
3239
- let c = ca[i];
3240
- while (c.charAt(0) == ' ') c = c.substring(1, c.length);
3241
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
3242
- }
3243
- return null;
3244
- }
3245
- function removeVariants() {
3246
- variants?.forEach(function (_, index) {
3247
- document.querySelector('template[data-variant-id="' + blockId + '-' + index + '"]')?.remove();
3248
- });
3249
- document.querySelector('script[data-id="variants-script-' + blockId + '"]')?.remove();
3250
- document.querySelector('style[data-id="variants-styles-' + blockId + '"]')?.remove();
3251
- }
3252
- const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
3253
- if (locale) {
3254
- attributes.locale = locale;
3255
- }
3256
- const winningVariantIndex = variants?.findIndex(function (variant) {
3257
- return filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
3258
- });
3259
- const isDebug = location.href.includes('builder.debug=true');
3260
- if (isDebug) {
3261
- console.debug('PersonalizationContainer', {
3262
- attributes,
3263
- variants,
3264
- winningVariantIndex
3265
- });
3266
- }
3267
- if (winningVariantIndex !== -1) {
3268
- const winningVariant = document.querySelector('template[data-variant-id="' + blockId + '-' + winningVariantIndex + '"]');
3269
- if (winningVariant) {
3270
- const parentNode = winningVariant.parentNode;
3271
- if (parentNode) {
3272
- const newParent = parentNode.cloneNode(false);
3273
- newParent.appendChild(winningVariant.content.firstChild);
3274
- newParent.appendChild(winningVariant.content.lastChild);
3275
- parentNode.parentNode?.replaceChild(newParent, parentNode);
3276
- }
3277
- if (isDebug) {
3278
- console.debug('PersonalizationContainer', 'Winning variant Replaced:', winningVariant);
3279
- }
3280
- }
3281
- } else if (variants && variants.length > 0) {
3282
- removeVariants();
3283
- }
3284
- }`;
3285
- var FILTER_WITH_CUSTOM_TARGETING_SCRIPT = "function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {\n function isString(val) {\n return typeof val === 'string';\n }\n function isNumber(val) {\n return typeof val === 'number';\n }\n function objectMatchesQuery(userattr, query) {\n const result = (() => {\n const property = query.property;\n const operator = query.operator;\n let testValue = query.value;\n if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {\n testValue = query.value.slice(0, -1);\n }\n if (!(property && operator)) {\n return true;\n }\n if (Array.isArray(testValue)) {\n if (operator === 'isNot') {\n return testValue.every(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n return !!testValue.find(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n const value = userattr[property];\n if (Array.isArray(value)) {\n return value.includes(testValue);\n }\n switch (operator) {\n case 'is':\n return value === testValue;\n case 'isNot':\n return value !== testValue;\n case 'contains':\n return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));\n case 'startsWith':\n return isString(value) && value.startsWith(String(testValue));\n case 'endsWith':\n return isString(value) && value.endsWith(String(testValue));\n case 'greaterThan':\n return isNumber(value) && isNumber(testValue) && value > testValue;\n case 'lessThan':\n return isNumber(value) && isNumber(testValue) && value < testValue;\n case 'greaterThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value >= testValue;\n case 'lessThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value <= testValue;\n default:\n return false;\n }\n })();\n return result;\n }\n const item = {\n query,\n startDate,\n endDate\n };\n const now = userAttributes.date && new Date(userAttributes.date) || new Date();\n if (item.startDate && new Date(item.startDate) > now) {\n return false;\n } else if (item.endDate && new Date(item.endDate) < now) {\n return false;\n }\n if (!item.query || !item.query.length) {\n return true;\n }\n return item.query.every(filter => {\n return objectMatchesQuery(userAttributes, filter);\n });\n}";
3286
-
3287
- // src/blocks/personalization-container/helpers.ts
3288
- function checkShouldRenderVariants(variants, canTrack) {
3289
- const hasVariants = variants && variants.length > 0;
3290
- if (TARGET === "reactNative")
3291
- return false;
3292
- if (!hasVariants)
3293
- return false;
3294
- if (!canTrack)
3295
- return false;
3296
- if (TARGET === "vue" || TARGET === "svelte")
3297
- return true;
3298
- if (isBrowser())
3299
- return false;
3300
- return true;
3301
- }
3302
- function getBlocksToRender({
3303
- variants,
3304
- previewingIndex,
3305
- isHydrated,
3306
- filteredVariants,
3307
- fallbackBlocks
3308
- }) {
3309
- const fallback = {
3310
- blocks: fallbackBlocks ?? [],
3311
- path: "this.children"
3312
- };
3313
- if (isHydrated && isEditing()) {
3314
- if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
3315
- const variant = variants[previewingIndex];
3316
- return {
3317
- blocks: variant.blocks,
3318
- path: `component.options.variants.${previewingIndex}.blocks`
3319
- };
3320
- }
3321
- return fallback;
3322
- }
3323
- if (isBrowser()) {
3324
- const winningVariant = filteredVariants?.[0];
3325
- if (winningVariant) {
3326
- return {
3327
- blocks: winningVariant.blocks,
3328
- path: `component.options.variants.${variants?.indexOf(winningVariant)}.blocks`
3329
- };
3330
- }
3331
- }
3332
- return fallback;
3333
- }
3334
- var getPersonalizationScript = (variants, blockId, locale) => {
3335
- return `
3336
- (function() {
3337
- ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
3338
- ${PERSONALIZATION_SCRIPT}
3339
- getPersonalizedVariant(${JSON.stringify(variants)}, "${blockId}"${locale ? `, "${locale}"` : ""})
3340
- })();
3341
- `;
3342
- };
3343
-
3344
3334
  // src/blocks/personalization-container/personalization-container.tsx
3345
3335
  function PersonalizationContainer(props) {
3346
3336
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -3353,6 +3343,13 @@ function PersonalizationContainer(props) {
3353
3343
  props.builderContext?.rootState?.locale
3354
3344
  )
3355
3345
  );
3346
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
3347
+ getUpdateVisibilityStylesScript(
3348
+ props.variants,
3349
+ props.builderBlock?.id || "none",
3350
+ props.builderContext?.rootState?.locale
3351
+ )
3352
+ );
3356
3353
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
3357
3354
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
3358
3355
  checkShouldRenderVariants(
@@ -3360,7 +3357,14 @@ function PersonalizationContainer(props) {
3360
3357
  getDefaultCanTrack(props.builderContext?.canTrack)
3361
3358
  )
3362
3359
  );
3363
- const [isHydrated, setIsHydrated] = createSignal10(false);
3360
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
3361
+ const attrs = createMemo10(() => {
3362
+ return {
3363
+ ...props.attributes,
3364
+ ...{},
3365
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
3366
+ };
3367
+ });
3364
3368
  const filteredVariants = createMemo10(() => {
3365
3369
  return (props.variants || []).filter((variant) => {
3366
3370
  return filterWithCustomTargeting(
@@ -3380,22 +3384,25 @@ function PersonalizationContainer(props) {
3380
3384
  return getBlocksToRender({
3381
3385
  variants: props.variants,
3382
3386
  fallbackBlocks: props.builderBlock?.children,
3383
- isHydrated: isHydrated(),
3387
+ isHydrated: shouldResetVariants(),
3384
3388
  filteredVariants: filteredVariants(),
3385
3389
  previewingIndex: props.previewingIndex
3386
3390
  });
3387
3391
  });
3388
3392
  const hideVariantsStyleString = createMemo10(() => {
3389
3393
  return (props.variants || []).map(
3390
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
3394
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
3391
3395
  ).join("");
3392
3396
  });
3393
3397
  let rootRef;
3394
3398
  onMount5(() => {
3395
- setIsHydrated(true);
3399
+ setShouldResetVariants(true);
3396
3400
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
3397
- (attrs) => {
3398
- setUserAttributes(attrs);
3401
+ (attrs2) => {
3402
+ setUserAttributes(attrs2);
3403
+ },
3404
+ {
3405
+ fireImmediately: TARGET === "qwik"
3399
3406
  }
3400
3407
  );
3401
3408
  if (!(isEditing() || isPreviewing())) {
@@ -3404,7 +3411,7 @@ function PersonalizationContainer(props) {
3404
3411
  rootRef.dispatchEvent(
3405
3412
  new CustomEvent("builder.variantLoaded", {
3406
3413
  detail: {
3407
- variant: variant || "default",
3414
+ variant: variant || DEFAULT_INDEX,
3408
3415
  content: props.builderContext?.content
3409
3416
  },
3410
3417
  bubbles: true
@@ -3416,7 +3423,7 @@ function PersonalizationContainer(props) {
3416
3423
  rootRef.dispatchEvent(
3417
3424
  new CustomEvent("builder.variantDisplayed", {
3418
3425
  detail: {
3419
- variant: variant || "default",
3426
+ variant: variant || DEFAULT_INDEX,
3420
3427
  content: props.builderContext?.content
3421
3428
  },
3422
3429
  bubbles: true
@@ -3430,39 +3437,72 @@ function PersonalizationContainer(props) {
3430
3437
  }
3431
3438
  unsubscribers().push(unsub);
3432
3439
  });
3433
- return <><div
3434
- class={`builder-personalization-container ${props.attributes?.className || ""}`}
3435
- ref={rootRef}
3436
- {...props.attributes}
3437
- >
3438
- <Show10 when={shouldRenderVariants()}>
3439
- <For6 each={props.variants}>{(variant, _index) => {
3440
- const index = _index();
3441
- return <template
3442
- key={index}
3443
- data-variant-id={`${props.builderBlock?.id}-${index}`}
3444
- ><Blocks_default
3445
- blocks={variant.blocks}
3446
- parent={props.builderBlock?.id}
3447
- path={`component.options.variants.${index}.blocks`}
3448
- /></template>;
3449
- }}</For6>
3450
- <Inlined_styles_default
3451
- nonce={props.builderContext?.nonce || ""}
3452
- styles={hideVariantsStyleString()}
3453
- id={`variants-styles-${props.builderBlock?.id}`}
3454
- />
3455
- <Inlined_script_default
3456
- nonce={props.builderContext?.nonce || ""}
3457
- scriptStr={scriptStr()}
3458
- id={`variants-script-${props.builderBlock?.id}`}
3459
- />
3460
- </Show10>
3461
- <Blocks_default
3440
+ return <><div ref={rootRef} {...attrs()}>
3441
+ <Show10
3442
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3443
+ ><Blocks_default
3462
3444
  blocks={blocksToRender().blocks}
3463
3445
  parent={props.builderBlock?.id}
3464
3446
  path={blocksToRender().path}
3465
- />
3447
+ context={props.builderContext}
3448
+ registeredComponents={props.builderComponents}
3449
+ BlocksWrapperProps={{
3450
+ ...props.builderContext?.BlocksWrapperProps,
3451
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3452
+ }}
3453
+ /></Show10>
3454
+ <Show10
3455
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3456
+ >
3457
+ <Show10 when={shouldRenderVariants()}>
3458
+ <Inlined_styles_default
3459
+ nonce={props.builderContext?.nonce || ""}
3460
+ styles={hideVariantsStyleString()}
3461
+ id={`variants-styles-${props.builderBlock?.id}`}
3462
+ />
3463
+ <Inlined_script_default
3464
+ nonce={props.builderContext?.nonce || ""}
3465
+ scriptStr={updateVisibilityStylesScript()}
3466
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
3467
+ />
3468
+ <For6 each={props.variants}>{(variant, _index) => {
3469
+ const index = _index();
3470
+ return <Blocks_default
3471
+ key={`${props.builderBlock?.id}-${index}`}
3472
+ BlocksWrapperProps={{
3473
+ ...props.builderContext?.BlocksWrapperProps,
3474
+ "aria-hidden": true,
3475
+ hidden: true,
3476
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
3477
+ }}
3478
+ blocks={variant.blocks}
3479
+ parent={props.builderBlock?.id}
3480
+ path={`component.options.variants.${index}.blocks`}
3481
+ context={props.builderContext}
3482
+ registeredComponents={props.builderComponents}
3483
+ ><Inlined_script_default
3484
+ nonce={props.builderContext?.nonce || ""}
3485
+ scriptStr={scriptStr()}
3486
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
3487
+ /></Blocks_default>;
3488
+ }}</For6>
3489
+ </Show10>
3490
+ <Blocks_default
3491
+ blocks={blocksToRender().blocks}
3492
+ parent={props.builderBlock?.id}
3493
+ path={blocksToRender().path}
3494
+ context={props.builderContext}
3495
+ registeredComponents={props.builderComponents}
3496
+ BlocksWrapperProps={{
3497
+ ...props.builderContext?.BlocksWrapperProps,
3498
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3499
+ }}
3500
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
3501
+ nonce={props.builderContext?.nonce || ""}
3502
+ scriptStr={scriptStr()}
3503
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
3504
+ /></Show10></Blocks_default>
3505
+ </Show10>
3466
3506
  </div></>;
3467
3507
  }
3468
3508
  var personalization_container_default = PersonalizationContainer;
@@ -4343,6 +4383,14 @@ function FormComponent(props) {
4343
4383
  }
4344
4384
  }
4345
4385
  setFormState("sending");
4386
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
4387
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
4388
+ setFormState("error");
4389
+ mergeNewRootState({
4390
+ formErrorMessage: message
4391
+ });
4392
+ return;
4393
+ }
4346
4394
  const formUrl = `${getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(
4347
4395
  props.sendSubmissionsToEmail || ""
4348
4396
  )}&name=${encodeURIComponent(props.name || "")}`;
@@ -4361,17 +4409,30 @@ function FormComponent(props) {
4361
4409
  } else {
4362
4410
  body2 = await res.text();
4363
4411
  }
4364
- if (!res.ok && props.errorMessagePath) {
4365
- let message = get(body2, props.errorMessagePath);
4366
- if (message) {
4367
- if (typeof message !== "string") {
4368
- message = JSON.stringify(message);
4412
+ if (!res.ok) {
4413
+ const submitErrorEvent = new CustomEvent("submit:error", {
4414
+ detail: {
4415
+ error: body2,
4416
+ status: res.status
4369
4417
  }
4370
- setFormErrorMessage(message);
4371
- mergeNewRootState({
4372
- formErrorMessage: message
4373
- });
4418
+ });
4419
+ if (formRef?.nativeElement) {
4420
+ formRef?.nativeElement.dispatchEvent(submitErrorEvent);
4421
+ if (submitErrorEvent.defaultPrevented) {
4422
+ return;
4423
+ }
4424
+ }
4425
+ setResponseData(body2);
4426
+ setFormState("error");
4427
+ let message = props.errorMessagePath ? get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
4428
+ if (typeof message !== "string") {
4429
+ message = JSON.stringify(message);
4374
4430
  }
4431
+ setFormErrorMessage(message);
4432
+ mergeNewRootState({
4433
+ formErrorMessage: message
4434
+ });
4435
+ return;
4375
4436
  }
4376
4437
  setResponseData(body2);
4377
4438
  setFormState(res.ok ? "success" : "error");
@@ -4450,14 +4511,14 @@ function FormComponent(props) {
4450
4511
  blocks={props.sendingMessage}
4451
4512
  context={props.builderContext}
4452
4513
  /></Show12>
4453
- <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-04a43b72">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4514
+ <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-7430044e">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4454
4515
  <Show12 when={submissionState() === "success"}><Blocks_default
4455
4516
  path="successMessage"
4456
4517
  blocks={props.successMessage}
4457
4518
  context={props.builderContext}
4458
4519
  /></Show12>
4459
4520
  </form>
4460
- <style>{`.pre-04a43b72 {
4521
+ <style>{`.pre-7430044e {
4461
4522
  padding: 10px;
4462
4523
  color: red;
4463
4524
  text-align: center;
@@ -4984,7 +5045,7 @@ var getDefaultRegisteredComponents = () => [{
4984
5045
  }, {
4985
5046
  component: text_default,
4986
5047
  ...componentInfo11
4987
- }, ...TARGET === "react" ? [{
5048
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
4988
5049
  component: personalization_container_default,
4989
5050
  ...componentInfo6
4990
5051
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -5021,7 +5082,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
5021
5082
 
5022
5083
  // src/components/content-variants/helpers.ts
5023
5084
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
5024
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
5085
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
5025
5086
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
5026
5087
  ...variant,
5027
5088
  testVariationId: variant.id,
@@ -5046,20 +5107,20 @@ var checkShouldRenderVariants2 = ({
5046
5107
  };
5047
5108
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
5048
5109
  var isAngularSDK = TARGET === "angular";
5049
- var isHydrationTarget = getIsHydrationTarget(TARGET);
5110
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
5050
5111
  var getInitVariantsFnsScriptString = () => `
5051
5112
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
5052
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5113
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5053
5114
  `;
5054
5115
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
5055
5116
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
5056
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
5117
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
5057
5118
  )`;
5058
5119
  var getUpdateVariantVisibilityScript = ({
5059
5120
  contentId,
5060
5121
  variationId
5061
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
5062
- "${variationId}", "${contentId}", ${isHydrationTarget}
5122
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
5123
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
5063
5124
  )`;
5064
5125
 
5065
5126
  // src/components/content/components/enable-editor.tsx
@@ -5079,7 +5140,7 @@ function getPreviewContent(_searchParams) {
5079
5140
  }
5080
5141
 
5081
5142
  // src/constants/sdk-version.ts
5082
- var SDK_VERSION = "4.0.8";
5143
+ var SDK_VERSION = "4.0.10";
5083
5144
 
5084
5145
  // src/helpers/sdk-headers.ts
5085
5146
  var getSdkHeaders = () => ({
@@ -6438,11 +6499,18 @@ function ContentVariants(props) {
6438
6499
  setShouldRenderVariants(false);
6439
6500
  });
6440
6501
  return <><>
6441
- <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}><Inlined_script_default
6442
- id="builderio-init-variants-fns"
6443
- scriptStr={getInitVariantsFnsScriptString()}
6444
- nonce={props.nonce || ""}
6445
- /></Show16>
6502
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
6503
+ <Inlined_script_default
6504
+ id="builderio-init-variants-fns"
6505
+ scriptStr={getInitVariantsFnsScriptString()}
6506
+ nonce={props.nonce || ""}
6507
+ />
6508
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
6509
+ id="builderio-init-personalization-variants-fns"
6510
+ nonce={props.nonce || ""}
6511
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
6512
+ /></Show16>
6513
+ </Show16>
6446
6514
  <Show16 when={shouldRenderVariants()}>
6447
6515
  <Inlined_styles_default
6448
6516
  id="builderio-variants"