@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.
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"];
2251
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte"];
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") {
@@ -3101,7 +3264,8 @@ var componentInfo6 = {
3101
3264
  name: "PersonalizationContainer",
3102
3265
  shouldReceiveBuilderProps: {
3103
3266
  builderBlock: true,
3104
- builderContext: true
3267
+ builderContext: true,
3268
+ builderComponents: true
3105
3269
  },
3106
3270
  noWrap: true,
3107
3271
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -3157,199 +3321,6 @@ function isPreviewing(_search) {
3157
3321
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
3158
3322
  }
3159
3323
 
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
3324
  // src/blocks/personalization-container/personalization-container.tsx
3354
3325
  function PersonalizationContainer(props) {
3355
3326
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -3362,6 +3333,13 @@ function PersonalizationContainer(props) {
3362
3333
  props.builderContext?.rootState?.locale
3363
3334
  )
3364
3335
  );
3336
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
3337
+ getUpdateVisibilityStylesScript(
3338
+ props.variants,
3339
+ props.builderBlock?.id || "none",
3340
+ props.builderContext?.rootState?.locale
3341
+ )
3342
+ );
3365
3343
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
3366
3344
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
3367
3345
  checkShouldRenderVariants(
@@ -3369,7 +3347,14 @@ function PersonalizationContainer(props) {
3369
3347
  getDefaultCanTrack(props.builderContext?.canTrack)
3370
3348
  )
3371
3349
  );
3372
- const [isHydrated, setIsHydrated] = createSignal10(false);
3350
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
3351
+ const attrs = createMemo10(() => {
3352
+ return {
3353
+ ...props.attributes,
3354
+ ...{},
3355
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
3356
+ };
3357
+ });
3373
3358
  const filteredVariants = createMemo10(() => {
3374
3359
  return (props.variants || []).filter((variant) => {
3375
3360
  return filterWithCustomTargeting(
@@ -3389,22 +3374,22 @@ function PersonalizationContainer(props) {
3389
3374
  return getBlocksToRender({
3390
3375
  variants: props.variants,
3391
3376
  fallbackBlocks: props.builderBlock?.children,
3392
- isHydrated: isHydrated(),
3377
+ isHydrated: shouldResetVariants(),
3393
3378
  filteredVariants: filteredVariants(),
3394
3379
  previewingIndex: props.previewingIndex
3395
3380
  });
3396
3381
  });
3397
3382
  const hideVariantsStyleString = createMemo10(() => {
3398
3383
  return (props.variants || []).map(
3399
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
3384
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
3400
3385
  ).join("");
3401
3386
  });
3402
3387
  let rootRef;
3403
3388
  onMount5(() => {
3404
- setIsHydrated(true);
3389
+ setShouldResetVariants(true);
3405
3390
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
3406
- (attrs) => {
3407
- setUserAttributes(attrs);
3391
+ (attrs2) => {
3392
+ setUserAttributes(attrs2);
3408
3393
  }
3409
3394
  );
3410
3395
  if (!(isEditing() || isPreviewing())) {
@@ -3413,7 +3398,7 @@ function PersonalizationContainer(props) {
3413
3398
  rootRef.dispatchEvent(
3414
3399
  new CustomEvent("builder.variantLoaded", {
3415
3400
  detail: {
3416
- variant: variant || "default",
3401
+ variant: variant || DEFAULT_INDEX,
3417
3402
  content: props.builderContext?.content
3418
3403
  },
3419
3404
  bubbles: true
@@ -3425,7 +3410,7 @@ function PersonalizationContainer(props) {
3425
3410
  rootRef.dispatchEvent(
3426
3411
  new CustomEvent("builder.variantDisplayed", {
3427
3412
  detail: {
3428
- variant: variant || "default",
3413
+ variant: variant || DEFAULT_INDEX,
3429
3414
  content: props.builderContext?.content
3430
3415
  },
3431
3416
  bubbles: true
@@ -3439,39 +3424,72 @@ function PersonalizationContainer(props) {
3439
3424
  }
3440
3425
  unsubscribers().push(unsub);
3441
3426
  });
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
3427
+ return <><div ref={rootRef} {...attrs()}>
3428
+ <Show10
3429
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3430
+ ><Blocks_default
3471
3431
  blocks={blocksToRender().blocks}
3472
3432
  parent={props.builderBlock?.id}
3473
3433
  path={blocksToRender().path}
3474
- />
3434
+ context={props.builderContext}
3435
+ registeredComponents={props.builderComponents}
3436
+ BlocksWrapperProps={{
3437
+ ...props.builderContext?.BlocksWrapperProps,
3438
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3439
+ }}
3440
+ /></Show10>
3441
+ <Show10
3442
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
3443
+ >
3444
+ <Show10 when={shouldRenderVariants()}>
3445
+ <Inlined_styles_default
3446
+ nonce={props.builderContext?.nonce || ""}
3447
+ styles={hideVariantsStyleString()}
3448
+ id={`variants-styles-${props.builderBlock?.id}`}
3449
+ />
3450
+ <Inlined_script_default
3451
+ nonce={props.builderContext?.nonce || ""}
3452
+ scriptStr={updateVisibilityStylesScript()}
3453
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
3454
+ />
3455
+ <For6 each={props.variants}>{(variant, _index) => {
3456
+ const index = _index();
3457
+ return <Blocks_default
3458
+ key={`${props.builderBlock?.id}-${index}`}
3459
+ BlocksWrapperProps={{
3460
+ ...props.builderContext?.BlocksWrapperProps,
3461
+ "aria-hidden": true,
3462
+ hidden: true,
3463
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
3464
+ }}
3465
+ blocks={variant.blocks}
3466
+ parent={props.builderBlock?.id}
3467
+ path={`component.options.variants.${index}.blocks`}
3468
+ context={props.builderContext}
3469
+ registeredComponents={props.builderComponents}
3470
+ ><Inlined_script_default
3471
+ nonce={props.builderContext?.nonce || ""}
3472
+ scriptStr={scriptStr()}
3473
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
3474
+ /></Blocks_default>;
3475
+ }}</For6>
3476
+ </Show10>
3477
+ <Blocks_default
3478
+ blocks={blocksToRender().blocks}
3479
+ parent={props.builderBlock?.id}
3480
+ path={blocksToRender().path}
3481
+ context={props.builderContext}
3482
+ registeredComponents={props.builderComponents}
3483
+ BlocksWrapperProps={{
3484
+ ...props.builderContext?.BlocksWrapperProps,
3485
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
3486
+ }}
3487
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
3488
+ nonce={props.builderContext?.nonce || ""}
3489
+ scriptStr={scriptStr()}
3490
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
3491
+ /></Show10></Blocks_default>
3492
+ </Show10>
3475
3493
  </div></>;
3476
3494
  }
3477
3495
  var personalization_container_default = PersonalizationContainer;
@@ -4994,7 +5012,7 @@ var getDefaultRegisteredComponents = () => [{
4994
5012
  }, {
4995
5013
  component: text_default,
4996
5014
  ...componentInfo11
4997
- }, ...TARGET === "react" ? [{
5015
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
4998
5016
  component: personalization_container_default,
4999
5017
  ...componentInfo6
5000
5018
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -5031,7 +5049,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
5031
5049
 
5032
5050
  // src/components/content-variants/helpers.ts
5033
5051
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
5034
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
5052
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
5035
5053
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
5036
5054
  ...variant,
5037
5055
  testVariationId: variant.id,
@@ -5056,20 +5074,20 @@ var checkShouldRenderVariants2 = ({
5056
5074
  };
5057
5075
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
5058
5076
  var isAngularSDK = TARGET === "angular";
5059
- var isHydrationTarget = getIsHydrationTarget(TARGET);
5077
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
5060
5078
  var getInitVariantsFnsScriptString = () => `
5061
5079
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
5062
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5080
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
5063
5081
  `;
5064
5082
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
5065
5083
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
5066
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
5084
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
5067
5085
  )`;
5068
5086
  var getUpdateVariantVisibilityScript = ({
5069
5087
  contentId,
5070
5088
  variationId
5071
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
5072
- "${variationId}", "${contentId}", ${isHydrationTarget}
5089
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
5090
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
5073
5091
  )`;
5074
5092
 
5075
5093
  // src/components/content/components/enable-editor.tsx
@@ -5089,7 +5107,7 @@ function getPreviewContent(_searchParams) {
5089
5107
  }
5090
5108
 
5091
5109
  // src/constants/sdk-version.ts
5092
- var SDK_VERSION = "4.0.8";
5110
+ var SDK_VERSION = "4.0.9";
5093
5111
 
5094
5112
  // src/helpers/sdk-headers.ts
5095
5113
  var getSdkHeaders = () => ({
@@ -6455,11 +6473,18 @@ function ContentVariants(props) {
6455
6473
  setShouldRenderVariants(false);
6456
6474
  });
6457
6475
  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>
6476
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
6477
+ <Inlined_script_default
6478
+ id="builderio-init-variants-fns"
6479
+ scriptStr={getInitVariantsFnsScriptString()}
6480
+ nonce={props.nonce || ""}
6481
+ />
6482
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
6483
+ id="builderio-init-personalization-variants-fns"
6484
+ nonce={props.nonce || ""}
6485
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
6486
+ /></Show16>
6487
+ </Show16>
6463
6488
  <Show16 when={shouldRenderVariants()}>
6464
6489
  <Inlined_styles_default
6465
6490
  id="builderio-variants"