@builder.io/sdk-solid 4.0.8 → 4.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { delegateEvents, createComponent, spread, mergeProps, insert, effect, setAttribute, className, style, template, use, Dynamic, memo } from 'solid-js/web';
1
+ import { delegateEvents, createComponent, memo, spread, mergeProps, insert, effect, setAttribute, className, style, template, use, Dynamic } from 'solid-js/web';
2
2
  import { createContext, useContext, Show, For, createMemo, onMount, createSignal, createEffect, on } from 'solid-js';
3
3
 
4
4
  // src/blocks/button/button.tsx
@@ -1668,7 +1668,7 @@ function Block(props) {
1668
1668
  });
1669
1669
  }
1670
1670
  var block_default = Block;
1671
- var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-023c60f2 {
1671
+ var _tmpl$2 = /* @__PURE__ */ template(`<style>.dynamic-450facf4 {
1672
1672
  display: flex;
1673
1673
  flex-direction: column;
1674
1674
  align-items: stretch;
@@ -1717,7 +1717,7 @@ function BlocksWrapper(props) {
1717
1717
  createEffect(on(() => [onUpdateFn_0_props_blocks()], onUpdateFn_0));
1718
1718
  return [createComponent(Dynamic, mergeProps({
1719
1719
  get ["class"]() {
1720
- return className() + " dynamic-023c60f2";
1720
+ return className() + " dynamic-450facf4";
1721
1721
  },
1722
1722
  ref(r$) {
1723
1723
  const _ref$ = blocksWrapperRef;
@@ -1764,17 +1764,17 @@ function Blocks(props) {
1764
1764
  get styleProp() {
1765
1765
  return props.styleProp;
1766
1766
  },
1767
+ get BlocksWrapperProps() {
1768
+ return props.BlocksWrapperProps || props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps;
1769
+ },
1767
1770
  get classNameProp() {
1768
1771
  return props.className;
1769
1772
  },
1770
1773
  get BlocksWrapper() {
1771
1774
  return props.context?.BlocksWrapper || builderContext?.BlocksWrapper;
1772
1775
  },
1773
- get BlocksWrapperProps() {
1774
- return props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps;
1775
- },
1776
1776
  get children() {
1777
- return createComponent(Show, {
1777
+ return [memo(() => props.children), createComponent(Show, {
1778
1778
  get when() {
1779
1779
  return props.blocks;
1780
1780
  },
@@ -1803,7 +1803,7 @@ function Blocks(props) {
1803
1803
  }
1804
1804
  });
1805
1805
  }
1806
- });
1806
+ })];
1807
1807
  }
1808
1808
  });
1809
1809
  }
@@ -2228,6 +2228,166 @@ function SectionComponent(props) {
2228
2228
  }
2229
2229
  var section_default = SectionComponent;
2230
2230
 
2231
+ // src/blocks/personalization-container/helpers/inlined-fns.ts
2232
+ function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
2233
+ function isString(val) {
2234
+ return typeof val === "string";
2235
+ }
2236
+ function isNumber(val) {
2237
+ return typeof val === "number";
2238
+ }
2239
+ function objectMatchesQuery(userattr, query2) {
2240
+ const result = (() => {
2241
+ const property = query2.property;
2242
+ const operator = query2.operator;
2243
+ let testValue = query2.value;
2244
+ if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
2245
+ testValue = query2.value.slice(0, -1);
2246
+ }
2247
+ if (!(property && operator)) {
2248
+ return true;
2249
+ }
2250
+ if (Array.isArray(testValue)) {
2251
+ if (operator === "isNot") {
2252
+ return testValue.every((val) => objectMatchesQuery(userattr, {
2253
+ property,
2254
+ operator,
2255
+ value: val
2256
+ }));
2257
+ }
2258
+ return !!testValue.find((val) => objectMatchesQuery(userattr, {
2259
+ property,
2260
+ operator,
2261
+ value: val
2262
+ }));
2263
+ }
2264
+ const value = userattr[property];
2265
+ if (Array.isArray(value)) {
2266
+ return value.includes(testValue);
2267
+ }
2268
+ switch (operator) {
2269
+ case "is":
2270
+ return value === testValue;
2271
+ case "isNot":
2272
+ return value !== testValue;
2273
+ case "contains":
2274
+ return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
2275
+ case "startsWith":
2276
+ return isString(value) && value.startsWith(String(testValue));
2277
+ case "endsWith":
2278
+ return isString(value) && value.endsWith(String(testValue));
2279
+ case "greaterThan":
2280
+ return isNumber(value) && isNumber(testValue) && value > testValue;
2281
+ case "lessThan":
2282
+ return isNumber(value) && isNumber(testValue) && value < testValue;
2283
+ case "greaterThanOrEqualTo":
2284
+ return isNumber(value) && isNumber(testValue) && value >= testValue;
2285
+ case "lessThanOrEqualTo":
2286
+ return isNumber(value) && isNumber(testValue) && value <= testValue;
2287
+ default:
2288
+ return false;
2289
+ }
2290
+ })();
2291
+ return result;
2292
+ }
2293
+ const item = {
2294
+ query,
2295
+ startDate,
2296
+ endDate
2297
+ };
2298
+ const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
2299
+ if (item.startDate && new Date(item.startDate) > now) {
2300
+ return false;
2301
+ } else if (item.endDate && new Date(item.endDate) < now) {
2302
+ return false;
2303
+ }
2304
+ if (!item.query || !item.query.length) {
2305
+ return true;
2306
+ }
2307
+ return item.query.every((filter) => {
2308
+ return objectMatchesQuery(userAttributes, filter);
2309
+ });
2310
+ }
2311
+ 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}";
2312
+ 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}";
2313
+ 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}";
2314
+
2315
+ // src/blocks/personalization-container/helpers.ts
2316
+ var DEFAULT_INDEX = "default";
2317
+ var FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME = "filterWithCustomTargeting";
2318
+ var BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME = "builderIoPersonalization";
2319
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
2320
+ var SDKS_SUPPORTING_PERSONALIZATION = ["react", "vue", "svelte"];
2321
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte"];
2322
+ function checkShouldRenderVariants(variants, canTrack) {
2323
+ const hasVariants = variants && variants.length > 0;
2324
+ if (TARGET === "reactNative")
2325
+ return false;
2326
+ if (!hasVariants)
2327
+ return false;
2328
+ if (!canTrack)
2329
+ return false;
2330
+ if (SDKS_REQUIRING_RESET_APPROACH.includes(TARGET))
2331
+ return true;
2332
+ if (isBrowser())
2333
+ return false;
2334
+ return true;
2335
+ }
2336
+ function getBlocksToRender({
2337
+ variants,
2338
+ previewingIndex,
2339
+ isHydrated,
2340
+ filteredVariants,
2341
+ fallbackBlocks
2342
+ }) {
2343
+ const fallback = {
2344
+ blocks: fallbackBlocks ?? [],
2345
+ path: "this.children",
2346
+ index: DEFAULT_INDEX
2347
+ };
2348
+ if (isHydrated && isEditing()) {
2349
+ if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
2350
+ const variant = variants?.[previewingIndex];
2351
+ if (variant) {
2352
+ return {
2353
+ blocks: variant.blocks,
2354
+ path: `variants.${previewingIndex}.blocks`,
2355
+ index: previewingIndex
2356
+ };
2357
+ }
2358
+ }
2359
+ return fallback;
2360
+ }
2361
+ if (isBrowser()) {
2362
+ const winningVariant = filteredVariants?.[0];
2363
+ if (winningVariant && variants) {
2364
+ const variantIndex = variants.indexOf(winningVariant);
2365
+ if (variantIndex !== -1) {
2366
+ return {
2367
+ blocks: winningVariant.blocks,
2368
+ path: `variants.${variantIndex}.blocks`,
2369
+ index: variantIndex
2370
+ };
2371
+ }
2372
+ }
2373
+ }
2374
+ return fallback;
2375
+ }
2376
+ var getInitPersonalizationVariantsFnsScriptString = () => {
2377
+ return `
2378
+ window.${FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME} = ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
2379
+ window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME} = ${PERSONALIZATION_SCRIPT}
2380
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VISIBILITY_STYLES_SCRIPT}
2381
+ `;
2382
+ };
2383
+ var isHydrationTarget = TARGET === "react";
2384
+ var getPersonalizationScript = (variants, blockId, locale) => {
2385
+ return `window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2386
+ };
2387
+ var getUpdateVisibilityStylesScript = (variants, blockId, locale) => {
2388
+ return `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
2389
+ };
2390
+
2231
2391
  // src/helpers/url.ts
2232
2392
  var getTopLevelDomain = (host) => {
2233
2393
  if (host === "localhost" || host === "127.0.0.1") {
@@ -3207,7 +3367,8 @@ var componentInfo6 = {
3207
3367
  name: "PersonalizationContainer",
3208
3368
  shouldReceiveBuilderProps: {
3209
3369
  builderBlock: true,
3210
- builderContext: true
3370
+ builderContext: true,
3371
+ builderComponents: true
3211
3372
  },
3212
3373
  noWrap: true,
3213
3374
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -3269,208 +3430,22 @@ function isPreviewing(_search) {
3269
3430
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
3270
3431
  }
3271
3432
 
3272
- // src/blocks/personalization-container/helpers/inlined-fns.ts
3273
- function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
3274
- function isString(val) {
3275
- return typeof val === "string";
3276
- }
3277
- function isNumber(val) {
3278
- return typeof val === "number";
3279
- }
3280
- function objectMatchesQuery(userattr, query2) {
3281
- const result = (() => {
3282
- const property = query2.property;
3283
- const operator = query2.operator;
3284
- let testValue = query2.value;
3285
- if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
3286
- testValue = query2.value.slice(0, -1);
3287
- }
3288
- if (!(property && operator)) {
3289
- return true;
3290
- }
3291
- if (Array.isArray(testValue)) {
3292
- if (operator === "isNot") {
3293
- return testValue.every((val) => objectMatchesQuery(userattr, {
3294
- property,
3295
- operator,
3296
- value: val
3297
- }));
3298
- }
3299
- return !!testValue.find((val) => objectMatchesQuery(userattr, {
3300
- property,
3301
- operator,
3302
- value: val
3303
- }));
3304
- }
3305
- const value = userattr[property];
3306
- if (Array.isArray(value)) {
3307
- return value.includes(testValue);
3308
- }
3309
- switch (operator) {
3310
- case "is":
3311
- return value === testValue;
3312
- case "isNot":
3313
- return value !== testValue;
3314
- case "contains":
3315
- return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
3316
- case "startsWith":
3317
- return isString(value) && value.startsWith(String(testValue));
3318
- case "endsWith":
3319
- return isString(value) && value.endsWith(String(testValue));
3320
- case "greaterThan":
3321
- return isNumber(value) && isNumber(testValue) && value > testValue;
3322
- case "lessThan":
3323
- return isNumber(value) && isNumber(testValue) && value < testValue;
3324
- case "greaterThanOrEqualTo":
3325
- return isNumber(value) && isNumber(testValue) && value >= testValue;
3326
- case "lessThanOrEqualTo":
3327
- return isNumber(value) && isNumber(testValue) && value <= testValue;
3328
- default:
3329
- return false;
3330
- }
3331
- })();
3332
- return result;
3333
- }
3334
- const item = {
3335
- query,
3336
- startDate,
3337
- endDate
3338
- };
3339
- const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
3340
- if (item.startDate && new Date(item.startDate) > now) {
3341
- return false;
3342
- } else if (item.endDate && new Date(item.endDate) < now) {
3343
- return false;
3344
- }
3345
- if (!item.query || !item.query.length) {
3346
- return true;
3347
- }
3348
- return item.query.every((filter) => {
3349
- return objectMatchesQuery(userAttributes, filter);
3350
- });
3351
- }
3352
- var PERSONALIZATION_SCRIPT = `function getPersonalizedVariant(variants, blockId, locale) {
3353
- if (!navigator.cookieEnabled) {
3354
- return;
3355
- }
3356
- function getCookie(name) {
3357
- const nameEQ = name + '=';
3358
- const ca = document.cookie.split(';');
3359
- for (let i = 0; i < ca.length; i++) {
3360
- let c = ca[i];
3361
- while (c.charAt(0) == ' ') c = c.substring(1, c.length);
3362
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
3363
- }
3364
- return null;
3365
- }
3366
- function removeVariants() {
3367
- variants?.forEach(function (_, index) {
3368
- document.querySelector('template[data-variant-id="' + blockId + '-' + index + '"]')?.remove();
3369
- });
3370
- document.querySelector('script[data-id="variants-script-' + blockId + '"]')?.remove();
3371
- document.querySelector('style[data-id="variants-styles-' + blockId + '"]')?.remove();
3372
- }
3373
- const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
3374
- if (locale) {
3375
- attributes.locale = locale;
3376
- }
3377
- const winningVariantIndex = variants?.findIndex(function (variant) {
3378
- return filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
3379
- });
3380
- const isDebug = location.href.includes('builder.debug=true');
3381
- if (isDebug) {
3382
- console.debug('PersonalizationContainer', {
3383
- attributes,
3384
- variants,
3385
- winningVariantIndex
3386
- });
3387
- }
3388
- if (winningVariantIndex !== -1) {
3389
- const winningVariant = document.querySelector('template[data-variant-id="' + blockId + '-' + winningVariantIndex + '"]');
3390
- if (winningVariant) {
3391
- const parentNode = winningVariant.parentNode;
3392
- if (parentNode) {
3393
- const newParent = parentNode.cloneNode(false);
3394
- newParent.appendChild(winningVariant.content.firstChild);
3395
- newParent.appendChild(winningVariant.content.lastChild);
3396
- parentNode.parentNode?.replaceChild(newParent, parentNode);
3397
- }
3398
- if (isDebug) {
3399
- console.debug('PersonalizationContainer', 'Winning variant Replaced:', winningVariant);
3400
- }
3401
- }
3402
- } else if (variants && variants.length > 0) {
3403
- removeVariants();
3404
- }
3405
- }`;
3406
- 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}";
3407
-
3408
- // src/blocks/personalization-container/helpers.ts
3409
- function checkShouldRenderVariants(variants, canTrack) {
3410
- const hasVariants = variants && variants.length > 0;
3411
- if (TARGET === "reactNative")
3412
- return false;
3413
- if (!hasVariants)
3414
- return false;
3415
- if (!canTrack)
3416
- return false;
3417
- if (TARGET === "vue" || TARGET === "svelte")
3418
- return true;
3419
- if (isBrowser())
3420
- return false;
3421
- return true;
3422
- }
3423
- function getBlocksToRender({
3424
- variants,
3425
- previewingIndex,
3426
- isHydrated,
3427
- filteredVariants,
3428
- fallbackBlocks
3429
- }) {
3430
- const fallback = {
3431
- blocks: fallbackBlocks ?? [],
3432
- path: "this.children"
3433
- };
3434
- if (isHydrated && isEditing()) {
3435
- if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
3436
- const variant = variants[previewingIndex];
3437
- return {
3438
- blocks: variant.blocks,
3439
- path: `component.options.variants.${previewingIndex}.blocks`
3440
- };
3441
- }
3442
- return fallback;
3443
- }
3444
- if (isBrowser()) {
3445
- const winningVariant = filteredVariants?.[0];
3446
- if (winningVariant) {
3447
- return {
3448
- blocks: winningVariant.blocks,
3449
- path: `component.options.variants.${variants?.indexOf(winningVariant)}.blocks`
3450
- };
3451
- }
3452
- }
3453
- return fallback;
3454
- }
3455
- var getPersonalizationScript = (variants, blockId, locale) => {
3456
- return `
3457
- (function() {
3458
- ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
3459
- ${PERSONALIZATION_SCRIPT}
3460
- getPersonalizedVariant(${JSON.stringify(variants)}, "${blockId}"${locale ? `, "${locale}"` : ""})
3461
- })();
3462
- `;
3463
- };
3464
-
3465
3433
  // src/blocks/personalization-container/personalization-container.tsx
3466
3434
  var _tmpl$9 = /* @__PURE__ */ template(`<div>`);
3467
- var _tmpl$25 = /* @__PURE__ */ template(`<template>`);
3468
3435
  function PersonalizationContainer(props) {
3469
3436
  const [userAttributes, setUserAttributes] = createSignal(userAttributesService.getUserAttributes());
3470
3437
  const [scriptStr, setScriptStr] = createSignal(getPersonalizationScript(props.variants, props.builderBlock?.id || "none", props.builderContext?.rootState?.locale));
3438
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal(getUpdateVisibilityStylesScript(props.variants, props.builderBlock?.id || "none", props.builderContext?.rootState?.locale));
3471
3439
  const [unsubscribers, setUnsubscribers] = createSignal([]);
3472
3440
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRenderVariants(props.variants, getDefaultCanTrack(props.builderContext?.canTrack)));
3473
- const [isHydrated, setIsHydrated] = createSignal(false);
3441
+ const [shouldResetVariants, setShouldResetVariants] = createSignal(false);
3442
+ const attrs = createMemo(() => {
3443
+ return {
3444
+ ...props.attributes,
3445
+ ...{},
3446
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
3447
+ };
3448
+ });
3474
3449
  const filteredVariants = createMemo(() => {
3475
3450
  return (props.variants || []).filter((variant) => {
3476
3451
  return filterWithCustomTargeting({
@@ -3485,26 +3460,26 @@ function PersonalizationContainer(props) {
3485
3460
  return getBlocksToRender({
3486
3461
  variants: props.variants,
3487
3462
  fallbackBlocks: props.builderBlock?.children,
3488
- isHydrated: isHydrated(),
3463
+ isHydrated: shouldResetVariants(),
3489
3464
  filteredVariants: filteredVariants(),
3490
3465
  previewingIndex: props.previewingIndex
3491
3466
  });
3492
3467
  });
3493
3468
  const hideVariantsStyleString = createMemo(() => {
3494
- return (props.variants || []).map((_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `).join("");
3469
+ return (props.variants || []).map((_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `).join("");
3495
3470
  });
3496
3471
  let rootRef;
3497
3472
  onMount(() => {
3498
- setIsHydrated(true);
3499
- const unsub = userAttributesService.subscribeOnUserAttributesChange((attrs) => {
3500
- setUserAttributes(attrs);
3473
+ setShouldResetVariants(true);
3474
+ const unsub = userAttributesService.subscribeOnUserAttributesChange((attrs2) => {
3475
+ setUserAttributes(attrs2);
3501
3476
  });
3502
3477
  if (!(isEditing() || isPreviewing())) {
3503
3478
  const variant = filteredVariants()[0];
3504
3479
  if (rootRef) {
3505
3480
  rootRef.dispatchEvent(new CustomEvent("builder.variantLoaded", {
3506
3481
  detail: {
3507
- variant: variant || "default",
3482
+ variant: variant || DEFAULT_INDEX,
3508
3483
  content: props.builderContext?.content
3509
3484
  },
3510
3485
  bubbles: true
@@ -3514,7 +3489,7 @@ function PersonalizationContainer(props) {
3514
3489
  if (entry.isIntersecting && rootRef) {
3515
3490
  rootRef.dispatchEvent(new CustomEvent("builder.variantDisplayed", {
3516
3491
  detail: {
3517
- variant: variant || "default",
3492
+ variant: variant || DEFAULT_INDEX,
3518
3493
  content: props.builderContext?.content
3519
3494
  },
3520
3495
  bubbles: true
@@ -3531,70 +3506,158 @@ function PersonalizationContainer(props) {
3531
3506
  const _el$ = _tmpl$9();
3532
3507
  const _ref$ = rootRef;
3533
3508
  typeof _ref$ === "function" ? use(_ref$, _el$) : rootRef = _el$;
3534
- spread(_el$, mergeProps({
3535
- get ["class"]() {
3536
- return `builder-personalization-container ${props.attributes?.className || ""}`;
3537
- }
3538
- }, () => props.attributes), false, true);
3509
+ spread(_el$, mergeProps(attrs), false, true);
3539
3510
  insert(_el$, createComponent(Show, {
3540
3511
  get when() {
3541
- return shouldRenderVariants();
3512
+ return memo(() => !!shouldResetVariants())() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET);
3542
3513
  },
3543
3514
  get children() {
3544
- return [createComponent(For, {
3545
- get each() {
3546
- return props.variants;
3515
+ return createComponent(blocks_default, {
3516
+ get blocks() {
3517
+ return blocksToRender().blocks;
3547
3518
  },
3548
- children: (variant, _index) => {
3549
- const index = _index();
3550
- return (() => {
3551
- const _el$2 = _tmpl$25();
3552
- setAttribute(_el$2, "key", index);
3553
- insert(_el$2, createComponent(blocks_default, {
3554
- get blocks() {
3555
- return variant.blocks;
3556
- },
3557
- get parent() {
3558
- return props.builderBlock?.id;
3559
- },
3560
- path: `component.options.variants.${index}.blocks`
3561
- }));
3562
- effect(() => setAttribute(_el$2, "data-variant-id", `${props.builderBlock?.id}-${index}`));
3563
- return _el$2;
3564
- })();
3565
- }
3566
- }), createComponent(inlined_styles_default, {
3567
- get nonce() {
3568
- return props.builderContext?.nonce || "";
3519
+ get parent() {
3520
+ return props.builderBlock?.id;
3569
3521
  },
3570
- get styles() {
3571
- return hideVariantsStyleString();
3522
+ get path() {
3523
+ return blocksToRender().path;
3572
3524
  },
3573
- get id() {
3574
- return `variants-styles-${props.builderBlock?.id}`;
3575
- }
3576
- }), createComponent(inlined_script_default, {
3577
- get nonce() {
3578
- return props.builderContext?.nonce || "";
3525
+ get context() {
3526
+ return props.builderContext;
3579
3527
  },
3580
- get scriptStr() {
3581
- return scriptStr();
3528
+ get registeredComponents() {
3529
+ return props.builderComponents;
3582
3530
  },
3583
- get id() {
3584
- return `variants-script-${props.builderBlock?.id}`;
3531
+ get BlocksWrapperProps() {
3532
+ return {
3533
+ ...props.builderContext?.BlocksWrapperProps,
3534
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3535
+ };
3585
3536
  }
3586
- })];
3537
+ });
3587
3538
  }
3588
3539
  }), null);
3589
- insert(_el$, createComponent(blocks_default, {
3590
- get blocks() {
3591
- return blocksToRender().blocks;
3592
- },
3593
- get parent() {
3594
- return props.builderBlock?.id;
3540
+ insert(_el$, createComponent(Show, {
3541
+ get when() {
3542
+ return memo(() => !!!shouldResetVariants())() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET);
3595
3543
  },
3596
- get path() {
3597
- return blocksToRender().path;
3544
+ get children() {
3545
+ return [createComponent(Show, {
3546
+ get when() {
3547
+ return shouldRenderVariants();
3548
+ },
3549
+ get children() {
3550
+ return [createComponent(inlined_styles_default, {
3551
+ get nonce() {
3552
+ return props.builderContext?.nonce || "";
3553
+ },
3554
+ get styles() {
3555
+ return hideVariantsStyleString();
3556
+ },
3557
+ get id() {
3558
+ return `variants-styles-${props.builderBlock?.id}`;
3559
+ }
3560
+ }), createComponent(inlined_script_default, {
3561
+ get nonce() {
3562
+ return props.builderContext?.nonce || "";
3563
+ },
3564
+ get scriptStr() {
3565
+ return updateVisibilityStylesScript();
3566
+ },
3567
+ get id() {
3568
+ return `variants-visibility-script-${props.builderBlock?.id}`;
3569
+ }
3570
+ }), createComponent(For, {
3571
+ get each() {
3572
+ return props.variants;
3573
+ },
3574
+ children: (variant, _index) => {
3575
+ const index = _index();
3576
+ return createComponent(blocks_default, {
3577
+ get key() {
3578
+ return `${props.builderBlock?.id}-${index}`;
3579
+ },
3580
+ get BlocksWrapperProps() {
3581
+ return {
3582
+ ...props.builderContext?.BlocksWrapperProps,
3583
+ "aria-hidden": true,
3584
+ hidden: true,
3585
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
3586
+ };
3587
+ },
3588
+ get blocks() {
3589
+ return variant.blocks;
3590
+ },
3591
+ get parent() {
3592
+ return props.builderBlock?.id;
3593
+ },
3594
+ path: `component.options.variants.${index}.blocks`,
3595
+ get context() {
3596
+ return props.builderContext;
3597
+ },
3598
+ get registeredComponents() {
3599
+ return props.builderComponents;
3600
+ },
3601
+ get children() {
3602
+ return createComponent(inlined_script_default, {
3603
+ get nonce() {
3604
+ return props.builderContext?.nonce || "";
3605
+ },
3606
+ get scriptStr() {
3607
+ return scriptStr();
3608
+ },
3609
+ get id() {
3610
+ return `variants-script-${props.builderBlock?.id}-${index}`;
3611
+ }
3612
+ });
3613
+ }
3614
+ });
3615
+ }
3616
+ })];
3617
+ }
3618
+ }), createComponent(blocks_default, {
3619
+ get blocks() {
3620
+ return blocksToRender().blocks;
3621
+ },
3622
+ get parent() {
3623
+ return props.builderBlock?.id;
3624
+ },
3625
+ get path() {
3626
+ return blocksToRender().path;
3627
+ },
3628
+ get context() {
3629
+ return props.builderContext;
3630
+ },
3631
+ get registeredComponents() {
3632
+ return props.builderComponents;
3633
+ },
3634
+ get BlocksWrapperProps() {
3635
+ return {
3636
+ ...props.builderContext?.BlocksWrapperProps,
3637
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3638
+ };
3639
+ },
3640
+ get children() {
3641
+ return createComponent(Show, {
3642
+ get when() {
3643
+ return shouldRenderVariants();
3644
+ },
3645
+ get children() {
3646
+ return createComponent(inlined_script_default, {
3647
+ get nonce() {
3648
+ return props.builderContext?.nonce || "";
3649
+ },
3650
+ get scriptStr() {
3651
+ return scriptStr();
3652
+ },
3653
+ get id() {
3654
+ return `variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`;
3655
+ }
3656
+ });
3657
+ }
3658
+ });
3659
+ }
3660
+ })];
3598
3661
  }
3599
3662
  }), null);
3600
3663
  return _el$;
@@ -3881,7 +3944,7 @@ var componentInfo10 = {
3881
3944
  }
3882
3945
  };
3883
3946
  var _tmpl$11 = /* @__PURE__ */ template(`<div>`);
3884
- var _tmpl$26 = /* @__PURE__ */ template(`<div><div class=builder-tabs-wrap>`);
3947
+ var _tmpl$25 = /* @__PURE__ */ template(`<div><div class=builder-tabs-wrap>`);
3885
3948
  var _tmpl$33 = /* @__PURE__ */ template(`<span>`);
3886
3949
  function Tabs(props) {
3887
3950
  const [activeTab, setActiveTab] = createSignal(props.defaultActiveTab ? props.defaultActiveTab - 1 : 0);
@@ -3896,7 +3959,7 @@ function Tabs(props) {
3896
3959
  }
3897
3960
  }
3898
3961
  return (() => {
3899
- const _el$ = _tmpl$26(), _el$2 = _el$.firstChild;
3962
+ const _el$ = _tmpl$25(), _el$2 = _el$.firstChild;
3900
3963
  _el$2.style.setProperty("display", "flex");
3901
3964
  _el$2.style.setProperty("flex-direction", "row");
3902
3965
  _el$2.style.setProperty("overflow", "auto");
@@ -4428,7 +4491,7 @@ function logFetch(url) {
4428
4491
 
4429
4492
  // src/blocks/form/form/form.tsx
4430
4493
  var _tmpl$15 = /* @__PURE__ */ template(`<pre class="builder-form-error-text pre-04a43b72">`);
4431
- var _tmpl$27 = /* @__PURE__ */ template(`<form>`);
4494
+ var _tmpl$26 = /* @__PURE__ */ template(`<form>`);
4432
4495
  var _tmpl$34 = /* @__PURE__ */ template(`<style>.pre-04a43b72 {
4433
4496
  padding: 10px;
4434
4497
  color: red;
@@ -4621,7 +4684,7 @@ function FormComponent(props) {
4621
4684
  }
4622
4685
  let formRef;
4623
4686
  return [(() => {
4624
- const _el$ = _tmpl$27();
4687
+ const _el$ = _tmpl$26();
4625
4688
  _el$.addEventListener("submit", (event) => onSubmit(event));
4626
4689
  const _ref$ = formRef;
4627
4690
  typeof _ref$ === "function" ? use(_ref$, _el$) : formRef = _el$;
@@ -4833,7 +4896,7 @@ var componentInfo16 = {
4833
4896
  noWrap: true
4834
4897
  };
4835
4898
  var _tmpl$17 = /* @__PURE__ */ template(`<select>`);
4836
- var _tmpl$28 = /* @__PURE__ */ template(`<option>`);
4899
+ var _tmpl$27 = /* @__PURE__ */ template(`<option>`);
4837
4900
  function SelectComponent(props) {
4838
4901
  return (() => {
4839
4902
  const _el$ = _tmpl$17();
@@ -4861,7 +4924,7 @@ function SelectComponent(props) {
4861
4924
  children: (option, _index) => {
4862
4925
  const index = _index();
4863
4926
  return (() => {
4864
- const _el$2 = _tmpl$28();
4927
+ const _el$2 = _tmpl$27();
4865
4928
  insert(_el$2, () => option.name || option.value);
4866
4929
  effect(() => setAttribute(_el$2, "key", `${option.name}-${index}`));
4867
4930
  effect(() => _el$2.value = option.value);
@@ -5105,7 +5168,7 @@ var componentInfo20 = {
5105
5168
  }
5106
5169
  };
5107
5170
  var _tmpl$21 = /* @__PURE__ */ template(`<div>`);
5108
- var _tmpl$29 = /* @__PURE__ */ template(`<div><video class=builder-video><source type=video/mp4>`);
5171
+ var _tmpl$28 = /* @__PURE__ */ template(`<div><video class=builder-video><source type=video/mp4>`);
5109
5172
  function Video(props) {
5110
5173
  const [lazyVideoObserver, setLazyVideoObserver] = createSignal(void 0);
5111
5174
  const videoProps = createMemo(() => {
@@ -5161,7 +5224,7 @@ function Video(props) {
5161
5224
  }
5162
5225
  });
5163
5226
  return (() => {
5164
- const _el$ = _tmpl$29(), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild;
5227
+ const _el$ = _tmpl$28(), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild;
5165
5228
  _el$.style.setProperty("position", "relative");
5166
5229
  const _ref$ = videoRef;
5167
5230
  typeof _ref$ === "function" ? use(_ref$, _el$2) : videoRef = _el$2;
@@ -5298,7 +5361,7 @@ var getDefaultRegisteredComponents = () => [{
5298
5361
  }, {
5299
5362
  component: text_default,
5300
5363
  ...componentInfo11
5301
- }, ...TARGET === "react" ? [{
5364
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
5302
5365
  component: personalization_container_default,
5303
5366
  ...componentInfo6
5304
5367
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -5335,7 +5398,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
5335
5398
 
5336
5399
  // src/components/content-variants/helpers.ts
5337
5400
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
5338
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
5401
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
5339
5402
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
5340
5403
  ...variant,
5341
5404
  testVariationId: variant.id,
@@ -5360,20 +5423,20 @@ var checkShouldRenderVariants2 = ({
5360
5423
  };
5361
5424
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
5362
5425
  var isAngularSDK = TARGET === "angular";
5363
- var isHydrationTarget = getIsHydrationTarget(TARGET);
5426
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
5364
5427
  var getInitVariantsFnsScriptString = () => `
5365
5428
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
5366
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5429
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5367
5430
  `;
5368
5431
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
5369
5432
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
5370
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
5433
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
5371
5434
  )`;
5372
5435
  var getUpdateVariantVisibilityScript = ({
5373
5436
  contentId,
5374
5437
  variationId
5375
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
5376
- "${variationId}", "${contentId}", ${isHydrationTarget}
5438
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
5439
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
5377
5440
  )`;
5378
5441
 
5379
5442
  // src/helpers/preview-lru-cache/get.ts
@@ -5382,7 +5445,7 @@ function getPreviewContent(_searchParams) {
5382
5445
  }
5383
5446
 
5384
5447
  // src/constants/sdk-version.ts
5385
- var SDK_VERSION = "4.0.8";
5448
+ var SDK_VERSION = "4.0.9";
5386
5449
 
5387
5450
  // src/helpers/sdk-headers.ts
5388
5451
  var getSdkHeaders = () => ({
@@ -6805,7 +6868,7 @@ function ContentVariants(props) {
6805
6868
  return !props.isNestedRender && TARGET !== "reactNative";
6806
6869
  },
6807
6870
  get children() {
6808
- return createComponent(inlined_script_default, {
6871
+ return [createComponent(inlined_script_default, {
6809
6872
  id: "builderio-init-variants-fns",
6810
6873
  get scriptStr() {
6811
6874
  return getInitVariantsFnsScriptString();
@@ -6813,7 +6876,22 @@ function ContentVariants(props) {
6813
6876
  get nonce() {
6814
6877
  return props.nonce || "";
6815
6878
  }
6816
- });
6879
+ }), createComponent(Show, {
6880
+ get when() {
6881
+ return SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET);
6882
+ },
6883
+ get children() {
6884
+ return createComponent(inlined_script_default, {
6885
+ id: "builderio-init-personalization-variants-fns",
6886
+ get nonce() {
6887
+ return props.nonce || "";
6888
+ },
6889
+ get scriptStr() {
6890
+ return getInitPersonalizationVariantsFnsScriptString();
6891
+ }
6892
+ });
6893
+ }
6894
+ })];
6817
6895
  }
6818
6896
  }), createComponent(Show, {
6819
6897
  get when() {
@@ -7001,7 +7079,7 @@ var fetchSymbolContent = async ({
7001
7079
  };
7002
7080
 
7003
7081
  // src/blocks/symbol/symbol.tsx
7004
- var _tmpl$30 = /* @__PURE__ */ template(`<div>`);
7082
+ var _tmpl$29 = /* @__PURE__ */ template(`<div>`);
7005
7083
  function Symbol(props) {
7006
7084
  const [contentToUse, setContentToUse] = createSignal(props.symbol?.content);
7007
7085
  const [symbolEntry, setSymbolEntry] = createSignal(props.symbol?.entry);
@@ -7035,7 +7113,7 @@ function Symbol(props) {
7035
7113
  }
7036
7114
  createEffect(on(() => [onUpdateFn_0_props_symbol()], onUpdateFn_0));
7037
7115
  return (() => {
7038
- const _el$ = _tmpl$30();
7116
+ const _el$ = _tmpl$29();
7039
7117
  spread(_el$, mergeProps({
7040
7118
  get ["class"]() {
7041
7119
  return className();