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