@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/dist/index.d.ts CHANGED
@@ -557,7 +557,11 @@ interface VideoProps {
557
557
  position?: "center" | "top" | "left" | "right" | "bottom" | "top left" | "top right" | "bottom left" | "bottom right";
558
558
  posterImage?: string;
559
559
  lazyLoad?: boolean;
560
+ children?: any;
561
+ fitContent?: boolean;
562
+ builderBlock?: BuilderBlock;
560
563
  }
564
+
561
565
  declare function Video(props: VideoProps): solid_js.JSX.Element;
562
566
 
563
567
  type BlocksWrapperProps = {
@@ -888,10 +892,6 @@ type AndUndefined<T> = {
888
892
  type EnforcePartials<From> = Prettify<AndUndefined<Enforced<OptionalFieldsOnly<From>>> & RequiredFieldsOnly<From>>;
889
893
 
890
894
  interface InternalRenderProps {
891
- /**
892
- * TO-DO: improve qwik generator to not remap this name for non-HTML tags, then name it `className`
893
- */
894
- classNameProp: string | undefined;
895
895
  showContent: boolean;
896
896
  isSsrAbTest: boolean;
897
897
  }
@@ -943,7 +943,7 @@ function Block(props) {
943
943
  });
944
944
  }
945
945
  function processedBlock() {
946
- return repeatItem() ? props.block : getProcessedBlock({
946
+ return props.block.repeat?.collection ? props.block : getProcessedBlock({
947
947
  block: props.block,
948
948
  localState: props.context.localState,
949
949
  rootState: props.context.rootState,
@@ -962,6 +962,9 @@ function Block(props) {
962
962
  if ("show" in processedBlock()) {
963
963
  return processedBlock().show;
964
964
  }
965
+ if (props.block.repeat?.collection && !repeatItem()?.length) {
966
+ return false;
967
+ }
965
968
  return true;
966
969
  }
967
970
  function childrenWithoutParentComponent() {
@@ -2641,7 +2644,9 @@ var componentInfo11 = {
2641
2644
  advanced: true
2642
2645
  }]
2643
2646
  };
2644
- var _tmpl$13 = /* @__PURE__ */ template(`<video>`);
2647
+ var _tmpl$13 = /* @__PURE__ */ template(`<source type=video/mp4>`);
2648
+ var _tmpl$23 = /* @__PURE__ */ template(`<div>`);
2649
+ var _tmpl$33 = /* @__PURE__ */ template(`<div><video class=builder-video>`);
2645
2650
  function Video(props) {
2646
2651
  function videoProps() {
2647
2652
  return {
@@ -2664,13 +2669,13 @@ function Video(props) {
2664
2669
  }
2665
2670
  function spreadProps() {
2666
2671
  return {
2667
- ...props.attributes,
2668
2672
  ...videoProps()
2669
2673
  };
2670
2674
  }
2671
2675
  return (() => {
2672
- const _el$ = _tmpl$13();
2673
- spread(_el$, mergeProps(spreadProps, {
2676
+ const _el$ = _tmpl$33(), _el$2 = _el$.firstChild;
2677
+ _el$.style.setProperty("position", "relative");
2678
+ spread(_el$2, mergeProps(spreadProps, {
2674
2679
  get preload() {
2675
2680
  return props.preload || "metadata";
2676
2681
  },
@@ -2683,7 +2688,11 @@ function Video(props) {
2683
2688
  "object-position": props.position,
2684
2689
  // Hack to get object fit to work as expected and
2685
2690
  // not have the video overflow
2686
- "border-radius": 1
2691
+ "z-index": 2,
2692
+ "border-radius": "1px",
2693
+ ...props.aspectRatio ? {
2694
+ position: "absolute"
2695
+ } : null
2687
2696
  };
2688
2697
  },
2689
2698
  get src() {
@@ -2692,7 +2701,62 @@ function Video(props) {
2692
2701
  get poster() {
2693
2702
  return props.posterImage;
2694
2703
  }
2695
- }), false, false);
2704
+ }), false, true);
2705
+ insert(_el$2, createComponent(Show, {
2706
+ get when() {
2707
+ return !props.lazyLoad;
2708
+ },
2709
+ get children() {
2710
+ const _el$3 = _tmpl$13();
2711
+ effect(() => setAttribute(_el$3, "src", props.video));
2712
+ return _el$3;
2713
+ }
2714
+ }));
2715
+ insert(_el$, createComponent(Show, {
2716
+ get when() {
2717
+ return props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length);
2718
+ },
2719
+ get children() {
2720
+ const _el$4 = _tmpl$23();
2721
+ _el$4.style.setProperty("width", "100%");
2722
+ _el$4.style.setProperty("pointer-events", "none");
2723
+ _el$4.style.setProperty("font-size", "0px");
2724
+ effect(() => props.aspectRatio * 100 + "%" != null ? _el$4.style.setProperty("padding-top", props.aspectRatio * 100 + "%") : _el$4.style.removeProperty("padding-top"));
2725
+ return _el$4;
2726
+ }
2727
+ }), null);
2728
+ insert(_el$, createComponent(Show, {
2729
+ get when() {
2730
+ return props.builderBlock?.children?.length && props.fitContent;
2731
+ },
2732
+ get children() {
2733
+ const _el$5 = _tmpl$23();
2734
+ _el$5.style.setProperty("display", "flex");
2735
+ _el$5.style.setProperty("flex-direction", "column");
2736
+ _el$5.style.setProperty("align-items", "stretch");
2737
+ insert(_el$5, () => props.children);
2738
+ return _el$5;
2739
+ }
2740
+ }), null);
2741
+ insert(_el$, createComponent(Show, {
2742
+ get when() {
2743
+ return props.builderBlock?.children?.length && !props.fitContent;
2744
+ },
2745
+ get children() {
2746
+ const _el$6 = _tmpl$23();
2747
+ _el$6.style.setProperty("pointer-events", "none");
2748
+ _el$6.style.setProperty("display", "flex");
2749
+ _el$6.style.setProperty("flex-direction", "column");
2750
+ _el$6.style.setProperty("align-items", "stretch");
2751
+ _el$6.style.setProperty("position", "absolute");
2752
+ _el$6.style.setProperty("top", "0");
2753
+ _el$6.style.setProperty("left", "0");
2754
+ _el$6.style.setProperty("width", "100%");
2755
+ _el$6.style.setProperty("height", "100%");
2756
+ insert(_el$6, () => props.children);
2757
+ return _el$6;
2758
+ }
2759
+ }), null);
2696
2760
  return _el$;
2697
2761
  })();
2698
2762
  }
@@ -2757,13 +2821,19 @@ var serializeComponentInfo = ({
2757
2821
  }), {}))
2758
2822
  });
2759
2823
 
2824
+ // src/components/content-variants/inlined-fns.ts
2825
+ 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}";
2826
+ 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}";
2827
+
2760
2828
  // src/components/content-variants/helpers.ts
2829
+ var UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME = "builderIoAbTest";
2830
+ var UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = "builderIoRenderContent";
2761
2831
  var getVariants = (content) => Object.values(content?.variations || {}).map((variant) => ({
2762
2832
  ...variant,
2763
2833
  testVariationId: variant.id,
2764
2834
  id: content?.id
2765
2835
  }));
2766
- var checkShouldRunVariants = ({
2836
+ var checkShouldRenderVariants = ({
2767
2837
  canTrack,
2768
2838
  content
2769
2839
  }) => {
@@ -2774,139 +2844,34 @@ var checkShouldRunVariants = ({
2774
2844
  return false;
2775
2845
  if (!canTrack)
2776
2846
  return false;
2777
- if (TARGET === "vue2" || TARGET === "vue3")
2847
+ if (TARGET === "vue2" || TARGET === "vue3" || TARGET === "svelte")
2778
2848
  return true;
2779
2849
  if (isBrowser())
2780
2850
  return false;
2781
2851
  return true;
2782
2852
  };
2783
- function bldrAbTest(contentId, variants, isHydrationTarget2) {
2784
- function getAndSetVariantId2() {
2785
- function setCookie2(name, value, days) {
2786
- let expires = "";
2787
- if (days) {
2788
- const date = /* @__PURE__ */ new Date();
2789
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1e3);
2790
- expires = "; expires=" + date.toUTCString();
2791
- }
2792
- document.cookie = name + "=" + (value || "") + expires + "; path=/; Secure; SameSite=None";
2793
- }
2794
- function getCookie2(name) {
2795
- const nameEQ = name + "=";
2796
- const ca = document.cookie.split(";");
2797
- for (let i = 0; i < ca.length; i++) {
2798
- let c = ca[i];
2799
- while (c.charAt(0) === " ")
2800
- c = c.substring(1, c.length);
2801
- if (c.indexOf(nameEQ) === 0)
2802
- return c.substring(nameEQ.length, c.length);
2803
- }
2804
- return null;
2805
- }
2806
- const cookieName = `builder.tests.${contentId}`;
2807
- const variantInCookie = getCookie2(cookieName);
2808
- const availableIDs = variants.map((vr) => vr.id).concat(contentId);
2809
- if (variantInCookie && availableIDs.includes(variantInCookie)) {
2810
- return variantInCookie;
2811
- }
2812
- let n = 0;
2813
- const random = Math.random();
2814
- for (let i = 0; i < variants.length; i++) {
2815
- const variant = variants[i];
2816
- const testRatio = variant.testRatio;
2817
- n += testRatio;
2818
- if (random < n) {
2819
- setCookie2(cookieName, variant.id);
2820
- return variant.id;
2821
- }
2822
- }
2823
- setCookie2(cookieName, contentId);
2824
- return contentId;
2825
- }
2826
- const winningVariantId = getAndSetVariantId2();
2827
- const styleEl = document.currentScript?.previousElementSibling;
2828
- if (isHydrationTarget2) {
2829
- styleEl.remove();
2830
- const thisScriptEl = document.currentScript;
2831
- thisScriptEl?.remove();
2832
- } else {
2833
- const newStyleStr = variants.concat({
2834
- id: contentId
2835
- }).filter((variant) => variant.id !== winningVariantId).map((value) => {
2836
- return `.variant-${value.id} { display: none; }
2837
- `;
2838
- }).join("");
2839
- styleEl.innerHTML = newStyleStr;
2840
- }
2841
- }
2842
- function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2) {
2843
- if (!navigator.cookieEnabled) {
2844
- return;
2845
- }
2846
- function getCookie2(name) {
2847
- const nameEQ = name + "=";
2848
- const ca = document.cookie.split(";");
2849
- for (let i = 0; i < ca.length; i++) {
2850
- let c = ca[i];
2851
- while (c.charAt(0) === " ")
2852
- c = c.substring(1, c.length);
2853
- if (c.indexOf(nameEQ) === 0)
2854
- return c.substring(nameEQ.length, c.length);
2855
- }
2856
- return null;
2857
- }
2858
- const cookieName = `builder.tests.${defaultContentId}`;
2859
- const variantId = getCookie2(cookieName);
2860
- const parentDiv = document.currentScript?.parentElement;
2861
- const variantIsDefaultContent = variantContentId === defaultContentId;
2862
- if (variantId === variantContentId) {
2863
- if (variantIsDefaultContent) {
2864
- return;
2865
- }
2866
- parentDiv?.removeAttribute("hidden");
2867
- parentDiv?.removeAttribute("aria-hidden");
2868
- } else {
2869
- if (variantIsDefaultContent) {
2870
- if (isHydrationTarget2) {
2871
- parentDiv?.remove();
2872
- } else {
2873
- parentDiv?.setAttribute("hidden", "true");
2874
- parentDiv?.setAttribute("aria-hidden", "true");
2875
- }
2876
- }
2877
- return;
2878
- }
2879
- return;
2880
- }
2881
2853
  var getIsHydrationTarget = (target) => target === "react" || target === "reactNative";
2882
2854
  var isHydrationTarget = getIsHydrationTarget(TARGET);
2883
- var AB_TEST_FN_NAME = "builderIoAbTest";
2884
- var CONTENT_FN_NAME = "builderIoRenderContent";
2885
- var getScriptString = () => {
2886
- const fnStr = bldrAbTest.toString().replace(/\s+/g, " ");
2887
- const fnStr2 = bldrCntntScrpt.toString().replace(/\s+/g, " ");
2888
- return `
2889
- window.${AB_TEST_FN_NAME} = ${fnStr}
2890
- window.${CONTENT_FN_NAME} = ${fnStr2}
2855
+ var getScriptString = () => `
2856
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
2857
+ window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
2891
2858
  `;
2892
- };
2893
- var getVariantsScriptString = (variants, contentId) => {
2894
- return `
2895
- window.${AB_TEST_FN_NAME}("${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget})`;
2896
- };
2897
- var getRenderContentScriptString = ({
2859
+ var getUpdateCookieAndStylesScript = (variants, contentId) => `
2860
+ window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME}(
2861
+ "${contentId}",${JSON.stringify(variants)}, ${isHydrationTarget}
2862
+ )`;
2863
+ var getUpdateVariantVisibilityScript = ({
2898
2864
  contentId,
2899
2865
  variationId
2900
- }) => {
2901
- return `
2902
- window.${CONTENT_FN_NAME}("${variationId}", "${contentId}", ${isHydrationTarget})`;
2903
- };
2866
+ }) => `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(
2867
+ "${variationId}", "${contentId}", ${isHydrationTarget}
2868
+ )`;
2904
2869
  var _tmpl$14 = /* @__PURE__ */ template(`<script>`);
2905
2870
  function InlinedScript(props) {
2906
2871
  return (() => {
2907
2872
  const _el$ = _tmpl$14();
2908
2873
  effect((_p$) => {
2909
- const _v$ = props.scriptStr, _v$2 = props.id;
2874
+ const _v$ = props.scriptStr, _v$2 = props.id || "";
2910
2875
  _v$ !== _p$._v$ && (_el$.innerHTML = _p$._v$ = _v$);
2911
2876
  _v$2 !== _p$._v$2 && setAttribute(_el$, "id", _p$._v$2 = _v$2);
2912
2877
  return _p$;
@@ -3404,7 +3369,7 @@ var getInteractionPropertiesForEvent = (event) => {
3404
3369
  };
3405
3370
 
3406
3371
  // src/constants/sdk-version.ts
3407
- var SDK_VERSION = "0.7.3";
3372
+ var SDK_VERSION = "0.7.5";
3408
3373
 
3409
3374
  // src/functions/register.ts
3410
3375
  var registry = {};
@@ -3780,7 +3745,7 @@ function EnableEditor(props) {
3780
3745
  typeof _ref$ === "function" ? use(_ref$, _el$) : elementRef = _el$;
3781
3746
  spread(_el$, mergeProps({
3782
3747
  get ["class"]() {
3783
- return props.classNameProp;
3748
+ return `variant-${props.content?.testVariationId || props.content?.id}`;
3784
3749
  }
3785
3750
  }, {}, {
3786
3751
  get key() {
@@ -3900,22 +3865,20 @@ var getContextStateInitialValue = ({
3900
3865
  locale
3901
3866
  }) => {
3902
3867
  const defaultValues = {};
3868
+ const initialState = content?.data?.state || {};
3903
3869
  content?.data?.inputs?.forEach((input) => {
3904
- if (input.name && input.defaultValue !== void 0 && content?.data?.state && content.data.state[input.name] === void 0) {
3870
+ if (input.name && input.defaultValue !== void 0) {
3905
3871
  defaultValues[input.name] = input.defaultValue;
3906
3872
  }
3907
3873
  });
3908
- const stateToUse = {
3909
- ...content?.data?.state,
3874
+ return {
3875
+ ...defaultValues,
3876
+ ...initialState,
3910
3877
  ...data,
3911
3878
  ...locale ? {
3912
3879
  locale
3913
3880
  } : {}
3914
3881
  };
3915
- return {
3916
- ...defaultValues,
3917
- ...stateToUse
3918
- };
3919
3882
  };
3920
3883
  var getContentInitialValue = ({
3921
3884
  content,
@@ -3933,7 +3896,7 @@ var getContentInitialValue = ({
3933
3896
 
3934
3897
  // src/components/content/content.tsx
3935
3898
  function ContentComponent(props) {
3936
- const [scriptStr, setScriptStr] = createSignal(getRenderContentScriptString({
3899
+ const [scriptStr, setScriptStr] = createSignal(getUpdateVariantVisibilityScript({
3937
3900
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
3938
3901
  variationId: props.content?.testVariationId,
3939
3902
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
@@ -4029,9 +3992,6 @@ function ContentComponent(props) {
4029
3992
  get enrich() {
4030
3993
  return props.enrich;
4031
3994
  },
4032
- get classNameProp() {
4033
- return props.classNameProp;
4034
- },
4035
3995
  get showContent() {
4036
3996
  return props.showContent;
4037
3997
  },
@@ -4088,12 +4048,12 @@ var content_default = ContentComponent;
4088
4048
 
4089
4049
  // src/components/content-variants/content-variants.tsx
4090
4050
  function ContentVariants(props) {
4091
- const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRunVariants({
4051
+ const [shouldRenderVariants, setShouldRenderVariants] = createSignal(checkShouldRenderVariants({
4092
4052
  canTrack: getDefaultCanTrack(props.canTrack),
4093
4053
  content: props.content
4094
4054
  }));
4095
- function variantScriptStr() {
4096
- return getVariantsScriptString(getVariants(props.content).map((value) => ({
4055
+ function updateCookieAndStylesScriptStr() {
4056
+ return getUpdateCookieAndStylesScript(getVariants(props.content).map((value) => ({
4097
4057
  id: value.testVariationId,
4098
4058
  testRatio: value.testRatio
4099
4059
  })), props.content?.id || "");
@@ -4138,7 +4098,7 @@ function ContentVariants(props) {
4138
4098
  }
4139
4099
  }), createComponent(inlined_script_default, {
4140
4100
  get scriptStr() {
4141
- return variantScriptStr();
4101
+ return updateCookieAndStylesScriptStr();
4142
4102
  }
4143
4103
  }), createComponent(For, {
4144
4104
  get each() {
@@ -4152,7 +4112,6 @@ function ContentVariants(props) {
4152
4112
  },
4153
4113
  content: variant,
4154
4114
  showContent: false,
4155
- classNameProp: void 0,
4156
4115
  get model() {
4157
4116
  return props.model;
4158
4117
  },
@@ -4194,9 +4153,6 @@ function ContentVariants(props) {
4194
4153
  get content() {
4195
4154
  return defaultContent();
4196
4155
  },
4197
- get classNameProp() {
4198
- return `variant-${props.content?.id}`;
4199
- },
4200
4156
  showContent: true,
4201
4157
  get model() {
4202
4158
  return props.model;