@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/index.js CHANGED
@@ -4084,7 +4084,7 @@ function Block(props) {
4084
4084
  });
4085
4085
  }
4086
4086
  function processedBlock() {
4087
- return repeatItem() ? props.block : getProcessedBlock({
4087
+ return props.block.repeat?.collection ? props.block : getProcessedBlock({
4088
4088
  block: props.block,
4089
4089
  localState: props.context.localState,
4090
4090
  rootState: props.context.rootState,
@@ -4103,6 +4103,9 @@ function Block(props) {
4103
4103
  if ("show" in processedBlock()) {
4104
4104
  return processedBlock().show;
4105
4105
  }
4106
+ if (props.block.repeat?.collection && !repeatItem()?.length) {
4107
+ return false;
4108
+ }
4106
4109
  return true;
4107
4110
  }
4108
4111
  function childrenWithoutParentComponent() {
@@ -5778,7 +5781,9 @@ var componentInfo11 = {
5778
5781
  advanced: true
5779
5782
  }]
5780
5783
  };
5781
- var _tmpl$13 = /* @__PURE__ */ template(`<video>`);
5784
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
5785
+ var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
5786
+ var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
5782
5787
  function Video(props) {
5783
5788
  function videoProps() {
5784
5789
  return {
@@ -5801,13 +5806,13 @@ function Video(props) {
5801
5806
  }
5802
5807
  function spreadProps() {
5803
5808
  return {
5804
- ...props.attributes,
5805
5809
  ...videoProps()
5806
5810
  };
5807
5811
  }
5808
5812
  return (() => {
5809
- const _el$ = _tmpl$13();
5810
- spread(_el$, mergeProps(spreadProps, {
5813
+ const _el$ = _tmpl$33(), _el$2 = _el$.firstChild;
5814
+ _el$.style.setProperty("position", "relative");
5815
+ spread(_el$2, mergeProps(spreadProps, {
5811
5816
  get preload() {
5812
5817
  return props.preload || "metadata";
5813
5818
  },
@@ -5820,7 +5825,11 @@ function Video(props) {
5820
5825
  "object-position": props.position,
5821
5826
  // Hack to get object fit to work as expected and
5822
5827
  // not have the video overflow
5823
- "border-radius": 1
5828
+ "z-index": 2,
5829
+ "border-radius": "1px",
5830
+ ...props.aspectRatio ? {
5831
+ position: "absolute"
5832
+ } : null
5824
5833
  };
5825
5834
  },
5826
5835
  get src() {
@@ -5829,7 +5838,62 @@ function Video(props) {
5829
5838
  get poster() {
5830
5839
  return props.posterImage;
5831
5840
  }
5832
- }), false, false);
5841
+ }), false, true);
5842
+ insert(_el$2, createComponent(Show, {
5843
+ get when() {
5844
+ return !props.lazyLoad;
5845
+ },
5846
+ get children() {
5847
+ const _el$3 = _tmpl$13();
5848
+ effect(() => setAttribute(_el$3, "src", props.video));
5849
+ return _el$3;
5850
+ }
5851
+ }));
5852
+ insert(_el$, createComponent(Show, {
5853
+ get when() {
5854
+ return props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length);
5855
+ },
5856
+ get children() {
5857
+ const _el$4 = _tmpl$23();
5858
+ _el$4.style.setProperty("width", "100%");
5859
+ _el$4.style.setProperty("pointer-events", "none");
5860
+ _el$4.style.setProperty("font-size", "0px");
5861
+ effect(() => props.aspectRatio * 100 + "%" != null ? _el$4.style.setProperty("padding-top", props.aspectRatio * 100 + "%") : _el$4.style.removeProperty("padding-top"));
5862
+ return _el$4;
5863
+ }
5864
+ }), null);
5865
+ insert(_el$, createComponent(Show, {
5866
+ get when() {
5867
+ return props.builderBlock?.children?.length && props.fitContent;
5868
+ },
5869
+ get children() {
5870
+ const _el$5 = _tmpl$23();
5871
+ _el$5.style.setProperty("display", "flex");
5872
+ _el$5.style.setProperty("flex-direction", "column");
5873
+ _el$5.style.setProperty("align-items", "stretch");
5874
+ insert(_el$5, () => props.children);
5875
+ return _el$5;
5876
+ }
5877
+ }), null);
5878
+ insert(_el$, createComponent(Show, {
5879
+ get when() {
5880
+ return props.builderBlock?.children?.length && !props.fitContent;
5881
+ },
5882
+ get children() {
5883
+ const _el$6 = _tmpl$23();
5884
+ _el$6.style.setProperty("pointer-events", "none");
5885
+ _el$6.style.setProperty("display", "flex");
5886
+ _el$6.style.setProperty("flex-direction", "column");
5887
+ _el$6.style.setProperty("align-items", "stretch");
5888
+ _el$6.style.setProperty("position", "absolute");
5889
+ _el$6.style.setProperty("top", "0");
5890
+ _el$6.style.setProperty("left", "0");
5891
+ _el$6.style.setProperty("width", "100%");
5892
+ _el$6.style.setProperty("height", "100%");
5893
+ insert(_el$6, () => props.children);
5894
+ return _el$6;
5895
+ }
5896
+ }), null);
5833
5897
  return _el$;
5834
5898
  })();
5835
5899
  }
@@ -5894,13 +5958,19 @@ var serializeComponentInfo = ({
5894
5958
  }), {}))
5895
5959
  });
5896
5960
 
5961
+ // src/components/content-variants/inlined-fns.ts
5962
+ 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}";
5963
+ 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}";
5964
+
5897
5965
  // src/components/content-variants/helpers.ts
5966
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
5967
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
5898
5968
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
5899
5969
  ...variant,
5900
5970
  testVariationId: variant.id,
5901
5971
  id: content?.id
5902
5972
  }));
5903
- var checkShouldRunVariants = ({
5973
+ var checkShouldRenderVariants = ({
5904
5974
  canTrack,
5905
5975
  content
5906
5976
  }) => {
@@ -5911,139 +5981,34 @@ var checkShouldRunVariants = ({
5911
5981
  return false;
5912
5982
  if (!canTrack)
5913
5983
  return false;
5914
- if (TARGET === "vue2" || TARGET === "vue3")
5984
+ if (TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte")
5915
5985
  return true;
5916
5986
  if (isBrowser())
5917
5987
  return false;
5918
5988
  return true;
5919
5989
  };
5920
- function bldrAbTest(contentId, variants, isHydrationTarget2) {
5921
- function getAndSetVariantId2() {
5922
- function setCookie2(name, value, days) {
5923
- let expires = "";
5924
- if (days) {
5925
- const date = /* @__PURE__ */ new Date();
5926
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
5927
- expires = "; expires=" + date.toUTCString();
5928
- }
5929
- document.cookie = name + "=" + (value || "") + expires + "; path=/; Secure; SameSite=None";
5930
- }
5931
- function getCookie2(name) {
5932
- const nameEQ = name + "=";
5933
- const ca2 = document.cookie.split(";");
5934
- for (let i = 0; i < ca2.length; i++) {
5935
- let c = ca2[i];
5936
- while (c.charAt(0) === " ")
5937
- c = c.substring(1, c.length);
5938
- if (c.indexOf(nameEQ) === 0)
5939
- return c.substring(nameEQ.length, c.length);
5940
- }
5941
- return null;
5942
- }
5943
- const cookieName = `builder.tests.${contentId}`;
5944
- const variantInCookie = getCookie2(cookieName);
5945
- const availableIDs = variants.map((vr) => vr.id).concat(contentId);
5946
- if (variantInCookie && availableIDs.includes(variantInCookie)) {
5947
- return variantInCookie;
5948
- }
5949
- let n = 0;
5950
- const random = Math.random();
5951
- for (let i = 0; i < variants.length; i++) {
5952
- const variant = variants[i];
5953
- const testRatio = variant.testRatio;
5954
- n += testRatio;
5955
- if (random < n) {
5956
- setCookie2(cookieName, variant.id);
5957
- return variant.id;
5958
- }
5959
- }
5960
- setCookie2(cookieName, contentId);
5961
- return contentId;
5962
- }
5963
- const winningVariantId = getAndSetVariantId2();
5964
- const styleEl = document.currentScript?.previousElementSibling;
5965
- if (isHydrationTarget2) {
5966
- styleEl.remove();
5967
- const thisScriptEl = document.currentScript;
5968
- thisScriptEl?.remove();
5969
- } else {
5970
- const newStyleStr = variants.concat({
5971
- id: contentId
5972
- }).filter((variant) => variant.id !== winningVariantId).map((value) => {
5973
- return `.variant-${value.id} { display: none; }
5974
- `;
5975
- }).join("");
5976
- styleEl.innerHTML = newStyleStr;
5977
- }
5978
- }
5979
- function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
5980
- if (!navigator.cookieEnabled) {
5981
- return;
5982
- }
5983
- function getCookie2(name) {
5984
- const nameEQ = name + "=";
5985
- const ca2 = document.cookie.split(";");
5986
- for (let i = 0; i < ca2.length; i++) {
5987
- let c = ca2[i];
5988
- while (c.charAt(0) === " ")
5989
- c = c.substring(1, c.length);
5990
- if (c.indexOf(nameEQ) === 0)
5991
- return c.substring(nameEQ.length, c.length);
5992
- }
5993
- return null;
5994
- }
5995
- const cookieName = `builder.tests.${defaultContentId}`;
5996
- const variantId = getCookie2(cookieName);
5997
- const parentDiv = document.currentScript?.parentElement;
5998
- const variantIsDefaultContent = variantContentId === defaultContentId;
5999
- if (variantId === variantContentId) {
6000
- if (variantIsDefaultContent) {
6001
- return;
6002
- }
6003
- parentDiv?.removeAttribute("hidden");
6004
- parentDiv?.removeAttribute("aria-hidden");
6005
- } else {
6006
- if (variantIsDefaultContent) {
6007
- if (isHydrationTarget2) {
6008
- parentDiv?.remove();
6009
- } else {
6010
- parentDiv?.setAttribute("hidden", "true");
6011
- parentDiv?.setAttribute("aria-hidden", "true");
6012
- }
6013
- }
6014
- return;
6015
- }
6016
- return;
6017
- }
6018
5990
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
6019
5991
  var isHydrationTarget = getIsHydrationTarget(TARGET);
6020
- var AB_TEST_FN_NAME = "builderIoAbTest";
6021
- var CONTENT_FN_NAME = "builderIoRenderContent";
6022
- var getScriptString = () => {
6023
- const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
6024
- const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
6025
- return `
6026
- window.${AB_TEST_FN_NAME} = ${fnStr}
6027
- window.${CONTENT_FN_NAME} = ${fnStr2}
5992
+ var getScriptString = () => `
5993
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
5994
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
6028
5995
  `;
6029
- };
6030
- var getVariantsScriptString = (variants, contentId) => {
6031
- return `
6032
- window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
6033
- };
6034
- var getRenderContentScriptString = ({
5996
+ var getUpdateCookieAndStylesScript = (variants, contentId) => `
5997
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
5998
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
5999
+ )`;
6000
+ var getUpdateVariantVisibilityScript = ({
6035
6001
  contentId,
6036
6002
  variationId
6037
- }) => {
6038
- return `
6039
- window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
6040
- };
6003
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
6004
+ "${variationId}", "${contentId}", ${isHydrationTarget}
6005
+ )`;
6041
6006
  var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
6042
6007
  function InlinedScript(props) {
6043
6008
  return (() => {
6044
6009
  const _el$ = _tmpl$14();
6045
6010
  effect((_p$) => {
6046
- const _v$ = props.scriptStr, _v$2 = props.id;
6011
+ const _v$ = props.scriptStr, _v$2 = props.id || "";
6047
6012
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
6048
6013
  _v$2 !== _p$._v$2 && setAttribute(_el$, "id", _p$._v$2 = _v$2);
6049
6014
  return _p$;
@@ -6536,7 +6501,7 @@ var getInteractionPropertiesForEvent = (event) => {
6536
6501
  };
6537
6502
 
6538
6503
  // src/constants/sdk-version.ts
6539
- var SDK_VERSION = "0.7.3";
6504
+ var SDK_VERSION = "0.7.5";
6540
6505
 
6541
6506
  // src/functions/register.ts
6542
6507
  var registry = {};
@@ -6910,7 +6875,7 @@ function EnableEditor(props) {
6910
6875
  typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
6911
6876
  spread(_el$, mergeProps({
6912
6877
  get ["class"]() {
6913
- return props.classNameProp;
6878
+ return `variant-${props.content?.testVariationId || props.content?.id}`;
6914
6879
  }
6915
6880
  }, {}, {
6916
6881
  get key() {
@@ -7030,22 +6995,20 @@ var getContextStateInitialValue = ({
7030
6995
  locale
7031
6996
  }) => {
7032
6997
  const defaultValues = {};
6998
+ const initialState = content?.data?.state || {};
7033
6999
  content?.data?.inputs?.forEach((input) => {
7034
- if (input.name && input.defaultValue !== void 0 && content?.data?.state && content.data.state[input.name] === void 0) {
7000
+ if (input.name && input.defaultValue !== void 0) {
7035
7001
  defaultValues[input.name] = input.defaultValue;
7036
7002
  }
7037
7003
  });
7038
- const stateToUse = {
7039
- ...content?.data?.state,
7004
+ return {
7005
+ ...defaultValues,
7006
+ ...initialState,
7040
7007
  ...data,
7041
7008
  ...locale ? {
7042
7009
  locale
7043
7010
  } : {}
7044
7011
  };
7045
- return {
7046
- ...defaultValues,
7047
- ...stateToUse
7048
- };
7049
7012
  };
7050
7013
  var getContentInitialValue = ({
7051
7014
  content,
@@ -7063,7 +7026,7 @@ var getContentInitialValue = ({
7063
7026
 
7064
7027
  // src/components/content/content.tsx
7065
7028
  function ContentComponent(props) {
7066
- const [scriptStr, setScriptStr] = createSignal(getRenderContentScriptString({
7029
+ const [scriptStr, setScriptStr] = createSignal(getUpdateVariantVisibilityScript({
7067
7030
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
7068
7031
  variationId: props.content?.testVariationId,
7069
7032
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
@@ -7159,9 +7122,6 @@ function ContentComponent(props) {
7159
7122
  get enrich() {
7160
7123
  return props.enrich;
7161
7124
  },
7162
- get classNameProp() {
7163
- return props.classNameProp;
7164
- },
7165
7125
  get showContent() {
7166
7126
  return props.showContent;
7167
7127
  },
@@ -7218,12 +7178,12 @@ var content_default = ContentComponent;
7218
7178
 
7219
7179
  // src/components/content-variants/content-variants.tsx
7220
7180
  function ContentVariants(props) {
7221
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRunVariants({
7181
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRenderVariants({
7222
7182
  canTrack: getDefaultCanTrack(props.canTrack),
7223
7183
  content: props.content
7224
7184
  }));
7225
- function variantScriptStr() {
7226
- return getVariantsScriptString(getVariants(props.content).map((value) => ({
7185
+ function updateCookieAndStylesScriptStr() {
7186
+ return getUpdateCookieAndStylesScript(getVariants(props.content).map((value) => ({
7227
7187
  id: value.testVariationId,
7228
7188
  testRatio: value.testRatio
7229
7189
  })), props.content?.id || "");
@@ -7268,7 +7228,7 @@ function ContentVariants(props) {
7268
7228
  }
7269
7229
  }), createComponent(inlined_script_default, {
7270
7230
  get scriptStr() {
7271
- return variantScriptStr();
7231
+ return updateCookieAndStylesScriptStr();
7272
7232
  }
7273
7233
  }), createComponent(For, {
7274
7234
  get each() {
@@ -7282,7 +7242,6 @@ function ContentVariants(props) {
7282
7242
  },
7283
7243
  content: variant,
7284
7244
  showContent: false,
7285
- classNameProp: void 0,
7286
7245
  get model() {
7287
7246
  return props.model;
7288
7247
  },
@@ -7324,9 +7283,6 @@ function ContentVariants(props) {
7324
7283
  get content() {
7325
7284
  return defaultContent();
7326
7285
  },
7327
- get classNameProp() {
7328
- return `variant-${props.content?.id}`;
7329
- },
7330
7286
  showContent: true,
7331
7287
  get model() {
7332
7288
  return props.model;