@builder.io/sdk-solid 4.0.8 → 4.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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", "qwik"];
5255
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte", "qwik"];
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") {
@@ -5347,6 +5510,11 @@ var handleABTesting = async ({
5347
5510
  };
5348
5511
  };
5349
5512
 
5513
+ // src/helpers/no-serialize-wrapper.ts
5514
+ function noSerializeWrapper(fn) {
5515
+ return fn;
5516
+ }
5517
+
5350
5518
  // src/helpers/user-attributes.ts
5351
5519
  var USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
5352
5520
  function createUserAttributesService() {
@@ -5377,18 +5545,32 @@ function createUserAttributesService() {
5377
5545
  canTrack
5378
5546
  }) || "{}");
5379
5547
  },
5380
- subscribeOnUserAttributesChange(callback) {
5548
+ subscribeOnUserAttributesChange(callback, {
5549
+ fireImmediately
5550
+ } = {}) {
5381
5551
  subscribers.add(callback);
5382
- return () => {
5552
+ if (fireImmediately) {
5553
+ callback(this.getUserAttributes());
5554
+ }
5555
+ return noSerializeWrapper(function() {
5383
5556
  subscribers.delete(callback);
5384
- };
5557
+ });
5385
5558
  },
5386
5559
  setCanTrack(value) {
5387
5560
  canTrack = value;
5388
5561
  }
5389
5562
  };
5390
5563
  }
5391
- var userAttributesService = createUserAttributesService();
5564
+ var _userAttributesService;
5565
+ if (isBrowser() && TARGET === "qwik") {
5566
+ if (!window.__BUILDER_USER_ATTRIBUTES_SERVICE__) {
5567
+ window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
5568
+ }
5569
+ _userAttributesService = window.__BUILDER_USER_ATTRIBUTES_SERVICE__;
5570
+ } else {
5571
+ _userAttributesService = createUserAttributesService();
5572
+ }
5573
+ var userAttributesService = _userAttributesService;
5392
5574
  var setClientUserAttributes = (attributes) => {
5393
5575
  userAttributesService.setUserAttributes(attributes);
5394
5576
  };
@@ -6104,7 +6286,8 @@ var componentInfo6 = {
6104
6286
  name: "PersonalizationContainer",
6105
6287
  shouldReceiveBuilderProps: {
6106
6288
  builderBlock: true,
6107
- builderContext: true
6289
+ builderContext: true,
6290
+ builderComponents: true
6108
6291
  },
6109
6292
  noWrap: true,
6110
6293
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -6160,199 +6343,6 @@ function isPreviewing(_search) {
6160
6343
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
6161
6344
  }
6162
6345
 
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
6346
  // src/blocks/personalization-container/personalization-container.tsx
6357
6347
  function PersonalizationContainer(props) {
6358
6348
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -6365,6 +6355,13 @@ function PersonalizationContainer(props) {
6365
6355
  props.builderContext?.rootState?.locale
6366
6356
  )
6367
6357
  );
6358
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
6359
+ getUpdateVisibilityStylesScript(
6360
+ props.variants,
6361
+ props.builderBlock?.id || "none",
6362
+ props.builderContext?.rootState?.locale
6363
+ )
6364
+ );
6368
6365
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
6369
6366
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
6370
6367
  checkShouldRenderVariants(
@@ -6372,7 +6369,14 @@ function PersonalizationContainer(props) {
6372
6369
  getDefaultCanTrack(props.builderContext?.canTrack)
6373
6370
  )
6374
6371
  );
6375
- const [isHydrated, setIsHydrated] = createSignal10(false);
6372
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
6373
+ const attrs = createMemo10(() => {
6374
+ return {
6375
+ ...props.attributes,
6376
+ ...{},
6377
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
6378
+ };
6379
+ });
6376
6380
  const filteredVariants = createMemo10(() => {
6377
6381
  return (props.variants || []).filter((variant) => {
6378
6382
  return filterWithCustomTargeting(
@@ -6392,22 +6396,25 @@ function PersonalizationContainer(props) {
6392
6396
  return getBlocksToRender({
6393
6397
  variants: props.variants,
6394
6398
  fallbackBlocks: props.builderBlock?.children,
6395
- isHydrated: isHydrated(),
6399
+ isHydrated: shouldResetVariants(),
6396
6400
  filteredVariants: filteredVariants(),
6397
6401
  previewingIndex: props.previewingIndex
6398
6402
  });
6399
6403
  });
6400
6404
  const hideVariantsStyleString = createMemo10(() => {
6401
6405
  return (props.variants || []).map(
6402
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
6406
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
6403
6407
  ).join("");
6404
6408
  });
6405
6409
  let rootRef;
6406
6410
  onMount5(() => {
6407
- setIsHydrated(true);
6411
+ setShouldResetVariants(true);
6408
6412
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
6409
- (attrs) => {
6410
- setUserAttributes(attrs);
6413
+ (attrs2) => {
6414
+ setUserAttributes(attrs2);
6415
+ },
6416
+ {
6417
+ fireImmediately: TARGET === "qwik"
6411
6418
  }
6412
6419
  );
6413
6420
  if (!(isEditing() || isPreviewing())) {
@@ -6416,7 +6423,7 @@ function PersonalizationContainer(props) {
6416
6423
  rootRef.dispatchEvent(
6417
6424
  new CustomEvent("builder.variantLoaded", {
6418
6425
  detail: {
6419
- variant: variant || "default",
6426
+ variant: variant || DEFAULT_INDEX,
6420
6427
  content: props.builderContext?.content
6421
6428
  },
6422
6429
  bubbles: true
@@ -6428,7 +6435,7 @@ function PersonalizationContainer(props) {
6428
6435
  rootRef.dispatchEvent(
6429
6436
  new CustomEvent("builder.variantDisplayed", {
6430
6437
  detail: {
6431
- variant: variant || "default",
6438
+ variant: variant || DEFAULT_INDEX,
6432
6439
  content: props.builderContext?.content
6433
6440
  },
6434
6441
  bubbles: true
@@ -6442,39 +6449,72 @@ function PersonalizationContainer(props) {
6442
6449
  }
6443
6450
  unsubscribers().push(unsub);
6444
6451
  });
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
6452
+ return <><div ref={rootRef} {...attrs()}>
6453
+ <Show10
6454
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
6455
+ ><Blocks_default
6474
6456
  blocks={blocksToRender().blocks}
6475
6457
  parent={props.builderBlock?.id}
6476
6458
  path={blocksToRender().path}
6477
- />
6459
+ context={props.builderContext}
6460
+ registeredComponents={props.builderComponents}
6461
+ BlocksWrapperProps={{
6462
+ ...props.builderContext?.BlocksWrapperProps,
6463
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
6464
+ }}
6465
+ /></Show10>
6466
+ <Show10
6467
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
6468
+ >
6469
+ <Show10 when={shouldRenderVariants()}>
6470
+ <Inlined_styles_default
6471
+ nonce={props.builderContext?.nonce || ""}
6472
+ styles={hideVariantsStyleString()}
6473
+ id={`variants-styles-${props.builderBlock?.id}`}
6474
+ />
6475
+ <Inlined_script_default
6476
+ nonce={props.builderContext?.nonce || ""}
6477
+ scriptStr={updateVisibilityStylesScript()}
6478
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
6479
+ />
6480
+ <For6 each={props.variants}>{(variant, _index) => {
6481
+ const index = _index();
6482
+ return <Blocks_default
6483
+ key={`${props.builderBlock?.id}-${index}`}
6484
+ BlocksWrapperProps={{
6485
+ ...props.builderContext?.BlocksWrapperProps,
6486
+ "aria-hidden": true,
6487
+ hidden: true,
6488
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
6489
+ }}
6490
+ blocks={variant.blocks}
6491
+ parent={props.builderBlock?.id}
6492
+ path={`component.options.variants.${index}.blocks`}
6493
+ context={props.builderContext}
6494
+ registeredComponents={props.builderComponents}
6495
+ ><Inlined_script_default
6496
+ nonce={props.builderContext?.nonce || ""}
6497
+ scriptStr={scriptStr()}
6498
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
6499
+ /></Blocks_default>;
6500
+ }}</For6>
6501
+ </Show10>
6502
+ <Blocks_default
6503
+ blocks={blocksToRender().blocks}
6504
+ parent={props.builderBlock?.id}
6505
+ path={blocksToRender().path}
6506
+ context={props.builderContext}
6507
+ registeredComponents={props.builderComponents}
6508
+ BlocksWrapperProps={{
6509
+ ...props.builderContext?.BlocksWrapperProps,
6510
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
6511
+ }}
6512
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
6513
+ nonce={props.builderContext?.nonce || ""}
6514
+ scriptStr={scriptStr()}
6515
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
6516
+ /></Show10></Blocks_default>
6517
+ </Show10>
6478
6518
  </div></>;
6479
6519
  }
6480
6520
  var personalization_container_default = PersonalizationContainer;
@@ -7355,6 +7395,14 @@ function FormComponent(props) {
7355
7395
  }
7356
7396
  }
7357
7397
  setFormState("sending");
7398
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
7399
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
7400
+ setFormState("error");
7401
+ mergeNewRootState({
7402
+ formErrorMessage: message
7403
+ });
7404
+ return;
7405
+ }
7358
7406
  const formUrl = `${getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(
7359
7407
  props.sendSubmissionsToEmail || ""
7360
7408
  )}&name=${encodeURIComponent(props.name || "")}`;
@@ -7373,17 +7421,30 @@ function FormComponent(props) {
7373
7421
  } else {
7374
7422
  body2 = await res.text();
7375
7423
  }
7376
- if (!res.ok && props.errorMessagePath) {
7377
- let message = get(body2, props.errorMessagePath);
7378
- if (message) {
7379
- if (typeof message !== "string") {
7380
- message = JSON.stringify(message);
7424
+ if (!res.ok) {
7425
+ const submitErrorEvent = new CustomEvent("submit:error", {
7426
+ detail: {
7427
+ error: body2,
7428
+ status: res.status
7381
7429
  }
7382
- setFormErrorMessage(message);
7383
- mergeNewRootState({
7384
- formErrorMessage: message
7385
- });
7430
+ });
7431
+ if (formRef?.nativeElement) {
7432
+ formRef?.nativeElement.dispatchEvent(submitErrorEvent);
7433
+ if (submitErrorEvent.defaultPrevented) {
7434
+ return;
7435
+ }
7436
+ }
7437
+ setResponseData(body2);
7438
+ setFormState("error");
7439
+ let message = props.errorMessagePath ? get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
7440
+ if (typeof message !== "string") {
7441
+ message = JSON.stringify(message);
7386
7442
  }
7443
+ setFormErrorMessage(message);
7444
+ mergeNewRootState({
7445
+ formErrorMessage: message
7446
+ });
7447
+ return;
7387
7448
  }
7388
7449
  setResponseData(body2);
7389
7450
  setFormState(res.ok ? "success" : "error");
@@ -7462,14 +7523,14 @@ function FormComponent(props) {
7462
7523
  blocks={props.sendingMessage}
7463
7524
  context={props.builderContext}
7464
7525
  /></Show12>
7465
- <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-04a43b72">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
7526
+ <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-7430044e">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
7466
7527
  <Show12 when={submissionState() === "success"}><Blocks_default
7467
7528
  path="successMessage"
7468
7529
  blocks={props.successMessage}
7469
7530
  context={props.builderContext}
7470
7531
  /></Show12>
7471
7532
  </form>
7472
- <style>{`.pre-04a43b72 {
7533
+ <style>{`.pre-7430044e {
7473
7534
  padding: 10px;
7474
7535
  color: red;
7475
7536
  text-align: center;
@@ -7996,7 +8057,7 @@ var getDefaultRegisteredComponents = () => [{
7996
8057
  }, {
7997
8058
  component: text_default,
7998
8059
  ...componentInfo11
7999
- }, ...TARGET === "react" ? [{
8060
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
8000
8061
  component: personalization_container_default,
8001
8062
  ...componentInfo6
8002
8063
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -8033,7 +8094,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
8033
8094
 
8034
8095
  // src/components/content-variants/helpers.ts
8035
8096
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
8036
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
8097
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
8037
8098
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
8038
8099
  ...variant,
8039
8100
  testVariationId: variant.id,
@@ -8058,20 +8119,20 @@ var checkShouldRenderVariants2 = ({
8058
8119
  };
8059
8120
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
8060
8121
  var isAngularSDK = TARGET === "angular";
8061
- var isHydrationTarget = getIsHydrationTarget(TARGET);
8122
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
8062
8123
  var getInitVariantsFnsScriptString = () => `
8063
8124
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
8064
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
8125
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
8065
8126
  `;
8066
8127
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
8067
8128
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
8068
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
8129
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
8069
8130
  )`;
8070
8131
  var getUpdateVariantVisibilityScript = ({
8071
8132
  contentId,
8072
8133
  variationId
8073
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
8074
- "${variationId}", "${contentId}", ${isHydrationTarget}
8134
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
8135
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
8075
8136
  )`;
8076
8137
 
8077
8138
  // src/components/content/components/enable-editor.tsx
@@ -8091,7 +8152,7 @@ function getPreviewContent(_searchParams) {
8091
8152
  }
8092
8153
 
8093
8154
  // src/constants/sdk-version.ts
8094
- var SDK_VERSION = "4.0.8";
8155
+ var SDK_VERSION = "4.0.10";
8095
8156
 
8096
8157
  // src/helpers/sdk-headers.ts
8097
8158
  var getSdkHeaders = () => ({
@@ -9450,11 +9511,18 @@ function ContentVariants(props) {
9450
9511
  setShouldRenderVariants(false);
9451
9512
  });
9452
9513
  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>
9514
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
9515
+ <Inlined_script_default
9516
+ id="builderio-init-variants-fns"
9517
+ scriptStr={getInitVariantsFnsScriptString()}
9518
+ nonce={props.nonce || ""}
9519
+ />
9520
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
9521
+ id="builderio-init-personalization-variants-fns"
9522
+ nonce={props.nonce || ""}
9523
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
9524
+ /></Show16>
9525
+ </Show16>
9458
9526
  <Show16 when={shouldRenderVariants()}>
9459
9527
  <Inlined_styles_default
9460
9528
  id="builderio-variants"