@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.
@@ -4766,7 +4766,7 @@ function BlocksWrapper(props) {
4766
4766
  createEffect5(on5(() => [onUpdateFn_0_props_blocks()], onUpdateFn_0));
4767
4767
  return <>
4768
4768
  <Dynamic4
4769
- class={className() + " dynamic-023c60f2"}
4769
+ class={className() + " dynamic-450facf4"}
4770
4770
  ref={blocksWrapperRef}
4771
4771
  builder-path={dataPath()}
4772
4772
  builder-parent-id={props.parent}
@@ -4778,7 +4778,7 @@ function BlocksWrapper(props) {
4778
4778
  {...props.BlocksWrapperProps}
4779
4779
  component={props.BlocksWrapper}
4780
4780
  >{props.children}</Dynamic4>
4781
- <style>{`.dynamic-023c60f2 {
4781
+ <style>{`.dynamic-450facf4 {
4782
4782
  display: flex;
4783
4783
  flex-direction: column;
4784
4784
  align-items: stretch;
@@ -4796,19 +4796,22 @@ function Blocks(props) {
4796
4796
  parent={props.parent}
4797
4797
  path={props.path}
4798
4798
  styleProp={props.styleProp}
4799
+ BlocksWrapperProps={props.BlocksWrapperProps || props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
4799
4800
  classNameProp={props.className}
4800
4801
  BlocksWrapper={props.context?.BlocksWrapper || builderContext?.BlocksWrapper}
4801
- BlocksWrapperProps={props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps}
4802
- ><Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
4803
- const index = _index();
4804
- return <Block_default
4805
- key={block.id}
4806
- block={block}
4807
- linkComponent={props.linkComponent}
4808
- context={props.context || builderContext}
4809
- registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
4810
- />;
4811
- }}</For3></Show6></Blocks_wrapper_default></>;
4802
+ >
4803
+ {props.children}
4804
+ <Show6 when={props.blocks}><For3 each={props.blocks}>{(block, _index) => {
4805
+ const index = _index();
4806
+ return <Block_default
4807
+ key={block.id}
4808
+ block={block}
4809
+ linkComponent={props.linkComponent}
4810
+ context={props.context || builderContext}
4811
+ registeredComponents={props.registeredComponents || componentsContext?.registeredComponents}
4812
+ />;
4813
+ }}</For3></Show6>
4814
+ </Blocks_wrapper_default></>;
4812
4815
  }
4813
4816
  var Blocks_default = Blocks;
4814
4817
 
@@ -5159,6 +5162,166 @@ import { onMount as onMount10, on as on9, createEffect as createEffect9, createM
5159
5162
  // src/components/content-variants/content-variants.tsx
5160
5163
  import { Show as Show16, For as For9, onMount as onMount9, createSignal as createSignal19, createMemo as createMemo19 } from "solid-js";
5161
5164
 
5165
+ // src/blocks/personalization-container/helpers/inlined-fns.ts
5166
+ function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
5167
+ function isString(val) {
5168
+ return typeof val === "string";
5169
+ }
5170
+ function isNumber(val) {
5171
+ return typeof val === "number";
5172
+ }
5173
+ function objectMatchesQuery(userattr, query2) {
5174
+ const result = (() => {
5175
+ const property = query2.property;
5176
+ const operator = query2.operator;
5177
+ let testValue = query2.value;
5178
+ if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
5179
+ testValue = query2.value.slice(0, -1);
5180
+ }
5181
+ if (!(property && operator)) {
5182
+ return true;
5183
+ }
5184
+ if (Array.isArray(testValue)) {
5185
+ if (operator === "isNot") {
5186
+ return testValue.every((val) => objectMatchesQuery(userattr, {
5187
+ property,
5188
+ operator,
5189
+ value: val
5190
+ }));
5191
+ }
5192
+ return !!testValue.find((val) => objectMatchesQuery(userattr, {
5193
+ property,
5194
+ operator,
5195
+ value: val
5196
+ }));
5197
+ }
5198
+ const value = userattr[property];
5199
+ if (Array.isArray(value)) {
5200
+ return value.includes(testValue);
5201
+ }
5202
+ switch (operator) {
5203
+ case "is":
5204
+ return value === testValue;
5205
+ case "isNot":
5206
+ return value !== testValue;
5207
+ case "contains":
5208
+ return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
5209
+ case "startsWith":
5210
+ return isString(value) && value.startsWith(String(testValue));
5211
+ case "endsWith":
5212
+ return isString(value) && value.endsWith(String(testValue));
5213
+ case "greaterThan":
5214
+ return isNumber(value) && isNumber(testValue) && value > testValue;
5215
+ case "lessThan":
5216
+ return isNumber(value) && isNumber(testValue) && value < testValue;
5217
+ case "greaterThanOrEqualTo":
5218
+ return isNumber(value) && isNumber(testValue) && value >= testValue;
5219
+ case "lessThanOrEqualTo":
5220
+ return isNumber(value) && isNumber(testValue) && value <= testValue;
5221
+ default:
5222
+ return false;
5223
+ }
5224
+ })();
5225
+ return result;
5226
+ }
5227
+ const item = {
5228
+ query,
5229
+ startDate,
5230
+ endDate
5231
+ };
5232
+ const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
5233
+ if (item.startDate && new Date(item.startDate) > now) {
5234
+ return false;
5235
+ } else if (item.endDate && new Date(item.endDate) < now) {
5236
+ return false;
5237
+ }
5238
+ if (!item.query || !item.query.length) {
5239
+ return true;
5240
+ }
5241
+ return item.query.every((filter) => {
5242
+ return objectMatchesQuery(userAttributes, filter);
5243
+ });
5244
+ }
5245
+ 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}";
5246
+ 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}";
5247
+ 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}";
5248
+
5249
+ // src/blocks/personalization-container/helpers.ts
5250
+ var DEFAULT_INDEX = "default";
5251
+ var FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME = "filterWithCustomTargeting";
5252
+ var BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME = "builderIoPersonalization";
5253
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "updateVisibilityStylesScript";
5254
+ var SDKS_SUPPORTING_PERSONALIZATION = ["react", "vue", "svelte"];
5255
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte"];
5256
+ function checkShouldRenderVariants(variants, canTrack) {
5257
+ const hasVariants = variants && variants.length > 0;
5258
+ if (TARGET === "reactNative")
5259
+ return false;
5260
+ if (!hasVariants)
5261
+ return false;
5262
+ if (!canTrack)
5263
+ return false;
5264
+ if (SDKS_REQUIRING_RESET_APPROACH.includes(TARGET))
5265
+ return true;
5266
+ if (isBrowser())
5267
+ return false;
5268
+ return true;
5269
+ }
5270
+ function getBlocksToRender({
5271
+ variants,
5272
+ previewingIndex,
5273
+ isHydrated,
5274
+ filteredVariants,
5275
+ fallbackBlocks
5276
+ }) {
5277
+ const fallback = {
5278
+ blocks: fallbackBlocks ?? [],
5279
+ path: "this.children",
5280
+ index: DEFAULT_INDEX
5281
+ };
5282
+ if (isHydrated && isEditing()) {
5283
+ if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
5284
+ const variant = variants?.[previewingIndex];
5285
+ if (variant) {
5286
+ return {
5287
+ blocks: variant.blocks,
5288
+ path: `variants.${previewingIndex}.blocks`,
5289
+ index: previewingIndex
5290
+ };
5291
+ }
5292
+ }
5293
+ return fallback;
5294
+ }
5295
+ if (isBrowser()) {
5296
+ const winningVariant = filteredVariants?.[0];
5297
+ if (winningVariant && variants) {
5298
+ const variantIndex = variants.indexOf(winningVariant);
5299
+ if (variantIndex !== -1) {
5300
+ return {
5301
+ blocks: winningVariant.blocks,
5302
+ path: `variants.${variantIndex}.blocks`,
5303
+ index: variantIndex
5304
+ };
5305
+ }
5306
+ }
5307
+ }
5308
+ return fallback;
5309
+ }
5310
+ var getInitPersonalizationVariantsFnsScriptString = () => {
5311
+ return `
5312
+ window.${FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME} = ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
5313
+ window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME} = ${PERSONALIZATION_SCRIPT}
5314
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VISIBILITY_STYLES_SCRIPT}
5315
+ `;
5316
+ };
5317
+ var isHydrationTarget = TARGET === "react";
5318
+ var getPersonalizationScript = (variants, blockId, locale) => {
5319
+ return `window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
5320
+ };
5321
+ var getUpdateVisibilityStylesScript = (variants, blockId, locale) => {
5322
+ return `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ""})`;
5323
+ };
5324
+
5162
5325
  // src/helpers/url.ts
5163
5326
  var getTopLevelDomain = (host) => {
5164
5327
  if (host === "localhost" || host === "127.0.0.1") {
@@ -6104,7 +6267,8 @@ var componentInfo6 = {
6104
6267
  name: "PersonalizationContainer",
6105
6268
  shouldReceiveBuilderProps: {
6106
6269
  builderBlock: true,
6107
- builderContext: true
6270
+ builderContext: true,
6271
+ builderComponents: true
6108
6272
  },
6109
6273
  noWrap: true,
6110
6274
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -6160,199 +6324,6 @@ function isPreviewing(_search) {
6160
6324
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
6161
6325
  }
6162
6326
 
6163
- // src/blocks/personalization-container/helpers/inlined-fns.ts
6164
- function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
6165
- function isString(val) {
6166
- return typeof val === "string";
6167
- }
6168
- function isNumber(val) {
6169
- return typeof val === "number";
6170
- }
6171
- function objectMatchesQuery(userattr, query2) {
6172
- const result = (() => {
6173
- const property = query2.property;
6174
- const operator = query2.operator;
6175
- let testValue = query2.value;
6176
- if (query2 && query2.property === "urlPath" && query2.value && typeof query2.value === "string" && query2.value !== "/" && query2.value.endsWith("/")) {
6177
- testValue = query2.value.slice(0, -1);
6178
- }
6179
- if (!(property && operator)) {
6180
- return true;
6181
- }
6182
- if (Array.isArray(testValue)) {
6183
- if (operator === "isNot") {
6184
- return testValue.every((val) => objectMatchesQuery(userattr, {
6185
- property,
6186
- operator,
6187
- value: val
6188
- }));
6189
- }
6190
- return !!testValue.find((val) => objectMatchesQuery(userattr, {
6191
- property,
6192
- operator,
6193
- value: val
6194
- }));
6195
- }
6196
- const value = userattr[property];
6197
- if (Array.isArray(value)) {
6198
- return value.includes(testValue);
6199
- }
6200
- switch (operator) {
6201
- case "is":
6202
- return value === testValue;
6203
- case "isNot":
6204
- return value !== testValue;
6205
- case "contains":
6206
- return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
6207
- case "startsWith":
6208
- return isString(value) && value.startsWith(String(testValue));
6209
- case "endsWith":
6210
- return isString(value) && value.endsWith(String(testValue));
6211
- case "greaterThan":
6212
- return isNumber(value) && isNumber(testValue) && value > testValue;
6213
- case "lessThan":
6214
- return isNumber(value) && isNumber(testValue) && value < testValue;
6215
- case "greaterThanOrEqualTo":
6216
- return isNumber(value) && isNumber(testValue) && value >= testValue;
6217
- case "lessThanOrEqualTo":
6218
- return isNumber(value) && isNumber(testValue) && value <= testValue;
6219
- default:
6220
- return false;
6221
- }
6222
- })();
6223
- return result;
6224
- }
6225
- const item = {
6226
- query,
6227
- startDate,
6228
- endDate
6229
- };
6230
- const now = userAttributes.date && new Date(userAttributes.date) || /* @__PURE__ */ new Date();
6231
- if (item.startDate && new Date(item.startDate) > now) {
6232
- return false;
6233
- } else if (item.endDate && new Date(item.endDate) < now) {
6234
- return false;
6235
- }
6236
- if (!item.query || !item.query.length) {
6237
- return true;
6238
- }
6239
- return item.query.every((filter) => {
6240
- return objectMatchesQuery(userAttributes, filter);
6241
- });
6242
- }
6243
- var PERSONALIZATION_SCRIPT = `function getPersonalizedVariant(variants, blockId, locale) {
6244
- if (!navigator.cookieEnabled) {
6245
- return;
6246
- }
6247
- function getCookie(name) {
6248
- const nameEQ = name + '=';
6249
- const ca = document.cookie.split(';');
6250
- for (let i = 0; i < ca.length; i++) {
6251
- let c = ca[i];
6252
- while (c.charAt(0) == ' ') c = c.substring(1, c.length);
6253
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
6254
- }
6255
- return null;
6256
- }
6257
- function removeVariants() {
6258
- variants?.forEach(function (_, index) {
6259
- document.querySelector('template[data-variant-id="' + blockId + '-' + index + '"]')?.remove();
6260
- });
6261
- document.querySelector('script[data-id="variants-script-' + blockId + '"]')?.remove();
6262
- document.querySelector('style[data-id="variants-styles-' + blockId + '"]')?.remove();
6263
- }
6264
- const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
6265
- if (locale) {
6266
- attributes.locale = locale;
6267
- }
6268
- const winningVariantIndex = variants?.findIndex(function (variant) {
6269
- return filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
6270
- });
6271
- const isDebug = location.href.includes('builder.debug=true');
6272
- if (isDebug) {
6273
- console.debug('PersonalizationContainer', {
6274
- attributes,
6275
- variants,
6276
- winningVariantIndex
6277
- });
6278
- }
6279
- if (winningVariantIndex !== -1) {
6280
- const winningVariant = document.querySelector('template[data-variant-id="' + blockId + '-' + winningVariantIndex + '"]');
6281
- if (winningVariant) {
6282
- const parentNode = winningVariant.parentNode;
6283
- if (parentNode) {
6284
- const newParent = parentNode.cloneNode(false);
6285
- newParent.appendChild(winningVariant.content.firstChild);
6286
- newParent.appendChild(winningVariant.content.lastChild);
6287
- parentNode.parentNode?.replaceChild(newParent, parentNode);
6288
- }
6289
- if (isDebug) {
6290
- console.debug('PersonalizationContainer', 'Winning variant Replaced:', winningVariant);
6291
- }
6292
- }
6293
- } else if (variants && variants.length > 0) {
6294
- removeVariants();
6295
- }
6296
- }`;
6297
- 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}";
6298
-
6299
- // src/blocks/personalization-container/helpers.ts
6300
- function checkShouldRenderVariants(variants, canTrack) {
6301
- const hasVariants = variants && variants.length > 0;
6302
- if (TARGET === "reactNative")
6303
- return false;
6304
- if (!hasVariants)
6305
- return false;
6306
- if (!canTrack)
6307
- return false;
6308
- if (TARGET === "vue" || TARGET === "svelte")
6309
- return true;
6310
- if (isBrowser())
6311
- return false;
6312
- return true;
6313
- }
6314
- function getBlocksToRender({
6315
- variants,
6316
- previewingIndex,
6317
- isHydrated,
6318
- filteredVariants,
6319
- fallbackBlocks
6320
- }) {
6321
- const fallback = {
6322
- blocks: fallbackBlocks ?? [],
6323
- path: "this.children"
6324
- };
6325
- if (isHydrated && isEditing()) {
6326
- if (typeof previewingIndex === "number" && previewingIndex < (variants?.length ?? 0)) {
6327
- const variant = variants[previewingIndex];
6328
- return {
6329
- blocks: variant.blocks,
6330
- path: `component.options.variants.${previewingIndex}.blocks`
6331
- };
6332
- }
6333
- return fallback;
6334
- }
6335
- if (isBrowser()) {
6336
- const winningVariant = filteredVariants?.[0];
6337
- if (winningVariant) {
6338
- return {
6339
- blocks: winningVariant.blocks,
6340
- path: `component.options.variants.${variants?.indexOf(winningVariant)}.blocks`
6341
- };
6342
- }
6343
- }
6344
- return fallback;
6345
- }
6346
- var getPersonalizationScript = (variants, blockId, locale) => {
6347
- return `
6348
- (function() {
6349
- ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
6350
- ${PERSONALIZATION_SCRIPT}
6351
- getPersonalizedVariant(${JSON.stringify(variants)}, "${blockId}"${locale ? `, "${locale}"` : ""})
6352
- })();
6353
- `;
6354
- };
6355
-
6356
6327
  // src/blocks/personalization-container/personalization-container.tsx
6357
6328
  function PersonalizationContainer(props) {
6358
6329
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -6365,6 +6336,13 @@ function PersonalizationContainer(props) {
6365
6336
  props.builderContext?.rootState?.locale
6366
6337
  )
6367
6338
  );
6339
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
6340
+ getUpdateVisibilityStylesScript(
6341
+ props.variants,
6342
+ props.builderBlock?.id || "none",
6343
+ props.builderContext?.rootState?.locale
6344
+ )
6345
+ );
6368
6346
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
6369
6347
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
6370
6348
  checkShouldRenderVariants(
@@ -6372,7 +6350,14 @@ function PersonalizationContainer(props) {
6372
6350
  getDefaultCanTrack(props.builderContext?.canTrack)
6373
6351
  )
6374
6352
  );
6375
- const [isHydrated, setIsHydrated] = createSignal10(false);
6353
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
6354
+ const attrs = createMemo10(() => {
6355
+ return {
6356
+ ...props.attributes,
6357
+ ...{},
6358
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
6359
+ };
6360
+ });
6376
6361
  const filteredVariants = createMemo10(() => {
6377
6362
  return (props.variants || []).filter((variant) => {
6378
6363
  return filterWithCustomTargeting(
@@ -6392,22 +6377,22 @@ function PersonalizationContainer(props) {
6392
6377
  return getBlocksToRender({
6393
6378
  variants: props.variants,
6394
6379
  fallbackBlocks: props.builderBlock?.children,
6395
- isHydrated: isHydrated(),
6380
+ isHydrated: shouldResetVariants(),
6396
6381
  filteredVariants: filteredVariants(),
6397
6382
  previewingIndex: props.previewingIndex
6398
6383
  });
6399
6384
  });
6400
6385
  const hideVariantsStyleString = createMemo10(() => {
6401
6386
  return (props.variants || []).map(
6402
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
6387
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
6403
6388
  ).join("");
6404
6389
  });
6405
6390
  let rootRef;
6406
6391
  onMount5(() => {
6407
- setIsHydrated(true);
6392
+ setShouldResetVariants(true);
6408
6393
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
6409
- (attrs) => {
6410
- setUserAttributes(attrs);
6394
+ (attrs2) => {
6395
+ setUserAttributes(attrs2);
6411
6396
  }
6412
6397
  );
6413
6398
  if (!(isEditing() || isPreviewing())) {
@@ -6416,7 +6401,7 @@ function PersonalizationContainer(props) {
6416
6401
  rootRef.dispatchEvent(
6417
6402
  new CustomEvent("builder.variantLoaded", {
6418
6403
  detail: {
6419
- variant: variant || "default",
6404
+ variant: variant || DEFAULT_INDEX,
6420
6405
  content: props.builderContext?.content
6421
6406
  },
6422
6407
  bubbles: true
@@ -6428,7 +6413,7 @@ function PersonalizationContainer(props) {
6428
6413
  rootRef.dispatchEvent(
6429
6414
  new CustomEvent("builder.variantDisplayed", {
6430
6415
  detail: {
6431
- variant: variant || "default",
6416
+ variant: variant || DEFAULT_INDEX,
6432
6417
  content: props.builderContext?.content
6433
6418
  },
6434
6419
  bubbles: true
@@ -6442,39 +6427,72 @@ function PersonalizationContainer(props) {
6442
6427
  }
6443
6428
  unsubscribers().push(unsub);
6444
6429
  });
6445
- return <><div
6446
- class={`builder-personalization-container ${props.attributes?.className || ""}`}
6447
- ref={rootRef}
6448
- {...props.attributes}
6449
- >
6450
- <Show10 when={shouldRenderVariants()}>
6451
- <For6 each={props.variants}>{(variant, _index) => {
6452
- const index = _index();
6453
- return <template
6454
- key={index}
6455
- data-variant-id={`${props.builderBlock?.id}-${index}`}
6456
- ><Blocks_default
6457
- blocks={variant.blocks}
6458
- parent={props.builderBlock?.id}
6459
- path={`component.options.variants.${index}.blocks`}
6460
- /></template>;
6461
- }}</For6>
6462
- <Inlined_styles_default
6463
- nonce={props.builderContext?.nonce || ""}
6464
- styles={hideVariantsStyleString()}
6465
- id={`variants-styles-${props.builderBlock?.id}`}
6466
- />
6467
- <Inlined_script_default
6468
- nonce={props.builderContext?.nonce || ""}
6469
- scriptStr={scriptStr()}
6470
- id={`variants-script-${props.builderBlock?.id}`}
6471
- />
6472
- </Show10>
6473
- <Blocks_default
6430
+ return <><div ref={rootRef} {...attrs()}>
6431
+ <Show10
6432
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
6433
+ ><Blocks_default
6474
6434
  blocks={blocksToRender().blocks}
6475
6435
  parent={props.builderBlock?.id}
6476
6436
  path={blocksToRender().path}
6477
- />
6437
+ context={props.builderContext}
6438
+ registeredComponents={props.builderComponents}
6439
+ BlocksWrapperProps={{
6440
+ ...props.builderContext?.BlocksWrapperProps,
6441
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
6442
+ }}
6443
+ /></Show10>
6444
+ <Show10
6445
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
6446
+ >
6447
+ <Show10 when={shouldRenderVariants()}>
6448
+ <Inlined_styles_default
6449
+ nonce={props.builderContext?.nonce || ""}
6450
+ styles={hideVariantsStyleString()}
6451
+ id={`variants-styles-${props.builderBlock?.id}`}
6452
+ />
6453
+ <Inlined_script_default
6454
+ nonce={props.builderContext?.nonce || ""}
6455
+ scriptStr={updateVisibilityStylesScript()}
6456
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
6457
+ />
6458
+ <For6 each={props.variants}>{(variant, _index) => {
6459
+ const index = _index();
6460
+ return <Blocks_default
6461
+ key={`${props.builderBlock?.id}-${index}`}
6462
+ BlocksWrapperProps={{
6463
+ ...props.builderContext?.BlocksWrapperProps,
6464
+ "aria-hidden": true,
6465
+ hidden: true,
6466
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
6467
+ }}
6468
+ blocks={variant.blocks}
6469
+ parent={props.builderBlock?.id}
6470
+ path={`component.options.variants.${index}.blocks`}
6471
+ context={props.builderContext}
6472
+ registeredComponents={props.builderComponents}
6473
+ ><Inlined_script_default
6474
+ nonce={props.builderContext?.nonce || ""}
6475
+ scriptStr={scriptStr()}
6476
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
6477
+ /></Blocks_default>;
6478
+ }}</For6>
6479
+ </Show10>
6480
+ <Blocks_default
6481
+ blocks={blocksToRender().blocks}
6482
+ parent={props.builderBlock?.id}
6483
+ path={blocksToRender().path}
6484
+ context={props.builderContext}
6485
+ registeredComponents={props.builderComponents}
6486
+ BlocksWrapperProps={{
6487
+ ...props.builderContext?.BlocksWrapperProps,
6488
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
6489
+ }}
6490
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
6491
+ nonce={props.builderContext?.nonce || ""}
6492
+ scriptStr={scriptStr()}
6493
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
6494
+ /></Show10></Blocks_default>
6495
+ </Show10>
6478
6496
  </div></>;
6479
6497
  }
6480
6498
  var personalization_container_default = PersonalizationContainer;
@@ -7996,7 +8014,7 @@ var getDefaultRegisteredComponents = () => [{
7996
8014
  }, {
7997
8015
  component: text_default,
7998
8016
  ...componentInfo11
7999
- }, ...TARGET === "react" ? [{
8017
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
8000
8018
  component: personalization_container_default,
8001
8019
  ...componentInfo6
8002
8020
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -8033,7 +8051,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
8033
8051
 
8034
8052
  // src/components/content-variants/helpers.ts
8035
8053
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
8036
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
8054
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
8037
8055
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
8038
8056
  ...variant,
8039
8057
  testVariationId: variant.id,
@@ -8058,20 +8076,20 @@ var checkShouldRenderVariants2 = ({
8058
8076
  };
8059
8077
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
8060
8078
  var isAngularSDK = TARGET === "angular";
8061
- var isHydrationTarget = getIsHydrationTarget(TARGET);
8079
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
8062
8080
  var getInitVariantsFnsScriptString = () => `
8063
8081
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
8064
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
8082
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
8065
8083
  `;
8066
8084
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
8067
8085
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
8068
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
8086
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
8069
8087
  )`;
8070
8088
  var getUpdateVariantVisibilityScript = ({
8071
8089
  contentId,
8072
8090
  variationId
8073
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
8074
- "${variationId}", "${contentId}", ${isHydrationTarget}
8091
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
8092
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
8075
8093
  )`;
8076
8094
 
8077
8095
  // src/components/content/components/enable-editor.tsx
@@ -8091,7 +8109,7 @@ function getPreviewContent(_searchParams) {
8091
8109
  }
8092
8110
 
8093
8111
  // src/constants/sdk-version.ts
8094
- var SDK_VERSION = "4.0.8";
8112
+ var SDK_VERSION = "4.0.9";
8095
8113
 
8096
8114
  // src/helpers/sdk-headers.ts
8097
8115
  var getSdkHeaders = () => ({
@@ -9450,11 +9468,18 @@ function ContentVariants(props) {
9450
9468
  setShouldRenderVariants(false);
9451
9469
  });
9452
9470
  return <><>
9453
- <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}><Inlined_script_default
9454
- id="builderio-init-variants-fns"
9455
- scriptStr={getInitVariantsFnsScriptString()}
9456
- nonce={props.nonce || ""}
9457
- /></Show16>
9471
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
9472
+ <Inlined_script_default
9473
+ id="builderio-init-variants-fns"
9474
+ scriptStr={getInitVariantsFnsScriptString()}
9475
+ nonce={props.nonce || ""}
9476
+ />
9477
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
9478
+ id="builderio-init-personalization-variants-fns"
9479
+ nonce={props.nonce || ""}
9480
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
9481
+ /></Show16>
9482
+ </Show16>
9458
9483
  <Show16 when={shouldRenderVariants()}>
9459
9484
  <Inlined_styles_default
9460
9485
  id="builderio-variants"