@builder.io/sdk-solid 0.12.1 → 0.12.2

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
@@ -635,6 +635,10 @@ interface ContentVariantsPrps {
635
635
  * Additonal props to pass to `blocksWrapper`. Defaults to `{}`.
636
636
  */
637
637
  blocksWrapperProps?: any;
638
+ /**
639
+ * List of hosts to allow editing content from.
640
+ */
641
+ trustedHosts?: string[];
638
642
  }
639
643
 
640
644
  type VariantsProviderProps = ContentVariantsPrps & {
@@ -1,4 +1,4 @@
1
- import { createComponent, spread, mergeProps, insert, effect, setAttribute, className, style, template, memo, Dynamic, use } from 'solid-js/web';
1
+ import { createComponent, spread, mergeProps, insert, effect, setAttribute, className, style, template, Dynamic, memo, use } from 'solid-js/web';
2
2
  import { createContext, Show, useContext, For, createSignal, onMount, createEffect, on } from 'solid-js';
3
3
  import { css } from 'solid-styled-components';
4
4
 
@@ -333,10 +333,6 @@ function getProcessedBlock({
333
333
  }
334
334
 
335
335
  // src/components/block/block.helpers.ts
336
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
337
- var isEmptyHtmlElement = (tagName) => {
338
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
339
- };
340
336
  var getComponent = ({
341
337
  block,
342
338
  context,
@@ -658,48 +654,80 @@ function getStyleAttribute(style) {
658
654
  }
659
655
  }
660
656
 
661
- // src/components/block/components/block-wrapper.tsx
662
- function BlockWrapper(props) {
657
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
658
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
659
+ var isEmptyElement = (tagName) => {
660
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
661
+ };
662
+
663
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
664
+ function DynamicRenderer(props) {
663
665
  return createComponent(Show, {
664
666
  get fallback() {
665
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
666
- block: props.block,
667
- context: props.context
668
- }), () => getBlockActions({
669
- block: props.block,
670
- rootState: props.context.rootState,
671
- rootSetState: props.context.rootSetState,
672
- localState: props.context.localState,
673
- context: props.context.context,
674
- stripPrefix: true
675
- }), {
667
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
676
668
  get component() {
677
- return props.Wrapper;
669
+ return props.TagName;
678
670
  }
679
671
  }));
680
672
  },
681
673
  get when() {
682
- return props.hasChildren;
674
+ return !isEmptyElement(props.TagName);
683
675
  },
684
676
  get children() {
685
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
677
+ return createComponent(Show, {
678
+ get fallback() {
679
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
680
+ get component() {
681
+ return props.TagName;
682
+ },
683
+ get children() {
684
+ return props.children;
685
+ }
686
+ }));
687
+ },
688
+ get when() {
689
+ return typeof props.TagName === "string";
690
+ },
691
+ get children() {
692
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
693
+ get component() {
694
+ return props.TagName;
695
+ },
696
+ get children() {
697
+ return props.children;
698
+ }
699
+ }));
700
+ }
701
+ });
702
+ }
703
+ });
704
+ }
705
+ var dynamic_renderer_default = DynamicRenderer;
706
+
707
+ // src/components/block/components/block-wrapper.tsx
708
+ function BlockWrapper(props) {
709
+ return createComponent(dynamic_renderer_default, {
710
+ get TagName() {
711
+ return props.Wrapper;
712
+ },
713
+ get attributes() {
714
+ return getBlockProperties({
686
715
  block: props.block,
687
716
  context: props.context
688
- }), () => getBlockActions({
717
+ });
718
+ },
719
+ get actionAttributes() {
720
+ return getBlockActions({
689
721
  block: props.block,
690
722
  rootState: props.context.rootState,
691
723
  rootSetState: props.context.rootSetState,
692
724
  localState: props.context.localState,
693
725
  context: props.context.context,
694
726
  stripPrefix: true
695
- }), {
696
- get component() {
697
- return props.Wrapper;
698
- },
699
- get children() {
700
- return props.children;
701
- }
702
- }));
727
+ });
728
+ },
729
+ get children() {
730
+ return props.children;
703
731
  }
704
732
  });
705
733
  }
@@ -940,29 +968,8 @@ function Block(props) {
940
968
  return !blockComponent()?.noWrap;
941
969
  },
942
970
  get children() {
943
- return [createComponent(Show, {
944
- get when() {
945
- return isEmptyHtmlElement(Tag());
946
- },
947
- get children() {
948
- return createComponent(block_wrapper_default, {
949
- get Wrapper() {
950
- return Tag();
951
- },
952
- get block() {
953
- return processedBlock();
954
- },
955
- get context() {
956
- return props.context;
957
- },
958
- hasChildren: false
959
- });
960
- }
961
- }), createComponent(Show, {
962
- get when() {
963
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && repeatItem();
964
- },
965
- get children() {
971
+ return createComponent(Show, {
972
+ get fallback() {
966
973
  return createComponent(For, {
967
974
  get each() {
968
975
  return repeatItem();
@@ -983,10 +990,9 @@ function Block(props) {
983
990
  });
984
991
  }
985
992
  });
986
- }
987
- }), createComponent(Show, {
993
+ },
988
994
  get when() {
989
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
995
+ return !repeatItem();
990
996
  },
991
997
  get children() {
992
998
  return createComponent(block_wrapper_default, {
@@ -999,7 +1005,6 @@ function Block(props) {
999
1005
  get context() {
1000
1006
  return props.context;
1001
1007
  },
1002
- hasChildren: true,
1003
1008
  get children() {
1004
1009
  return [createComponent(component_ref_default, {
1005
1010
  get componentRef() {
@@ -1049,7 +1054,7 @@ function Block(props) {
1049
1054
  }
1050
1055
  });
1051
1056
  }
1052
- })];
1057
+ });
1053
1058
  }
1054
1059
  })];
1055
1060
  }
@@ -3044,6 +3049,13 @@ async function fetchEntries(options) {
3044
3049
  }
3045
3050
  var getAllContent = fetchEntries;
3046
3051
 
3052
+ // src/functions/is-from-trusted-host.ts
3053
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3054
+ function isFromTrustedHost(trustedHosts, e) {
3055
+ const url = new URL(e.origin), hostname = url.hostname;
3056
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3057
+ }
3058
+
3047
3059
  // src/functions/is-previewing.ts
3048
3060
  function isPreviewing() {
3049
3061
  if (!isBrowser()) {
@@ -3295,7 +3307,7 @@ var getInteractionPropertiesForEvent = (event) => {
3295
3307
  };
3296
3308
 
3297
3309
  // src/constants/sdk-version.ts
3298
- var SDK_VERSION = "0.12.1";
3310
+ var SDK_VERSION = "0.12.2";
3299
3311
 
3300
3312
  // src/functions/register.ts
3301
3313
  var registry = {};
@@ -3373,9 +3385,13 @@ var setupBrowserForEditing = (options = {}) => {
3373
3385
  options
3374
3386
  }
3375
3387
  }, "*");
3376
- window.addEventListener("message", ({
3377
- data
3378
- }) => {
3388
+ window.addEventListener("message", (event) => {
3389
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
3390
+ return;
3391
+ }
3392
+ const {
3393
+ data
3394
+ } = event;
3379
3395
  if (!data?.type) {
3380
3396
  return;
3381
3397
  }
@@ -3471,6 +3487,9 @@ function EnableEditor(props) {
3471
3487
  }));
3472
3488
  }
3473
3489
  function processMessage(event) {
3490
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
3491
+ return;
3492
+ }
3474
3493
  const {
3475
3494
  data
3476
3495
  } = event;
@@ -3602,6 +3621,9 @@ function EnableEditor(props) {
3602
3621
  } : {},
3603
3622
  ...props.enrich ? {
3604
3623
  enrich: props.enrich
3624
+ } : {},
3625
+ ...props.trustedHosts ? {
3626
+ trustedHosts: props.trustedHosts
3605
3627
  } : {}
3606
3628
  });
3607
3629
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -3969,6 +3991,9 @@ function ContentComponent(props) {
3969
3991
  },
3970
3992
  get contentWrapperProps() {
3971
3993
  return props.contentWrapperProps;
3994
+ },
3995
+ get trustedHosts() {
3996
+ return props.trustedHosts;
3972
3997
  }
3973
3998
  }, {
3974
3999
  setBuilderContextSignal
@@ -4128,6 +4153,9 @@ function ContentVariants(props) {
4128
4153
  },
4129
4154
  get contentWrapperProps() {
4130
4155
  return props.contentWrapperProps;
4156
+ },
4157
+ get trustedHosts() {
4158
+ return props.trustedHosts;
4131
4159
  }
4132
4160
  });
4133
4161
  }
@@ -4182,6 +4210,9 @@ function ContentVariants(props) {
4182
4210
  },
4183
4211
  get contentWrapperProps() {
4184
4212
  return props.contentWrapperProps;
4213
+ },
4214
+ get trustedHosts() {
4215
+ return props.trustedHosts;
4185
4216
  }
4186
4217
  }))];
4187
4218
  }
@@ -325,10 +325,6 @@ function getProcessedBlock({
325
325
  }
326
326
 
327
327
  // src/components/block/block.helpers.ts
328
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
329
- var isEmptyHtmlElement = (tagName) => {
330
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
331
- };
332
328
  var getComponent = ({
333
329
  block,
334
330
  context,
@@ -553,10 +549,6 @@ function BlockStyles(props) {
553
549
  }
554
550
  var Block_styles_default = BlockStyles;
555
551
 
556
- // src/components/block/components/block-wrapper.tsx
557
- import { Show as Show3 } from "solid-js";
558
- import { Dynamic } from "solid-js/web";
559
-
560
552
  // src/functions/event-handler-name.ts
561
553
  function capitalizeFirstLetter(string) {
562
554
  return string.charAt(0).toUpperCase() + string.slice(1);
@@ -643,31 +635,49 @@ function getStyleAttribute(style) {
643
635
  }
644
636
  }
645
637
 
646
- // src/components/block/components/block-wrapper.tsx
647
- function BlockWrapper(props) {
638
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
639
+ import { Show as Show3 } from "solid-js";
640
+ import { Dynamic } from "solid-js/web";
641
+
642
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
643
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
644
+ var isEmptyElement = (tagName) => {
645
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
646
+ };
647
+
648
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
649
+ function DynamicRenderer(props) {
648
650
  return <Show3
649
651
  fallback={<Dynamic
650
- {...getBlockProperties({
651
- block: props.block,
652
- context: props.context
653
- })}
654
- {...getBlockActions({
655
- block: props.block,
656
- rootState: props.context.rootState,
657
- rootSetState: props.context.rootSetState,
658
- localState: props.context.localState,
659
- context: props.context.context,
660
- stripPrefix: true
661
- })}
662
- component={props.Wrapper}
652
+ {...props.attributes}
653
+ {...props.actionAttributes}
654
+ component={props.TagName}
663
655
  />}
664
- when={props.hasChildren}
656
+ when={!isEmptyElement(props.TagName)}
657
+ ><Show3
658
+ fallback={<Dynamic
659
+ {...props.attributes}
660
+ {...props.actionAttributes}
661
+ component={props.TagName}
662
+ >{props.children}</Dynamic>}
663
+ when={typeof props.TagName === "string"}
665
664
  ><Dynamic
666
- {...getBlockProperties({
665
+ {...props.attributes}
666
+ {...props.actionAttributes}
667
+ component={props.TagName}
668
+ >{props.children}</Dynamic></Show3></Show3>;
669
+ }
670
+ var Dynamic_renderer_default = DynamicRenderer;
671
+
672
+ // src/components/block/components/block-wrapper.tsx
673
+ function BlockWrapper(props) {
674
+ return <Dynamic_renderer_default
675
+ TagName={props.Wrapper}
676
+ attributes={getBlockProperties({
667
677
  block: props.block,
668
678
  context: props.context
669
679
  })}
670
- {...getBlockActions({
680
+ actionAttributes={getBlockActions({
671
681
  block: props.block,
672
682
  rootState: props.context.rootState,
673
683
  rootSetState: props.context.rootSetState,
@@ -675,8 +685,7 @@ function BlockWrapper(props) {
675
685
  context: props.context.context,
676
686
  stripPrefix: true
677
687
  })}
678
- component={props.Wrapper}
679
- >{props.children}</Dynamic></Show3>;
688
+ >{props.children}</Dynamic_renderer_default>;
680
689
  }
681
690
  var Block_wrapper_default = BlockWrapper;
682
691
 
@@ -855,14 +864,8 @@ function Block(props) {
855
864
  isInteractive={componentRefProps().isInteractive}
856
865
  />}
857
866
  when={!blockComponent()?.noWrap}
858
- >
859
- <Show5 when={isEmptyHtmlElement(Tag())}><Block_wrapper_default
860
- Wrapper={Tag()}
861
- block={processedBlock()}
862
- context={props.context}
863
- hasChildren={false}
864
- /></Show5>
865
- <Show5 when={!isEmptyHtmlElement(Tag()) && repeatItem()}><For2 each={repeatItem()}>{(data, _index) => {
867
+ ><Show5
868
+ fallback={<For2 each={repeatItem()}>{(data, _index) => {
866
869
  const index = _index();
867
870
  return <Repeated_block_default
868
871
  key={index}
@@ -870,34 +873,33 @@ function Block(props) {
870
873
  block={data.block}
871
874
  registeredComponents={props.registeredComponents}
872
875
  />;
873
- }}</For2></Show5>
874
- <Show5 when={!isEmptyHtmlElement(Tag()) && !repeatItem()}><Block_wrapper_default
875
- Wrapper={Tag()}
876
- block={processedBlock()}
877
- context={props.context}
878
- hasChildren={true}
879
- >
880
- <Component_ref_default
881
- componentRef={componentRefProps().componentRef}
882
- componentOptions={componentRefProps().componentOptions}
883
- blockChildren={componentRefProps().blockChildren}
884
- context={componentRefProps().context}
885
- registeredComponents={componentRefProps().registeredComponents}
886
- builderBlock={componentRefProps().builderBlock}
887
- includeBlockProps={componentRefProps().includeBlockProps}
888
- isInteractive={componentRefProps().isInteractive}
889
- />
890
- <For2 each={childrenWithoutParentComponent()}>{(child, _index) => {
891
- const index = _index();
892
- return <Block
893
- key={child.id}
894
- block={child}
895
- context={childrenContext()}
896
- registeredComponents={props.registeredComponents}
897
- />;
898
- }}</For2>
899
- </Block_wrapper_default></Show5>
900
- </Show5>
876
+ }}</For2>}
877
+ when={!repeatItem()}
878
+ ><Block_wrapper_default
879
+ Wrapper={Tag()}
880
+ block={processedBlock()}
881
+ context={props.context}
882
+ >
883
+ <Component_ref_default
884
+ componentRef={componentRefProps().componentRef}
885
+ componentOptions={componentRefProps().componentOptions}
886
+ blockChildren={componentRefProps().blockChildren}
887
+ context={componentRefProps().context}
888
+ registeredComponents={componentRefProps().registeredComponents}
889
+ builderBlock={componentRefProps().builderBlock}
890
+ includeBlockProps={componentRefProps().includeBlockProps}
891
+ isInteractive={componentRefProps().isInteractive}
892
+ />
893
+ <For2 each={childrenWithoutParentComponent()}>{(child, _index) => {
894
+ const index = _index();
895
+ return <Block
896
+ key={child.id}
897
+ block={child}
898
+ context={childrenContext()}
899
+ registeredComponents={props.registeredComponents}
900
+ />;
901
+ }}</For2>
902
+ </Block_wrapper_default></Show5></Show5>
901
903
  </Show5>;
902
904
  }
903
905
  var Block_default = Block;
@@ -2724,6 +2726,13 @@ async function fetchEntries(options) {
2724
2726
  }
2725
2727
  var getAllContent = fetchEntries;
2726
2728
 
2729
+ // src/functions/is-from-trusted-host.ts
2730
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
2731
+ function isFromTrustedHost(trustedHosts, e) {
2732
+ const url = new URL(e.origin), hostname = url.hostname;
2733
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
2734
+ }
2735
+
2727
2736
  // src/functions/is-previewing.ts
2728
2737
  function isPreviewing() {
2729
2738
  if (!isBrowser()) {
@@ -2975,7 +2984,7 @@ var getInteractionPropertiesForEvent = (event) => {
2975
2984
  };
2976
2985
 
2977
2986
  // src/constants/sdk-version.ts
2978
- var SDK_VERSION = "0.12.1";
2987
+ var SDK_VERSION = "0.12.2";
2979
2988
 
2980
2989
  // src/functions/register.ts
2981
2990
  var registry = {};
@@ -3053,9 +3062,13 @@ var setupBrowserForEditing = (options = {}) => {
3053
3062
  options
3054
3063
  }
3055
3064
  }, "*");
3056
- window.addEventListener("message", ({
3057
- data
3058
- }) => {
3065
+ window.addEventListener("message", (event) => {
3066
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
3067
+ return;
3068
+ }
3069
+ const {
3070
+ data
3071
+ } = event;
3059
3072
  if (!data?.type) {
3060
3073
  return;
3061
3074
  }
@@ -3153,6 +3166,9 @@ function EnableEditor(props) {
3153
3166
  }));
3154
3167
  }
3155
3168
  function processMessage(event) {
3169
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
3170
+ return;
3171
+ }
3156
3172
  const { data } = event;
3157
3173
  if (data) {
3158
3174
  switch (data.type) {
@@ -3284,6 +3300,9 @@ function EnableEditor(props) {
3284
3300
  } : {},
3285
3301
  ...props.enrich ? {
3286
3302
  enrich: props.enrich
3303
+ } : {},
3304
+ ...props.trustedHosts ? {
3305
+ trustedHosts: props.trustedHosts
3287
3306
  } : {}
3288
3307
  });
3289
3308
  Object.values(
@@ -3622,6 +3641,7 @@ function ContentComponent(props) {
3622
3641
  builderContextSignal={builderContextSignal()}
3623
3642
  contentWrapper={props.contentWrapper}
3624
3643
  contentWrapperProps={props.contentWrapperProps}
3644
+ trustedHosts={props.trustedHosts}
3625
3645
  {...{
3626
3646
  setBuilderContextSignal
3627
3647
  }}
@@ -3704,6 +3724,7 @@ function ContentVariants(props) {
3704
3724
  blocksWrapperProps={props.blocksWrapperProps}
3705
3725
  contentWrapper={props.contentWrapper}
3706
3726
  contentWrapperProps={props.contentWrapperProps}
3727
+ trustedHosts={props.trustedHosts}
3707
3728
  />;
3708
3729
  }}</For5>
3709
3730
  </Show12>
@@ -3726,6 +3747,7 @@ function ContentVariants(props) {
3726
3747
  blocksWrapperProps={props.blocksWrapperProps}
3727
3748
  contentWrapper={props.contentWrapper}
3728
3749
  contentWrapperProps={props.contentWrapperProps}
3750
+ trustedHosts={props.trustedHosts}
3729
3751
  />
3730
3752
  </>;
3731
3753
  }