@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.
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", "qwik"];
5263
+ var SDKS_REQUIRING_RESET_APPROACH = ["vue", "svelte", "qwik"];
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") {
@@ -5355,6 +5518,11 @@ var handleABTesting = async ({
5355
5518
  };
5356
5519
  };
5357
5520
 
5521
+ // src/helpers/no-serialize-wrapper.ts
5522
+ function noSerializeWrapper(fn) {
5523
+ return fn;
5524
+ }
5525
+
5358
5526
  // src/helpers/user-attributes.ts
5359
5527
  var USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
5360
5528
  function createUserAttributesService() {
@@ -5385,18 +5553,32 @@ function createUserAttributesService() {
5385
5553
  canTrack
5386
5554
  }) || "{}");
5387
5555
  },
5388
- subscribeOnUserAttributesChange(callback) {
5556
+ subscribeOnUserAttributesChange(callback, {
5557
+ fireImmediately
5558
+ } = {}) {
5389
5559
  subscribers.add(callback);
5390
- return () => {
5560
+ if (fireImmediately) {
5561
+ callback(this.getUserAttributes());
5562
+ }
5563
+ return noSerializeWrapper(function() {
5391
5564
  subscribers.delete(callback);
5392
- };
5565
+ });
5393
5566
  },
5394
5567
  setCanTrack(value) {
5395
5568
  canTrack = value;
5396
5569
  }
5397
5570
  };
5398
5571
  }
5399
- var userAttributesService = createUserAttributesService();
5572
+ var _userAttributesService;
5573
+ if (isBrowser() && TARGET === "qwik") {
5574
+ if (!window.__BUILDER_USER_ATTRIBUTES_SERVICE__) {
5575
+ window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
5576
+ }
5577
+ _userAttributesService = window.__BUILDER_USER_ATTRIBUTES_SERVICE__;
5578
+ } else {
5579
+ _userAttributesService = createUserAttributesService();
5580
+ }
5581
+ var userAttributesService = _userAttributesService;
5400
5582
  var setClientUserAttributes = (attributes) => {
5401
5583
  userAttributesService.setUserAttributes(attributes);
5402
5584
  };
@@ -6113,7 +6295,8 @@ var componentInfo6 = {
6113
6295
  name: "PersonalizationContainer",
6114
6296
  shouldReceiveBuilderProps: {
6115
6297
  builderBlock: true,
6116
- builderContext: true
6298
+ builderContext: true,
6299
+ builderComponents: true
6117
6300
  },
6118
6301
  noWrap: true,
6119
6302
  image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
@@ -6169,199 +6352,6 @@ function isPreviewing(_search) {
6169
6352
  return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
6170
6353
  }
6171
6354
 
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
6355
  // src/blocks/personalization-container/personalization-container.tsx
6366
6356
  function PersonalizationContainer(props) {
6367
6357
  const [userAttributes, setUserAttributes] = createSignal10(
@@ -6374,6 +6364,13 @@ function PersonalizationContainer(props) {
6374
6364
  props.builderContext?.rootState?.locale
6375
6365
  )
6376
6366
  );
6367
+ const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] = createSignal10(
6368
+ getUpdateVisibilityStylesScript(
6369
+ props.variants,
6370
+ props.builderBlock?.id || "none",
6371
+ props.builderContext?.rootState?.locale
6372
+ )
6373
+ );
6377
6374
  const [unsubscribers, setUnsubscribers] = createSignal10([]);
6378
6375
  const [shouldRenderVariants, setShouldRenderVariants] = createSignal10(
6379
6376
  checkShouldRenderVariants(
@@ -6381,7 +6378,14 @@ function PersonalizationContainer(props) {
6381
6378
  getDefaultCanTrack(props.builderContext?.canTrack)
6382
6379
  )
6383
6380
  );
6384
- const [isHydrated, setIsHydrated] = createSignal10(false);
6381
+ const [shouldResetVariants, setShouldResetVariants] = createSignal10(false);
6382
+ const attrs = createMemo10(() => {
6383
+ return {
6384
+ ...props.attributes,
6385
+ ...{},
6386
+ [getClassPropName()]: `builder-personalization-container ${props.attributes[getClassPropName()] || ""}`
6387
+ };
6388
+ });
6385
6389
  const filteredVariants = createMemo10(() => {
6386
6390
  return (props.variants || []).filter((variant) => {
6387
6391
  return filterWithCustomTargeting(
@@ -6401,22 +6405,25 @@ function PersonalizationContainer(props) {
6401
6405
  return getBlocksToRender({
6402
6406
  variants: props.variants,
6403
6407
  fallbackBlocks: props.builderBlock?.children,
6404
- isHydrated: isHydrated(),
6408
+ isHydrated: shouldResetVariants(),
6405
6409
  filteredVariants: filteredVariants(),
6406
6410
  previewingIndex: props.previewingIndex
6407
6411
  });
6408
6412
  });
6409
6413
  const hideVariantsStyleString = createMemo10(() => {
6410
6414
  return (props.variants || []).map(
6411
- (_, index) => `[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
6415
+ (_, index) => `div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
6412
6416
  ).join("");
6413
6417
  });
6414
6418
  let rootRef;
6415
6419
  onMount5(() => {
6416
- setIsHydrated(true);
6420
+ setShouldResetVariants(true);
6417
6421
  const unsub = userAttributesService.subscribeOnUserAttributesChange(
6418
- (attrs) => {
6419
- setUserAttributes(attrs);
6422
+ (attrs2) => {
6423
+ setUserAttributes(attrs2);
6424
+ },
6425
+ {
6426
+ fireImmediately: TARGET === "qwik"
6420
6427
  }
6421
6428
  );
6422
6429
  if (!(isEditing() || isPreviewing())) {
@@ -6425,7 +6432,7 @@ function PersonalizationContainer(props) {
6425
6432
  rootRef.dispatchEvent(
6426
6433
  new CustomEvent("builder.variantLoaded", {
6427
6434
  detail: {
6428
- variant: variant || "default",
6435
+ variant: variant || DEFAULT_INDEX,
6429
6436
  content: props.builderContext?.content
6430
6437
  },
6431
6438
  bubbles: true
@@ -6437,7 +6444,7 @@ function PersonalizationContainer(props) {
6437
6444
  rootRef.dispatchEvent(
6438
6445
  new CustomEvent("builder.variantDisplayed", {
6439
6446
  detail: {
6440
- variant: variant || "default",
6447
+ variant: variant || DEFAULT_INDEX,
6441
6448
  content: props.builderContext?.content
6442
6449
  },
6443
6450
  bubbles: true
@@ -6451,39 +6458,72 @@ function PersonalizationContainer(props) {
6451
6458
  }
6452
6459
  unsubscribers().push(unsub);
6453
6460
  });
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
6461
+ return <><div ref={rootRef} {...attrs()}>
6462
+ <Show10
6463
+ when={shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
6464
+ ><Blocks_default
6483
6465
  blocks={blocksToRender().blocks}
6484
6466
  parent={props.builderBlock?.id}
6485
6467
  path={blocksToRender().path}
6486
- />
6468
+ context={props.builderContext}
6469
+ registeredComponents={props.builderComponents}
6470
+ BlocksWrapperProps={{
6471
+ ...props.builderContext?.BlocksWrapperProps,
6472
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
6473
+ }}
6474
+ /></Show10>
6475
+ <Show10
6476
+ when={!shouldResetVariants() && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
6477
+ >
6478
+ <Show10 when={shouldRenderVariants()}>
6479
+ <Inlined_styles_default
6480
+ nonce={props.builderContext?.nonce || ""}
6481
+ styles={hideVariantsStyleString()}
6482
+ id={`variants-styles-${props.builderBlock?.id}`}
6483
+ />
6484
+ <Inlined_script_default
6485
+ nonce={props.builderContext?.nonce || ""}
6486
+ scriptStr={updateVisibilityStylesScript()}
6487
+ id={`variants-visibility-script-${props.builderBlock?.id}`}
6488
+ />
6489
+ <For6 each={props.variants}>{(variant, _index) => {
6490
+ const index = _index();
6491
+ return <Blocks_default
6492
+ key={`${props.builderBlock?.id}-${index}`}
6493
+ BlocksWrapperProps={{
6494
+ ...props.builderContext?.BlocksWrapperProps,
6495
+ "aria-hidden": true,
6496
+ hidden: true,
6497
+ "data-variant-id": `${props.builderBlock?.id}-${index}`
6498
+ }}
6499
+ blocks={variant.blocks}
6500
+ parent={props.builderBlock?.id}
6501
+ path={`component.options.variants.${index}.blocks`}
6502
+ context={props.builderContext}
6503
+ registeredComponents={props.builderComponents}
6504
+ ><Inlined_script_default
6505
+ nonce={props.builderContext?.nonce || ""}
6506
+ scriptStr={scriptStr()}
6507
+ id={`variants-script-${props.builderBlock?.id}-${index}`}
6508
+ /></Blocks_default>;
6509
+ }}</For6>
6510
+ </Show10>
6511
+ <Blocks_default
6512
+ blocks={blocksToRender().blocks}
6513
+ parent={props.builderBlock?.id}
6514
+ path={blocksToRender().path}
6515
+ context={props.builderContext}
6516
+ registeredComponents={props.builderComponents}
6517
+ BlocksWrapperProps={{
6518
+ ...props.builderContext?.BlocksWrapperProps,
6519
+ "data-variant-id": `${props.builderBlock?.id}-${blocksToRender().index}`
6520
+ }}
6521
+ ><Show10 when={shouldRenderVariants()}><Inlined_script_default
6522
+ nonce={props.builderContext?.nonce || ""}
6523
+ scriptStr={scriptStr()}
6524
+ id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
6525
+ /></Show10></Blocks_default>
6526
+ </Show10>
6487
6527
  </div></>;
6488
6528
  }
6489
6529
  var personalization_container_default = PersonalizationContainer;
@@ -7364,6 +7404,15 @@ function FormComponent(props) {
7364
7404
  }
7365
7405
  }
7366
7406
  setFormState("sending");
7407
+ if (props.sendSubmissionsTo === "email" && (props.sendSubmissionsToEmail === "your@email.com" || !props.sendSubmissionsToEmail)) {
7408
+ const message = "SubmissionsToEmail is required when sendSubmissionsTo is set to email";
7409
+ console.error(message);
7410
+ setFormState("error");
7411
+ mergeNewRootState({
7412
+ formErrorMessage: message
7413
+ });
7414
+ return;
7415
+ }
7367
7416
  const formUrl = `${getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(
7368
7417
  props.sendSubmissionsToEmail || ""
7369
7418
  )}&name=${encodeURIComponent(props.name || "")}`;
@@ -7382,17 +7431,30 @@ function FormComponent(props) {
7382
7431
  } else {
7383
7432
  body2 = await res.text();
7384
7433
  }
7385
- if (!res.ok && props.errorMessagePath) {
7386
- let message = get(body2, props.errorMessagePath);
7387
- if (message) {
7388
- if (typeof message !== "string") {
7389
- message = JSON.stringify(message);
7434
+ if (!res.ok) {
7435
+ const submitErrorEvent = new CustomEvent("submit:error", {
7436
+ detail: {
7437
+ error: body2,
7438
+ status: res.status
7390
7439
  }
7391
- setFormErrorMessage(message);
7392
- mergeNewRootState({
7393
- formErrorMessage: message
7394
- });
7440
+ });
7441
+ if (formRef?.nativeElement) {
7442
+ formRef?.nativeElement.dispatchEvent(submitErrorEvent);
7443
+ if (submitErrorEvent.defaultPrevented) {
7444
+ return;
7445
+ }
7446
+ }
7447
+ setResponseData(body2);
7448
+ setFormState("error");
7449
+ let message = props.errorMessagePath ? get(body2, props.errorMessagePath) : body2.message || body2.error || body2;
7450
+ if (typeof message !== "string") {
7451
+ message = JSON.stringify(message);
7395
7452
  }
7453
+ setFormErrorMessage(message);
7454
+ mergeNewRootState({
7455
+ formErrorMessage: message
7456
+ });
7457
+ return;
7396
7458
  }
7397
7459
  setResponseData(body2);
7398
7460
  setFormState(res.ok ? "success" : "error");
@@ -7471,14 +7533,14 @@ function FormComponent(props) {
7471
7533
  blocks={props.sendingMessage}
7472
7534
  context={props.builderContext}
7473
7535
  /></Show12>
7474
- <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-04a43b72">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
7536
+ <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-7430044e">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
7475
7537
  <Show12 when={submissionState() === "success"}><Blocks_default
7476
7538
  path="successMessage"
7477
7539
  blocks={props.successMessage}
7478
7540
  context={props.builderContext}
7479
7541
  /></Show12>
7480
7542
  </form>
7481
- <style>{`.pre-04a43b72 {
7543
+ <style>{`.pre-7430044e {
7482
7544
  padding: 10px;
7483
7545
  color: red;
7484
7546
  text-align: center;
@@ -8006,7 +8068,7 @@ var getDefaultRegisteredComponents = () => [{
8006
8068
  }, {
8007
8069
  component: text_default,
8008
8070
  ...componentInfo11
8009
- }, ...TARGET === "react" ? [{
8071
+ }, ...SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
8010
8072
  component: personalization_container_default,
8011
8073
  ...componentInfo6
8012
8074
  }] : [], ...TARGET === "rsc" ? [] : [{
@@ -8043,7 +8105,7 @@ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variant
8043
8105
 
8044
8106
  // src/components/content-variants/helpers.ts
8045
8107
  var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
8046
- var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
8108
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2 = "builderIoRenderContent";
8047
8109
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
8048
8110
  ...variant,
8049
8111
  testVariationId: variant.id,
@@ -8068,20 +8130,20 @@ var checkShouldRenderVariants2 = ({
8068
8130
  };
8069
8131
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
8070
8132
  var isAngularSDK = TARGET === "angular";
8071
- var isHydrationTarget = getIsHydrationTarget(TARGET);
8133
+ var isHydrationTarget2 = getIsHydrationTarget(TARGET);
8072
8134
  var getInitVariantsFnsScriptString = () => `
8073
8135
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
8074
- window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
8136
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
8075
8137
  `;
8076
8138
  var getUpdateCookieAndStylesScript = (variants, contentId) => `
8077
8139
  window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
8078
- "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}, ${isAngularSDK}
8140
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget2}, ${isAngularSDK}
8079
8141
  )`;
8080
8142
  var getUpdateVariantVisibilityScript = ({
8081
8143
  contentId,
8082
8144
  variationId
8083
- }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
8084
- "${variationId}", "${contentId}", ${isHydrationTarget}
8145
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME2}(
8146
+ "${variationId}", "${contentId}", ${isHydrationTarget2}
8085
8147
  )`;
8086
8148
 
8087
8149
  // src/components/content/components/enable-editor.tsx
@@ -8101,7 +8163,7 @@ function getPreviewContent(_searchParams) {
8101
8163
  }
8102
8164
 
8103
8165
  // src/constants/sdk-version.ts
8104
- var SDK_VERSION = "4.0.8";
8166
+ var SDK_VERSION = "4.0.10";
8105
8167
 
8106
8168
  // src/helpers/sdk-headers.ts
8107
8169
  var getSdkHeaders = () => ({
@@ -9467,11 +9529,18 @@ function ContentVariants(props) {
9467
9529
  setShouldRenderVariants(false);
9468
9530
  });
9469
9531
  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>
9532
+ <Show16 when={!props.isNestedRender && TARGET !== "reactNative"}>
9533
+ <Inlined_script_default
9534
+ id="builderio-init-variants-fns"
9535
+ scriptStr={getInitVariantsFnsScriptString()}
9536
+ nonce={props.nonce || ""}
9537
+ />
9538
+ <Show16 when={SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}><Inlined_script_default
9539
+ id="builderio-init-personalization-variants-fns"
9540
+ nonce={props.nonce || ""}
9541
+ scriptStr={getInitPersonalizationVariantsFnsScriptString()}
9542
+ /></Show16>
9543
+ </Show16>
9475
9544
  <Show16 when={shouldRenderVariants()}>
9476
9545
  <Inlined_styles_default
9477
9546
  id="builderio-variants"