@builder.io/sdk-qwik 0.1.4 → 0.1.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.
@@ -1,4 +1,4 @@
1
- import { createContext, _IMMUTABLE, _wrapSignal, inlinedQrl, useLexicalScope, componentQrl, useContextProvider, useStore, useStylesScopedQrl, useContext, Fragment as Fragment$1, Slot, useRef, useWatchQrl, useClientEffectQrl, useCleanupQrl } from "@builder.io/qwik";
1
+ import { componentQrl, inlinedQrl, useStylesScopedQrl, _wrapSignal, _IMMUTABLE, createContext, useLexicalScope, useContextProvider, useStore, useContext, Slot, Fragment as Fragment$1, useTaskQrl, useRef, useClientEffectQrl, useCleanupQrl } from "@builder.io/qwik";
2
2
  import { jsx, Fragment, jsxs } from "@builder.io/qwik/jsx-runtime";
3
3
  const TARGET = "qwik";
4
4
  function isBrowser() {
@@ -130,7 +130,35 @@ const setupBrowserForEditing = (options = {}) => {
130
130
  });
131
131
  }
132
132
  };
133
- const BuilderContext = createContext("Builder");
133
+ const Button = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
134
+ useStylesScopedQrl(inlinedQrl(STYLES$3, "Button_component_useStylesScoped_a1JZ0Q0Q2Oc"));
135
+ return /* @__PURE__ */ jsx(Fragment, {
136
+ children: props.link ? /* @__PURE__ */ jsx("a", {
137
+ role: "button",
138
+ ...props.attributes,
139
+ get href() {
140
+ return props.link;
141
+ },
142
+ target: props.openLinkInNewTab ? "_blank" : void 0,
143
+ children: _wrapSignal(props, "text"),
144
+ [_IMMUTABLE]: {
145
+ href: _wrapSignal(props, "link")
146
+ }
147
+ }) : /* @__PURE__ */ jsx("button", {
148
+ class: "button-Button",
149
+ ...props.attributes,
150
+ children: _wrapSignal(props, "text")
151
+ }),
152
+ [_IMMUTABLE]: {
153
+ children: false
154
+ }
155
+ }, "jc_0");
156
+ }, "Button_component_gJoMUICXoUQ"));
157
+ const STYLES$3 = `
158
+ .button-Button {
159
+ all: unset;
160
+ }`;
161
+ const builderContext = createContext("Builder");
134
162
  function isIframe() {
135
163
  return isBrowser() && window.self !== window.top;
136
164
  }
@@ -504,7 +532,7 @@ const RenderComponent = (props) => {
504
532
  }, "R9_0");
505
533
  };
506
534
  const RenderRepeatedBlock = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
507
- useContextProvider(BuilderContext, useStore({
535
+ useContextProvider(builderContext, useStore({
508
536
  content: props.repeatContext.content,
509
537
  state: props.repeatContext.state,
510
538
  context: props.repeatContext.context,
@@ -542,10 +570,24 @@ const useBlock = function useBlock22(props, state) {
542
570
  shouldEvaluateBindings: true
543
571
  });
544
572
  };
573
+ const proxyState = function proxyState2(props, state) {
574
+ if (typeof Proxy === "undefined") {
575
+ console.error("no Proxy available in this environment, cannot proxy state.");
576
+ return props.context.state;
577
+ }
578
+ const useState = new Proxy(props.context.state, {
579
+ set: (obj, prop, value) => {
580
+ obj[prop] = value;
581
+ props.context.setState?.(obj);
582
+ return true;
583
+ }
584
+ });
585
+ return useState;
586
+ };
545
587
  const actions = function actions2(props, state) {
546
588
  return getBlockActions({
547
589
  block: useBlock(props),
548
- state: props.context.state,
590
+ state: proxyState(props),
549
591
  context: props.context.context
550
592
  });
551
593
  };
@@ -592,6 +634,7 @@ const childrenContext = function childrenContext2(props, state) {
592
634
  state: props.context.state,
593
635
  content: props.context.content,
594
636
  context: props.context.context,
637
+ setState: props.context.setState,
595
638
  registeredComponents: props.context.registeredComponents,
596
639
  inheritedStyles: getInheritedTextStyles()
597
640
  };
@@ -654,10 +697,10 @@ const RenderBlock = (props) => {
654
697
  }, "9d_3");
655
698
  };
656
699
  const RenderBlock$1 = RenderBlock;
657
- const className$1 = function className2(props, state, builderContext) {
700
+ const className$1 = function className2(props, state, builderContext2) {
658
701
  return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
659
702
  };
660
- const onClick$1 = function onClick2(props, state, builderContext) {
703
+ const onClick$1 = function onClick2(props, state, builderContext2) {
661
704
  if (isEditing() && !props.blocks?.length)
662
705
  window.parent?.postMessage({
663
706
  type: "builder.clickEmptyBlocks",
@@ -667,7 +710,7 @@ const onClick$1 = function onClick2(props, state, builderContext) {
667
710
  }
668
711
  }, "*");
669
712
  };
670
- const onMouseEnter = function onMouseEnter2(props, state, builderContext) {
713
+ const onMouseEnter = function onMouseEnter2(props, state, builderContext2) {
671
714
  if (isEditing() && !props.blocks?.length)
672
715
  window.parent?.postMessage({
673
716
  type: "builder.hoverEmptyBlocks",
@@ -678,8 +721,8 @@ const onMouseEnter = function onMouseEnter2(props, state, builderContext) {
678
721
  }, "*");
679
722
  };
680
723
  const RenderBlocks = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
681
- useStylesScopedQrl(inlinedQrl(STYLES$3, "RenderBlocks_component_useStylesScoped_0XKYzaR059E"));
682
- const builderContext = useContext(BuilderContext);
724
+ useStylesScopedQrl(inlinedQrl(STYLES$2, "RenderBlocks_component_useStylesScoped_0XKYzaR059E"));
725
+ const builderContext$1 = useContext(builderContext);
683
726
  const state = {};
684
727
  return /* @__PURE__ */ jsxs("div", {
685
728
  class: className$1(props) + " div-RenderBlocks",
@@ -696,7 +739,7 @@ const RenderBlocks = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
696
739
  const [builderContext2, props2, state2] = useLexicalScope();
697
740
  return onClick$1(props2);
698
741
  }, "RenderBlocks_component_div_onClick_RzhhZa265Yg", [
699
- builderContext,
742
+ builderContext$1,
700
743
  props,
701
744
  state
702
745
  ]),
@@ -704,7 +747,7 @@ const RenderBlocks = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
704
747
  const [builderContext2, props2, state2] = useLexicalScope();
705
748
  return onMouseEnter(props2);
706
749
  }, "RenderBlocks_component_div_onMouseEnter_nG7I7RYG3JQ", [
707
- builderContext,
750
+ builderContext$1,
708
751
  props,
709
752
  state
710
753
  ]),
@@ -712,13 +755,13 @@ const RenderBlocks = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
712
755
  props.blocks ? (props.blocks || []).map(function(block) {
713
756
  return /* @__PURE__ */ jsx(RenderBlock$1, {
714
757
  block,
715
- context: builderContext
758
+ context: builderContext$1
716
759
  }, "render-block-" + block.id);
717
760
  }) : null,
718
761
  props.blocks ? (props.blocks || []).map(function(block) {
719
762
  return /* @__PURE__ */ jsx(BlockStyles, {
720
763
  block,
721
- context: builderContext
764
+ context: builderContext$1
722
765
  }, "block-style-" + block.id);
723
766
  }) : null
724
767
  ],
@@ -730,7 +773,7 @@ const RenderBlocks = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
730
773
  }
731
774
  });
732
775
  }, "RenderBlocks_component_MYUZ0j1uLsw"));
733
- const STYLES$3 = `
776
+ const STYLES$2 = `
734
777
  .div-RenderBlocks {
735
778
  display: flex;
736
779
  flex-direction: column;
@@ -825,7 +868,7 @@ const columnsStyles = function columnsStyles2(props, state) {
825
868
  `;
826
869
  };
827
870
  const Columns = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
828
- useStylesScopedQrl(inlinedQrl(STYLES$2, "Columns_component_useStylesScoped_s7JLZz7MCCQ"));
871
+ useStylesScopedQrl(inlinedQrl(STYLES$1, "Columns_component_useStylesScoped_s7JLZz7MCCQ"));
829
872
  const state = {};
830
873
  return /* @__PURE__ */ jsxs("div", {
831
874
  class: `builder-columns ${props.builderBlock.id}-breakpoints div-Columns`,
@@ -870,7 +913,7 @@ const Columns = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
870
913
  }
871
914
  });
872
915
  }, "Columns_component_7yLj4bxdI6c"));
873
- const STYLES$2 = `
916
+ const STYLES$1 = `
874
917
  .div-Columns {
875
918
  display: flex;
876
919
  line-height: normal;
@@ -879,6 +922,11 @@ const STYLES$2 = `
879
922
  flex-direction: column;
880
923
  align-items: stretch;
881
924
  }`;
925
+ const FragmentComponent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
926
+ return /* @__PURE__ */ jsx("span", {
927
+ children: /* @__PURE__ */ jsx(Slot, {}, "oj_0")
928
+ });
929
+ }, "FragmentComponent_component_T0AypnadAK0"));
882
930
  function removeProtocol(path) {
883
931
  return path.replace(/http(s)?:/, "");
884
932
  }
@@ -965,7 +1013,7 @@ const aspectRatioCss = function aspectRatioCss2(props, state) {
965
1013
  return out;
966
1014
  };
967
1015
  const Image = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
968
- useStylesScopedQrl(inlinedQrl(STYLES$1, "Image_component_useStylesScoped_fBMYiVf9fuU"));
1016
+ useStylesScopedQrl(inlinedQrl(STYLES, "Image_component_useStylesScoped_fBMYiVf9fuU"));
969
1017
  return /* @__PURE__ */ jsxs(Fragment$1, {
970
1018
  children: [
971
1019
  /* @__PURE__ */ jsxs("picture", {
@@ -1021,7 +1069,7 @@ const Image = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1021
1069
  }
1022
1070
  }, "0A_2");
1023
1071
  }, "Image_component_LRxDkFa1EfU"));
1024
- const STYLES$1 = `
1072
+ const STYLES = `
1025
1073
  .img-Image {
1026
1074
  opacity: 1;
1027
1075
  transition: opacity 0.2s ease-in-out;
@@ -1039,90 +1087,6 @@ const STYLES$1 = `
1039
1087
  width: 100%;
1040
1088
  height: 100%;
1041
1089
  }`;
1042
- const Text = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1043
- return /* @__PURE__ */ jsx("span", {
1044
- class: "builder-text",
1045
- get dangerouslySetInnerHTML() {
1046
- return props.text;
1047
- },
1048
- [_IMMUTABLE]: {
1049
- dangerouslySetInnerHTML: _wrapSignal(props, "text")
1050
- }
1051
- });
1052
- }, "Text_component_15p0cKUxgIE"));
1053
- const videoProps = function videoProps2(props, state) {
1054
- return {
1055
- ...props.autoPlay === true ? {
1056
- autoPlay: true
1057
- } : {},
1058
- ...props.muted === true ? {
1059
- muted: true
1060
- } : {},
1061
- ...props.controls === true ? {
1062
- controls: true
1063
- } : {},
1064
- ...props.loop === true ? {
1065
- loop: true
1066
- } : {},
1067
- ...props.playsInline === true ? {
1068
- playsInline: true
1069
- } : {}
1070
- };
1071
- };
1072
- const spreadProps = function spreadProps2(props, state) {
1073
- return {
1074
- ...props.attributes,
1075
- ...videoProps(props)
1076
- };
1077
- };
1078
- const Video = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1079
- return /* @__PURE__ */ jsx("video", {
1080
- ...spreadProps(props),
1081
- style: {
1082
- width: "100%",
1083
- height: "100%",
1084
- ...props.attributes?.style,
1085
- objectFit: props.fit,
1086
- objectPosition: props.position,
1087
- borderRadius: 1
1088
- },
1089
- src: props.video || "no-src",
1090
- get poster() {
1091
- return props.posterImage;
1092
- },
1093
- [_IMMUTABLE]: {
1094
- poster: _wrapSignal(props, "posterImage")
1095
- }
1096
- });
1097
- }, "Video_component_qdcTZflYyoQ"));
1098
- const Button = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1099
- useStylesScopedQrl(inlinedQrl(STYLES, "Button_component_useStylesScoped_a1JZ0Q0Q2Oc"));
1100
- return /* @__PURE__ */ jsx(Fragment, {
1101
- children: props.link ? /* @__PURE__ */ jsx("a", {
1102
- role: "button",
1103
- ...props.attributes,
1104
- get href() {
1105
- return props.link;
1106
- },
1107
- target: props.openLinkInNewTab ? "_blank" : void 0,
1108
- children: _wrapSignal(props, "text"),
1109
- [_IMMUTABLE]: {
1110
- href: _wrapSignal(props, "link")
1111
- }
1112
- }) : /* @__PURE__ */ jsx("button", {
1113
- class: "button-Button",
1114
- ...props.attributes,
1115
- children: _wrapSignal(props, "text")
1116
- }),
1117
- [_IMMUTABLE]: {
1118
- children: false
1119
- }
1120
- }, "jc_0");
1121
- }, "Button_component_gJoMUICXoUQ"));
1122
- const STYLES = `
1123
- .button-Button {
1124
- all: unset;
1125
- }`;
1126
1090
  const componentInfo$a = {
1127
1091
  name: "Core:Button",
1128
1092
  builtIn: true,
@@ -1415,11 +1379,6 @@ const componentInfo$8 = {
1415
1379
  canHaveChildren: true,
1416
1380
  noWrap: true
1417
1381
  };
1418
- const FragmentComponent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1419
- return /* @__PURE__ */ jsx("span", {
1420
- children: /* @__PURE__ */ jsx(Slot, {}, "oj_0")
1421
- });
1422
- }, "FragmentComponent_component_T0AypnadAK0"));
1423
1382
  const componentInfo$7 = {
1424
1383
  name: "Image",
1425
1384
  static: true,
@@ -1673,667 +1632,787 @@ const componentInfo$5 = {
1673
1632
  }
1674
1633
  ]
1675
1634
  };
1676
- const componentInfo$4 = {
1677
- name: "Text",
1678
- static: true,
1679
- builtIn: true,
1680
- image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-text_fields-24px%20(1).svg?alt=media&token=12177b73-0ee3-42ca-98c6-0dd003de1929",
1681
- inputs: [
1682
- {
1683
- name: "text",
1684
- type: "html",
1685
- required: true,
1686
- autoFocus: true,
1687
- bubble: true,
1688
- defaultValue: "Enter some text..."
1689
- }
1635
+ function getGlobalThis() {
1636
+ if (typeof globalThis !== "undefined")
1637
+ return globalThis;
1638
+ if (typeof window !== "undefined")
1639
+ return window;
1640
+ if (typeof global !== "undefined")
1641
+ return global;
1642
+ if (typeof self !== "undefined")
1643
+ return self;
1644
+ return globalThis;
1645
+ }
1646
+ function getFetch() {
1647
+ const globalFetch = getGlobalThis().fetch;
1648
+ if (typeof globalFetch === "undefined") {
1649
+ console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
1650
+ For more information, read https://github.com/BuilderIO/this-package-uses-fetch`);
1651
+ throw new Error("Builder SDK could not find a global `fetch` function");
1652
+ }
1653
+ return globalFetch;
1654
+ }
1655
+ const fetch$1 = getFetch();
1656
+ const getTopLevelDomain = (host) => {
1657
+ if (host === "localhost" || host === "127.0.0.1")
1658
+ return host;
1659
+ const parts = host.split(".");
1660
+ if (parts.length > 2)
1661
+ return parts.slice(1).join(".");
1662
+ return host;
1663
+ };
1664
+ const getCookie = async ({ name, canTrack }) => {
1665
+ try {
1666
+ if (!canTrack)
1667
+ return void 0;
1668
+ return document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))?.split("=")[1];
1669
+ } catch (err) {
1670
+ console.debug("[COOKIE] GET error: ", err);
1671
+ return void 0;
1672
+ }
1673
+ };
1674
+ const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).filter(checkIsDefined).join("; ");
1675
+ const SECURE_CONFIG = [
1676
+ [
1677
+ "secure",
1678
+ ""
1690
1679
  ],
1691
- defaultStyles: {
1692
- lineHeight: "normal",
1693
- height: "auto",
1694
- textAlign: "center"
1680
+ [
1681
+ "SameSite",
1682
+ "None"
1683
+ ]
1684
+ ];
1685
+ const createCookieString = ({ name, value, expires }) => {
1686
+ const secure = isBrowser() ? location.protocol === "https:" : true;
1687
+ const secureObj = secure ? SECURE_CONFIG : [
1688
+ []
1689
+ ];
1690
+ const expiresObj = expires ? [
1691
+ [
1692
+ "expires",
1693
+ expires.toUTCString()
1694
+ ]
1695
+ ] : [
1696
+ []
1697
+ ];
1698
+ const cookieValue = [
1699
+ [
1700
+ name,
1701
+ value
1702
+ ],
1703
+ ...expiresObj,
1704
+ [
1705
+ "path",
1706
+ "/"
1707
+ ],
1708
+ [
1709
+ "domain",
1710
+ getTopLevelDomain(window.location.hostname)
1711
+ ],
1712
+ ...secureObj
1713
+ ];
1714
+ const cookie = stringifyCookie(cookieValue);
1715
+ return cookie;
1716
+ };
1717
+ const setCookie = async ({ name, value, expires, canTrack }) => {
1718
+ try {
1719
+ if (!canTrack)
1720
+ return;
1721
+ const cookie = createCookieString({
1722
+ name,
1723
+ value,
1724
+ expires
1725
+ });
1726
+ document.cookie = cookie;
1727
+ } catch (err) {
1728
+ console.warn("[COOKIE] SET error: ", err);
1695
1729
  }
1696
1730
  };
1697
- const componentInfo$3 = {
1698
- name: "Video",
1699
- canHaveChildren: true,
1700
- builtIn: true,
1701
- defaultStyles: {
1702
- minHeight: "20px",
1703
- minWidth: "20px"
1704
- },
1705
- image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-videocam-24px%20(1).svg?alt=media&token=49a84e4a-b20e-4977-a650-047f986874bb",
1706
- inputs: [
1707
- {
1708
- name: "video",
1709
- type: "file",
1710
- allowedFileTypes: [
1711
- "mp4"
1712
- ],
1713
- bubble: true,
1714
- defaultValue: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/assets%2FKQlEmWDxA0coC3PK6UvkrjwkIGI2%2F28cb070609f546cdbe5efa20e931aa4b?alt=media&token=912e9551-7a7c-4dfb-86b6-3da1537d1a7f",
1715
- required: true
1716
- },
1717
- {
1718
- name: "posterImage",
1719
- type: "file",
1720
- allowedFileTypes: [
1721
- "jpeg",
1722
- "png"
1723
- ],
1724
- helperText: "Image to show before the video plays"
1725
- },
1726
- {
1727
- name: "autoPlay",
1728
- type: "boolean",
1729
- defaultValue: true
1730
- },
1731
- {
1732
- name: "controls",
1733
- type: "boolean",
1734
- defaultValue: false
1735
- },
1736
- {
1737
- name: "muted",
1738
- type: "boolean",
1739
- defaultValue: true
1740
- },
1741
- {
1742
- name: "loop",
1743
- type: "boolean",
1744
- defaultValue: true
1745
- },
1746
- {
1747
- name: "playsInline",
1748
- type: "boolean",
1749
- defaultValue: true
1750
- },
1751
- {
1752
- name: "fit",
1753
- type: "text",
1754
- defaultValue: "cover",
1755
- enum: [
1756
- "contain",
1757
- "cover",
1758
- "fill",
1759
- "auto"
1760
- ]
1761
- },
1762
- {
1763
- name: "fitContent",
1764
- type: "boolean",
1765
- helperText: "When child blocks are provided, fit to them instead of using the aspect ratio",
1766
- defaultValue: true,
1767
- advanced: true
1768
- },
1769
- {
1770
- name: "position",
1771
- type: "text",
1772
- defaultValue: "center",
1773
- enum: [
1774
- "center",
1775
- "top",
1776
- "left",
1777
- "right",
1778
- "bottom",
1779
- "top left",
1780
- "top right",
1781
- "bottom left",
1782
- "bottom right"
1783
- ]
1784
- },
1785
- {
1786
- name: "height",
1787
- type: "number",
1788
- advanced: true
1789
- },
1790
- {
1791
- name: "width",
1792
- type: "number",
1793
- advanced: true
1794
- },
1795
- {
1796
- name: "aspectRatio",
1797
- type: "number",
1798
- advanced: true,
1799
- defaultValue: 0.7004048582995948
1800
- },
1801
- {
1802
- name: "lazyLoad",
1803
- type: "boolean",
1804
- helperText: 'Load this video "lazily" - as in only when a user scrolls near the video. Recommended for optmized performance and bandwidth consumption',
1805
- defaultValue: true,
1806
- advanced: true
1807
- }
1808
- ]
1731
+ const BUILDER_STORE_PREFIX = "builderio.variations";
1732
+ const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
1733
+ const getContentVariationCookie = ({ contentId, canTrack }) => getCookie({
1734
+ name: getContentTestKey(contentId),
1735
+ canTrack
1736
+ });
1737
+ const setContentVariationCookie = ({ contentId, canTrack, value }) => setCookie({
1738
+ name: getContentTestKey(contentId),
1739
+ value,
1740
+ canTrack
1741
+ });
1742
+ const checkIsBuilderContentWithVariations = (item) => checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
1743
+ const getRandomVariationId = ({ id, variations }) => {
1744
+ let n = 0;
1745
+ const random = Math.random();
1746
+ for (const id1 in variations) {
1747
+ const testRatio = variations[id1]?.testRatio;
1748
+ n += testRatio;
1749
+ if (random < n)
1750
+ return id1;
1751
+ }
1752
+ return id;
1809
1753
  };
1810
- const componentInfo$2 = {
1811
- name: "Embed",
1812
- static: true,
1813
- builtIn: true,
1814
- inputs: [
1815
- {
1816
- name: "url",
1817
- type: "url",
1818
- required: true,
1819
- defaultValue: "",
1820
- helperText: "e.g. enter a youtube url, google map, etc",
1821
- onChange: serializeFn((options) => {
1822
- const url = options.get("url");
1823
- if (url) {
1824
- options.set("content", "Loading...");
1825
- const apiKey = "ae0e60e78201a3f2b0de4b";
1826
- return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then((res) => res.json()).then((data) => {
1827
- if (options.get("url") === url) {
1828
- if (data.html)
1829
- options.set("content", data.html);
1830
- else
1831
- options.set("content", "Invalid url, please try another");
1832
- }
1833
- }).catch((_err) => {
1834
- options.set("content", "There was an error embedding this URL, please try again or another URL");
1835
- });
1836
- } else
1837
- options.delete("content");
1838
- })
1839
- },
1840
- {
1841
- name: "content",
1842
- type: "html",
1843
- defaultValue: '<div style="padding: 20px; text-align: center">(Choose an embed URL)<div>',
1844
- hideFromUI: true
1845
- }
1846
- ]
1754
+ const getTestFields = ({ item, testGroupId }) => {
1755
+ const variationValue = item.variations[testGroupId];
1756
+ if (testGroupId === item.id || !variationValue)
1757
+ return {
1758
+ testVariationId: item.id,
1759
+ testVariationName: "Default"
1760
+ };
1761
+ else
1762
+ return {
1763
+ data: variationValue.data,
1764
+ testVariationId: variationValue.id,
1765
+ testVariationName: variationValue.name || (variationValue.id === item.id ? "Default" : "")
1766
+ };
1847
1767
  };
1848
- const SCRIPT_MIME_TYPES = [
1849
- "text/javascript",
1850
- "application/javascript",
1851
- "application/ecmascript"
1852
- ];
1853
- const isJsScript = (script) => SCRIPT_MIME_TYPES.includes(script.type);
1854
- const findAndRunScripts$1 = function findAndRunScripts2(props, state, elem) {
1855
- if (!elem || !elem.getElementsByTagName)
1768
+ const getContentVariation = async ({ item, canTrack }) => {
1769
+ const testGroupId = await getContentVariationCookie({
1770
+ canTrack,
1771
+ contentId: item.id
1772
+ });
1773
+ const testFields = testGroupId ? getTestFields({
1774
+ item,
1775
+ testGroupId
1776
+ }) : void 0;
1777
+ if (testFields)
1778
+ return testFields;
1779
+ else {
1780
+ const randomVariationId = getRandomVariationId({
1781
+ variations: item.variations,
1782
+ id: item.id
1783
+ });
1784
+ setContentVariationCookie({
1785
+ contentId: item.id,
1786
+ value: randomVariationId,
1787
+ canTrack
1788
+ }).catch((err) => {
1789
+ console.error("could not store A/B test variation: ", err);
1790
+ });
1791
+ return getTestFields({
1792
+ item,
1793
+ testGroupId: randomVariationId
1794
+ });
1795
+ }
1796
+ };
1797
+ const handleABTesting = async ({ item, canTrack }) => {
1798
+ if (!checkIsBuilderContentWithVariations(item))
1856
1799
  return;
1857
- const scripts = elem.getElementsByTagName("script");
1858
- for (let i = 0; i < scripts.length; i++) {
1859
- const script = scripts[i];
1860
- if (script.src && !state.scriptsInserted.includes(script.src)) {
1861
- state.scriptsInserted.push(script.src);
1862
- const newScript = document.createElement("script");
1863
- newScript.async = true;
1864
- newScript.src = script.src;
1865
- document.head.appendChild(newScript);
1866
- } else if (isJsScript(script) && !state.scriptsRun.includes(script.innerText))
1867
- try {
1868
- state.scriptsRun.push(script.innerText);
1869
- new Function(script.innerText)();
1870
- } catch (error) {
1871
- console.warn("`Embed`: Error running script:", error);
1872
- }
1800
+ const variationValue = await getContentVariation({
1801
+ item,
1802
+ canTrack
1803
+ });
1804
+ Object.assign(item, variationValue);
1805
+ };
1806
+ function flatten(object, path = null, separator = ".") {
1807
+ return Object.keys(object).reduce((acc, key) => {
1808
+ const value = object[key];
1809
+ const newPath = [
1810
+ path,
1811
+ key
1812
+ ].filter(Boolean).join(separator);
1813
+ const isObject = [
1814
+ typeof value === "object",
1815
+ value !== null,
1816
+ !(Array.isArray(value) && value.length === 0)
1817
+ ].every(Boolean);
1818
+ return isObject ? {
1819
+ ...acc,
1820
+ ...flatten(value, newPath, separator)
1821
+ } : {
1822
+ ...acc,
1823
+ [newPath]: value
1824
+ };
1825
+ }, {});
1826
+ }
1827
+ const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
1828
+ const BUILDER_OPTIONS_PREFIX = "options.";
1829
+ const convertSearchParamsToQueryObject = (searchParams) => {
1830
+ const options = {};
1831
+ searchParams.forEach((value, key) => {
1832
+ options[key] = value;
1833
+ });
1834
+ return options;
1835
+ };
1836
+ const getBuilderSearchParams = (_options) => {
1837
+ if (!_options)
1838
+ return {};
1839
+ const options = normalizeSearchParams(_options);
1840
+ const newOptions = {};
1841
+ Object.keys(options).forEach((key) => {
1842
+ if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
1843
+ const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
1844
+ newOptions[trimmedKey] = options[key];
1845
+ }
1846
+ });
1847
+ return newOptions;
1848
+ };
1849
+ const getBuilderSearchParamsFromWindow = () => {
1850
+ if (!isBrowser())
1851
+ return {};
1852
+ const searchParams = new URLSearchParams(window.location.search);
1853
+ return getBuilderSearchParams(searchParams);
1854
+ };
1855
+ const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
1856
+ const generateContentUrl = (options) => {
1857
+ const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale } = options;
1858
+ if (!apiKey)
1859
+ throw new Error("Missing API key");
1860
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
1861
+ const queryOptions = {
1862
+ ...getBuilderSearchParamsFromWindow(),
1863
+ ...normalizeSearchParams(options.options || {})
1864
+ };
1865
+ const flattened = flatten(queryOptions);
1866
+ for (const key in flattened)
1867
+ url.searchParams.set(key, String(flattened[key]));
1868
+ if (userAttributes)
1869
+ url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
1870
+ if (query) {
1871
+ const flattened1 = flatten({
1872
+ query
1873
+ });
1874
+ for (const key1 in flattened1)
1875
+ url.searchParams.set(key1, JSON.stringify(flattened1[key1]));
1873
1876
  }
1877
+ return url;
1874
1878
  };
1875
- const Embed = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1876
- const elem = useRef();
1879
+ async function getContent(options) {
1880
+ return (await getAllContent({
1881
+ ...options,
1882
+ limit: 1
1883
+ })).results[0] || null;
1884
+ }
1885
+ async function getAllContent(options) {
1886
+ const url = generateContentUrl(options);
1887
+ const res = await fetch$1(url.href);
1888
+ const content = await res.json();
1889
+ const canTrack = options.canTrack !== false;
1890
+ if (canTrack && Array.isArray(content.results))
1891
+ for (const item of content.results)
1892
+ await handleABTesting({
1893
+ item,
1894
+ canTrack
1895
+ });
1896
+ return content;
1897
+ }
1898
+ const className = function className22(props, state, builderContext2) {
1899
+ return [
1900
+ ...[
1901
+ props.attributes.class
1902
+ ],
1903
+ "builder-symbol",
1904
+ props.symbol?.inline ? "builder-inline-symbol" : void 0,
1905
+ props.symbol?.dynamic || props.dynamic ? "builder-dynamic-symbol" : void 0
1906
+ ].filter(Boolean).join(" ");
1907
+ };
1908
+ const contentToUse = function contentToUse2(props, state, builderContext2) {
1909
+ return props.symbol?.content || state.fetchedContent;
1910
+ };
1911
+ const Symbol$1 = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1912
+ const builderContext$1 = useContext(builderContext);
1877
1913
  const state = useStore({
1878
- ranInitFn: false,
1879
- scriptsInserted: [],
1880
- scriptsRun: []
1914
+ fetchedContent: null
1881
1915
  });
1882
- useWatchQrl(inlinedQrl(({ track: track2 }) => {
1883
- const [elem2, props2, state2] = useLexicalScope();
1884
- state2 && track2(state2, "ranInitFn");
1885
- if (elem2 && !state2.ranInitFn) {
1886
- state2.ranInitFn = true;
1887
- findAndRunScripts$1(props2, state2, elem2);
1888
- }
1889
- }, "Embed_component_useWatch_AxgWjrHdlAI", [
1890
- elem,
1916
+ useTaskQrl(inlinedQrl(({ track: track2 }) => {
1917
+ const [builderContext2, props2, state2] = useLexicalScope();
1918
+ track2(() => props2.symbol);
1919
+ track2(() => state2.fetchedContent);
1920
+ const symbolToUse = props2.symbol;
1921
+ if (symbolToUse && !symbolToUse.content && !state2.fetchedContent && symbolToUse.model && builderContext2?.apiKey)
1922
+ getContent({
1923
+ model: symbolToUse.model,
1924
+ apiKey: builderContext2.apiKey,
1925
+ query: {
1926
+ id: symbolToUse.entry
1927
+ }
1928
+ }).then((response) => {
1929
+ state2.fetchedContent = response;
1930
+ });
1931
+ }, "Symbol_component_useTask_NIAWAC1bMBo", [
1932
+ builderContext$1,
1891
1933
  props,
1892
1934
  state
1893
1935
  ]));
1894
1936
  return /* @__PURE__ */ jsx("div", {
1895
- class: "builder-embed",
1896
- ref: elem,
1937
+ ...props.attributes,
1938
+ class: className(props),
1939
+ children: /* @__PURE__ */ jsx(RenderContent$1, {
1940
+ get apiKey() {
1941
+ return builderContext$1.apiKey;
1942
+ },
1943
+ get context() {
1944
+ return builderContext$1.context;
1945
+ },
1946
+ customComponents: Object.values(builderContext$1.registeredComponents),
1947
+ data: {
1948
+ ...props.symbol?.data,
1949
+ ...builderContext$1.state,
1950
+ ...props.symbol?.content?.data?.state
1951
+ },
1952
+ model: props.symbol?.model,
1953
+ content: contentToUse(props, state),
1954
+ [_IMMUTABLE]: {
1955
+ apiKey: _wrapSignal(builderContext$1, "apiKey"),
1956
+ context: _wrapSignal(builderContext$1, "context")
1957
+ }
1958
+ }, "Wt_0")
1959
+ });
1960
+ }, "Symbol_component_WVvggdkUPdk"));
1961
+ const componentInfo$4 = {
1962
+ name: "Text",
1963
+ static: true,
1964
+ builtIn: true,
1965
+ image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-text_fields-24px%20(1).svg?alt=media&token=12177b73-0ee3-42ca-98c6-0dd003de1929",
1966
+ inputs: [
1967
+ {
1968
+ name: "text",
1969
+ type: "html",
1970
+ required: true,
1971
+ autoFocus: true,
1972
+ bubble: true,
1973
+ defaultValue: "Enter some text..."
1974
+ }
1975
+ ],
1976
+ defaultStyles: {
1977
+ lineHeight: "normal",
1978
+ height: "auto",
1979
+ textAlign: "center"
1980
+ }
1981
+ };
1982
+ const Text = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1983
+ return /* @__PURE__ */ jsx("span", {
1984
+ class: "builder-text",
1897
1985
  get dangerouslySetInnerHTML() {
1898
- return props.content;
1986
+ return props.text;
1899
1987
  },
1900
1988
  [_IMMUTABLE]: {
1901
- dangerouslySetInnerHTML: _wrapSignal(props, "content")
1989
+ dangerouslySetInnerHTML: _wrapSignal(props, "text")
1902
1990
  }
1903
1991
  });
1904
- }, "Embed_component_Uji08ORjXbE"));
1905
- const ImgComponent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1906
- return /* @__PURE__ */ jsx("img", {
1907
- style: {
1908
- objectFit: props.backgroundSize || "cover",
1909
- objectPosition: props.backgroundPosition || "center"
1910
- },
1911
- get alt() {
1912
- return props.altText;
1913
- },
1914
- src: props.imgSrc || props.image,
1915
- ...props.attributes,
1916
- [_IMMUTABLE]: {
1917
- alt: _wrapSignal(props, "altText")
1918
- }
1919
- }, isEditing() && props.imgSrc || "default-key");
1920
- }, "ImgComponent_component_FXvIDBSffO8"));
1921
- const componentInfo$1 = {
1922
- name: "Raw:Img",
1923
- hideFromInsertMenu: true,
1992
+ }, "Text_component_15p0cKUxgIE"));
1993
+ const componentInfo$3 = {
1994
+ name: "Video",
1995
+ canHaveChildren: true,
1924
1996
  builtIn: true,
1925
- image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4",
1997
+ defaultStyles: {
1998
+ minHeight: "20px",
1999
+ minWidth: "20px"
2000
+ },
2001
+ image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-videocam-24px%20(1).svg?alt=media&token=49a84e4a-b20e-4977-a650-047f986874bb",
1926
2002
  inputs: [
1927
2003
  {
1928
- name: "image",
2004
+ name: "video",
2005
+ type: "file",
2006
+ allowedFileTypes: [
2007
+ "mp4"
2008
+ ],
1929
2009
  bubble: true,
2010
+ defaultValue: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/assets%2FKQlEmWDxA0coC3PK6UvkrjwkIGI2%2F28cb070609f546cdbe5efa20e931aa4b?alt=media&token=912e9551-7a7c-4dfb-86b6-3da1537d1a7f",
2011
+ required: true
2012
+ },
2013
+ {
2014
+ name: "posterImage",
1930
2015
  type: "file",
1931
2016
  allowedFileTypes: [
1932
2017
  "jpeg",
1933
- "jpg",
1934
- "png",
1935
- "svg"
2018
+ "png"
1936
2019
  ],
1937
- required: true
1938
- }
1939
- ],
1940
- noWrap: true,
1941
- static: true
1942
- };
1943
- const findAndRunScripts = function findAndRunScripts22(props, state, elem) {
1944
- if (elem && elem.getElementsByTagName && typeof window !== "undefined") {
1945
- const scripts = elem.getElementsByTagName("script");
1946
- for (let i = 0; i < scripts.length; i++) {
1947
- const script = scripts[i];
1948
- if (script.src) {
1949
- if (state.scriptsInserted.includes(script.src))
1950
- continue;
1951
- state.scriptsInserted.push(script.src);
1952
- const newScript = document.createElement("script");
1953
- newScript.async = true;
1954
- newScript.src = script.src;
1955
- document.head.appendChild(newScript);
1956
- } else if (!script.type || [
1957
- "text/javascript",
1958
- "application/javascript",
1959
- "application/ecmascript"
1960
- ].includes(script.type)) {
1961
- if (state.scriptsRun.includes(script.innerText))
1962
- continue;
1963
- try {
1964
- state.scriptsRun.push(script.innerText);
1965
- new Function(script.innerText)();
1966
- } catch (error) {
1967
- console.warn("`CustomCode`: Error running script:", error);
1968
- }
1969
- }
1970
- }
1971
- }
1972
- };
1973
- const CustomCode = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
1974
- const elem = useRef();
1975
- const state = useStore({
1976
- scriptsInserted: [],
1977
- scriptsRun: []
1978
- });
1979
- useClientEffectQrl(inlinedQrl(() => {
1980
- const [elem2, props2, state2] = useLexicalScope();
1981
- findAndRunScripts(props2, state2, elem2);
1982
- }, "CustomCode_component_useClientEffect_4w4c951ufB4", [
1983
- elem,
1984
- props,
1985
- state
1986
- ]));
1987
- return /* @__PURE__ */ jsx("div", {
1988
- ref: elem,
1989
- class: "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : ""),
1990
- get dangerouslySetInnerHTML() {
1991
- return props.code;
2020
+ helperText: "Image to show before the video plays"
2021
+ },
2022
+ {
2023
+ name: "autoPlay",
2024
+ type: "boolean",
2025
+ defaultValue: true
1992
2026
  },
1993
- [_IMMUTABLE]: {
1994
- dangerouslySetInnerHTML: _wrapSignal(props, "code")
1995
- }
1996
- });
1997
- }, "CustomCode_component_uYOSy7w7Zqw"));
1998
- const componentInfo = {
1999
- name: "Custom Code",
2000
- static: true,
2001
- builtIn: true,
2002
- requiredPermissions: [
2003
- "editCode"
2004
- ],
2005
- inputs: [
2006
2027
  {
2007
- name: "code",
2008
- type: "html",
2009
- required: true,
2010
- defaultValue: "<p>Hello there, I am custom HTML code!</p>",
2011
- code: true
2028
+ name: "controls",
2029
+ type: "boolean",
2030
+ defaultValue: false
2012
2031
  },
2013
2032
  {
2014
- name: "replaceNodes",
2033
+ name: "muted",
2015
2034
  type: "boolean",
2016
- helperText: "Preserve server rendered dom nodes",
2017
- advanced: true
2035
+ defaultValue: true
2018
2036
  },
2019
2037
  {
2020
- name: "scriptsClientOnly",
2038
+ name: "loop",
2021
2039
  type: "boolean",
2022
- defaultValue: false,
2023
- helperText: "Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads",
2040
+ defaultValue: true
2041
+ },
2042
+ {
2043
+ name: "playsInline",
2044
+ type: "boolean",
2045
+ defaultValue: true
2046
+ },
2047
+ {
2048
+ name: "fit",
2049
+ type: "text",
2050
+ defaultValue: "cover",
2051
+ enum: [
2052
+ "contain",
2053
+ "cover",
2054
+ "fill",
2055
+ "auto"
2056
+ ]
2057
+ },
2058
+ {
2059
+ name: "fitContent",
2060
+ type: "boolean",
2061
+ helperText: "When child blocks are provided, fit to them instead of using the aspect ratio",
2062
+ defaultValue: true,
2024
2063
  advanced: true
2025
- }
2026
- ]
2027
- };
2028
- const getDefaultRegisteredComponents = () => [
2029
- {
2030
- component: Columns,
2031
- ...componentInfo$9
2032
- },
2033
- {
2034
- component: Image,
2035
- ...componentInfo$7
2036
- },
2037
- {
2038
- component: ImgComponent,
2039
- ...componentInfo$1
2040
- },
2041
- {
2042
- component: Text,
2043
- ...componentInfo$4
2044
- },
2045
- {
2046
- component: Video,
2047
- ...componentInfo$3
2048
- },
2049
- {
2050
- component: Symbol$1,
2051
- ...componentInfo$5
2052
- },
2053
- {
2054
- component: Button,
2055
- ...componentInfo$a
2056
- },
2057
- {
2058
- component: SectionComponent,
2059
- ...componentInfo$6
2060
- },
2061
- {
2062
- component: FragmentComponent,
2063
- ...componentInfo$8
2064
- },
2065
- {
2066
- component: Embed,
2067
- ...componentInfo$2
2068
- },
2069
- {
2070
- component: CustomCode,
2071
- ...componentInfo
2072
- }
2073
- ];
2074
- function getGlobalThis() {
2075
- if (typeof globalThis !== "undefined")
2076
- return globalThis;
2077
- if (typeof window !== "undefined")
2078
- return window;
2079
- if (typeof global !== "undefined")
2080
- return global;
2081
- if (typeof self !== "undefined")
2082
- return self;
2083
- return globalThis;
2084
- }
2085
- function getFetch() {
2086
- const globalFetch = getGlobalThis().fetch;
2087
- if (typeof globalFetch === "undefined") {
2088
- console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
2089
- For more information, read https://github.com/BuilderIO/this-package-uses-fetch`);
2090
- throw new Error("Builder SDK could not find a global `fetch` function");
2091
- }
2092
- return globalFetch;
2093
- }
2094
- const fetch$1 = getFetch();
2095
- const getTopLevelDomain = (host) => {
2096
- if (host === "localhost" || host === "127.0.0.1")
2097
- return host;
2098
- const parts = host.split(".");
2099
- if (parts.length > 2)
2100
- return parts.slice(1).join(".");
2101
- return host;
2102
- };
2103
- const getCookie = async ({ name, canTrack }) => {
2104
- try {
2105
- if (!canTrack)
2106
- return void 0;
2107
- return document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))?.split("=")[1];
2108
- } catch (err) {
2109
- console.debug("[COOKIE] GET error: ", err);
2110
- return void 0;
2111
- }
2112
- };
2113
- const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).filter(checkIsDefined).join("; ");
2114
- const SECURE_CONFIG = [
2115
- [
2116
- "secure",
2117
- ""
2118
- ],
2119
- [
2120
- "SameSite",
2121
- "None"
2122
- ]
2123
- ];
2124
- const createCookieString = ({ name, value, expires }) => {
2125
- const secure = isBrowser() ? location.protocol === "https:" : true;
2126
- const secureObj = secure ? SECURE_CONFIG : [
2127
- []
2128
- ];
2129
- const expiresObj = expires ? [
2130
- [
2131
- "expires",
2132
- expires.toUTCString()
2133
- ]
2134
- ] : [
2135
- []
2136
- ];
2137
- const cookieValue = [
2138
- [
2139
- name,
2140
- value
2141
- ],
2142
- ...expiresObj,
2143
- [
2144
- "path",
2145
- "/"
2146
- ],
2147
- [
2148
- "domain",
2149
- getTopLevelDomain(window.location.hostname)
2150
- ],
2151
- ...secureObj
2152
- ];
2153
- const cookie = stringifyCookie(cookieValue);
2154
- return cookie;
2155
- };
2156
- const setCookie = async ({ name, value, expires, canTrack }) => {
2157
- try {
2158
- if (!canTrack)
2159
- return;
2160
- const cookie = createCookieString({
2161
- name,
2162
- value,
2163
- expires
2164
- });
2165
- document.cookie = cookie;
2166
- } catch (err) {
2167
- console.warn("[COOKIE] SET error: ", err);
2168
- }
2169
- };
2170
- const BUILDER_STORE_PREFIX = "builderio.variations";
2171
- const getContentTestKey = (id) => `${BUILDER_STORE_PREFIX}.${id}`;
2172
- const getContentVariationCookie = ({ contentId, canTrack }) => getCookie({
2173
- name: getContentTestKey(contentId),
2174
- canTrack
2175
- });
2176
- const setContentVariationCookie = ({ contentId, canTrack, value }) => setCookie({
2177
- name: getContentTestKey(contentId),
2178
- value,
2179
- canTrack
2180
- });
2181
- const checkIsBuilderContentWithVariations = (item) => checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
2182
- const getRandomVariationId = ({ id, variations }) => {
2183
- let n = 0;
2184
- const random = Math.random();
2185
- for (const id1 in variations) {
2186
- const testRatio = variations[id1]?.testRatio;
2187
- n += testRatio;
2188
- if (random < n)
2189
- return id1;
2190
- }
2191
- return id;
2064
+ },
2065
+ {
2066
+ name: "position",
2067
+ type: "text",
2068
+ defaultValue: "center",
2069
+ enum: [
2070
+ "center",
2071
+ "top",
2072
+ "left",
2073
+ "right",
2074
+ "bottom",
2075
+ "top left",
2076
+ "top right",
2077
+ "bottom left",
2078
+ "bottom right"
2079
+ ]
2080
+ },
2081
+ {
2082
+ name: "height",
2083
+ type: "number",
2084
+ advanced: true
2085
+ },
2086
+ {
2087
+ name: "width",
2088
+ type: "number",
2089
+ advanced: true
2090
+ },
2091
+ {
2092
+ name: "aspectRatio",
2093
+ type: "number",
2094
+ advanced: true,
2095
+ defaultValue: 0.7004048582995948
2096
+ },
2097
+ {
2098
+ name: "lazyLoad",
2099
+ type: "boolean",
2100
+ helperText: 'Load this video "lazily" - as in only when a user scrolls near the video. Recommended for optmized performance and bandwidth consumption',
2101
+ defaultValue: true,
2102
+ advanced: true
2103
+ }
2104
+ ]
2192
2105
  };
2193
- const getTestFields = ({ item, testGroupId }) => {
2194
- const variationValue = item.variations[testGroupId];
2195
- if (testGroupId === item.id || !variationValue)
2196
- return {
2197
- testVariationId: item.id,
2198
- testVariationName: "Default"
2199
- };
2200
- else
2201
- return {
2202
- data: variationValue.data,
2203
- testVariationId: variationValue.id,
2204
- testVariationName: variationValue.name || (variationValue.id === item.id ? "Default" : "")
2205
- };
2106
+ const videoProps = function videoProps2(props, state) {
2107
+ return {
2108
+ ...props.autoPlay === true ? {
2109
+ autoPlay: true
2110
+ } : {},
2111
+ ...props.muted === true ? {
2112
+ muted: true
2113
+ } : {},
2114
+ ...props.controls === true ? {
2115
+ controls: true
2116
+ } : {},
2117
+ ...props.loop === true ? {
2118
+ loop: true
2119
+ } : {},
2120
+ ...props.playsInline === true ? {
2121
+ playsInline: true
2122
+ } : {}
2123
+ };
2206
2124
  };
2207
- const getContentVariation = async ({ item, canTrack }) => {
2208
- const testGroupId = await getContentVariationCookie({
2209
- canTrack,
2210
- contentId: item.id
2125
+ const spreadProps = function spreadProps2(props, state) {
2126
+ return {
2127
+ ...props.attributes,
2128
+ ...videoProps(props)
2129
+ };
2130
+ };
2131
+ const Video = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2132
+ return /* @__PURE__ */ jsx("video", {
2133
+ ...spreadProps(props),
2134
+ style: {
2135
+ width: "100%",
2136
+ height: "100%",
2137
+ ...props.attributes?.style,
2138
+ objectFit: props.fit,
2139
+ objectPosition: props.position,
2140
+ borderRadius: 1
2141
+ },
2142
+ src: props.video || "no-src",
2143
+ get poster() {
2144
+ return props.posterImage;
2145
+ },
2146
+ [_IMMUTABLE]: {
2147
+ poster: _wrapSignal(props, "posterImage")
2148
+ }
2211
2149
  });
2212
- const testFields = testGroupId ? getTestFields({
2213
- item,
2214
- testGroupId
2215
- }) : void 0;
2216
- if (testFields)
2217
- return testFields;
2218
- else {
2219
- const randomVariationId = getRandomVariationId({
2220
- variations: item.variations,
2221
- id: item.id
2222
- });
2223
- setContentVariationCookie({
2224
- contentId: item.id,
2225
- value: randomVariationId,
2226
- canTrack
2227
- }).catch((err) => {
2228
- console.error("could not store A/B test variation: ", err);
2229
- });
2230
- return getTestFields({
2231
- item,
2232
- testGroupId: randomVariationId
2233
- });
2234
- }
2150
+ }, "Video_component_qdcTZflYyoQ"));
2151
+ const componentInfo$2 = {
2152
+ name: "Embed",
2153
+ static: true,
2154
+ builtIn: true,
2155
+ inputs: [
2156
+ {
2157
+ name: "url",
2158
+ type: "url",
2159
+ required: true,
2160
+ defaultValue: "",
2161
+ helperText: "e.g. enter a youtube url, google map, etc",
2162
+ onChange: serializeFn((options) => {
2163
+ const url = options.get("url");
2164
+ if (url) {
2165
+ options.set("content", "Loading...");
2166
+ const apiKey = "ae0e60e78201a3f2b0de4b";
2167
+ return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then((res) => res.json()).then((data) => {
2168
+ if (options.get("url") === url) {
2169
+ if (data.html)
2170
+ options.set("content", data.html);
2171
+ else
2172
+ options.set("content", "Invalid url, please try another");
2173
+ }
2174
+ }).catch((_err) => {
2175
+ options.set("content", "There was an error embedding this URL, please try again or another URL");
2176
+ });
2177
+ } else
2178
+ options.delete("content");
2179
+ })
2180
+ },
2181
+ {
2182
+ name: "content",
2183
+ type: "html",
2184
+ defaultValue: '<div style="padding: 20px; text-align: center">(Choose an embed URL)<div>',
2185
+ hideFromUI: true
2186
+ }
2187
+ ]
2235
2188
  };
2236
- const handleABTesting = async ({ item, canTrack }) => {
2237
- if (!checkIsBuilderContentWithVariations(item))
2189
+ const SCRIPT_MIME_TYPES = [
2190
+ "text/javascript",
2191
+ "application/javascript",
2192
+ "application/ecmascript"
2193
+ ];
2194
+ const isJsScript = (script) => SCRIPT_MIME_TYPES.includes(script.type);
2195
+ const findAndRunScripts$1 = function findAndRunScripts2(props, state, elem) {
2196
+ if (!elem || !elem.getElementsByTagName)
2238
2197
  return;
2239
- const variationValue = await getContentVariation({
2240
- item,
2241
- canTrack
2242
- });
2243
- Object.assign(item, variationValue);
2198
+ const scripts = elem.getElementsByTagName("script");
2199
+ for (let i = 0; i < scripts.length; i++) {
2200
+ const script = scripts[i];
2201
+ if (script.src && !state.scriptsInserted.includes(script.src)) {
2202
+ state.scriptsInserted.push(script.src);
2203
+ const newScript = document.createElement("script");
2204
+ newScript.async = true;
2205
+ newScript.src = script.src;
2206
+ document.head.appendChild(newScript);
2207
+ } else if (isJsScript(script) && !state.scriptsRun.includes(script.innerText))
2208
+ try {
2209
+ state.scriptsRun.push(script.innerText);
2210
+ new Function(script.innerText)();
2211
+ } catch (error) {
2212
+ console.warn("`Embed`: Error running script:", error);
2213
+ }
2214
+ }
2244
2215
  };
2245
- function flatten(object, path = null, separator = ".") {
2246
- return Object.keys(object).reduce((acc, key) => {
2247
- const value = object[key];
2248
- const newPath = [
2249
- path,
2250
- key
2251
- ].filter(Boolean).join(separator);
2252
- const isObject = [
2253
- typeof value === "object",
2254
- value !== null,
2255
- !(Array.isArray(value) && value.length === 0)
2256
- ].every(Boolean);
2257
- return isObject ? {
2258
- ...acc,
2259
- ...flatten(value, newPath, separator)
2260
- } : {
2261
- ...acc,
2262
- [newPath]: value
2263
- };
2264
- }, {});
2265
- }
2266
- const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
2267
- const BUILDER_OPTIONS_PREFIX = "options.";
2268
- const convertSearchParamsToQueryObject = (searchParams) => {
2269
- const options = {};
2270
- searchParams.forEach((value, key) => {
2271
- options[key] = value;
2216
+ const Embed = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2217
+ const elem = useRef();
2218
+ const state = useStore({
2219
+ ranInitFn: false,
2220
+ scriptsInserted: [],
2221
+ scriptsRun: []
2272
2222
  });
2273
- return options;
2223
+ useTaskQrl(inlinedQrl(({ track: track2 }) => {
2224
+ const [elem2, props2, state2] = useLexicalScope();
2225
+ track2(() => elem2);
2226
+ track2(() => state2.ranInitFn);
2227
+ if (elem2 && !state2.ranInitFn) {
2228
+ state2.ranInitFn = true;
2229
+ findAndRunScripts$1(props2, state2, elem2);
2230
+ }
2231
+ }, "Embed_component_useTask_bg7ez0XUtiM", [
2232
+ elem,
2233
+ props,
2234
+ state
2235
+ ]));
2236
+ return /* @__PURE__ */ jsx("div", {
2237
+ class: "builder-embed",
2238
+ ref: elem,
2239
+ get dangerouslySetInnerHTML() {
2240
+ return props.content;
2241
+ },
2242
+ [_IMMUTABLE]: {
2243
+ dangerouslySetInnerHTML: _wrapSignal(props, "content")
2244
+ }
2245
+ });
2246
+ }, "Embed_component_Uji08ORjXbE"));
2247
+ const ImgComponent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2248
+ return /* @__PURE__ */ jsx("img", {
2249
+ style: {
2250
+ objectFit: props.backgroundSize || "cover",
2251
+ objectPosition: props.backgroundPosition || "center"
2252
+ },
2253
+ get alt() {
2254
+ return props.altText;
2255
+ },
2256
+ src: props.imgSrc || props.image,
2257
+ ...props.attributes,
2258
+ [_IMMUTABLE]: {
2259
+ alt: _wrapSignal(props, "altText")
2260
+ }
2261
+ }, isEditing() && props.imgSrc || "default-key");
2262
+ }, "ImgComponent_component_FXvIDBSffO8"));
2263
+ const componentInfo$1 = {
2264
+ name: "Raw:Img",
2265
+ hideFromInsertMenu: true,
2266
+ builtIn: true,
2267
+ image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4",
2268
+ inputs: [
2269
+ {
2270
+ name: "image",
2271
+ bubble: true,
2272
+ type: "file",
2273
+ allowedFileTypes: [
2274
+ "jpeg",
2275
+ "jpg",
2276
+ "png",
2277
+ "svg"
2278
+ ],
2279
+ required: true
2280
+ }
2281
+ ],
2282
+ noWrap: true,
2283
+ static: true
2284
+ };
2285
+ const findAndRunScripts = function findAndRunScripts22(props, state, elem) {
2286
+ if (elem && elem.getElementsByTagName && typeof window !== "undefined") {
2287
+ const scripts = elem.getElementsByTagName("script");
2288
+ for (let i = 0; i < scripts.length; i++) {
2289
+ const script = scripts[i];
2290
+ if (script.src) {
2291
+ if (state.scriptsInserted.includes(script.src))
2292
+ continue;
2293
+ state.scriptsInserted.push(script.src);
2294
+ const newScript = document.createElement("script");
2295
+ newScript.async = true;
2296
+ newScript.src = script.src;
2297
+ document.head.appendChild(newScript);
2298
+ } else if (!script.type || [
2299
+ "text/javascript",
2300
+ "application/javascript",
2301
+ "application/ecmascript"
2302
+ ].includes(script.type)) {
2303
+ if (state.scriptsRun.includes(script.innerText))
2304
+ continue;
2305
+ try {
2306
+ state.scriptsRun.push(script.innerText);
2307
+ new Function(script.innerText)();
2308
+ } catch (error) {
2309
+ console.warn("`CustomCode`: Error running script:", error);
2310
+ }
2311
+ }
2312
+ }
2313
+ }
2274
2314
  };
2275
- const getBuilderSearchParams = (_options) => {
2276
- if (!_options)
2277
- return {};
2278
- const options = normalizeSearchParams(_options);
2279
- const newOptions = {};
2280
- Object.keys(options).forEach((key) => {
2281
- if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
2282
- const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
2283
- newOptions[trimmedKey] = options[key];
2315
+ const CustomCode = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2316
+ const elem = useRef();
2317
+ const state = useStore({
2318
+ scriptsInserted: [],
2319
+ scriptsRun: []
2320
+ });
2321
+ useClientEffectQrl(inlinedQrl(() => {
2322
+ const [elem2, props2, state2] = useLexicalScope();
2323
+ findAndRunScripts(props2, state2, elem2);
2324
+ }, "CustomCode_component_useClientEffect_4w4c951ufB4", [
2325
+ elem,
2326
+ props,
2327
+ state
2328
+ ]));
2329
+ return /* @__PURE__ */ jsx("div", {
2330
+ ref: elem,
2331
+ class: "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : ""),
2332
+ get dangerouslySetInnerHTML() {
2333
+ return props.code;
2334
+ },
2335
+ [_IMMUTABLE]: {
2336
+ dangerouslySetInnerHTML: _wrapSignal(props, "code")
2284
2337
  }
2285
2338
  });
2286
- return newOptions;
2287
- };
2288
- const getBuilderSearchParamsFromWindow = () => {
2289
- if (!isBrowser())
2290
- return {};
2291
- const searchParams = new URLSearchParams(window.location.search);
2292
- return getBuilderSearchParams(searchParams);
2339
+ }, "CustomCode_component_uYOSy7w7Zqw"));
2340
+ const componentInfo = {
2341
+ name: "Custom Code",
2342
+ static: true,
2343
+ builtIn: true,
2344
+ requiredPermissions: [
2345
+ "editCode"
2346
+ ],
2347
+ inputs: [
2348
+ {
2349
+ name: "code",
2350
+ type: "html",
2351
+ required: true,
2352
+ defaultValue: "<p>Hello there, I am custom HTML code!</p>",
2353
+ code: true
2354
+ },
2355
+ {
2356
+ name: "replaceNodes",
2357
+ type: "boolean",
2358
+ helperText: "Preserve server rendered dom nodes",
2359
+ advanced: true
2360
+ },
2361
+ {
2362
+ name: "scriptsClientOnly",
2363
+ type: "boolean",
2364
+ defaultValue: false,
2365
+ helperText: "Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads",
2366
+ advanced: true
2367
+ }
2368
+ ]
2293
2369
  };
2294
- const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
2295
- const generateContentUrl = (options) => {
2296
- const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale } = options;
2297
- if (!apiKey)
2298
- throw new Error("Missing API key");
2299
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
2300
- const queryOptions = {
2301
- ...getBuilderSearchParamsFromWindow(),
2302
- ...normalizeSearchParams(options.options || {})
2303
- };
2304
- const flattened = flatten(queryOptions);
2305
- for (const key in flattened)
2306
- url.searchParams.set(key, String(flattened[key]));
2307
- if (userAttributes)
2308
- url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
2309
- if (query) {
2310
- const flattened1 = flatten({
2311
- query
2312
- });
2313
- for (const key1 in flattened1)
2314
- url.searchParams.set(key1, JSON.stringify(flattened1[key1]));
2370
+ const getDefaultRegisteredComponents = () => [
2371
+ {
2372
+ component: Button,
2373
+ ...componentInfo$a
2374
+ },
2375
+ {
2376
+ component: Columns,
2377
+ ...componentInfo$9
2378
+ },
2379
+ {
2380
+ component: CustomCode,
2381
+ ...componentInfo
2382
+ },
2383
+ {
2384
+ component: Embed,
2385
+ ...componentInfo$2
2386
+ },
2387
+ {
2388
+ component: FragmentComponent,
2389
+ ...componentInfo$8
2390
+ },
2391
+ {
2392
+ component: Image,
2393
+ ...componentInfo$7
2394
+ },
2395
+ {
2396
+ component: ImgComponent,
2397
+ ...componentInfo$1
2398
+ },
2399
+ {
2400
+ component: SectionComponent,
2401
+ ...componentInfo$6
2402
+ },
2403
+ {
2404
+ component: Symbol$1,
2405
+ ...componentInfo$5
2406
+ },
2407
+ {
2408
+ component: Text,
2409
+ ...componentInfo$4
2410
+ },
2411
+ {
2412
+ component: Video,
2413
+ ...componentInfo$3
2315
2414
  }
2316
- return url;
2317
- };
2318
- async function getContent(options) {
2319
- return (await getAllContent({
2320
- ...options,
2321
- limit: 1
2322
- })).results[0] || null;
2323
- }
2324
- async function getAllContent(options) {
2325
- const url = generateContentUrl(options);
2326
- const res = await fetch$1(url.href);
2327
- const content = await res.json();
2328
- const canTrack = options.canTrack !== false;
2329
- if (canTrack && Array.isArray(content.results))
2330
- for (const item of content.results)
2331
- await handleABTesting({
2332
- item,
2333
- canTrack
2334
- });
2335
- return content;
2336
- }
2415
+ ];
2337
2416
  function isPreviewing() {
2338
2417
  if (!isBrowser())
2339
2418
  return false;
@@ -2594,20 +2673,20 @@ const getInteractionPropertiesForEvent = (event) => {
2594
2673
  }
2595
2674
  };
2596
2675
  };
2597
- const getCssFromFont = function getCssFromFont2(props, state, font) {
2676
+ const getCssFromFont = (font) => {
2598
2677
  const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
2599
2678
  const name = family.split(",")[0];
2600
2679
  const url = font.fileUrl ?? font?.files?.regular;
2601
2680
  let str = "";
2602
2681
  if (url && family && name)
2603
2682
  str += `
2604
- @font-face {
2605
- font-family: "${family}";
2606
- src: local("${name}"), url('${url}') format('woff2');
2607
- font-display: fallback;
2608
- font-weight: 400;
2609
- }
2610
- `.trim();
2683
+ @font-face {
2684
+ font-family: "${family}";
2685
+ src: local("${name}"), url('${url}') format('woff2');
2686
+ font-display: fallback;
2687
+ font-weight: 400;
2688
+ }
2689
+ `.trim();
2611
2690
  if (font.files)
2612
2691
  for (const weight in font.files) {
2613
2692
  const isNumber = String(Number(weight)) === weight;
@@ -2616,60 +2695,102 @@ const getCssFromFont = function getCssFromFont2(props, state, font) {
2616
2695
  const weightUrl = font.files[weight];
2617
2696
  if (weightUrl && weightUrl !== url)
2618
2697
  str += `
2619
- @font-face {
2620
- font-family: "${family}";
2621
- src: url('${weightUrl}') format('woff2');
2622
- font-display: fallback;
2623
- font-weight: ${weight};
2624
- }
2625
- `.trim();
2698
+ @font-face {
2699
+ font-family: "${family}";
2700
+ src: url('${weightUrl}') format('woff2');
2701
+ font-display: fallback;
2702
+ font-weight: ${weight};
2703
+ }
2704
+ `.trim();
2626
2705
  }
2627
2706
  return str;
2628
2707
  };
2629
- const getFontCss = function getFontCss2(props, state, { customFonts }) {
2630
- return customFonts?.map((font) => getCssFromFont(props, state, font))?.join(" ") || "";
2708
+ const getFontCss = ({ customFonts }) => {
2709
+ return customFonts?.map((font) => getCssFromFont(font))?.join(" ") || "";
2631
2710
  };
2632
- const injectedStyles = function injectedStyles2(props, state) {
2633
- return `
2634
- ${props.cssCode || ""}
2635
- ${getFontCss(props, state, {
2636
- customFonts: props.customFonts
2637
- })}`;
2711
+ const getCss = ({ cssCode, contentId }) => {
2712
+ if (!cssCode)
2713
+ return "";
2714
+ if (!contentId)
2715
+ return cssCode;
2716
+ return cssCode?.replace(/&/g, `div[builder-content-id="${contentId}"]`) || "";
2638
2717
  };
2639
2718
  const RenderContentStyles = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2640
- const state = {};
2719
+ const state = useStore({
2720
+ injectedStyles: `
2721
+ ${getCss({
2722
+ cssCode: props.cssCode,
2723
+ contentId: props.contentId
2724
+ })}
2725
+ ${getFontCss({
2726
+ customFonts: props.customFonts
2727
+ })}
2728
+ `
2729
+ });
2641
2730
  return /* @__PURE__ */ jsx(RenderInlinedStyles, {
2642
- styles: injectedStyles(props, state)
2731
+ get styles() {
2732
+ return state.injectedStyles;
2733
+ },
2734
+ [_IMMUTABLE]: {
2735
+ styles: _wrapSignal(state, "injectedStyles")
2736
+ }
2643
2737
  }, "V0_0");
2644
2738
  }, "RenderContentStyles_component_Og0xL34Zbvc"));
2645
- const useContent = function useContent2(props, state, elementRef) {
2646
- if (!props.content && !state.overrideContent)
2647
- return void 0;
2739
+ const getContextStateInitialValue = ({ content, data, locale }) => {
2740
+ const defaultValues = {};
2741
+ content?.data?.inputs?.forEach((input) => {
2742
+ if (input.name && input.defaultValue !== void 0 && content?.data?.state && content.data.state[input.name] === void 0)
2743
+ defaultValues[input.name] = input.defaultValue;
2744
+ });
2745
+ const stateToUse = {
2746
+ ...content?.data?.state,
2747
+ ...data,
2748
+ ...locale ? {
2749
+ locale
2750
+ } : {}
2751
+ };
2648
2752
  return {
2649
- ...props.content,
2650
- ...state.overrideContent,
2753
+ ...defaultValues,
2754
+ ...stateToUse
2755
+ };
2756
+ };
2757
+ const getContentInitialValue = ({ content, data }) => {
2758
+ return !content ? void 0 : {
2759
+ ...content,
2760
+ data: {
2761
+ ...content?.data,
2762
+ ...data
2763
+ },
2764
+ meta: content?.meta
2765
+ };
2766
+ };
2767
+ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newContent) {
2768
+ state.useContent = {
2769
+ ...state.useContent,
2770
+ ...newContent,
2651
2771
  data: {
2652
- ...props.content?.data,
2653
- ...props.data,
2654
- ...state.overrideContent?.data
2772
+ ...state.useContent?.data,
2773
+ ...newContent?.data
2655
2774
  },
2656
2775
  meta: {
2657
- ...props.content?.meta,
2658
- ...state.overrideContent?.meta,
2659
- breakpoints: state.useBreakpoints || state.overrideContent?.meta?.breakpoints || props.content?.meta?.breakpoints
2776
+ ...state.useContent?.meta,
2777
+ ...newContent?.meta,
2778
+ breakpoints: newContent?.meta?.breakpoints || state.useContent?.meta?.breakpoints
2660
2779
  }
2661
2780
  };
2662
2781
  };
2663
- const contentState = function contentState2(props, state, elementRef) {
2664
- return {
2665
- ...props.content?.data?.state,
2666
- ...props.data,
2667
- ...props.locale ? {
2668
- locale: props.locale
2669
- } : {},
2670
- ...state.overrideState
2782
+ const setBreakpoints = function setBreakpoints2(props, state, elementRef, breakpoints) {
2783
+ state.useContent = {
2784
+ ...state.useContent,
2785
+ meta: {
2786
+ ...state.useContent?.meta,
2787
+ breakpoints
2788
+ }
2671
2789
  };
2672
2790
  };
2791
+ const setContextState = function setContextState2(props, state, elementRef, newState) {
2792
+ state.contentState = newState;
2793
+ };
2673
2794
  const processMessage = function processMessage2(props, state, elementRef, event) {
2674
2795
  const { data } = event;
2675
2796
  if (data)
@@ -2677,9 +2798,10 @@ const processMessage = function processMessage2(props, state, elementRef, event)
2677
2798
  case "builder.configureSdk": {
2678
2799
  const messageContent = data.data;
2679
2800
  const { breakpoints, contentId } = messageContent;
2680
- if (!contentId || contentId !== useContent(props, state)?.id)
2801
+ if (!contentId || contentId !== state.useContent?.id)
2681
2802
  return;
2682
- state.useBreakpoints = breakpoints;
2803
+ if (breakpoints)
2804
+ setBreakpoints(props, state, elementRef, breakpoints);
2683
2805
  state.forceReRenderCount = state.forceReRenderCount + 1;
2684
2806
  break;
2685
2807
  }
@@ -2688,7 +2810,7 @@ const processMessage = function processMessage2(props, state, elementRef, event)
2688
2810
  const key = messageContent1.key || messageContent1.alias || messageContent1.entry || messageContent1.modelName;
2689
2811
  const contentData = messageContent1.data;
2690
2812
  if (key === props.model) {
2691
- state.overrideContent = contentData;
2813
+ mergeNewContent(props, state, elementRef, contentData);
2692
2814
  state.forceReRenderCount = state.forceReRenderCount + 1;
2693
2815
  }
2694
2816
  break;
@@ -2696,18 +2818,18 @@ const processMessage = function processMessage2(props, state, elementRef, event)
2696
2818
  }
2697
2819
  };
2698
2820
  const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
2699
- const jsCode = useContent(props, state)?.data?.jsCode;
2821
+ const jsCode = state.useContent?.data?.jsCode;
2700
2822
  if (jsCode)
2701
2823
  evaluate({
2702
2824
  code: jsCode,
2703
- context: state.contextContext,
2704
- state: contentState(props, state)
2825
+ context: props.context || {},
2826
+ state: state.contentState
2705
2827
  });
2706
2828
  };
2707
2829
  const onClick = function onClick22(props, state, elementRef, event) {
2708
- if (useContent(props, state)) {
2709
- const variationId = useContent(props, state)?.testVariationId;
2710
- const contentId = useContent(props, state)?.id;
2830
+ if (state.useContent) {
2831
+ const variationId = state.useContent?.testVariationId;
2832
+ const contentId = state.useContent?.id;
2711
2833
  _track({
2712
2834
  type: "click",
2713
2835
  canTrack: state.canTrackToUse,
@@ -2724,23 +2846,23 @@ const onClick = function onClick22(props, state, elementRef, event) {
2724
2846
  const evalExpression = function evalExpression2(props, state, elementRef, expression) {
2725
2847
  return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
2726
2848
  code: group,
2727
- context: state.contextContext,
2728
- state: contentState(props, state)
2849
+ context: props.context || {},
2850
+ state: state.contentState
2729
2851
  }));
2730
2852
  };
2731
2853
  const handleRequest = function handleRequest2(props, state, elementRef, { url, key }) {
2732
2854
  fetch$1(url).then((response) => response.json()).then((json) => {
2733
- const newOverrideState = {
2734
- ...state.overrideState,
2855
+ const newState = {
2856
+ ...state.contentState,
2735
2857
  [key]: json
2736
2858
  };
2737
- state.overrideState = newOverrideState;
2859
+ setContextState(props, state, elementRef, newState);
2738
2860
  }).catch((err) => {
2739
2861
  console.log("error fetching dynamic data", url, err);
2740
2862
  });
2741
2863
  };
2742
2864
  const runHttpRequests = function runHttpRequests2(props, state, elementRef) {
2743
- const requests = useContent(props, state)?.data?.httpRequests ?? {};
2865
+ const requests = state.useContent?.data?.httpRequests ?? {};
2744
2866
  Object.entries(requests).forEach(([key, url]) => {
2745
2867
  if (url && (!state.httpReqsData[key] || isEditing())) {
2746
2868
  const evaluatedUrl = evalExpression(props, state, elementRef, url);
@@ -2755,7 +2877,7 @@ const emitStateUpdate = function emitStateUpdate2(props, state, elementRef) {
2755
2877
  if (isEditing())
2756
2878
  window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
2757
2879
  detail: {
2758
- state: contentState(props, state),
2880
+ state: state.contentState,
2759
2881
  ref: {
2760
2882
  name: props.model
2761
2883
  }
@@ -2763,7 +2885,7 @@ const emitStateUpdate = function emitStateUpdate2(props, state, elementRef) {
2763
2885
  }));
2764
2886
  };
2765
2887
  const shouldRenderContentStyles = function shouldRenderContentStyles2(props, state, elementRef) {
2766
- return Boolean((useContent(props, state)?.data?.cssCode || useContent(props, state)?.data?.customFonts?.length) && TARGET !== "reactNative");
2888
+ return Boolean((state.useContent?.data?.cssCode || state.useContent?.data?.customFonts?.length) && TARGET !== "reactNative");
2767
2889
  };
2768
2890
  const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2769
2891
  const elementRef = useRef();
@@ -2778,18 +2900,24 @@ const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2778
2900
  }), {}),
2779
2901
  canTrackToUse: checkIsDefined(props.canTrack) ? props.canTrack : true,
2780
2902
  clicked: false,
2781
- contextContext: props.context || {},
2903
+ contentState: getContextStateInitialValue({
2904
+ content: props.content,
2905
+ data: props.data,
2906
+ locale: props.locale
2907
+ }),
2782
2908
  forceReRenderCount: 0,
2783
2909
  httpReqsData: {},
2784
2910
  overrideContent: null,
2785
- overrideState: {},
2786
2911
  update: 0,
2787
- useBreakpoints: null
2912
+ useContent: getContentInitialValue({
2913
+ content: props.content,
2914
+ data: props.data
2915
+ })
2788
2916
  });
2789
- useContextProvider(BuilderContext, useStore({
2790
- content: useContent(props, state),
2791
- state: contentState(props, state),
2792
- context: state.contextContext,
2917
+ useContextProvider(builderContext, useStore({
2918
+ content: state.useContent,
2919
+ state: state.contentState,
2920
+ context: props.context || {},
2793
2921
  apiKey: props.apiKey,
2794
2922
  registeredComponents: state.allRegisteredComponents
2795
2923
  }));
@@ -2816,9 +2944,9 @@ const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2816
2944
  window.addEventListener("message", processMessage.bind(null, props2, state2, elementRef2));
2817
2945
  window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate.bind(null, props2, state2, elementRef2));
2818
2946
  }
2819
- if (useContent(props2, state2)) {
2820
- const variationId = useContent(props2, state2)?.testVariationId;
2821
- const contentId = useContent(props2, state2)?.id;
2947
+ if (state2.useContent) {
2948
+ const variationId = state2.useContent?.testVariationId;
2949
+ const contentId = state2.useContent?.id;
2822
2950
  _track({
2823
2951
  type: "impression",
2824
2952
  canTrack: state2.canTrackToUse,
@@ -2837,7 +2965,7 @@ const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2837
2965
  apiKey: props2.apiKey
2838
2966
  }).then((content) => {
2839
2967
  if (content)
2840
- state2.overrideContent = content;
2968
+ mergeNewContent(props2, state2, elementRef2, content);
2841
2969
  });
2842
2970
  }
2843
2971
  evaluateJsCode(props2, state2);
@@ -2849,30 +2977,30 @@ const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2849
2977
  props,
2850
2978
  state
2851
2979
  ]));
2852
- useWatchQrl(inlinedQrl(({ track: track2 }) => {
2980
+ useTaskQrl(inlinedQrl(({ track: track2 }) => {
2853
2981
  const [elementRef2, props2, state2] = useLexicalScope();
2854
- state2.useContent?.data && track2(state2.useContent?.data, "jsCode");
2855
- state2 && track2(state2, "contentState");
2982
+ track2(() => state2.useContent?.data?.jsCode);
2983
+ track2(() => state2.contentState);
2856
2984
  evaluateJsCode(props2, state2);
2857
- }, "RenderContent_component_useWatch_OIBatobA0hE", [
2985
+ }, "RenderContent_component_useTask_Kulmlf9pM08", [
2858
2986
  elementRef,
2859
2987
  props,
2860
2988
  state
2861
2989
  ]));
2862
- useWatchQrl(inlinedQrl(({ track: track2 }) => {
2990
+ useTaskQrl(inlinedQrl(({ track: track2 }) => {
2863
2991
  const [elementRef2, props2, state2] = useLexicalScope();
2864
- state2.useContent?.data && track2(state2.useContent?.data, "httpRequests");
2992
+ track2(() => state2.useContent?.data?.httpRequests);
2865
2993
  runHttpRequests(props2, state2, elementRef2);
2866
- }, "RenderContent_component_useWatch_1_LQM67VNl14k", [
2994
+ }, "RenderContent_component_useTask_1_X59YMGOetns", [
2867
2995
  elementRef,
2868
2996
  props,
2869
2997
  state
2870
2998
  ]));
2871
- useWatchQrl(inlinedQrl(({ track: track2 }) => {
2999
+ useTaskQrl(inlinedQrl(({ track: track2 }) => {
2872
3000
  const [elementRef2, props2, state2] = useLexicalScope();
2873
- state2 && track2(state2, "contentState");
3001
+ track2(() => state2.contentState);
2874
3002
  emitStateUpdate(props2, state2);
2875
- }, "RenderContent_component_useWatch_2_aGi0RpYNBO0", [
3003
+ }, "RenderContent_component_useTask_2_u3gn3Pj2b2s", [
2876
3004
  elementRef,
2877
3005
  props,
2878
3006
  state
@@ -2889,7 +3017,7 @@ const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2889
3017
  state
2890
3018
  ]));
2891
3019
  return /* @__PURE__ */ jsx(Fragment, {
2892
- children: useContent(props, state) ? /* @__PURE__ */ jsxs("div", {
3020
+ children: state.useContent ? /* @__PURE__ */ jsxs("div", {
2893
3021
  ref: elementRef,
2894
3022
  onClick$: inlinedQrl((event) => {
2895
3023
  const [elementRef2, props2, state2] = useLexicalScope();
@@ -2899,17 +3027,18 @@ const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2899
3027
  props,
2900
3028
  state
2901
3029
  ]),
2902
- "builder-content-id": useContent(props, state)?.id,
3030
+ "builder-content-id": state.useContent?.id,
2903
3031
  get "builder-model"() {
2904
3032
  return props.model;
2905
3033
  },
2906
3034
  children: [
2907
3035
  shouldRenderContentStyles(props, state) ? /* @__PURE__ */ jsx(RenderContentStyles, {
2908
- cssCode: useContent(props, state)?.data?.cssCode,
2909
- customFonts: useContent(props, state)?.data?.customFonts
3036
+ contentId: state.useContent?.id,
3037
+ cssCode: state.useContent?.data?.cssCode,
3038
+ customFonts: state.useContent?.data?.customFonts
2910
3039
  }, "03_0") : null,
2911
3040
  /* @__PURE__ */ jsx(RenderBlocks, {
2912
- blocks: useContent(props, state)?.data?.blocks
3041
+ blocks: state.useContent?.data?.blocks
2913
3042
  }, state.forceReRenderCount)
2914
3043
  ],
2915
3044
  [_IMMUTABLE]: {
@@ -2922,69 +3051,7 @@ const RenderContent = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2922
3051
  }
2923
3052
  }, "03_1");
2924
3053
  }, "RenderContent_component_hEAI0ahViXM"));
2925
- const className = function className22(props, state, builderContext) {
2926
- return [
2927
- ...[
2928
- props.attributes.class
2929
- ],
2930
- "builder-symbol",
2931
- props.symbol?.inline ? "builder-inline-symbol" : void 0,
2932
- props.symbol?.dynamic || props.dynamic ? "builder-dynamic-symbol" : void 0
2933
- ].filter(Boolean).join(" ");
2934
- };
2935
- const contentToUse = function contentToUse2(props, state, builderContext) {
2936
- return props.symbol?.content || state.fetchedContent;
2937
- };
2938
- const Symbol$1 = /* @__PURE__ */ componentQrl(inlinedQrl((props) => {
2939
- const builderContext = useContext(BuilderContext);
2940
- const state = useStore({
2941
- fetchedContent: null
2942
- });
2943
- useWatchQrl(inlinedQrl(({ track: track2 }) => {
2944
- const [builderContext2, props2, state2] = useLexicalScope();
2945
- props2 && track2(props2, "symbol");
2946
- state2 && track2(state2, "fetchedContent");
2947
- const symbolToUse = props2.symbol;
2948
- if (symbolToUse && !symbolToUse.content && !state2.fetchedContent && symbolToUse.model && builderContext2?.apiKey)
2949
- getContent({
2950
- model: symbolToUse.model,
2951
- apiKey: builderContext2.apiKey,
2952
- query: {
2953
- id: symbolToUse.entry
2954
- }
2955
- }).then((response) => {
2956
- state2.fetchedContent = response;
2957
- });
2958
- }, "Symbol_component_useWatch_9HNT04zd0Dk", [
2959
- builderContext,
2960
- props,
2961
- state
2962
- ]));
2963
- return /* @__PURE__ */ jsx("div", {
2964
- ...props.attributes,
2965
- class: className(props),
2966
- children: /* @__PURE__ */ jsx(RenderContent, {
2967
- get apiKey() {
2968
- return builderContext.apiKey;
2969
- },
2970
- get context() {
2971
- return builderContext.context;
2972
- },
2973
- customComponents: Object.values(builderContext.registeredComponents),
2974
- data: {
2975
- ...props.symbol?.data,
2976
- ...builderContext.state,
2977
- ...props.symbol?.content?.data?.state
2978
- },
2979
- model: props.symbol?.model,
2980
- content: contentToUse(props, state),
2981
- [_IMMUTABLE]: {
2982
- apiKey: _wrapSignal(builderContext, "apiKey"),
2983
- context: _wrapSignal(builderContext, "context")
2984
- }
2985
- }, "Wt_0")
2986
- });
2987
- }, "Symbol_component_WVvggdkUPdk"));
3054
+ const RenderContent$1 = RenderContent;
2988
3055
  const settings = {};
2989
3056
  function setEditorSettings(newSettings) {
2990
3057
  if (isBrowser()) {
@@ -3002,7 +3069,7 @@ export {
3002
3069
  FragmentComponent as Fragment,
3003
3070
  Image,
3004
3071
  RenderBlocks,
3005
- RenderContent,
3072
+ RenderContent$1 as RenderContent,
3006
3073
  SectionComponent as Section,
3007
3074
  Symbol$1 as Symbol,
3008
3075
  Text,