@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/lib/node/dev.js CHANGED
@@ -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
  import { createRequire } from 'node:module';
@@ -457,10 +457,6 @@ function getProcessedBlock({
457
457
  }
458
458
 
459
459
  // src/components/block/block.helpers.ts
460
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
461
- var isEmptyHtmlElement = (tagName) => {
462
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
463
- };
464
460
  var getComponent = ({
465
461
  block,
466
462
  context,
@@ -782,48 +778,80 @@ function getStyleAttribute(style) {
782
778
  }
783
779
  }
784
780
 
785
- // src/components/block/components/block-wrapper.tsx
786
- function BlockWrapper(props) {
781
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
782
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
783
+ var isEmptyElement = (tagName) => {
784
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
785
+ };
786
+
787
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
788
+ function DynamicRenderer(props) {
787
789
  return createComponent(Show, {
788
790
  get fallback() {
789
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
790
- block: props.block,
791
- context: props.context
792
- }), () => getBlockActions({
793
- block: props.block,
794
- rootState: props.context.rootState,
795
- rootSetState: props.context.rootSetState,
796
- localState: props.context.localState,
797
- context: props.context.context,
798
- stripPrefix: true
799
- }), {
791
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
800
792
  get component() {
801
- return props.Wrapper;
793
+ return props.TagName;
802
794
  }
803
795
  }));
804
796
  },
805
797
  get when() {
806
- return props.hasChildren;
798
+ return !isEmptyElement(props.TagName);
807
799
  },
808
800
  get children() {
809
- return createComponent(Dynamic, mergeProps(() => getBlockProperties({
801
+ return createComponent(Show, {
802
+ get fallback() {
803
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
804
+ get component() {
805
+ return props.TagName;
806
+ },
807
+ get children() {
808
+ return props.children;
809
+ }
810
+ }));
811
+ },
812
+ get when() {
813
+ return typeof props.TagName === "string";
814
+ },
815
+ get children() {
816
+ return createComponent(Dynamic, mergeProps(() => props.attributes, () => props.actionAttributes, {
817
+ get component() {
818
+ return props.TagName;
819
+ },
820
+ get children() {
821
+ return props.children;
822
+ }
823
+ }));
824
+ }
825
+ });
826
+ }
827
+ });
828
+ }
829
+ var dynamic_renderer_default = DynamicRenderer;
830
+
831
+ // src/components/block/components/block-wrapper.tsx
832
+ function BlockWrapper(props) {
833
+ return createComponent(dynamic_renderer_default, {
834
+ get TagName() {
835
+ return props.Wrapper;
836
+ },
837
+ get attributes() {
838
+ return getBlockProperties({
810
839
  block: props.block,
811
840
  context: props.context
812
- }), () => getBlockActions({
841
+ });
842
+ },
843
+ get actionAttributes() {
844
+ return getBlockActions({
813
845
  block: props.block,
814
846
  rootState: props.context.rootState,
815
847
  rootSetState: props.context.rootSetState,
816
848
  localState: props.context.localState,
817
849
  context: props.context.context,
818
850
  stripPrefix: true
819
- }), {
820
- get component() {
821
- return props.Wrapper;
822
- },
823
- get children() {
824
- return props.children;
825
- }
826
- }));
851
+ });
852
+ },
853
+ get children() {
854
+ return props.children;
827
855
  }
828
856
  });
829
857
  }
@@ -1064,29 +1092,8 @@ function Block(props) {
1064
1092
  return !blockComponent()?.noWrap;
1065
1093
  },
1066
1094
  get children() {
1067
- return [createComponent(Show, {
1068
- get when() {
1069
- return isEmptyHtmlElement(Tag());
1070
- },
1071
- get children() {
1072
- return createComponent(block_wrapper_default, {
1073
- get Wrapper() {
1074
- return Tag();
1075
- },
1076
- get block() {
1077
- return processedBlock();
1078
- },
1079
- get context() {
1080
- return props.context;
1081
- },
1082
- hasChildren: false
1083
- });
1084
- }
1085
- }), createComponent(Show, {
1086
- get when() {
1087
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && repeatItem();
1088
- },
1089
- get children() {
1095
+ return createComponent(Show, {
1096
+ get fallback() {
1090
1097
  return createComponent(For, {
1091
1098
  get each() {
1092
1099
  return repeatItem();
@@ -1107,10 +1114,9 @@ function Block(props) {
1107
1114
  });
1108
1115
  }
1109
1116
  });
1110
- }
1111
- }), createComponent(Show, {
1117
+ },
1112
1118
  get when() {
1113
- return memo(() => !!!isEmptyHtmlElement(Tag()))() && !repeatItem();
1119
+ return !repeatItem();
1114
1120
  },
1115
1121
  get children() {
1116
1122
  return createComponent(block_wrapper_default, {
@@ -1123,7 +1129,6 @@ function Block(props) {
1123
1129
  get context() {
1124
1130
  return props.context;
1125
1131
  },
1126
- hasChildren: true,
1127
1132
  get children() {
1128
1133
  return [createComponent(component_ref_default, {
1129
1134
  get componentRef() {
@@ -1173,7 +1178,7 @@ function Block(props) {
1173
1178
  }
1174
1179
  });
1175
1180
  }
1176
- })];
1181
+ });
1177
1182
  }
1178
1183
  })];
1179
1184
  }
@@ -3168,6 +3173,13 @@ async function fetchEntries(options) {
3168
3173
  }
3169
3174
  var getAllContent = fetchEntries;
3170
3175
 
3176
+ // src/functions/is-from-trusted-host.ts
3177
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3178
+ function isFromTrustedHost(trustedHosts, e) {
3179
+ const url = new URL(e.origin), hostname = url.hostname;
3180
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3181
+ }
3182
+
3171
3183
  // src/functions/is-previewing.ts
3172
3184
  function isPreviewing() {
3173
3185
  if (!isBrowser()) {
@@ -3419,7 +3431,7 @@ var getInteractionPropertiesForEvent = (event) => {
3419
3431
  };
3420
3432
 
3421
3433
  // src/constants/sdk-version.ts
3422
- var SDK_VERSION = "0.12.1";
3434
+ var SDK_VERSION = "0.12.2";
3423
3435
 
3424
3436
  // src/functions/register.ts
3425
3437
  var registry = {};
@@ -3497,9 +3509,13 @@ var setupBrowserForEditing = (options = {}) => {
3497
3509
  options
3498
3510
  }
3499
3511
  }, "*");
3500
- window.addEventListener("message", ({
3501
- data
3502
- }) => {
3512
+ window.addEventListener("message", (event) => {
3513
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
3514
+ return;
3515
+ }
3516
+ const {
3517
+ data
3518
+ } = event;
3503
3519
  if (!data?.type) {
3504
3520
  return;
3505
3521
  }
@@ -3595,6 +3611,9 @@ function EnableEditor(props) {
3595
3611
  }));
3596
3612
  }
3597
3613
  function processMessage(event) {
3614
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
3615
+ return;
3616
+ }
3598
3617
  const {
3599
3618
  data
3600
3619
  } = event;
@@ -3726,6 +3745,9 @@ function EnableEditor(props) {
3726
3745
  } : {},
3727
3746
  ...props.enrich ? {
3728
3747
  enrich: props.enrich
3748
+ } : {},
3749
+ ...props.trustedHosts ? {
3750
+ trustedHosts: props.trustedHosts
3729
3751
  } : {}
3730
3752
  });
3731
3753
  Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
@@ -4093,6 +4115,9 @@ function ContentComponent(props) {
4093
4115
  },
4094
4116
  get contentWrapperProps() {
4095
4117
  return props.contentWrapperProps;
4118
+ },
4119
+ get trustedHosts() {
4120
+ return props.trustedHosts;
4096
4121
  }
4097
4122
  }, {
4098
4123
  setBuilderContextSignal
@@ -4252,6 +4277,9 @@ function ContentVariants(props) {
4252
4277
  },
4253
4278
  get contentWrapperProps() {
4254
4279
  return props.contentWrapperProps;
4280
+ },
4281
+ get trustedHosts() {
4282
+ return props.trustedHosts;
4255
4283
  }
4256
4284
  });
4257
4285
  }
@@ -4306,6 +4334,9 @@ function ContentVariants(props) {
4306
4334
  },
4307
4335
  get contentWrapperProps() {
4308
4336
  return props.contentWrapperProps;
4337
+ },
4338
+ get trustedHosts() {
4339
+ return props.trustedHosts;
4309
4340
  }
4310
4341
  }))];
4311
4342
  }
package/lib/node/dev.jsx CHANGED
@@ -451,10 +451,6 @@ function getProcessedBlock({
451
451
  }
452
452
 
453
453
  // src/components/block/block.helpers.ts
454
- var EMPTY_HTML_ELEMENTS = ["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
455
- var isEmptyHtmlElement = (tagName) => {
456
- return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
457
- };
458
454
  var getComponent = ({
459
455
  block,
460
456
  context,
@@ -679,10 +675,6 @@ function BlockStyles(props) {
679
675
  }
680
676
  var Block_styles_default = BlockStyles;
681
677
 
682
- // src/components/block/components/block-wrapper.tsx
683
- import { Show as Show3 } from "solid-js";
684
- import { Dynamic } from "solid-js/web";
685
-
686
678
  // src/functions/event-handler-name.ts
687
679
  function capitalizeFirstLetter(string) {
688
680
  return string.charAt(0).toUpperCase() + string.slice(1);
@@ -769,31 +761,49 @@ function getStyleAttribute(style) {
769
761
  }
770
762
  }
771
763
 
772
- // src/components/block/components/block-wrapper.tsx
773
- function BlockWrapper(props) {
764
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
765
+ import { Show as Show3 } from "solid-js";
766
+ import { Dynamic } from "solid-js/web";
767
+
768
+ // src/components/dynamic-renderer/dynamic-renderer.helpers.ts
769
+ var EMPTY_HTML_ELEMENTS = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]);
770
+ var isEmptyElement = (tagName) => {
771
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.has(tagName.toLowerCase());
772
+ };
773
+
774
+ // src/components/dynamic-renderer/dynamic-renderer.tsx
775
+ function DynamicRenderer(props) {
774
776
  return <Show3
775
777
  fallback={<Dynamic
776
- {...getBlockProperties({
777
- block: props.block,
778
- context: props.context
779
- })}
780
- {...getBlockActions({
781
- block: props.block,
782
- rootState: props.context.rootState,
783
- rootSetState: props.context.rootSetState,
784
- localState: props.context.localState,
785
- context: props.context.context,
786
- stripPrefix: true
787
- })}
788
- component={props.Wrapper}
778
+ {...props.attributes}
779
+ {...props.actionAttributes}
780
+ component={props.TagName}
789
781
  />}
790
- when={props.hasChildren}
782
+ when={!isEmptyElement(props.TagName)}
783
+ ><Show3
784
+ fallback={<Dynamic
785
+ {...props.attributes}
786
+ {...props.actionAttributes}
787
+ component={props.TagName}
788
+ >{props.children}</Dynamic>}
789
+ when={typeof props.TagName === "string"}
791
790
  ><Dynamic
792
- {...getBlockProperties({
791
+ {...props.attributes}
792
+ {...props.actionAttributes}
793
+ component={props.TagName}
794
+ >{props.children}</Dynamic></Show3></Show3>;
795
+ }
796
+ var Dynamic_renderer_default = DynamicRenderer;
797
+
798
+ // src/components/block/components/block-wrapper.tsx
799
+ function BlockWrapper(props) {
800
+ return <Dynamic_renderer_default
801
+ TagName={props.Wrapper}
802
+ attributes={getBlockProperties({
793
803
  block: props.block,
794
804
  context: props.context
795
805
  })}
796
- {...getBlockActions({
806
+ actionAttributes={getBlockActions({
797
807
  block: props.block,
798
808
  rootState: props.context.rootState,
799
809
  rootSetState: props.context.rootSetState,
@@ -801,8 +811,7 @@ function BlockWrapper(props) {
801
811
  context: props.context.context,
802
812
  stripPrefix: true
803
813
  })}
804
- component={props.Wrapper}
805
- >{props.children}</Dynamic></Show3>;
814
+ >{props.children}</Dynamic_renderer_default>;
806
815
  }
807
816
  var Block_wrapper_default = BlockWrapper;
808
817
 
@@ -981,14 +990,8 @@ function Block(props) {
981
990
  isInteractive={componentRefProps().isInteractive}
982
991
  />}
983
992
  when={!blockComponent()?.noWrap}
984
- >
985
- <Show5 when={isEmptyHtmlElement(Tag())}><Block_wrapper_default
986
- Wrapper={Tag()}
987
- block={processedBlock()}
988
- context={props.context}
989
- hasChildren={false}
990
- /></Show5>
991
- <Show5 when={!isEmptyHtmlElement(Tag()) && repeatItem()}><For2 each={repeatItem()}>{(data, _index) => {
993
+ ><Show5
994
+ fallback={<For2 each={repeatItem()}>{(data, _index) => {
992
995
  const index = _index();
993
996
  return <Repeated_block_default
994
997
  key={index}
@@ -996,34 +999,33 @@ function Block(props) {
996
999
  block={data.block}
997
1000
  registeredComponents={props.registeredComponents}
998
1001
  />;
999
- }}</For2></Show5>
1000
- <Show5 when={!isEmptyHtmlElement(Tag()) && !repeatItem()}><Block_wrapper_default
1001
- Wrapper={Tag()}
1002
- block={processedBlock()}
1003
- context={props.context}
1004
- hasChildren={true}
1005
- >
1006
- <Component_ref_default
1007
- componentRef={componentRefProps().componentRef}
1008
- componentOptions={componentRefProps().componentOptions}
1009
- blockChildren={componentRefProps().blockChildren}
1010
- context={componentRefProps().context}
1011
- registeredComponents={componentRefProps().registeredComponents}
1012
- builderBlock={componentRefProps().builderBlock}
1013
- includeBlockProps={componentRefProps().includeBlockProps}
1014
- isInteractive={componentRefProps().isInteractive}
1015
- />
1016
- <For2 each={childrenWithoutParentComponent()}>{(child, _index) => {
1017
- const index = _index();
1018
- return <Block
1019
- key={child.id}
1020
- block={child}
1021
- context={childrenContext()}
1022
- registeredComponents={props.registeredComponents}
1023
- />;
1024
- }}</For2>
1025
- </Block_wrapper_default></Show5>
1026
- </Show5>
1002
+ }}</For2>}
1003
+ when={!repeatItem()}
1004
+ ><Block_wrapper_default
1005
+ Wrapper={Tag()}
1006
+ block={processedBlock()}
1007
+ context={props.context}
1008
+ >
1009
+ <Component_ref_default
1010
+ componentRef={componentRefProps().componentRef}
1011
+ componentOptions={componentRefProps().componentOptions}
1012
+ blockChildren={componentRefProps().blockChildren}
1013
+ context={componentRefProps().context}
1014
+ registeredComponents={componentRefProps().registeredComponents}
1015
+ builderBlock={componentRefProps().builderBlock}
1016
+ includeBlockProps={componentRefProps().includeBlockProps}
1017
+ isInteractive={componentRefProps().isInteractive}
1018
+ />
1019
+ <For2 each={childrenWithoutParentComponent()}>{(child, _index) => {
1020
+ const index = _index();
1021
+ return <Block
1022
+ key={child.id}
1023
+ block={child}
1024
+ context={childrenContext()}
1025
+ registeredComponents={props.registeredComponents}
1026
+ />;
1027
+ }}</For2>
1028
+ </Block_wrapper_default></Show5></Show5>
1027
1029
  </Show5>;
1028
1030
  }
1029
1031
  var Block_default = Block;
@@ -2850,6 +2852,13 @@ async function fetchEntries(options) {
2850
2852
  }
2851
2853
  var getAllContent = fetchEntries;
2852
2854
 
2855
+ // src/functions/is-from-trusted-host.ts
2856
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
2857
+ function isFromTrustedHost(trustedHosts, e) {
2858
+ const url = new URL(e.origin), hostname = url.hostname;
2859
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
2860
+ }
2861
+
2853
2862
  // src/functions/is-previewing.ts
2854
2863
  function isPreviewing() {
2855
2864
  if (!isBrowser()) {
@@ -3101,7 +3110,7 @@ var getInteractionPropertiesForEvent = (event) => {
3101
3110
  };
3102
3111
 
3103
3112
  // src/constants/sdk-version.ts
3104
- var SDK_VERSION = "0.12.1";
3113
+ var SDK_VERSION = "0.12.2";
3105
3114
 
3106
3115
  // src/functions/register.ts
3107
3116
  var registry = {};
@@ -3179,9 +3188,13 @@ var setupBrowserForEditing = (options = {}) => {
3179
3188
  options
3180
3189
  }
3181
3190
  }, "*");
3182
- window.addEventListener("message", ({
3183
- data
3184
- }) => {
3191
+ window.addEventListener("message", (event) => {
3192
+ if (!isFromTrustedHost(options.trustedHosts, event)) {
3193
+ return;
3194
+ }
3195
+ const {
3196
+ data
3197
+ } = event;
3185
3198
  if (!data?.type) {
3186
3199
  return;
3187
3200
  }
@@ -3279,6 +3292,9 @@ function EnableEditor(props) {
3279
3292
  }));
3280
3293
  }
3281
3294
  function processMessage(event) {
3295
+ if (!isFromTrustedHost(props.trustedHosts, event)) {
3296
+ return;
3297
+ }
3282
3298
  const { data } = event;
3283
3299
  if (data) {
3284
3300
  switch (data.type) {
@@ -3410,6 +3426,9 @@ function EnableEditor(props) {
3410
3426
  } : {},
3411
3427
  ...props.enrich ? {
3412
3428
  enrich: props.enrich
3429
+ } : {},
3430
+ ...props.trustedHosts ? {
3431
+ trustedHosts: props.trustedHosts
3413
3432
  } : {}
3414
3433
  });
3415
3434
  Object.values(
@@ -3748,6 +3767,7 @@ function ContentComponent(props) {
3748
3767
  builderContextSignal={builderContextSignal()}
3749
3768
  contentWrapper={props.contentWrapper}
3750
3769
  contentWrapperProps={props.contentWrapperProps}
3770
+ trustedHosts={props.trustedHosts}
3751
3771
  {...{
3752
3772
  setBuilderContextSignal
3753
3773
  }}
@@ -3830,6 +3850,7 @@ function ContentVariants(props) {
3830
3850
  blocksWrapperProps={props.blocksWrapperProps}
3831
3851
  contentWrapper={props.contentWrapper}
3832
3852
  contentWrapperProps={props.contentWrapperProps}
3853
+ trustedHosts={props.trustedHosts}
3833
3854
  />;
3834
3855
  }}</For5>
3835
3856
  </Show12>
@@ -3852,6 +3873,7 @@ function ContentVariants(props) {
3852
3873
  blocksWrapperProps={props.blocksWrapperProps}
3853
3874
  contentWrapper={props.contentWrapper}
3854
3875
  contentWrapperProps={props.contentWrapperProps}
3876
+ trustedHosts={props.trustedHosts}
3855
3877
  />
3856
3878
  </>;
3857
3879
  }