@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.
package/lib/node/dev.jsx CHANGED
@@ -1761,7 +1761,7 @@ function BlocksWrapper(props) {
1761
1761
  createEffect5(on5(() => [onUpdateFn_0_props_blocks()], onUpdateFn_0));
1762
1762
  return <>
1763
1763
  <Dynamic4
1764
- class={className() + " dynamic-023c60f2"}
1764
+ class={className() + " dynamic-450facf4"}
1765
1765
  ref={blocksWrapperRef}
1766
1766
  builder-path={dataPath()}
1767
1767
  builder-parent-id={props.parent}
@@ -1773,7 +1773,7 @@ function BlocksWrapper(props) {
1773
1773
  {...props.BlocksWrapperProps}
1774
1774
  component={props.BlocksWrapper}
1775
1775
  >{props.children}</Dynamic4>
1776
- <style>{`.dynamic-023c60f2 {
1776
+ <style>{`.dynamic-450facf4 {
1777
1777
  display: flex;
1778
1778
  flex-direction: column;
1779
1779
  align-items: stretch;
@@ -1791,19 +1791,22 @@ function Blocks(props) {
1791
1791
  parent={props.parent}
1792
1792
  path={props.path}
1793
1793
  styleProp={props.styleProp}
1794
+ BlocksWrapperProps={props.BlocksWrapperProps || props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
1794
1795
  classNameProp={props.className}
1795
1796
  BlocksWrapper={props.context?.BlocksWrapper || builderContext?.BlocksWrapper}
1796
- BlocksWrapperProps={props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
1797
- ><Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
1798
- const index = _index();
1799
- return <Block_default
1800
- key={block.id}
1801
- block={block}
1802
- linkComponent={props.linkComponent}
1803
- context={props.context || builderContext}
1804
- registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
1805
- />;
1806
- }}</For3></Show6></Blocks_wrapper_default></>;
1797
+ >
1798
+ {props.children}
1799
+ <Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
1800
+ const index = _index();
1801
+ return <Block_default
1802
+ key={block.id}
1803
+ block={block}
1804
+ linkComponent={props.linkComponent}
1805
+ context={props.context || builderContext}
1806
+ registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
1807
+ />;
1808
+ }}</For3></Show6>
1809
+ </Blocks_wrapper_default></>;
1807
1810
  }
1808
1811
  var Blocks_default = Blocks;
1809
1812
 
@@ -2155,6 +2158,166 @@ import { onMount as onMount10, on as on9, createEffect as createEffect9, createM
2155
2158
  // src/components/content-variants/content-variants.tsx
2156
2159
  import { Show as Show16, For as For9, onMount as onMount9, createSignal as createSignal19, createMemo as createMemo19 } from "solid-js";
2157
2160
 
2161
+ // src/blocks/personalization-container/helpers/inlined-fns.ts
2162
+ function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
2163
+ function isString(val) {
2164
+ return typeof val === "string";
2165
+ }
2166
+ function isNumber(val) {
2167
+ return typeof val === "number";
2168
+ }
2169
+ function objectMatchesQuery(userattr, query2) {
2170
+ const result = (() => {
2171
+ const property = query2.property;
2172
+ const operator = query2.operator;
2173
+ let testValue = query2.value;
2174
+ if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
2175
+ testValue = query2.value.slice(0, -1);
2176
+ }
2177
+ if (!(property && operator)) {
2178
+ return true;
2179
+ }
2180
+ if (Array.isArray(testValue)) {
2181
+ if (operator === "isNot") {
2182
+ return testValue.every((val) => objectMatchesQuery(userattr, {
2183
+ property,
2184
+ operator,
2185
+ value: val
2186
+ }));
2187
+ }
2188
+ return !!testValue.find((val) => objectMatchesQuery(userattr, {
2189
+ property,
2190
+ operator,
2191
+ value: val
2192
+ }));
2193
+ }
2194
+ const value = userattr[property];
2195
+ if (Array.isArray(value)) {
2196
+ return value.includes(testValue);
2197
+ }
2198
+ switch (operator) {
2199
+ case "is":
2200
+ return value === testValue;
2201
+ case "isNot":
2202
+ return value !== testValue;
2203
+ case "contains":
2204
+ return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
2205
+ case "startsWith":
2206
+ return isString(value) && value.startsWith(String(testValue));
2207
+ case "endsWith":
2208
+ return isString(value) && value.endsWith(String(testValue));
2209
+ case "greaterThan":
2210
+ return isNumber(value) && isNumber(testValue) && value > testValue;
2211
+ case "lessThan":
2212
+ return isNumber(value) && isNumber(testValue) && value < testValue;
2213
+ case "greaterThanOrEqualTo":
2214
+ return isNumber(value) && isNumber(testValue) && value >= testValue;
2215
+ case "lessThanOrEqualTo":
2216
+ return isNumber(value) && isNumber(testValue) && value <= testValue;
2217
+ default:
2218
+ return false;
2219
+ }
2220
+ })();
2221
+ return result;
2222
+ }
2223
+ const item = {
2224
+ query,
2225
+ startDate,
2226
+ endDate
2227
+ };
2228
+ const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
2229
+ if (item.startDate && new Date(item.startDate) > now) {
2230
+ return false;
2231
+ } else if (item.endDate && new Date(item.endDate) < now) {
2232
+ return false;
2233
+ }
2234
+ if (!item.query || !item.query.length) {
2235
+ return true;
2236
+ }
2237
+ return item.query.every((filter) => {
2238
+ return objectMatchesQuery(userAttributes, filter);
2239
+ });
2240
+ }
2241
+ 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}";
2242
+ 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}";
2243
+ 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}";
2244
+
2245
+ // src/blocks/personalization-container/helpers.ts
2246
+ var DEFAULT_INDEX = "default";
2247
+ var FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME = "filterWithCustomTargeting";
2248
+ var BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME = "builderIoPersonalization";
2249
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
2250
+ var SDKS_SUPPORTING_PERSONALIZATION = ["react", "vue", "svelte", "qwik"];
2251
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte", "qwik"];
2252
+ function checkShouldRenderVariants(variants, canTrack) {
2253
+ const hasVariants = variants && variants.length > 0;
2254
+ if (TARGET === "reactNative")
2255
+ return false;
2256
+ if (!hasVariants)
2257
+ return false;
2258
+ if (!canTrack)
2259
+ return false;
2260
+ if (SDKS_REQUIRING_RESET_APPROACH.includes(TARGET))
2261
+ return true;
2262
+ if (isBrowser())
2263
+ return false;
2264
+ return true;
2265
+ }
2266
+ function getBlocksToRender({
2267
+ variants,
2268
+ previewingIndex,
2269
+ isHydrated,
2270
+ filteredVariants,
2271
+ fallbackBlocks
2272
+ }) {
2273
+ const fallback = {
2274
+ blocks: fallbackBlocks ?? [],
2275
+ path: "this.children",
2276
+ index: DEFAULT_INDEX
2277
+ };
2278
+ if (isHydrated && isEditing()) {
2279
+ if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
2280
+ const variant = variants?.[previewingIndex];
2281
+ if (variant) {
2282
+ return {
2283
+ blocks: variant.blocks,
2284
+ path: `variants.${previewingIndex}.blocks`,
2285
+ index: previewingIndex
2286
+ };
2287
+ }
2288
+ }
2289
+ return fallback;
2290
+ }
2291
+ if (isBrowser()) {
2292
+ const winningVariant = filteredVariants?.[0];
2293
+ if (winningVariant && variants) {
2294
+ const variantIndex = variants.indexOf(winningVariant);
2295
+ if (variantIndex !== -1) {
2296
+ return {
2297
+ blocks: winningVariant.blocks,
2298
+ path: `variants.${variantIndex}.blocks`,
2299
+ index: variantIndex
2300
+ };
2301
+ }
2302
+ }
2303
+ }
2304
+ return fallback;
2305
+ }
2306
+ var getInitPersonalizationVariantsFnsScriptString = () => {
2307
+ return `
2308
+ window.${FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME} = ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
2309
+ window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME} = ${PERSONALIZATION_SCRIPT}
2310
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VISIBILITY_STYLES_SCRIPT}
2311
+ `;
2312
+ };
2313
+ var isHydrationTarget = TARGET === "react";
2314
+ var getPersonalizationScript = (variants, blockId, locale) => {
2315
+ return `window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2316
+ };
2317
+ var getUpdateVisibilityStylesScript = (variants, blockId, locale) => {
2318
+ return `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2319
+ };
2320
+
2158
2321
  // src/helpers/url.ts
2159
2322
  var getTopLevelDomain = (host) => {
2160
2323
  if (host === "localhost" || host === "127.0.0.1") {
@@ -2343,6 +2506,11 @@ var handleABTesting = async ({
2343
2506
  };
2344
2507
  };
2345
2508
 
2509
+ // src/helpers/no-serialize-wrapper.ts
2510
+ function noSerializeWrapper(fn) {
2511
+ return fn;
2512
+ }
2513
+
2346
2514
  // src/helpers/user-attributes.ts
2347
2515
  var USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
2348
2516
  function createUserAttributesService() {
@@ -2373,18 +2541,32 @@ function createUserAttributesService() {
2373
2541
  canTrack
2374
2542
  }) || "{}");
2375
2543
  },
2376
- subscribeOnUserAttributesChange(callback) {
2544
+ subscribeOnUserAttributesChange(callback, {
2545
+ fireImmediately
2546
+ } = {}) {
2377
2547
  subscribers.add(callback);
2378
- return () => {
2548
+ if (fireImmediately) {
2549
+ callback(this.getUserAttributes());
2550
+ }
2551
+ return noSerializeWrapper(function() {
2379
2552
  subscribers.delete(callback);
2380
- };
2553
+ });
2381
2554
  },
2382
2555
  setCanTrack(value) {
2383
2556
  canTrack = value;
2384
2557
  }
2385
2558
  };
2386
2559
  }
2387
- var userAttributesService = createUserAttributesService();
2560
+ var _userAttributesService;
2561
+ if (isBrowser() && TARGET === "qwik") {
2562
+ if (!window.__BUILDER_USER_ATTRIBUTES_SERVICE__) {
2563
+ window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
2564
+ }
2565
+ _userAttributesService = window.__BUILDER_USER_ATTRIBUTES_SERVICE__;
2566
+ } else {
2567
+ _userAttributesService = createUserAttributesService();
2568
+ }
2569
+ var userAttributesService = _userAttributesService;
2388
2570
  var setClientUserAttributes = (attributes) => {
2389
2571
  userAttributesService.setUserAttributes(attributes);
2390
2572
  };
@@ -3101,7 +3283,8 @@ var componentInfo6 = {
3101
3283
  name: "PersonalizationContainer",
3102
3284
  shouldReceiveBuilderProps: {
3103
3285
  builderBlock: true,
3104
- builderContext: true
3286
+ builderContext: true,
3287
+ builderComponents: true
3105
3288
  },
3106
3289
  noWrap: true,
3107
3290
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -3157,199 +3340,6 @@ function isPreviewing(_search) {
3157
3340
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
3158
3341
  }
3159
3342
 
3160
- // src/blocks/personalization-container/helpers/inlined-fns.ts
3161
- function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
3162
- function isString(val) {
3163
- return typeof val === "string";
3164
- }
3165
- function isNumber(val) {
3166
- return typeof val === "number";
3167
- }
3168
- function objectMatchesQuery(userattr, query2) {
3169
- const result = (() => {
3170
- const property = query2.property;
3171
- const operator = query2.operator;
3172
- let testValue = query2.value;
3173
- if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
3174
- testValue = query2.value.slice(0, -1);
3175
- }
3176
- if (!(property && operator)) {
3177
- return true;
3178
- }
3179
- if (Array.isArray(testValue)) {
3180
- if (operator === "isNot") {
3181
- return testValue.every((val) => objectMatchesQuery(userattr, {
3182
- property,
3183
- operator,
3184
- value: val
3185
- }));
3186
- }
3187
- return !!testValue.find((val) => objectMatchesQuery(userattr, {
3188
- property,
3189
- operator,
3190
- value: val
3191
- }));
3192
- }
3193
- const value = userattr[property];
3194
- if (Array.isArray(value)) {
3195
- return value.includes(testValue);
3196
- }
3197
- switch (operator) {
3198
- case "is":
3199
- return value === testValue;
3200
- case "isNot":
3201
- return value !== testValue;
3202
- case "contains":
3203
- return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
3204
- case "startsWith":
3205
- return isString(value) && value.startsWith(String(testValue));
3206
- case "endsWith":
3207
- return isString(value) && value.endsWith(String(testValue));
3208
- case "greaterThan":
3209
- return isNumber(value) && isNumber(testValue) && value > testValue;
3210
- case "lessThan":
3211
- return isNumber(value) && isNumber(testValue) && value < testValue;
3212
- case "greaterThanOrEqualTo":
3213
- return isNumber(value) && isNumber(testValue) && value >= testValue;
3214
- case "lessThanOrEqualTo":
3215
- return isNumber(value) && isNumber(testValue) && value <= testValue;
3216
- default:
3217
- return false;
3218
- }
3219
- })();
3220
- return result;
3221
- }
3222
- const item = {
3223
- query,
3224
- startDate,
3225
- endDate
3226
- };
3227
- const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
3228
- if (item.startDate && new Date(item.startDate) > now) {
3229
- return false;
3230
- } else if (item.endDate && new Date(item.endDate) < now) {
3231
- return false;
3232
- }
3233
- if (!item.query || !item.query.length) {
3234
- return true;
3235
- }
3236
- return item.query.every((filter) => {
3237
- return objectMatchesQuery(userAttributes, filter);
3238
- });
3239
- }
3240
- var PERSONALIZATION_SCRIPT = `function getPersonalizedVariant(variants, blockId, locale) {
3241
- if (!navigator.cookieEnabled) {
3242
- return;
3243
- }
3244
- function getCookie(name) {
3245
- const nameEQ = name + '=';
3246
- const ca = document.cookie.split(';');
3247
- for (let i = 0; i < ca.length; i++) {
3248
- let c = ca[i];
3249
- while (c.charAt(0) == ' ') c = c.substring(1, c.length);
3250
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
3251
- }
3252
- return null;
3253
- }
3254
- function removeVariants() {
3255
- variants?.forEach(function (_, index) {
3256
- document.querySelector('template[data-variant-id="' + blockId + '-' + index + '"]')?.remove();
3257
- });
3258
- document.querySelector('script[data-id="variants-script-' + blockId + '"]')?.remove();
3259
- document.querySelector('style[data-id="variants-styles-' + blockId + '"]')?.remove();
3260
- }
3261
- const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
3262
- if (locale) {
3263
- attributes.locale = locale;
3264
- }
3265
- const winningVariantIndex = variants?.findIndex(function (variant) {
3266
- return filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
3267
- });
3268
- const isDebug = location.href.includes('builder.debug=true');
3269
- if (isDebug) {
3270
- console.debug('PersonalizationContainer', {
3271
- attributes,
3272
- variants,
3273
- winningVariantIndex
3274
- });
3275
- }
3276
- if (winningVariantIndex !== -1) {
3277
- const winningVariant = document.querySelector('template[data-variant-id="' + blockId + '-' + winningVariantIndex + '"]');
3278
- if (winningVariant) {
3279
- const parentNode = winningVariant.parentNode;
3280
- if (parentNode) {
3281
- const newParent = parentNode.cloneNode(false);
3282
- newParent.appendChild(winningVariant.content.firstChild);
3283
- newParent.appendChild(winningVariant.content.lastChild);
3284
- parentNode.parentNode?.replaceChild(newParent, parentNode);
3285
- }
3286
- if (isDebug) {
3287
- console.debug('PersonalizationContainer', 'Winning variant Replaced:', winningVariant);
3288
- }
3289
- }
3290
- } else if (variants && variants.length > 0) {
3291
- removeVariants();
3292
- }
3293
- }`;
3294
- 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}";
3295
-
3296
- // src/blocks/personalization-container/helpers.ts
3297
- function checkShouldRenderVariants(variants, canTrack) {
3298
- const hasVariants = variants && variants.length > 0;
3299
- if (TARGET === "reactNative")
3300
- return false;
3301
- if (!hasVariants)
3302
- return false;
3303
- if (!canTrack)
3304
- return false;
3305
- if (TARGET === "vue" || TARGET === "svelte")
3306
- return true;
3307
- if (isBrowser())
3308
- return false;
3309
- return true;
3310
- }
3311
- function getBlocksToRender({
3312
- variants,
3313
- previewingIndex,
3314
- isHydrated,
3315
- filteredVariants,
3316
- fallbackBlocks
3317
- }) {
3318
- const fallback = {
3319
- blocks: fallbackBlocks ?? [],
3320
- path: "this.children"
3321
- };
3322
- if (isHydrated && isEditing()) {
3323
- if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
3324
- const variant = variants[previewingIndex];
3325
- return {
3326
- blocks: variant.blocks,
3327
- path: `component.options.variants.${previewingIndex}.blocks`
3328
- };
3329
- }
3330
- return fallback;
3331
- }
3332
- if (isBrowser()) {
3333
- const winningVariant = filteredVariants?.[0];
3334
- if (winningVariant) {
3335
- return {
3336
- blocks: winningVariant.blocks,
3337
- path: `component.options.variants.${variants?.indexOf(winningVariant)}.blocks`
3338
- };
3339
- }
3340
- }
3341
- return fallback;
3342
- }
3343
- var getPersonalizationScript = (variants, blockId, locale) => {
3344
- return `
3345
- (function() {
3346
- ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
3347
- ${PERSONALIZATION_SCRIPT}
3348
- getPersonalizedVariant(${JSON.stringify(variants)}, "${blockId}"${locale ? `, "${locale}"` : ""})
3349
- })();
3350
- `;
3351
- };
3352
-
3353
3343
  // src/blocks/personalization-container/personalization-container.tsx
3354
3344
  function PersonalizationContainer(props) {
3355
3345
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -3362,6 +3352,13 @@ function PersonalizationContainer(props) {
3362
3352
  props.builderContext?.rootState?.locale
3363
3353
  )
3364
3354
  );
3355
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
3356
+ getUpdateVisibilityStylesScript(
3357
+ props.variants,
3358
+ props.builderBlock?.id || "none",
3359
+ props.builderContext?.rootState?.locale
3360
+ )
3361
+ );
3365
3362
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
3366
3363
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
3367
3364
  checkShouldRenderVariants(
@@ -3369,7 +3366,14 @@ function PersonalizationContainer(props) {
3369
3366
  getDefaultCanTrack(props.builderContext?.canTrack)
3370
3367
  )
3371
3368
  );
3372
- const [isHydrated, setIsHydrated] = createSignal10(false);
3369
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
3370
+ const attrs = createMemo10(() => {
3371
+ return {
3372
+ ...props.attributes,
3373
+ ...{},
3374
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
3375
+ };
3376
+ });
3373
3377
  const filteredVariants = createMemo10(() => {
3374
3378
  return (props.variants || []).filter((variant) => {
3375
3379
  return filterWithCustomTargeting(
@@ -3389,22 +3393,25 @@ function PersonalizationContainer(props) {
3389
3393
  return getBlocksToRender({
3390
3394
  variants: props.variants,
3391
3395
  fallbackBlocks: props.builderBlock?.children,
3392
- isHydrated: isHydrated(),
3396
+ isHydrated: shouldResetVariants(),
3393
3397
  filteredVariants: filteredVariants(),
3394
3398
  previewingIndex: props.previewingIndex
3395
3399
  });
3396
3400
  });
3397
3401
  const hideVariantsStyleString = createMemo10(() => {
3398
3402
  return (props.variants || []).map(
3399
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
3403
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
3400
3404
  ).join("");
3401
3405
  });
3402
3406
  let rootRef;
3403
3407
  onMount5(() => {
3404
- setIsHydrated(true);
3408
+ setShouldResetVariants(true);
3405
3409
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
3406
- (attrs) => {
3407
- setUserAttributes(attrs);
3410
+ (attrs2) => {
3411
+ setUserAttributes(attrs2);
3412
+ },
3413
+ {
3414
+ fireImmediately: TARGET === "qwik"
3408
3415
  }
3409
3416
  );
3410
3417
  if (!(isEditing() || isPreviewing())) {
@@ -3413,7 +3420,7 @@ function PersonalizationContainer(props) {
3413
3420
  rootRef.dispatchEvent(
3414
3421
  new CustomEvent("builder.variantLoaded", {
3415
3422
  detail: {
3416
- variant: variant || "default",
3423
+ variant: variant || DEFAULT_INDEX,
3417
3424
  content: props.builderContext?.content
3418
3425
  },
3419
3426
  bubbles: true
@@ -3425,7 +3432,7 @@ function PersonalizationContainer(props) {
3425
3432
  rootRef.dispatchEvent(
3426
3433
  new CustomEvent("builder.variantDisplayed", {
3427
3434
  detail: {
3428
- variant: variant || "default",
3435
+ variant: variant || DEFAULT_INDEX,
3429
3436
  content: props.builderContext?.content
3430
3437
  },
3431
3438
  bubbles: true
@@ -3439,39 +3446,72 @@ function PersonalizationContainer(props) {
3439
3446
  }
3440
3447
  unsubscribers().push(unsub);
3441
3448
  });
3442
- return <><div
3443
- class={`builder-personalization-container ${props.attributes?.className || ""}`}
3444
- ref={rootRef}
3445
- {...props.attributes}
3446
- >
3447
- <Show10 when={shouldRenderVariants()}>
3448
- <For6 each={props.variants}>{(variant, _index) => {
3449
- const index = _index();
3450
- return <template
3451
- key={index}
3452
- data-variant-id={`${props.builderBlock?.id}-${index}`}
3453
- ><Blocks_default
3454
- blocks={variant.blocks}
3455
- parent={props.builderBlock?.id}
3456
- path={`component.options.variants.${index}.blocks`}
3457
- /></template>;
3458
- }}</For6>
3459
- <Inlined_styles_default
3460
- nonce={props.builderContext?.nonce || ""}
3461
- styles={hideVariantsStyleString()}
3462
- id={`variants-styles-${props.builderBlock?.id}`}
3463
- />
3464
- <Inlined_script_default
3465
- nonce={props.builderContext?.nonce || ""}
3466
- scriptStr={scriptStr()}
3467
- id={`variants-script-${props.builderBlock?.id}`}
3468
- />
3469
- </Show10>
3470
- <Blocks_default
3449
+ return <><div ref={rootRef} {...attrs()}>
3450
+ <Show10
3451
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3452
+ ><Blocks_default
3471
3453
  blocks={blocksToRender().blocks}
3472
3454
  parent={props.builderBlock?.id}
3473
3455
  path={blocksToRender().path}
3474
- />
3456
+ context={props.builderContext}
3457
+ registeredComponents={props.builderComponents}
3458
+ BlocksWrapperProps={{
3459
+ ...props.builderContext?.BlocksWrapperProps,
3460
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3461
+ }}
3462
+ /></Show10>
3463
+ <Show10
3464
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3465
+ >
3466
+ <Show10 when={shouldRenderVariants()}>
3467
+ <Inlined_styles_default
3468
+ nonce={props.builderContext?.nonce || ""}
3469
+ styles={hideVariantsStyleString()}
3470
+ id={`variants-styles-${props.builderBlock?.id}`}
3471
+ />
3472
+ <Inlined_script_default
3473
+ nonce={props.builderContext?.nonce || ""}
3474
+ scriptStr={updateVisibilityStylesScript()}
3475
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
3476
+ />
3477
+ <For6 each={props.variants}>{(variant, _index) => {
3478
+ const index = _index();
3479
+ return <Blocks_default
3480
+ key={`${props.builderBlock?.id}-${index}`}
3481
+ BlocksWrapperProps={{
3482
+ ...props.builderContext?.BlocksWrapperProps,
3483
+ "aria-hidden": true,
3484
+ hidden: true,
3485
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
3486
+ }}
3487
+ blocks={variant.blocks}
3488
+ parent={props.builderBlock?.id}
3489
+ path={`component.options.variants.${index}.blocks`}
3490
+ context={props.builderContext}
3491
+ registeredComponents={props.builderComponents}
3492
+ ><Inlined_script_default
3493
+ nonce={props.builderContext?.nonce || ""}
3494
+ scriptStr={scriptStr()}
3495
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
3496
+ /></Blocks_default>;
3497
+ }}</For6>
3498
+ </Show10>
3499
+ <Blocks_default
3500
+ blocks={blocksToRender().blocks}
3501
+ parent={props.builderBlock?.id}
3502
+ path={blocksToRender().path}
3503
+ context={props.builderContext}
3504
+ registeredComponents={props.builderComponents}
3505
+ BlocksWrapperProps={{
3506
+ ...props.builderContext?.BlocksWrapperProps,
3507
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3508
+ }}
3509
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
3510
+ nonce={props.builderContext?.nonce || ""}
3511
+ scriptStr={scriptStr()}
3512
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
3513
+ /></Show10></Blocks_default>
3514
+ </Show10>
3475
3515
  </div></>;
3476
3516
  }
3477
3517
  var personalization_container_default = PersonalizationContainer;
@@ -4352,6 +4392,15 @@ function FormComponent(props) {
4352
4392
  }
4353
4393
  }
4354
4394
  setFormState("sending");
4395
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
4396
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
4397
+ console.error(message);
4398
+ setFormState("error");
4399
+ mergeNewRootState({
4400
+ formErrorMessage: message
4401
+ });
4402
+ return;
4403
+ }
4355
4404
  const formUrl = `${getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(
4356
4405
  props.sendSubmissionsToEmail || ""
4357
4406
  )}&name=${encodeURIComponent(props.name || "")}`;
@@ -4370,17 +4419,30 @@ function FormComponent(props) {
4370
4419
  } else {
4371
4420
  body2 = await res.text();
4372
4421
  }
4373
- if (!res.ok && props.errorMessagePath) {
4374
- let message = get(body2, props.errorMessagePath);
4375
- if (message) {
4376
- if (typeof message !== "string") {
4377
- message = JSON.stringify(message);
4422
+ if (!res.ok) {
4423
+ const submitErrorEvent = new CustomEvent("submit:error", {
4424
+ detail: {
4425
+ error: body2,
4426
+ status: res.status
4378
4427
  }
4379
- setFormErrorMessage(message);
4380
- mergeNewRootState({
4381
- formErrorMessage: message
4382
- });
4428
+ });
4429
+ if (formRef?.nativeElement) {
4430
+ formRef?.nativeElement.dispatchEvent(submitErrorEvent);
4431
+ if (submitErrorEvent.defaultPrevented) {
4432
+ return;
4433
+ }
4434
+ }
4435
+ setResponseData(body2);
4436
+ setFormState("error");
4437
+ let message = props.errorMessagePath ? get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
4438
+ if (typeof message !== "string") {
4439
+ message = JSON.stringify(message);
4383
4440
  }
4441
+ setFormErrorMessage(message);
4442
+ mergeNewRootState({
4443
+ formErrorMessage: message
4444
+ });
4445
+ return;
4384
4446
  }
4385
4447
  setResponseData(body2);
4386
4448
  setFormState(res.ok ? "success" : "error");
@@ -4459,14 +4521,14 @@ function FormComponent(props) {
4459
4521
  blocks={props.sendingMessage}
4460
4522
  context={props.builderContext}
4461
4523
  /></Show12>
4462
- <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-04a43b72">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4524
+ <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-7430044e">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4463
4525
  <Show12 when={submissionState() === "success"}><Blocks_default
4464
4526
  path="successMessage"
4465
4527
  blocks={props.successMessage}
4466
4528
  context={props.builderContext}
4467
4529
  /></Show12>
4468
4530
  </form>
4469
- <style>{`.pre-04a43b72 {
4531
+ <style>{`.pre-7430044e {
4470
4532
  padding: 10px;
4471
4533
  color: red;
4472
4534
  text-align: center;
@@ -4994,7 +5056,7 @@ var getDefaultRegisteredComponents = () => [{
4994
5056
  }, {
4995
5057
  component: text_default,
4996
5058
  ...componentInfo11
4997
- }, ...TARGET === "react" ? [{
5059
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
4998
5060
  component: personalization_container_default,
4999
5061
  ...componentInfo6
5000
5062
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -5031,7 +5093,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
5031
5093
 
5032
5094
  // src/components/content-variants/helpers.ts
5033
5095
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
5034
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
5096
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
5035
5097
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
5036
5098
  ...variant,
5037
5099
  testVariationId: variant.id,
@@ -5056,20 +5118,20 @@ var checkShouldRenderVariants2 = ({
5056
5118
  };
5057
5119
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
5058
5120
  var isAngularSDK = TARGET === "angular";
5059
- var isHydrationTarget = getIsHydrationTarget(TARGET);
5121
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
5060
5122
  var getInitVariantsFnsScriptString = () => `
5061
5123
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
5062
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5124
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5063
5125
  `;
5064
5126
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
5065
5127
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
5066
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
5128
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
5067
5129
  )`;
5068
5130
  var getUpdateVariantVisibilityScript = ({
5069
5131
  contentId,
5070
5132
  variationId
5071
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
5072
- "${variationId}", "${contentId}", ${isHydrationTarget}
5133
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
5134
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
5073
5135
  )`;
5074
5136
 
5075
5137
  // src/components/content/components/enable-editor.tsx
@@ -5089,7 +5151,7 @@ function getPreviewContent(_searchParams) {
5089
5151
  }
5090
5152
 
5091
5153
  // src/constants/sdk-version.ts
5092
- var SDK_VERSION = "4.0.8";
5154
+ var SDK_VERSION = "4.0.10";
5093
5155
 
5094
5156
  // src/helpers/sdk-headers.ts
5095
5157
  var getSdkHeaders = () => ({
@@ -6455,11 +6517,18 @@ function ContentVariants(props) {
6455
6517
  setShouldRenderVariants(false);
6456
6518
  });
6457
6519
  return <><>
6458
- <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}><Inlined_script_default
6459
- id="builderio-init-variants-fns"
6460
- scriptStr={getInitVariantsFnsScriptString()}
6461
- nonce={props.nonce || ""}
6462
- /></Show16>
6520
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
6521
+ <Inlined_script_default
6522
+ id="builderio-init-variants-fns"
6523
+ scriptStr={getInitVariantsFnsScriptString()}
6524
+ nonce={props.nonce || ""}
6525
+ />
6526
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
6527
+ id="builderio-init-personalization-variants-fns"
6528
+ nonce={props.nonce || ""}
6529
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
6530
+ /></Show16>
6531
+ </Show16>
6463
6532
  <Show16 when={shouldRenderVariants()}>
6464
6533
  <Inlined_styles_default
6465
6534
  id="builderio-variants"