@builder.io/sdk-solid 0.7.3 → 0.7.5

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.js CHANGED
@@ -4096,7 +4096,7 @@ function Block(props) {
4096
4096
  });
4097
4097
  }
4098
4098
  function processedBlock() {
4099
- return repeatItem() ? props.block : getProcessedBlock({
4099
+ return props.block.repeat?.collection ? props.block : getProcessedBlock({
4100
4100
  block: props.block,
4101
4101
  localState: props.context.localState,
4102
4102
  rootState: props.context.rootState,
@@ -4115,6 +4115,9 @@ function Block(props) {
4115
4115
  if ("show" in processedBlock()) {
4116
4116
  return processedBlock().show;
4117
4117
  }
4118
+ if (props.block.repeat?.collection && !repeatItem()?.length) {
4119
+ return false;
4120
+ }
4118
4121
  return true;
4119
4122
  }
4120
4123
  function childrenWithoutParentComponent() {
@@ -5794,7 +5797,9 @@ var componentInfo11 = {
5794
5797
  advanced: true
5795
5798
  }]
5796
5799
  };
5797
- var _tmpl$13 = /* @__PURE__ */ template(`<video>`);
5800
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
5801
+ var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
5802
+ var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
5798
5803
  function Video(props) {
5799
5804
  function videoProps() {
5800
5805
  return {
@@ -5817,13 +5822,13 @@ function Video(props) {
5817
5822
  }
5818
5823
  function spreadProps() {
5819
5824
  return {
5820
- ...props.attributes,
5821
5825
  ...videoProps()
5822
5826
  };
5823
5827
  }
5824
5828
  return (() => {
5825
- const _el$ = _tmpl$13();
5826
- spread(_el$, mergeProps(spreadProps, {
5829
+ const _el$ = _tmpl$33(), _el$2 = _el$.firstChild;
5830
+ _el$.style.setProperty("position", "relative");
5831
+ spread(_el$2, mergeProps(spreadProps, {
5827
5832
  get preload() {
5828
5833
  return props.preload || "metadata";
5829
5834
  },
@@ -5836,7 +5841,11 @@ function Video(props) {
5836
5841
  "object-position": props.position,
5837
5842
  // Hack to get object fit to work as expected and
5838
5843
  // not have the video overflow
5839
- "border-radius": 1
5844
+ "z-index": 2,
5845
+ "border-radius": "1px",
5846
+ ...props.aspectRatio ? {
5847
+ position: "absolute"
5848
+ } : null
5840
5849
  };
5841
5850
  },
5842
5851
  get src() {
@@ -5845,7 +5854,62 @@ function Video(props) {
5845
5854
  get poster() {
5846
5855
  return props.posterImage;
5847
5856
  }
5848
- }), false, false);
5857
+ }), false, true);
5858
+ insert(_el$2, createComponent(Show, {
5859
+ get when() {
5860
+ return !props.lazyLoad;
5861
+ },
5862
+ get children() {
5863
+ const _el$3 = _tmpl$13();
5864
+ effect(() => setAttribute(_el$3, "src", props.video));
5865
+ return _el$3;
5866
+ }
5867
+ }));
5868
+ insert(_el$, createComponent(Show, {
5869
+ get when() {
5870
+ return props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length);
5871
+ },
5872
+ get children() {
5873
+ const _el$4 = _tmpl$23();
5874
+ _el$4.style.setProperty("width", "100%");
5875
+ _el$4.style.setProperty("pointer-events", "none");
5876
+ _el$4.style.setProperty("font-size", "0px");
5877
+ effect(() => props.aspectRatio * 100 + "%" != null ? _el$4.style.setProperty("padding-top", props.aspectRatio * 100 + "%") : _el$4.style.removeProperty("padding-top"));
5878
+ return _el$4;
5879
+ }
5880
+ }), null);
5881
+ insert(_el$, createComponent(Show, {
5882
+ get when() {
5883
+ return props.builderBlock?.children?.length && props.fitContent;
5884
+ },
5885
+ get children() {
5886
+ const _el$5 = _tmpl$23();
5887
+ _el$5.style.setProperty("display", "flex");
5888
+ _el$5.style.setProperty("flex-direction", "column");
5889
+ _el$5.style.setProperty("align-items", "stretch");
5890
+ insert(_el$5, () => props.children);
5891
+ return _el$5;
5892
+ }
5893
+ }), null);
5894
+ insert(_el$, createComponent(Show, {
5895
+ get when() {
5896
+ return props.builderBlock?.children?.length && !props.fitContent;
5897
+ },
5898
+ get children() {
5899
+ const _el$6 = _tmpl$23();
5900
+ _el$6.style.setProperty("pointer-events", "none");
5901
+ _el$6.style.setProperty("display", "flex");
5902
+ _el$6.style.setProperty("flex-direction", "column");
5903
+ _el$6.style.setProperty("align-items", "stretch");
5904
+ _el$6.style.setProperty("position", "absolute");
5905
+ _el$6.style.setProperty("top", "0");
5906
+ _el$6.style.setProperty("left", "0");
5907
+ _el$6.style.setProperty("width", "100%");
5908
+ _el$6.style.setProperty("height", "100%");
5909
+ insert(_el$6, () => props.children);
5910
+ return _el$6;
5911
+ }
5912
+ }), null);
5849
5913
  return _el$;
5850
5914
  })();
5851
5915
  }
@@ -5910,13 +5974,19 @@ var serializeComponentInfo = ({
5910
5974
  }), {}))
5911
5975
  });
5912
5976
 
5977
+ // src/components/content-variants/inlined-fns.ts
5978
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT = "function updateCookiesAndStyles(contentId, variants, isHydrationTarget) {\n function getAndSetVariantId() {\n function setCookie(name, value, days) {\n let expires = '';\n if (days) {\n const date = new Date();\n date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);\n expires = '; expires=' + date.toUTCString();\n }\n document.cookie = name + '=' + (value || '') + expires + '; path=/' + '; Secure; SameSite=None';\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 cookieName = `builder.tests.${contentId}`;\n const variantInCookie = getCookie(cookieName);\n const availableIDs = variants.map(vr => vr.id).concat(contentId);\n if (variantInCookie && availableIDs.includes(variantInCookie)) {\n return variantInCookie;\n }\n let n = 0;\n const random = Math.random();\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i];\n const testRatio = variant.testRatio;\n n += testRatio;\n if (random < n) {\n setCookie(cookieName, variant.id);\n return variant.id;\n }\n }\n setCookie(cookieName, contentId);\n return contentId;\n }\n const winningVariantId = getAndSetVariantId();\n const styleEl = document.currentScript?.previousElementSibling;\n if (isHydrationTarget) {\n styleEl.remove();\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n } else {\n const newStyleStr = variants.concat({\n id: contentId\n }).filter(variant => variant.id !== winningVariantId).map(value => {\n return `.variant-${value.id} { display: none; }\n `;\n }).join('');\n styleEl.innerHTML = newStyleStr;\n }\n}";
5979
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT = "function updateVariantVisibility(variantContentId, defaultContentId, isHydrationTarget) {\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 cookieName = `builder.tests.${defaultContentId}`;\n const winningVariant = getCookie(cookieName);\n const parentDiv = document.currentScript?.parentElement;\n const isDefaultContent = variantContentId === defaultContentId;\n const isWinningVariant = winningVariant === variantContentId;\n if (isWinningVariant && !isDefaultContent) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultContent) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n parentDiv?.remove();\n }\n const thisScriptEl = document.currentScript;\n thisScriptEl?.remove();\n }\n return;\n}";
5980
+
5913
5981
  // src/components/content-variants/helpers.ts
5982
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
5983
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
5914
5984
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
5915
5985
  ...variant,
5916
5986
  testVariationId: variant.id,
5917
5987
  id: content?.id
5918
5988
  }));
5919
- var checkShouldRunVariants = ({
5989
+ var checkShouldRenderVariants = ({
5920
5990
  canTrack,
5921
5991
  content
5922
5992
  }) => {
@@ -5927,139 +5997,34 @@ var checkShouldRunVariants = ({
5927
5997
  return false;
5928
5998
  if (!canTrack)
5929
5999
  return false;
5930
- if (TARGET === "vue2" || TARGET === "vue3")
6000
+ if (TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte")
5931
6001
  return true;
5932
6002
  if (isBrowser())
5933
6003
  return false;
5934
6004
  return true;
5935
6005
  };
5936
- function bldrAbTest(contentId, variants, isHydrationTarget2) {
5937
- function getAndSetVariantId2() {
5938
- function setCookie2(name, value, days) {
5939
- let expires = "";
5940
- if (days) {
5941
- const date = /* @__PURE__ */ new Date();
5942
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
5943
- expires = "; expires=" + date.toUTCString();
5944
- }
5945
- document.cookie = name + "=" + (value || "") + expires + "; path=/; Secure; SameSite=None";
5946
- }
5947
- function getCookie2(name) {
5948
- const nameEQ = name + "=";
5949
- const ca2 = document.cookie.split(";");
5950
- for (let i = 0; i < ca2.length; i++) {
5951
- let c = ca2[i];
5952
- while (c.charAt(0) === " ")
5953
- c = c.substring(1, c.length);
5954
- if (c.indexOf(nameEQ) === 0)
5955
- return c.substring(nameEQ.length, c.length);
5956
- }
5957
- return null;
5958
- }
5959
- const cookieName = `builder.tests.${contentId}`;
5960
- const variantInCookie = getCookie2(cookieName);
5961
- const availableIDs = variants.map((vr) => vr.id).concat(contentId);
5962
- if (variantInCookie && availableIDs.includes(variantInCookie)) {
5963
- return variantInCookie;
5964
- }
5965
- let n = 0;
5966
- const random = Math.random();
5967
- for (let i = 0; i < variants.length; i++) {
5968
- const variant = variants[i];
5969
- const testRatio = variant.testRatio;
5970
- n += testRatio;
5971
- if (random < n) {
5972
- setCookie2(cookieName, variant.id);
5973
- return variant.id;
5974
- }
5975
- }
5976
- setCookie2(cookieName, contentId);
5977
- return contentId;
5978
- }
5979
- const winningVariantId = getAndSetVariantId2();
5980
- const styleEl = document.currentScript?.previousElementSibling;
5981
- if (isHydrationTarget2) {
5982
- styleEl.remove();
5983
- const thisScriptEl = document.currentScript;
5984
- thisScriptEl?.remove();
5985
- } else {
5986
- const newStyleStr = variants.concat({
5987
- id: contentId
5988
- }).filter((variant) => variant.id !== winningVariantId).map((value) => {
5989
- return `.variant-${value.id} { display: none; }
5990
- `;
5991
- }).join("");
5992
- styleEl.innerHTML = newStyleStr;
5993
- }
5994
- }
5995
- function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
5996
- if (!navigator.cookieEnabled) {
5997
- return;
5998
- }
5999
- function getCookie2(name) {
6000
- const nameEQ = name + "=";
6001
- const ca2 = document.cookie.split(";");
6002
- for (let i = 0; i < ca2.length; i++) {
6003
- let c = ca2[i];
6004
- while (c.charAt(0) === " ")
6005
- c = c.substring(1, c.length);
6006
- if (c.indexOf(nameEQ) === 0)
6007
- return c.substring(nameEQ.length, c.length);
6008
- }
6009
- return null;
6010
- }
6011
- const cookieName = `builder.tests.${defaultContentId}`;
6012
- const variantId = getCookie2(cookieName);
6013
- const parentDiv = document.currentScript?.parentElement;
6014
- const variantIsDefaultContent = variantContentId === defaultContentId;
6015
- if (variantId === variantContentId) {
6016
- if (variantIsDefaultContent) {
6017
- return;
6018
- }
6019
- parentDiv?.removeAttribute("hidden");
6020
- parentDiv?.removeAttribute("aria-hidden");
6021
- } else {
6022
- if (variantIsDefaultContent) {
6023
- if (isHydrationTarget2) {
6024
- parentDiv?.remove();
6025
- } else {
6026
- parentDiv?.setAttribute("hidden", "true");
6027
- parentDiv?.setAttribute("aria-hidden", "true");
6028
- }
6029
- }
6030
- return;
6031
- }
6032
- return;
6033
- }
6034
6006
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
6035
6007
  var isHydrationTarget = getIsHydrationTarget(TARGET);
6036
- var AB_TEST_FN_NAME = "builderIoAbTest";
6037
- var CONTENT_FN_NAME = "builderIoRenderContent";
6038
- var getScriptString = () => {
6039
- const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
6040
- const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
6041
- return `
6042
- window.${AB_TEST_FN_NAME} = ${fnStr}
6043
- window.${CONTENT_FN_NAME} = ${fnStr2}
6008
+ var getScriptString = () => `
6009
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
6010
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
6044
6011
  `;
6045
- };
6046
- var getVariantsScriptString = (variants, contentId) => {
6047
- return `
6048
- window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
6049
- };
6050
- var getRenderContentScriptString = ({
6012
+ var getUpdateCookieAndStylesScript = (variants, contentId) => `
6013
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
6014
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
6015
+ )`;
6016
+ var getUpdateVariantVisibilityScript = ({
6051
6017
  contentId,
6052
6018
  variationId
6053
- }) => {
6054
- return `
6055
- window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
6056
- };
6019
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
6020
+ "${variationId}", "${contentId}", ${isHydrationTarget}
6021
+ )`;
6057
6022
  var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
6058
6023
  function InlinedScript(props) {
6059
6024
  return (() => {
6060
6025
  const _el$ = _tmpl$14();
6061
6026
  effect((_p$) => {
6062
- const _v$ = props.scriptStr, _v$2 = props.id;
6027
+ const _v$ = props.scriptStr, _v$2 = props.id || "";
6063
6028
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
6064
6029
  _v$2 !== _p$._v$2 && setAttribute(_el$, "id", _p$._v$2 = _v$2);
6065
6030
  return _p$;
@@ -6557,7 +6522,7 @@ var getInteractionPropertiesForEvent = (event) => {
6557
6522
  };
6558
6523
 
6559
6524
  // src/constants/sdk-version.ts
6560
- var SDK_VERSION = "0.7.3";
6525
+ var SDK_VERSION = "0.7.5";
6561
6526
 
6562
6527
  // src/functions/register.ts
6563
6528
  var registry = {};
@@ -6933,7 +6898,7 @@ function EnableEditor(props) {
6933
6898
  typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
6934
6899
  spread(_el$, mergeProps({
6935
6900
  get ["class"]() {
6936
- return props.classNameProp;
6901
+ return `variant-${props.content?.testVariationId || props.content?.id}`;
6937
6902
  }
6938
6903
  }, {}, {
6939
6904
  get key() {
@@ -7053,22 +7018,20 @@ var getContextStateInitialValue = ({
7053
7018
  locale
7054
7019
  }) => {
7055
7020
  const defaultValues = {};
7021
+ const initialState = content?.data?.state || {};
7056
7022
  content?.data?.inputs?.forEach((input) => {
7057
- if (input.name && input.defaultValue !== void 0 && content?.data?.state && content.data.state[input.name] === void 0) {
7023
+ if (input.name && input.defaultValue !== void 0) {
7058
7024
  defaultValues[input.name] = input.defaultValue;
7059
7025
  }
7060
7026
  });
7061
- const stateToUse = {
7062
- ...content?.data?.state,
7027
+ return {
7028
+ ...defaultValues,
7029
+ ...initialState,
7063
7030
  ...data,
7064
7031
  ...locale ? {
7065
7032
  locale
7066
7033
  } : {}
7067
7034
  };
7068
- return {
7069
- ...defaultValues,
7070
- ...stateToUse
7071
- };
7072
7035
  };
7073
7036
  var getContentInitialValue = ({
7074
7037
  content,
@@ -7086,7 +7049,7 @@ var getContentInitialValue = ({
7086
7049
 
7087
7050
  // src/components/content/content.tsx
7088
7051
  function ContentComponent(props) {
7089
- const [scriptStr, setScriptStr] = createSignal(getRenderContentScriptString({
7052
+ const [scriptStr, setScriptStr] = createSignal(getUpdateVariantVisibilityScript({
7090
7053
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
7091
7054
  variationId: props.content?.testVariationId,
7092
7055
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
@@ -7182,9 +7145,6 @@ function ContentComponent(props) {
7182
7145
  get enrich() {
7183
7146
  return props.enrich;
7184
7147
  },
7185
- get classNameProp() {
7186
- return props.classNameProp;
7187
- },
7188
7148
  get showContent() {
7189
7149
  return props.showContent;
7190
7150
  },
@@ -7241,12 +7201,12 @@ var content_default = ContentComponent;
7241
7201
 
7242
7202
  // src/components/content-variants/content-variants.tsx
7243
7203
  function ContentVariants(props) {
7244
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRunVariants({
7204
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRenderVariants({
7245
7205
  canTrack: getDefaultCanTrack(props.canTrack),
7246
7206
  content: props.content
7247
7207
  }));
7248
- function variantScriptStr() {
7249
- return getVariantsScriptString(getVariants(props.content).map((value) => ({
7208
+ function updateCookieAndStylesScriptStr() {
7209
+ return getUpdateCookieAndStylesScript(getVariants(props.content).map((value) => ({
7250
7210
  id: value.testVariationId,
7251
7211
  testRatio: value.testRatio
7252
7212
  })), props.content?.id || "");
@@ -7291,7 +7251,7 @@ function ContentVariants(props) {
7291
7251
  }
7292
7252
  }), createComponent(inlined_script_default, {
7293
7253
  get scriptStr() {
7294
- return variantScriptStr();
7254
+ return updateCookieAndStylesScriptStr();
7295
7255
  }
7296
7256
  }), createComponent(For, {
7297
7257
  get each() {
@@ -7305,7 +7265,6 @@ function ContentVariants(props) {
7305
7265
  },
7306
7266
  content: variant,
7307
7267
  showContent: false,
7308
- classNameProp: void 0,
7309
7268
  get model() {
7310
7269
  return props.model;
7311
7270
  },
@@ -7347,9 +7306,6 @@ function ContentVariants(props) {
7347
7306
  get content() {
7348
7307
  return defaultContent();
7349
7308
  },
7350
- get classNameProp() {
7351
- return `variant-${props.content?.id}`;
7352
- },
7353
7309
  showContent: true,
7354
7310
  get model() {
7355
7311
  return props.model;